using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using System; using System.Collections.Generic; using System.Data; using System.Linq; using HRM.BO; namespace HRM.DA { #region GLTranUserRecord Service [Serializable] public class GLTranUserRecordService : ServiceTemplate //, IGLTranUserRecordService { #region Private functions and declaration public GLTranUserRecordService() { } #region Map Objects private void MapObject(GLTranUserRecord gLTranUserRecord, DataReader oReader) { this.SetObjectID(gLTranUserRecord, oReader.GetInt32("GLTranUserRecordID").Value); gLTranUserRecord.GLID = oReader.GetInt32("GLID").Value; gLTranUserRecord.GLTranID = oReader.GetInt32("GLTranID").Value; gLTranUserRecord.GLTranDetailID = oReader.GetInt32("GLTranDetailID").Value; gLTranUserRecord.UserObject1ID = oReader.GetInt32("UserObject1ID").Value; gLTranUserRecord.UserRecord1ID = oReader.GetInt32("UserRecord1ID").Value; gLTranUserRecord.UserObject2ID = oReader.GetInt32("UserObject2ID").Value; gLTranUserRecord.UserRecord2ID = oReader.GetInt32("UserRecord2ID").Value; gLTranUserRecord.Amount = oReader.GetDecimal("Amount").Value; gLTranUserRecord.Description = oReader.GetString("Description"); gLTranUserRecord.Modifiedby = oReader.GetInt32("Modifiedby").Value; gLTranUserRecord.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; gLTranUserRecord.OperationalStatus = (EnumOperationalStatus)oReader.GetInt32("OperationalStatus"); this.SetObjectState(gLTranUserRecord, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { GLTranUserRecord oGLTranUserRecord = new GLTranUserRecord(); MapObject(oGLTranUserRecord, oReader); return oGLTranUserRecord as T; } protected GLTranUserRecord CreateObject(DataReader oReader) { GLTranUserRecord oGLTranUserRecord = new GLTranUserRecord(); MapObject(oGLTranUserRecord, oReader); return oGLTranUserRecord; } //private GLTranUserRecords CreateObjects(IDataReader oReader) //{ // GLTranUserRecords oGLTranUserRecords = new GLTranUserRecords(); // NullHandler oreader = new NullHandler(oReader); // while (oReader.Read()) // { // GLTranUserRecord oItem = CreateObject(oreader); // oGLTranUserRecords.Add(oItem); // } // return oGLTranUserRecords; //} #endregion #region Map Open private void OpenMapObject(GLTranUserRecord gLTranUserRecord, DataReader oReader) { this.SetObjectID(gLTranUserRecord, oReader.GetInt32("GLTranUserRecordID").Value); gLTranUserRecord.GLID = oReader.GetInt32("GLID").Value; gLTranUserRecord.GLTranID = oReader.GetInt32("GLTranID").Value; gLTranUserRecord.GLTranDetailID = oReader.GetInt32("GLTranDetailID").Value; gLTranUserRecord.UserObject1ID = oReader.GetInt32("UserObject1ID").Value; gLTranUserRecord.UserRecord1ID = oReader.GetInt32("UserRecord1ID").Value; gLTranUserRecord.UserObject2ID = oReader.GetInt32("UserObject2ID").Value; gLTranUserRecord.UserRecord2ID = oReader.GetInt32("UserRecord2ID").Value; gLTranUserRecord.Amount = oReader.GetDecimal("Amount").Value; gLTranUserRecord.Description = oReader.GetString("Description"); gLTranUserRecord.Modifiedby = oReader.GetInt32("Modifiedby").Value; gLTranUserRecord.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; gLTranUserRecord.OperationalStatus = (EnumOperationalStatus)oReader.GetInt32("OperationalStatus"); this.SetObjectState(gLTranUserRecord, Ease.Core.ObjectState.Saved); } protected GLTranUserRecord OpenCreateObject(DataReader oReader) { GLTranUserRecord oGLTranUserRecord = new GLTranUserRecord(); MapObject(oGLTranUserRecord, oReader); return oGLTranUserRecord; } //private GLTranUserRecords OpenCreateObjects(IDataReader oReader) //{ // GLTranUserRecords oGLTranUserRecords = new GLTranUserRecords(); // NullHandler oreader = new NullHandler(oReader); // while (oReader.Read()) // { // GLTranUserRecord oItem = OpenCreateObject(oreader); // oGLTranUserRecords.Add(oItem); // } // return oGLTranUserRecords; //} #endregion #region Map Open private void YearEndMapObject(GLTranUserRecord gLTranUserRecord, DataReader oReader) { this.SetObjectID(gLTranUserRecord, oReader.GetInt32("GLTranUserRecordID").Value); gLTranUserRecord.GLID = oReader.GetInt32("GLID").Value; gLTranUserRecord.GLTranID = oReader.GetInt32("GLTranID").Value; gLTranUserRecord.GLTranDetailID = oReader.GetInt32("GLTranDetailID").Value; gLTranUserRecord.UserObject1ID = oReader.GetInt32("UserObject1ID").Value; gLTranUserRecord.UserRecord1ID = oReader.GetInt32("UserRecord1ID").Value; gLTranUserRecord.UserObject2ID = oReader.GetInt32("UserObject2ID").Value; gLTranUserRecord.UserRecord2ID = oReader.GetInt32("UserRecord2ID").Value; gLTranUserRecord.Amount = oReader.GetDecimal("Amount").Value; gLTranUserRecord.Description = oReader.GetString("Description"); gLTranUserRecord.Modifiedby = oReader.GetInt32("Modifiedby").Value; gLTranUserRecord.ModifiedDate = oReader.GetDateTime("ModifiedDate").Value; gLTranUserRecord.OperationalStatus = (EnumOperationalStatus)oReader.GetInt32("OperationalStatus"); this.SetObjectState(gLTranUserRecord, Ease.Core.ObjectState.Saved); } protected GLTranUserRecord YearEndCreateObject(DataReader oReader) { GLTranUserRecord oGLTranUserRecord = new GLTranUserRecord(); MapObject(oGLTranUserRecord, oReader); return oGLTranUserRecord; } //private GLTranUserRecords YearEndCreateObjects(IDataReader oReader) //{ // GLTranUserRecords oGLTranUserRecords = new GLTranUserRecords(); // NullHandler oreader = new NullHandler(oReader); // while (oReader.Read()) // { // GLTranUserRecord oItem = YearEndCreateObject(oreader); // oGLTranUserRecords.Add(oItem); // } // return oGLTranUserRecords; //} #endregion #endregion #region Service implementation public GLTranUserRecord Get(int id) { GLTranUserRecord oGLTranDetail = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GLTranUserRecordDA.Get(tc, id)); if (oreader.Read()) { oGLTranDetail = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranDetail; } public List Get() { List oGLTranUserRecord = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.Get(tc)); oGLTranUserRecord = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranUserRecord; } public List GetByGLID(int gLID) { List oGLTranUserRecord = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLID(tc, gLID)); oGLTranUserRecord = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranUserRecord; } public List GetByGLTranID(int gLTranID) { List oGLTranUserRecord = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLTranID(tc, gLTranID)); oGLTranUserRecord = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranUserRecord; } internal List GetByGLTranID(TransactionContext tc, int gLTranID) { List oGLTranUserRecord = new List(); //TransactionContext tc = null; try { // tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLTranID(tc, gLTranID)); oGLTranUserRecord = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranUserRecord; } internal List GetByGLTranIDOpen(TransactionContext tc, int gLTranID) { List oGLTranDetails = new List(); // TransactionContext tc = null; try { // tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLTranIDOpen(tc, gLTranID)); oGLTranDetails = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranDetails; } public List GetByGLTranDetailID(int gLTranDetailID) { List oGLTranDetails = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLTranDetailID(tc, gLTranDetailID)); oGLTranDetails = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranDetails; } internal List GetByGLTranDetailID(TransactionContext tc, int gLTranDetailID) { List oGLTranDetails = new List(); // TransactionContext tc = null; try { // tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLTranDetailID(tc, gLTranDetailID)); oGLTranDetails = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranDetails; } internal List GetByGLTranDetailIDOpen(TransactionContext tc, int gLTranDetailID) { List oGLTranDetails = new List(); // TransactionContext tc = null; try { //tc = TransactionContext.Begin(); DataReader dr = new DataReader(GLTranUserRecordDA.GetByGLTranDetailIDOpen(tc, gLTranDetailID)); oGLTranDetails = this.CreateObjects(dr); dr.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oGLTranDetails; } //internal List GetByVoucherDate(TransactionContext tc, DateTime firstDate, DateTime lastDate) //{ // List glTranUserRecords = new List(); // //TransactionContext tc = null; // try // { // //tc = TransactionContext.Begin(true); // /* DataReader oReader = new DataReader(GLTranUserRecordDA.GetByVoucherDate(tc, firstDate, lastDate)); // glTranUserRecords = this.CreateObjects(oReader); // oReader.Close(); */ // IDataReader oReader = GLTranUserRecordDA.GetByVoucherDate(tc, firstDate, lastDate); // glTranUserRecords = CreateObjects(oReader); // oReader.Close(); // IDataReader oOpenReader = GLTranUserRecordDA.GetByOpenVoucherDate(tc, firstDate, lastDate); // MapOpen(glTranUserRecords, oOpenReader); // oOpenReader.Close(); // IDataReader oYearEndReader = GLTranUserRecordDA.GetByYearEndVoucherDate(tc, firstDate, lastDate); // MapYearEnd(glTranUserRecords, oYearEndReader); // oYearEndReader.Close(); // //tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get GLTranUserRecords", e); // #endregion // } // return glTranUserRecords; //} //private void MapOpen(GLTranUserRecords glTranUserRecords, IDataReader oReader) //{ // NullHandler oreader = new NullHandler(oReader); // while (oReader.Read()) // { // GLTranUserRecord oItem = OpenCreateObject(oreader); // glTranUserRecords.Add(oItem); // } //} //private void MapYearEnd(GLTranUserRecords glTranUserRecords, IDataReader oReader) //{ // NullHandler oreader = new NullHandler(oReader); // while (oReader.Read()) // { // GLTranUserRecord oItem = YearEndCreateObject(oreader); // glTranUserRecords.Add(oItem); // } //} public int Save(GLTranUserRecord gLTranUserRecord) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (gLTranUserRecord.IsNew) { int id = tc.GenerateID("GLTranUserRecord", "GLTranUserRecordID"); base.SetObjectID(gLTranUserRecord, id); GLTranUserRecordDA.Insert(tc, gLTranUserRecord); } else { GLTranUserRecordDA.Update(tc, gLTranUserRecord); } tc.End(); return gLTranUserRecord.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } internal int Save(TransactionContext tc, GLTranUserRecord gLTranUserRecord) { try { //tc = TransactionContext.Begin(true); if (gLTranUserRecord.IsNew) { int id = tc.GenerateID("GLTranUserRecord", "GLTranUserRecordID"); base.SetObjectID(gLTranUserRecord, id); GLTranUserRecordDA.Insert(tc, gLTranUserRecord); } else { GLTranUserRecordDA.Update(tc, gLTranUserRecord); } tc.End(); return gLTranUserRecord.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } //internal int SaveOpen(TransactionContext tc, GLTranUserRecord gLTranUserRecord) //{ // try // { // if (gLTranUserRecord.IsNew) // { // #region Creator // //gLTranUserRecord.CreatedBy = User.CurrentUser.ID; // //gLTranUserRecord.CreateDate = DateTime.Now; // #endregion // this.SetObjectID(gLTranUserRecord, ID.FromInteger(GLTranUserRecordDA.GetNewIDOpen(tc))); // GLTranUserRecordDA.InsertOpen(tc, gLTranUserRecord); // } // else // { // #region Modifier // gLTranUserRecord.Modifiedby = User.CurrentUser.ID; // gLTranUserRecord.ModifiedDate = DateTime.Now; // #endregion // GLTranUserRecordDA.UpdateOpen(tc, gLTranUserRecord); // } // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get GLTranUserRecord", e); // #endregion // } // return gLTranUserRecord.ID; //} //internal int SaveYearEnd(TransactionContext tc, GLTranUserRecord gLTranUserRecord) //{ // try // { // if (gLTranUserRecord.IsNew) // { // #region Creator // //gLTranUserRecord.CreatedBy = User.CurrentUser.ID; // //gLTranUserRecord.CreateDate = DateTime.Now; // #endregion // this.SetObjectID(gLTranUserRecord, ID.FromInteger(GLTranUserRecordDA.GetNewIDYearEnd(tc))); // GLTranUserRecordDA.InsertYearEnd(tc, gLTranUserRecord); // } // else // { // #region Modifier // gLTranUserRecord.Modifiedby = User.CurrentUser.ID; // gLTranUserRecord.ModifiedDate = DateTime.Now; // #endregion // GLTranUserRecordDA.UpdateYearEnd(tc, gLTranUserRecord); // } // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to Get GLTranUserRecord", e); // #endregion // } // return gLTranUserRecord.ID; //} public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); GLTranUserRecordDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException("Failed to Delete " + e.Message); #endregion } } //public void DeleteOpen(ID id) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // GLTranUserRecordDA.DeleteOpen(tc, id); // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException("Failed to GetGLTranUserRecord", e); // #endregion // } //} #endregion } #endregion }