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 OTProcess Service [Serializable] public class OTProcessService : ServiceTemplate, IOTProcessService { #region Private functions and declaration Cache _cache = new Cache(typeof(OTProcess)); #endregion public OTProcessService() { } private void MapObject(OTProcess oOTProcess, DataReader oReader) { base.SetObjectID(oOTProcess, oReader.GetID("ProcessId")); oOTProcess.MonthDate = oReader.GetDateTime("ProcessMonth").Value; oOTProcess.EmployeeID = oReader.GetID("empID"); oOTProcess.Amount = oReader.GetDouble("amount").Value; oOTProcess.ArrearAmount = oReader.GetDouble("ArrearAmount").Value; oOTProcess.TermID = oReader.GetID("termID"); oOTProcess.TermParameterID = oReader.GetID("TermParameterID"); oOTProcess.EmpOverTimeID = oReader.GetID("EmpOverTimeID"); oOTProcess.TotalHour = oReader.GetDouble("Hours").Value; oOTProcess.CreatedBy = oReader.GetID("CreatedBy"); oOTProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value; oOTProcess.ModifiedBy = oReader.GetID("ModifiedBy"); oOTProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oOTProcess.OTMonth = oReader.GetDateTime("OTMonth").Value; this.SetObjectState(oOTProcess, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { OTProcess oOTProcess = new OTProcess(); MapObject(oOTProcess, oReader); return oOTProcess as T; } protected OTProcess CreateObject(DataReader oReader) { OTProcess oOTProcess = new OTProcess(); MapObject(oOTProcess, oReader); return oOTProcess; } #region Service implementation public ObjectsTemplate Get(DateTime dMonthDate) { #region Cache Header ObjectsTemplate oTProcess = _cache["Get", dMonthDate] as ObjectsTemplate; if (oTProcess != null) return oTProcess; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OTProcessDA.Get(tc, dMonthDate)); oTProcess = 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(oTProcess, "Get", dMonthDate); #endregion return oTProcess; } public OTProcess Get(ID id) { OTProcess oOTProcess = new OTProcess(); #region Cache Header oOTProcess = _cache["Get", id] as OTProcess; if (oOTProcess != null) return oOTProcess; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(OTProcessDA.Get(tc, id)); if (oreader.Read()) { oOTProcess = 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(oOTProcess, "Get", id); #endregion return oOTProcess; } public bool IsProcessed(DateTime dMonthDate, ID PayrollTypeID) { bool isProcessed = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OTProcessDA.IsProcessed(tc, dMonthDate, PayrollTypeID)); if (dr.Read()) { isProcessed = Convert.ToBoolean(dr.GetInt32(0)); } 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 isProcessed; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oTProcess = _cache["Get"] as ObjectsTemplate; if (oTProcess != null) return oTProcess; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OTProcessDA.Get(tc)); oTProcess = 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(oTProcess, "Get"); #endregion return oTProcess; } public DataSet GetOTProcessData(DateTime Month,string sEmpID) { DataSet oTProcess = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); oTProcess = OTProcessDA.GetOTProcessData(tc,Month,sEmpID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oTProcess; } public DataSet GetOTMonthRangeData(DateTime FDate,DateTime TDate) { DataSet oTProcess = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); oTProcess = OTProcessDA.GetOTMonthRangeData(tc,FDate,TDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oTProcess; } public DataSet GetBranchWiseOT(DateTime Month) { DataSet oTProcess = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); oTProcess = OTProcessDA.GetBranchWiseOT(tc, Month); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oTProcess; } public DataSet GetCostCenterWiseOT(DateTime dateTime, string sEmpID) { DataSet oTProcess = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); oTProcess = OTProcessDA.GetCostCenterWiseOT(tc, dateTime, sEmpID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oTProcess; } public DataSet GetLocationWiseOT(DateTime FDate, DateTime TDate) { DataSet oTProcess = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); oTProcess = OTProcessDA.GetLocationWiseOT(tc, FDate, TDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oTProcess; } public ObjectsTemplate GetbyOtMonth(string sEmpIDs, string sMonths) { #region Cache Header ObjectsTemplate oTProcess = _cache["Get", sEmpIDs,sMonths] as ObjectsTemplate; if (oTProcess != null) return oTProcess; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(OTProcessDA.GetbyOtMonth(tc, sEmpIDs, sMonths)); oTProcess = 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(oTProcess, "Get", sEmpIDs, sMonths); #endregion return oTProcess; } public ID Save(OTProcess oOTProcess) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oOTProcess.IsNew) { int id = tc.GenerateID("OTProcess", "ProcessId"); base.SetObjectID(oOTProcess, ID.FromInteger(id)); OTProcessDA.Insert(tc, oOTProcess); } else { OTProcessDA.Update(tc, oOTProcess); } tc.End(); return oOTProcess.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(TransactionContext tc,OTProcess oOTProcess) { try { if (oOTProcess.IsNew) { int id = tc.GenerateID("OTProcess", "ProcessId"); base.SetObjectID(oOTProcess, ID.FromInteger(id)); OTProcessDA.Insert(tc, oOTProcess); } else { OTProcessDA.Update(tc, oOTProcess); } return oOTProcess.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(ObjectsTemplate oOTProcesss) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (OTProcess process in oOTProcesss) { Save(tc, process); } 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(DateTime dMonthDate,ID nPayrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); OTProcessDA.Delete(tc, dMonthDate,nPayrollTypeID); 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); OTProcessDA.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 }