using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using Ease.CoreV35.DataAccess; using HRM.BO; namespace HRM.DA { #region GatePass Service [Serializable] public class GatePassService : ServiceTemplate { public GatePassService() { } private void MapObject(GatePass oGatePass, DataReader oReader) { base.SetObjectID(oGatePass, (oReader.GetInt32("GatePassID").Value)); oGatePass.TelephoneNo = oReader.GetString("TelephoneNo"); oGatePass.Remarks = oReader.GetString("Remarks"); oGatePass.EmployeeID = oReader.GetInt32("EmployeeID", 0); oGatePass.LineManagerID = oReader.GetInt32("LineManagerID", 0); oGatePass.ApprovedBy = oReader.GetInt32("ApprovedBy", 0); oGatePass.ClaimWFStatus = (EnumClaimWFStatus)oReader.GetInt32("ClaimWFStatus").Value; oGatePass.SystemMode = (EnumSystemMode)oReader.GetInt32("SystemMode").Value; oGatePass.TotalHour = oReader.GetDouble("TotalHour") == null ? 0 : oReader.GetDouble("TotalHour").Value; oGatePass.ApprovedDate = oReader.GetDateTime("ApprovedDate") == null ? DateTime.MinValue : oReader.GetDateTime("ApprovedDate").Value; oGatePass.EntryDate = oReader.GetDateTime("EntryDate") == null ? DateTime.MinValue : oReader.GetDateTime("EntryDate").Value; oGatePass.DepartureTime = oReader.GetDateTime("DepartureTime") == null ? DateTime.MinValue : oReader.GetDateTime("DepartureTime").Value; oGatePass.ReturnTime = oReader.GetDateTime("ReturnTime") == null ? DateTime.MinValue : oReader.GetDateTime("ReturnTime").Value; oGatePass.CreatedBy = oReader.GetInt32("CreatedBy", 0); oGatePass.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oGatePass.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oGatePass.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oGatePass, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { GatePass oGatePass = new GatePass(); MapObject(oGatePass, oReader); return oGatePass as T; } protected GatePass CreateObject(DataReader oReader) { GatePass oGatePass = new GatePass(); MapObject(oGatePass, oReader); return oGatePass; } #region Service implementation public GatePass Get(int id) { GatePass oGatePass = new GatePass(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(GatePassDA.Get(tc, id)); if (oreader.Read()) { oGatePass = 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 oGatePass; } public List GetByEmployeeID(int employeeID, DateTime fromDate, DateTime toDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GatePassDA.GetByEmployeeID(tc, employeeID, fromDate, toDate)); var GatePasss = this.CreateObjects(dr); dr.Close(); tc.End(); return GatePasss; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List Get() { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GatePassDA.Get(tc)); var GatePasss = this.CreateObjects(dr); dr.Close(); tc.End(); return GatePasss; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetByShiftManagerID(int employeeID, EnumClaimWFStatus wfStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GatePassDA.GetByShiftManagerID(tc, employeeID, wfStatus)); var oGatePasses = this.CreateObjects(dr); dr.Close(); tc.End(); return oGatePasses; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetByApproverID(int employeeID, DateTime fromdate, DateTime toDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GatePassDA.GetByApproverID(tc, employeeID, fromdate, toDate)); var oGatePasses = this.CreateObjects(dr); dr.Close(); tc.End(); return oGatePasses; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetByEmployeeID(string employeeIDs, EnumClaimWFStatus wfStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(GatePassDA.GetByEmployeeID(tc, employeeIDs, wfStatus)); var oGatePasss = this.CreateObjects(dr); dr.Close(); tc.End(); return oGatePasss; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(GatePass oGatePass) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oGatePass.IsNew) { int id = tc.GenerateID("GatePass", "GatePassID"); base.SetObjectID(oGatePass, (id)); GatePassDA.Insert(tc, oGatePass); } else { GatePassDA.Update(tc, oGatePass); } tc.End(); return oGatePass.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(List oGatePasss) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("GatePass", "GatePassID"); foreach (GatePass item in oGatePasss) { if (item.IsNew) { base.SetObjectID(item, (id)); GatePassDA.Insert(tc, item); id++; } else { GatePassDA.Update(tc, item); } } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int GetGatePassDataByWFStatusCount(DateTime fromDate, DateTime toDate, EnumWFAttnStatus status) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); return GatePassDA.GetGatePassDataByWFStatusCount(tc, fromDate, toDate, status); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } finally { if (tc != null) { tc.End(); } } } public void Save(List oGatePasss, List benefits, List auditTrails) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("GatePass", "GatePassID"); foreach (GatePass item in oGatePasss) { if (item.IsNew) { base.SetObjectID(item, (id)); GatePassDA.Insert(tc, item); id++; } else { GatePassDA.Update(tc, item); } } id = tc.GenerateID("AttnMonthlyBenefit", "AttnMonthlyBenefitID"); foreach (AttnMonthlyBenefit mbenifit in benefits) { if (mbenifit.IsNew) { if (AttnMonthlyBenefitDA.IsExist(tc, mbenifit.EmployeeID, mbenifit.SalaryMonth, mbenifit.ItemType, mbenifit.ItemID)) { AttnMonthlyBenefitDA.Delete(tc, mbenifit); base.SetObjectID(mbenifit, (id)); AttnMonthlyBenefitDA.Insert(tc, mbenifit); } else { base.SetObjectID(mbenifit, (id)); AttnMonthlyBenefitDA.Insert(tc, mbenifit); } } else { AttnMonthlyBenefitDA.Update(tc, mbenifit); } id++; } id = tc.GenerateID("ATTNBENEFITAUDITTRAIL", "ATTNBENEFITAUDITTRAILID"); foreach (AttnBenefitAuditTrail item in auditTrails) { base.SetObjectID(item, (id)); AttnBenefitAuditTrailDA.Insert(tc, item); id++; } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); GatePassDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } #endregion }