using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { #region AttnNationalHoliday Service [Serializable] public class AttnNationalHolidayService : ServiceTemplate, IAttnNationalHolidayService { public AttnNationalHolidayService() { } private void MapObject(AttnNationalHoliday oAttnNationalHoliday, DataReader oReader) { base.SetObjectID(oAttnNationalHoliday, (oReader.GetInt32("AttnNationalHolidayID").Value)); oAttnNationalHoliday.Description = oReader.GetString("Description"); oAttnNationalHoliday.FromDate = oReader.GetDateTime("FromDate").Value; oAttnNationalHoliday.ToDate = oReader.GetDateTime("ToDate").Value; oAttnNationalHoliday.FromTime = oReader.GetDateTime("FromTime", DateTime.MinValue); oAttnNationalHoliday.ToTime = oReader.GetDateTime("ToTime", DateTime.MinValue); oAttnNationalHoliday.HolidayHour = oReader.GetDouble("HolidayHour") == null ? 0.0 : oReader.GetDouble("HolidayHour").Value; oAttnNationalHoliday.LocationID = oReader.GetInt32("LocationID"); oAttnNationalHoliday.Sequence = oReader.GetInt32("SequenceNo").Value; oAttnNationalHoliday.Status = (EnumStatus)oReader.GetInt32("Status").Value; oAttnNationalHoliday.HolidayType = (HolidayType)oReader.GetInt32("HolidayType").Value; oAttnNationalHoliday.CreatedBy = oReader.GetInt32("CreatedBy", 0); oAttnNationalHoliday.CreatedDate = oReader.GetDateTime("CREATEDDATE").Value; oAttnNationalHoliday.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oAttnNationalHoliday.ModifiedDate = oReader.GetDateTime("ModifiedDate"); oAttnNationalHoliday.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 0); this.SetObjectState(oAttnNationalHoliday, Ease.Core.ObjectState.Saved); } private void MapChildObject(AttnNationalHolidayLocation oAttnNationalHolidayLocation, DataReader oReader) { base.SetObjectID(oAttnNationalHolidayLocation, (oReader.GetInt32("AttnNationalHolidayLocationID").Value)); oAttnNationalHolidayLocation.AttnNationalHolidayID = oReader.GetInt32("AttnNationalHolidayID", 0); oAttnNationalHolidayLocation.LocationID = oReader.GetInt32("LocationID", 0); this.SetObjectState(oAttnNationalHolidayLocation, Ease.Core.ObjectState.Saved); } private void MapChildObject(AttnShiftWiseNationalHoliday oAttnShiftWiseNationalHoliday, DataReader oReader) { base.SetObjectID(oAttnShiftWiseNationalHoliday, (oReader.GetInt32("AttnNationalHolidayShiftID").Value)); oAttnShiftWiseNationalHoliday.ANationalHolidayID = oReader.GetInt32("AttnNationalHolidayID", 0); oAttnShiftWiseNationalHoliday.ShiftID = oReader.GetInt32("ShiftID", 0); oAttnShiftWiseNationalHoliday.WorkPlanGroupID = oReader.GetInt32("WorkPlanGroupID", 0); this.SetObjectState(oAttnShiftWiseNationalHoliday, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { AttnNationalHoliday oAttnNationalHoliday = new AttnNationalHoliday(); MapObject(oAttnNationalHoliday, oReader); return oAttnNationalHoliday as T; } private List CreateChilds(DataReader oReader) { List oAttnNationalHolidayLocations = new List(); AttnNationalHolidayLocation oAttnNationalHolidayLocation; while (oReader.Read()) { oAttnNationalHolidayLocation = new AttnNationalHolidayLocation(); oAttnNationalHolidayLocation = CreateChild(oReader); oAttnNationalHolidayLocations.Add(oAttnNationalHolidayLocation); } return oAttnNationalHolidayLocations; } private AttnNationalHolidayLocation CreateChild(DataReader oReader) { AttnNationalHolidayLocation oAttnNationalHolidayLocation = new AttnNationalHolidayLocation(); MapChildObject(oAttnNationalHolidayLocation, oReader); return oAttnNationalHolidayLocation; } private List CreateShifts(DataReader oReader) { List oAttnShiftWiseNationalHolidays = new List(); AttnShiftWiseNationalHoliday oAttnShiftWiseNationalHoliday; while (oReader.Read()) { oAttnShiftWiseNationalHoliday = new AttnShiftWiseNationalHoliday(); oAttnShiftWiseNationalHoliday = CreateShift(oReader); oAttnShiftWiseNationalHolidays.Add(oAttnShiftWiseNationalHoliday); } return oAttnShiftWiseNationalHolidays; } private AttnShiftWiseNationalHoliday CreateShift(DataReader oReader) { AttnShiftWiseNationalHoliday oAttnShiftWiseNationalHoliday = new AttnShiftWiseNationalHoliday(); MapChildObject(oAttnShiftWiseNationalHoliday, oReader); return oAttnShiftWiseNationalHoliday; } #region Service implementation public AttnNationalHoliday Get(int id) { AttnNationalHoliday oAttnNationalHoliday = new AttnNationalHoliday(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(AttnNationalHolidayDA.Get(tc, id)); if (oreader.Read()) { oAttnNationalHoliday = 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 oAttnNationalHoliday; } public List GetByMonthAndPayrollType(DateTime fromDate, DateTime todate, int payrollTypeID) { List attnNationalHolidays = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, fromDate, todate, payrollTypeID)); attnNationalHolidays = 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 attnNationalHolidays; } public List GetByMonth(DateTime fromDate, DateTime todate) { List attnNationalHolidays = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, fromDate, todate)); attnNationalHolidays = 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 attnNationalHolidays; } public List GetByMonthAndPayrollTypeWithDetails(DateTime fromDate, DateTime todate, int payrollTypeID) { List attnNationalHolidays = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, fromDate, todate, payrollTypeID)); attnNationalHolidays = this.CreateObjects(dr); dr.Close(); foreach (AttnNationalHoliday item in attnNationalHolidays) { DataReader tempdr = new DataReader(AttnNationalHolidayDA.GetChild(tc, item.ID)); item.AttnNationalHolidayLocations = this.CreateChilds(tempdr); tempdr.Close(); DataReader tempdr2 = new DataReader(AttnNationalHolidayDA.GetHolidayShift(tc, item.ID)); item.AttnShiftWiseNationalHolidays = this.CreateShifts(tempdr2); tempdr2.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 attnNationalHolidays; } public List GetupcommintHoliday(DateTime fromDate, int payrollTypeID) { List attnNationalHolidays = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.getupcommingHoliday(tc, fromDate, payrollTypeID)); attnNationalHolidays = 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 attnNationalHolidays; } public List GetupcommintHolidayByUserId(DateTime fromDate, int userId) { List attnNationalHolidays = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.GetupcommintHolidayByUserId(tc, fromDate, userId)); attnNationalHolidays = 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 attnNationalHolidays; } public List Get(DateTime fromDate, DateTime todate, int payrollTypeID) { List attnNationalHolidays = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, fromDate, todate, payrollTypeID)); attnNationalHolidays = 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 attnNationalHolidays; } public List Get(EnumStatus status, int payrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, status, payrollTypeID)); var attnNationalHolidays = this.CreateObjects(dr); dr.Close(); tc.End(); return attnNationalHolidays; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public List GetAttnNationalHolidayLocation(int attnNationalHolidayID) { List attnNationalHolidayLocations = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.GetChild(tc, attnNationalHolidayID)); attnNationalHolidayLocations = this.CreateChilds(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 attnNationalHolidayLocations; } public List GetAttnNationalHolidayShift(int attnNationalHolidayID) { List attnShiftWiseNationalHolidays = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(AttnNationalHolidayDA.GetHolidayShift(tc, attnNationalHolidayID)); attnShiftWiseNationalHolidays = this.CreateShifts(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 attnShiftWiseNationalHolidays; } public int Save(AttnNationalHoliday oAttnNationalHoliday, int PayrollTypeID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oAttnNationalHoliday.IsNew) { int id = tc.GenerateID("AttnNationalHoliday", "AttnNationalHolidayID"); base.SetObjectID(oAttnNationalHoliday, id); int seqNo = tc.GenerateID("AttnNationalHoliday", "SequenceNo"); oAttnNationalHoliday.Sequence = seqNo; AttnNationalHolidayDA.Insert(tc, oAttnNationalHoliday, PayrollTypeID); } else { AttnNationalHolidayDA.Update(tc, oAttnNationalHoliday); AttnNationalHolidayDA.DeleteChild(tc, oAttnNationalHoliday.ID); } if (oAttnNationalHoliday.AttnNationalHolidayLocations != null) { foreach (AttnNationalHolidayLocation item in oAttnNationalHoliday.AttnNationalHolidayLocations) { int id = tc.GenerateID("AttnNationalHolidayLocation", "AttnNationalHolidayLocationID"); base.SetObjectID(item, (id)); item.AttnNationalHolidayID = oAttnNationalHoliday.ID; AttnNationalHolidayDA.InsertChild(tc, item); } } if (oAttnNationalHoliday.AttnShiftWiseNationalHolidays != null) { foreach (AttnShiftWiseNationalHoliday item in oAttnNationalHoliday.AttnShiftWiseNationalHolidays) { int id = tc.GenerateID("AttnNationalHolidayShift", "AttnNationalHolidayShiftID"); base.SetObjectID(item, (id)); item.ANationalHolidayID = oAttnNationalHoliday.ID; AttnNationalHolidayDA.InsertShift(tc, item); } } tc.End(); return oAttnNationalHoliday.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public AttnNationalHoliday GetHoliday(List attNHolidays, DateTime dDate, int locationID, int workPlanGroupID) { AttnNationalHoliday oAttNHoliday = null; if (attNHolidays.Count > 0) oAttNHoliday = attNHolidays.Where(o => dDate.Date >= o.FromDate.Date && dDate.Date <= o.ToDate.Date).FirstOrDefault(); if (oAttNHoliday != null && oAttNHoliday.AttnNationalHolidayLocations.Count == 0 && oAttNHoliday.AttnShiftWiseNationalHolidays.Count == 0) return oAttNHoliday; else if (oAttNHoliday != null && oAttNHoliday.AttnNationalHolidayLocations.Count > 0 && oAttNHoliday.AttnShiftWiseNationalHolidays.Count > 0) { if (oAttNHoliday.AttnNationalHolidayLocations.Exists(x => x.LocationID == locationID) == true && oAttNHoliday.AttnShiftWiseNationalHolidays.Exists(x => x.WorkPlanGroupID == workPlanGroupID) == true) return oAttNHoliday; } else if (oAttNHoliday != null && oAttNHoliday.AttnNationalHolidayLocations.Count > 0 && oAttNHoliday.AttnShiftWiseNationalHolidays.Count == 0) { if (oAttNHoliday.AttnNationalHolidayLocations.Exists(x => x.LocationID == locationID) == true) return oAttNHoliday; } else if (oAttNHoliday != null && oAttNHoliday.AttnNationalHolidayLocations.Count == 0 && oAttNHoliday.AttnShiftWiseNationalHolidays.Count > 0) if (oAttNHoliday.AttnShiftWiseNationalHolidays.Exists(x => x.WorkPlanGroupID == workPlanGroupID) == true) return oAttNHoliday; return null; } public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); AttnNationalHolidayDA.DeleteChild(tc, id); AttnNationalHolidayDA.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 int Save(AttnNationalHoliday item) { throw new NotImplementedException(); } //public List Get(EnumCardStatus status) //{ // #region Cache Header // List attnNationalHolidays = _cache["Get"] as List; // if (attnNationalHolidays != null) // return attnNationalHolidays; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, status)); // attnNationalHolidays = 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(attnNationalHolidays, "Get"); // #endregion // return attnNationalHolidays; //} //public void Insert(List oAttnNationalHolidays) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // foreach (AttnNationalHoliday ac in oAttnNationalHolidays) // { // if (ac.IsNew) // { // ac.Status = EnumCardStatus.Free; // int id = tc.GenerateID("AttnNationalHoliday", "AttnNationalHolidayID"); // base.SetObjectID(ac, ID.FromInteger(id)); // AttnNationalHolidayDA.Insert(tc, ac); // } // else // { // AttnNationalHolidayDA.Update(tc, ac); // } // } // tc.End(); // } // catch (Exception e) // { // #region Handle Exception // if (tc != null) // tc.HandleError(); // ExceptionLog.Write(e); // throw new ServiceException(e.Message, e); // #endregion // } //} //public List Get(params EnumCardStatus[] status) //{ // #region Cache Header // List accessCards = _cache["Get"] as List; // if (accessCards != null) // return accessCards; // #endregion // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // DataReader dr = new DataReader(AttnNationalHolidayDA.Get(tc, status)); // accessCards = 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(accessCards, "Get"); // #endregion // return accessCards; //} //public bool IsExist(string CardNumber) //{ // bool isExist = false; // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(); // isExist = AttnNationalHolidayDA.IsExist(tc, CardNumber); // //accessCards = 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 isExist; //} //public void UpdateStatus(ID cardID, EnumCardStatus status) //{ // TransactionContext tc = null; // try // { // tc = TransactionContext.Begin(true); // AttnNationalHolidayDA.UpdateStatus(tc, cardID, status); // 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 }