using System; using System.Data; using System.Linq; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.DataAccess; using System.Collections.Generic; using Payroll.BO; using Ease.CoreV35.Caching; namespace Payroll.Service { #region EmployeeHistory Service [Serializable] public class EmployeeHistoryService : ServiceTemplate, IEmployeeHistoryService { #region Private functions and declaration Cache _cache = new Cache(typeof(EmployeeHistory)); #endregion public EmployeeHistoryService() { } private void MapObject(EmployeeHistory oEmployeeHistory, DataReader oReader) { base.SetObjectID(oEmployeeHistory, oReader.GetID("ID")); oEmployeeHistory.EmployeeID = oReader.GetID("employeeID"); oEmployeeHistory.EffectDate = oReader.GetDateTime("effectDate").Value; oEmployeeHistory.EndDate = oReader.GetDateTime("EndDate").HasValue ? oReader.GetDateTime("EndDate").Value : DateTime.Now; oEmployeeHistory.EmployeeStatus = (EnumEmployeeStatus)oReader.GetInt32("paramID").Value; oEmployeeHistory.Remarks = oReader.GetString("remarks"); oEmployeeHistory.CreatedBy = oReader.GetID("CreatedBy"); oEmployeeHistory.CreatedDate = oReader.GetDateTime("CreationDate").Value; oEmployeeHistory.ModifiedBy = oReader.GetID("ModifiedBy"); oEmployeeHistory.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oEmployeeHistory, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { EmployeeHistory oEmployeeHistory = new EmployeeHistory(); MapObject(oEmployeeHistory, oReader); return oEmployeeHistory as T; } protected EmployeeHistory CreateObject(DataReader oReader) { EmployeeHistory oEmployeeHistory = new EmployeeHistory(); MapObject(oEmployeeHistory, oReader); return oEmployeeHistory; } #region Service implementation public EmployeeHistory Get(ID id) { EmployeeHistory oEmployeeHistory = new EmployeeHistory(); #region Cache Header oEmployeeHistory = _cache["Get", id] as EmployeeHistory; if (oEmployeeHistory != null) return oEmployeeHistory; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeHistoryDA.Get(tc, id)); if (oreader.Read()) { oEmployeeHistory = 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 } #region Cache Footer _cache.Add(oEmployeeHistory, "Get", id); #endregion return oEmployeeHistory; } public EmployeeHistory GetByEmpID(ID nEmpID) { EmployeeHistory oEmployeeHistory = new EmployeeHistory(); #region Cache Header oEmployeeHistory = _cache["Get", nEmpID] as EmployeeHistory; if (oEmployeeHistory != null) return oEmployeeHistory; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeHistoryDA.GetByEmpID(tc, nEmpID)); if (oreader.Read()) { oEmployeeHistory = 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 } #region Cache Footer _cache.Add(oEmployeeHistory, "Get", nEmpID); #endregion return oEmployeeHistory; } public EmployeeHistory GetEmpLastHistory(ID nEmpID) { EmployeeHistory oEmployeeHistory = new EmployeeHistory(); #region Cache Header oEmployeeHistory = _cache["GetEmpLastHistory", nEmpID] as EmployeeHistory; if (oEmployeeHistory != null) return oEmployeeHistory; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(EmployeeHistoryDA.GetEmpLastHistory(tc, nEmpID)); if (oreader.Read()) { oEmployeeHistory = 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 } #region Cache Footer _cache.Add(oEmployeeHistory, "GetEmpLastHistory", nEmpID); #endregion return oEmployeeHistory; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate employeeHistorys = _cache["Get"] as ObjectsTemplate; if (employeeHistorys != null) return employeeHistorys; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(EmployeeHistoryDA.Get(tc)); employeeHistorys = 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 } #region Cache Footer _cache.Add(employeeHistorys, "Get"); #endregion return employeeHistorys; } public ID DoContinue(TransactionContext tc, EmployeeHistory oEmployeeHistory, bool continuePF) { try { if (oEmployeeHistory.IsNew) { int id = tc.GenerateID("EmployeeHistory", "ID"); base.SetObjectID(oEmployeeHistory, ID.FromInteger(id)); EmployeeHistoryDA.Insert(tc, oEmployeeHistory); EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID); } else { EmployeeHistoryDA.Update(tc, oEmployeeHistory); EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID); } if (continuePF == false) { EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, EnumPFMembershipType.DiscontinuedfromPayroll, oEmployeeHistory.EffectDate); } else { EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, EnumPFMembershipType.Live, oEmployeeHistory.EffectDate); } return oEmployeeHistory.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID Save(EmployeeHistory oEmployeeHistory, bool disAfterCurrmonth, bool continuePF) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oEmployeeHistory.IsNew) { int id = tc.GenerateID("EmployeeHistory", "ID"); base.SetObjectID(oEmployeeHistory, ID.FromInteger(id)); EmployeeHistoryDA.Insert(tc, oEmployeeHistory); EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.ID, oEmployeeHistory.EffectDate, oEmployeeHistory.EmployeeStatus); } else { EmployeeHistoryDA.Update(tc, oEmployeeHistory); EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.ID, oEmployeeHistory.EffectDate, oEmployeeHistory.EmployeeStatus); } if (disAfterCurrmonth == true) { EmployeeDA.UpdatemiddleOfMonthDiscontinue(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus, oEmployeeHistory.EffectDate); } else { if (continuePF == false) EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, EnumPFMembershipType.DiscontinuedfromPayroll, oEmployeeHistory.EffectDate); if (continuePF == true) EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, EnumPFMembershipType.Live, oEmployeeHistory.EffectDate); //if (oEmployeeHistory.EmployeeStatus == EnumEmployeeStatus.Live) // EmployeeDA.UpdateConfirmation(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus, oEmployeeHistory.EffectDate); } tc.End(); return oEmployeeHistory.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(TransactionContext tc, EmployeeHistory oEmployeeHistory, bool disAfterCurrmonth) { try { if (oEmployeeHistory.IsNew) { int id = tc.GenerateID("EmployeeHistory", "ID"); base.SetObjectID(oEmployeeHistory, ID.FromInteger(id)); oEmployeeHistory.CreatedBy = Payroll.BO.User.CurrentUser.ID; oEmployeeHistory.CreatedDate = DateTime.Now; EmployeeHistoryDA.Insert(tc, oEmployeeHistory); HREmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus); } else { oEmployeeHistory.ModifiedBy = Payroll.BO.User.CurrentUser.ID; oEmployeeHistory.ModifiedDate = DateTime.Now; EmployeeHistoryDA.Update(tc, oEmployeeHistory); HREmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus); } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID DoContinue(EmployeeHistory oEmployeeHistory, bool continuePF) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oEmployeeHistory.IsNew) { int id = tc.GenerateID("EmployeeHistory", "ID"); base.SetObjectID(oEmployeeHistory, ID.FromInteger(id)); EmployeeHistoryDA.Insert(tc, oEmployeeHistory); EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID); } else { EmployeeHistoryDA.Update(tc, oEmployeeHistory); EmployeeDA.DoContinue(tc, oEmployeeHistory.EmployeeID); } if (continuePF == false) { EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, EnumPFMembershipType.DiscontinuedfromPayroll, oEmployeeHistory.EffectDate); } else { EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, EnumPFMembershipType.Live, oEmployeeHistory.EffectDate); } tc.End(); return oEmployeeHistory.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public DataSet GetEmpHistory(DateTime dEffectDate, DateTime dEffectDate2, int payrollTypeID) { DataSet oEmpPostings = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); oEmpPostings = EmployeeHistoryDA.GetEmpHistory(tc, dEffectDate, dEffectDate2, payrollTypeID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oEmpPostings; } public DateTime GetDate(int empID, EnumEmployeeStatus ParamID) { DateTime dt ; TransactionContext tc = null; try { tc = TransactionContext.Begin(); dt = EmployeeHistoryDA.GetByEmpIDandParam(tc, empID, ParamID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dt; } //public void SaveConfirm(EmployeeHistory oEmployeeHistory, bool confirmEmpPF,EnumEmployeeOtherStatus IsConfirm) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // //if (oEmployeeHistory.IsNew) // //{ // // int id = tc.GenerateID("EmployeeHistory", "ID"); // // base.SetObjectID(oEmployeeHistory, ID.FromInteger(id)); // // EmployeeHistoryDA.Insert(tc, oEmployeeHistory); // //} // //else // //{ // // EmployeeHistoryDA.Update(tc, oEmployeeHistory); // //} // if (oEmployeeHistory.EmployeeStatus == EnumEmployeeStatus.Live) // EmployeeDA.UpdateConfirmation(tc, oEmployeeHistory.EmployeeID, IsConfirm, oEmployeeHistory.EffectDate,confirmEmpPF); // 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 SaveContinue(EmployeeHistory oEmployeeHistory, bool continuePF) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // if (oEmployeeHistory.IsNew) // { // int id = tc.GenerateID("EmployeeHistory", "ID"); // base.SetObjectID(oEmployeeHistory, ID.FromInteger(id)); // EmployeeHistoryDA.Insert(tc, oEmployeeHistory); // EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus); // } // else // { // EmployeeHistoryDA.Update(tc, oEmployeeHistory); // EmployeeDA.UpdateStatus(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus); // } // if (continuePF == true) // EmployeeDA.UpdatePFMemship(tc, oEmployeeHistory.EmployeeID, // EnumPFMembershipType.Live, oEmployeeHistory.EffectDate); // //oEmployeeHistory.ID = ID.FromInteger(0); // EmployeeDA.UpdateEmpContinue(tc, oEmployeeHistory.EmployeeID, oEmployeeHistory.EmployeeStatus); // 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(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeHistoryDA.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 } } public void DeleteByEmpID(ID nEmpID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); EmployeeHistoryDA.DeleteByEmpID(tc, nEmpID); 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 }