using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; using Payroll.BO; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Payroll.Service.Attendence.DA; using Payroll.BO; using System.Data; namespace Payroll.Service.Attendence.Service { #region MonthlyWorkPlan Service [Serializable] public class MonthlyWorkPlanService : ServiceTemplate, IMonthlyWorkPlanService { #region Private functions and declaration Cache _cache = new Cache(typeof(MonthlyWorkPlan)); #endregion public MonthlyWorkPlanService() { } private void MapObject(MonthlyWorkPlan oMonthlyWorkPlan, DataReader oReader) { base.SetObjectID(oMonthlyWorkPlan, oReader.GetID("MonthlyWorkPlanID")); oMonthlyWorkPlan.EmployeeID = oReader.GetID("EmployeeID"); oMonthlyWorkPlan.WorkDate = oReader.GetDateTime("WorkDate").Value; oMonthlyWorkPlan.ShiftID = oReader.GetID("ShiftID"); oMonthlyWorkPlan.HolidayID = oReader.GetID("HolidayID"); oMonthlyWorkPlan.WorkPlanGroupID = oReader.GetID("WorkPlanGroupID"); oMonthlyWorkPlan.Type = (EnumWorkPlanDayType)oReader.GetInt32("Type").Value; oMonthlyWorkPlan.CreatedBy = oReader.GetID("CreatedBy"); oMonthlyWorkPlan.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oMonthlyWorkPlan.ModifiedBy = oReader.GetID("ModifiedBy"); oMonthlyWorkPlan.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oMonthlyWorkPlan, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan(); MapObject(oMonthlyWorkPlan, oReader); return oMonthlyWorkPlan as T; } protected MonthlyWorkPlan CreateObject(DataReader oReader) { MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan(); MapObject(oMonthlyWorkPlan, oReader); return oMonthlyWorkPlan; } #region Service implementation public MonthlyWorkPlan Get(ID id) { MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan(); #region Cache Header oMonthlyWorkPlan = _cache["Get", id] as MonthlyWorkPlan; if (oMonthlyWorkPlan != null) return oMonthlyWorkPlan; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(MonthlyWorkPlanDA.Get(tc, id)); if (oreader.Read()) { oMonthlyWorkPlan = 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(oMonthlyWorkPlan, "Get", id); #endregion return oMonthlyWorkPlan; } public MonthlyWorkPlan GetByEmpID(ID nEmpID, DateTime assDate, EnumWorkPlanGroup type) { MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan(); #region Cache Header oMonthlyWorkPlan = _cache["GetByEmpID", nEmpID, assDate, type] as MonthlyWorkPlan; if (oMonthlyWorkPlan != null) return oMonthlyWorkPlan; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(MonthlyWorkPlanDA.GetByEmpID(tc, nEmpID, assDate, type)); if (oreader.Read()) { oMonthlyWorkPlan = 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(oMonthlyWorkPlan, "GetByEmpID", nEmpID, assDate, type); #endregion return oMonthlyWorkPlan; } public MonthlyWorkPlan GetByEmpID(ID nEmpID, DateTime workDate) { MonthlyWorkPlan oMonthlyWorkPlan = new MonthlyWorkPlan(); #region Cache Header oMonthlyWorkPlan = _cache["GetByEmpID", nEmpID, workDate] as MonthlyWorkPlan; if (oMonthlyWorkPlan != null) return oMonthlyWorkPlan; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(MonthlyWorkPlanDA.GetByEmpID(tc, nEmpID, workDate)); if (oreader.Read()) { oMonthlyWorkPlan = 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(oMonthlyWorkPlan, "GetByEmpID", nEmpID, workDate); #endregion return oMonthlyWorkPlan; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate monthlyWorkPlans = _cache["Get"] as ObjectsTemplate; if (monthlyWorkPlans != null) return monthlyWorkPlans; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkPlanDA.Get(tc)); monthlyWorkPlans = 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(monthlyWorkPlans, "Get"); #endregion return monthlyWorkPlans; } public ObjectsTemplate Get(DateTime attnDate) { #region Cache Header ObjectsTemplate monthlyWorkPlans = _cache["Get", attnDate] as ObjectsTemplate; if (monthlyWorkPlans != null) return monthlyWorkPlans; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkPlanDA.Get(tc, attnDate)); monthlyWorkPlans = 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(monthlyWorkPlans, "Get", attnDate); #endregion return monthlyWorkPlans; } public ObjectsTemplate GetByType(EnumWorkPlanGroup type) { #region Cache Header ObjectsTemplate monthlyWorkPlans = _cache["GetByType", type] as ObjectsTemplate; if (monthlyWorkPlans != null) return monthlyWorkPlans; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkPlanDA.GetByType(tc, type)); monthlyWorkPlans = 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(monthlyWorkPlans, "GetByType"); #endregion return monthlyWorkPlans; } public ObjectsTemplate GetByDateAndWPGType(DateTime dAssDate, EnumWorkPlanGroup type) { #region Cache Header ObjectsTemplate monthlyWorkPlans = _cache["GetByDateAndWPGType", dAssDate, type] as ObjectsTemplate; if (monthlyWorkPlans != null) return monthlyWorkPlans; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkPlanDA.GetByDateAndWPGType(tc, dAssDate, type)); monthlyWorkPlans = 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(monthlyWorkPlans, "GetByDateAndWPGType"); #endregion return monthlyWorkPlans; } public ObjectsTemplate GetByDateAndGroupID(DateTime dAssDate, ID groupID) { #region Cache Header ObjectsTemplate monthlyWorkPlans = _cache["GetByDateAndGroupID", dAssDate, groupID] as ObjectsTemplate; if (monthlyWorkPlans != null) return monthlyWorkPlans; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkPlanDA.GetByDateAndGroupID(tc, dAssDate, groupID)); monthlyWorkPlans = 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(monthlyWorkPlans, "GetByDateAndGroupID"); #endregion return monthlyWorkPlans; } public ObjectsTemplate GetMonthlyDataByEmp(DateTime dAssDate, EnumWorkPlanGroup type, ID nEmpID) { #region Cache Header ObjectsTemplate monthlyWorkPlans = _cache["GetMonthlyDataByEmp", dAssDate, type, nEmpID] as ObjectsTemplate; if (monthlyWorkPlans != null) return monthlyWorkPlans; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(MonthlyWorkPlanDA.GetMonthlyDataByEmp(tc, dAssDate, type, nEmpID)); monthlyWorkPlans = 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(monthlyWorkPlans, "GetMonthlyDataByEmp"); #endregion return monthlyWorkPlans; } public ID Save(MonthlyWorkPlan oMonthlyWorkPlan) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oMonthlyWorkPlan.IsNew) { int id = tc.GenerateID("MonthlyWorkPlan", "MonthlyWorkPlanID"); base.SetObjectID(oMonthlyWorkPlan, ID.FromInteger(id)); MonthlyWorkPlanDA.Insert(tc, oMonthlyWorkPlan); } else { MonthlyWorkPlanDA.Update(tc, oMonthlyWorkPlan); } tc.End(); return oMonthlyWorkPlan.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 oMWPlans) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (MonthlyWorkPlan oMWPlan in oMWPlans) { if (oMWPlan.IsNew) { int id = tc.GenerateID("MonthlyWorkPlan", "MonthlyWorkPlanID"); base.SetObjectID(oMWPlan, ID.FromInteger(id)); MonthlyWorkPlanDA.Insert(tc, oMWPlan); } else { MonthlyWorkPlanDA.Update(tc, oMWPlan); } } 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); MonthlyWorkPlanDA.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 Delete(DateTime dFromDate, DateTime dToDate, EnumWorkPlanGroup type) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); MonthlyWorkPlanDA.Delete(tc, dFromDate, dToDate, type); 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 dFromDate, DateTime dToDate, ID wpGroupID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); MonthlyWorkPlanDA.Delete(tc, dFromDate, dToDate, wpGroupID); 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 dFromDate, DateTime dToDate) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); MonthlyWorkPlanDA.Delete(tc, dFromDate, dToDate); 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 assignDate, string empIDs) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); MonthlyWorkPlanDA.Delete(tc, assignDate, empIDs); 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 DayCount(EnumWorkPlanGroup type) { int count; TransactionContext tc = null; try { tc = TransactionContext.Begin(); count = MonthlyWorkPlanDA.DayCount(tc, type); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return count; } public DataSet GetMissingEmp(ID groupID, DateTime assignDate) { DataSet missingEmp = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); missingEmp = MonthlyWorkPlanDA.GetMissingEmp(tc, groupID, assignDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return missingEmp; } public DataSet GetEmpNotInMonthlyWorkPlan(DateTime assignDate) { DataSet missingEmp = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); missingEmp = MonthlyWorkPlanDA.GetEmpNotInMonthlyWorkPlan(tc, assignDate); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return missingEmp; } public bool IsExist(DateTime dAssDate, ID groupID) { bool isExist = false; TransactionContext tc = null; try { tc = TransactionContext.Begin(); isExist = MonthlyWorkPlanDA.IsExist(tc, dAssDate, groupID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return isExist; } #endregion } #endregion }