using System; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core.Utility; using System.Collections.Generic; using HRM.BO; using System.Data; using HRM.DA; namespace Payroll.Service { public class LTASetupService : ServiceTemplate, ILTASetupService { public LTASetupService() { } private void MapObject(LTASetup oLTASetup, DataReader oReader) { base.SetObjectID(oLTASetup, oReader.GetInt32("LTASetupID").Value); oLTASetup.FromMonth = oReader.GetDateTime("FromMonth").Value; oLTASetup.ToMonth = oReader.GetDateTime("ToMonth").Value; oLTASetup.Description = oReader.GetString("Description"); oLTASetup.CreatedBy = oReader.GetInt32("CreatedBy", 0); oLTASetup.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 0); oLTASetup.CreatedDate = oReader.GetDateTime("CreatedDate").Value; this.SetObjectState(oLTASetup, Ease.Core.ObjectState.Saved); } private void MapChildObjectLtaBasic(LTABasic oLTABasic, DataReader oReader) { base.SetObjectID(oLTABasic, oReader.GetInt32("LTABasicID").Value); oLTABasic.FromBasic = oReader.GetDouble("FromBasic").Value; oLTABasic.ToBasic = oReader.GetDouble("ToBasic").Value; oLTABasic.Increment = oReader.GetDouble("Incrment").Value; oLTABasic.Percent = oReader.GetDouble("Percent").Value; oLTABasic.LTASetupID = oReader.GetInt32("LTASetupID", 0); this.SetObjectState(oLTABasic, Ease.Core.ObjectState.Saved); } private void MapChildObjectLtaBenefit(LTABenefit oLTABenefit, DataReader oReader) { base.SetObjectID(oLTABenefit, oReader.GetInt32("LTABenefitID").Value); oLTABenefit.FlatIncrement = oReader.GetDouble("FlatIncrement").Value; oLTABenefit.FlatIncrementGF = oReader.GetDouble("FlatIncrementGF").Value; oLTABenefit.ItemID = oReader.GetInt32("ItemID", 0); oLTABenefit.ItemType = (enumPayrollComponentType)oReader.GetInt32("ItemType"); oLTABenefit.PreviousBasicPercent = oReader.GetDouble("PreBasicPercent").Value; oLTABenefit.PreviousBasicIncrementPercent = oReader.GetDouble("PreBasicIncrementPercent").Value; oLTABenefit.GFPreviousBasicPercent = oReader.GetDouble("GFPreBasicPercent").Value; oLTABenefit.GFPreviousBasicIncrementPercent = oReader.GetDouble("GFPreBasicIncrementPercent").Value; oLTABenefit.IsDependOnAttendance = oReader.GetBoolean("IsDependOnAttendance").Value; oLTABenefit.LTASetupID = oReader.GetInt32("LTASetupID", 0); this.SetObjectState(oLTABenefit, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { LTASetup oLTASetup = new LTASetup(); MapObject(oLTASetup, oReader); return oLTASetup as T; } private List CreateChildsLtaBasic(DataReader oReader) { List oLTABasics = new List(); LTABasic oLTABasic; while (oReader.Read()) { oLTABasic = new LTABasic(); oLTABasic = CreateChildLtaBasic(oReader); oLTABasics.Add(oLTABasic); } return oLTABasics; } private LTABasic CreateChildLtaBasic(DataReader oReader) { LTABasic oLTABasic = new LTABasic(); MapChildObjectLtaBasic(oLTABasic, oReader); return oLTABasic; } private List CreateChildsLtaBenefit(DataReader oReader) { List oLTABenefits = new List(); LTABenefit oLTABenefit; while (oReader.Read()) { oLTABenefit = new LTABenefit(); oLTABenefit = CreateChildLtaBenefit(oReader); oLTABenefits.Add(oLTABenefit); } return oLTABenefits; } private LTABenefit CreateChildLtaBenefit(DataReader oReader) { LTABenefit oLTABenefit = new LTABenefit(); MapChildObjectLtaBenefit(oLTABenefit, oReader); return oLTABenefit; } #region Service Implimentation public LTASetup Get(int id) { LTASetup oLTASetup = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(LTASetupDA.Get(tc, id)); if (oreader.Read()) { oLTASetup = 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 oLTASetup; } public List Get(DateTime fromDate, DateTime todate, int payrollTypeID) { List oLTASetups = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LTASetupDA.Get(tc, fromDate, todate, payrollTypeID)); oLTASetups = 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 oLTASetups; } public List GetWithPayrollType(int payrollTypeID) { List oLTASetups = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LTASetupDA.GetWithPayrollType(tc, payrollTypeID)); oLTASetups = 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 oLTASetups; } public List GetLTAbasic(int id) { List oLTABasics = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LTASetupDA.GetLTAbasic(tc, id)); oLTABasics = this.CreateChildsLtaBasic(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 oLTABasics; } public List GetLTAbenefit(int id) { List oLTABenefits = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LTASetupDA.GetLTAbenefit(tc, id)); oLTABenefits = this.CreateChildsLtaBenefit(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 oLTABenefits; } public List GetDistinctBenefit() { List oLTABenefits = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(LTASetupDA.GetDistinctBenefit(tc)); oLTABenefits = this.CreateChildsLtaBenefit(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 oLTABenefits; } public int Save(LTASetup oLTASetup) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oLTASetup.IsNew) { int id = tc.GenerateID("LTASetup", "LTASetupID"); base.SetObjectID(oLTASetup, id); oLTASetup.CreatedBy = oLTASetup.CreatedBy; oLTASetup.CreatedDate = DateTime.Now; LTASetupDA.Insert(tc, oLTASetup); } else { oLTASetup.ModifiedBy = oLTASetup.ModifiedBy; oLTASetup.ModifiedDate = DateTime.Now; LTASetupDA.Update(tc, oLTASetup); LTASetupDA.DeleteChilds(tc, oLTASetup.ID); } if (oLTASetup.LTABasics != null) { foreach (LTABasic item in oLTASetup.LTABasics) { int id = tc.GenerateID("LTABasic", "LTABasicID"); base.SetObjectID(item, id); item.LTASetupID = oLTASetup.ID; LTASetupDA.InsertLTABasic(tc, item); } } if (oLTASetup.LTABenefits != null) { foreach (LTABenefit item in oLTASetup.LTABenefits) { int id = tc.GenerateID("LTABenefit", "LTABenefitID"); base.SetObjectID(item, id); item.LTASetupID = oLTASetup.ID; LTASetupDA.InsertLTABenefit(tc, item); } } tc.End(); return oLTASetup.ID; } 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); //LTASetupDA.DeleteChilds(tc, id); LTASetupDA.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 } }