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 { public class PremiumProcessService : ServiceTemplate, IPremiumProcessService { private void MapObject(PremiumProcess oPremiumProcess, DataReader oReader) { this.SetObjectID(oPremiumProcess, oReader.GetID("PremiumProcessID")); oPremiumProcess.Month = oReader.GetDateTime("Month").Value; oPremiumProcess.Factor = oReader.GetDouble("Factor").GetValueOrDefault(); oPremiumProcess.PremierRate = oReader.GetDouble("PremierRate").GetValueOrDefault(); this.SetObjectState(oPremiumProcess, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PremiumProcess oPremiumProcess = new PremiumProcess(); MapObject(oPremiumProcess, oReader); return oPremiumProcess as T; } protected PremiumProcess CreateObject(DataReader oReader) { PremiumProcess oPremiumProcess = new PremiumProcess(); MapObject(oPremiumProcess, oReader); return oPremiumProcess; } public PremiumProcess Get(ID id) { PremiumProcess oPremiumProcess = new PremiumProcess(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(PremiumProcessDA.Get(tc, id)); if (oReader.Read()) { oPremiumProcess = 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 oPremiumProcess; } public ObjectsTemplate Get() { ObjectsTemplate oPremiumProcesses = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PremiumProcessDA.Get(tc)); oPremiumProcesses = this.CreateObjects(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 oPremiumProcesses; } public ID Save(PremiumProcess oPremiumProcess) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //if (oPremiumProcess.IsNew) //{ int id = tc.GenerateID("PremiumProcess", "PremiumProcessID"); base.SetObjectID(oPremiumProcess, ID.FromInteger(id)); PremiumProcessDA.Insert(tc, oPremiumProcess); foreach (PremiumProcessDetail detail in oPremiumProcess.PremiumProcessDetails) { int id2 = tc.GenerateID("PremiumProcessDetail", "PremiumProcessDetailID"); base.SetObjectID(detail, ID.FromInteger(id2)); detail.PremiumProcessID=ID.FromInteger(id); PremiumProcessDetailDA.Insert(tc, detail); } //} //else //{ // PremiumProcessDA.Update(tc, oPremiumProcess); //} tc.End(); return oPremiumProcess.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public DataTable GetGroupInsurance(DateTime dtCur) { DataTable dataTableOfEmployee = new DataTable("Employee"); new EmployeeService().GetEmployeeCurrentPosition(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet dataSet = PremiumProcessDA.GetGroupInsurance(tc, dtCur); dataTableOfEmployee = dataSet.Tables[0]; dataSet.Dispose(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataTableOfEmployee; } public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PremiumProcessDA.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 PremiumProcess GetByMonth(DateTime month) { PremiumProcess oPremiumProcess = new PremiumProcess(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oReader = new DataReader(PremiumProcessDA.GetByMonth(tc, month)); if (oReader.Read()) { oPremiumProcess = 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 oPremiumProcess; } } }