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 WeeklyHoliday Service [Serializable] public class WeeklyHolidayService : ServiceTemplate, IWeeklyHolidayService { #region Private functions and declaration Cache _cache = new Cache(typeof(WeeklyHoliday)); #endregion public WeeklyHolidayService() { } private void MapObject(WeeklyHoliday oWeeklyHoliday, DataReader oReader) { base.SetObjectID(oWeeklyHoliday, oReader.GetID("WeeklyHolidayID")); oWeeklyHoliday.DateType = oReader.GetInt16("DateType").Value; oWeeklyHoliday.LocationID = oReader.GetID("LocationID"); oWeeklyHoliday.Sequence = oReader.GetInt32("SequenceNo").Value; oWeeklyHoliday.Status = (EnumStatus)oReader.GetInt32("Status").Value; oWeeklyHoliday.CreatedBy = oReader.GetID("CreatedBy"); oWeeklyHoliday.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oWeeklyHoliday.ModifiedBy = oReader.GetID("ModifiedBy"); oWeeklyHoliday.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oWeeklyHoliday, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday(); MapObject(oWeeklyHoliday, oReader); return oWeeklyHoliday as T; } protected WeeklyHoliday CreateObject(DataReader oReader) { WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday(); MapObject(oWeeklyHoliday, oReader); return oWeeklyHoliday; } #region Service implementation public WeeklyHoliday Get(ID id) { WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday(); #region Cache Header oWeeklyHoliday = _cache["Get", id] as WeeklyHoliday; if (oWeeklyHoliday != null) return oWeeklyHoliday; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(WeeklyHolidayDA.Get(tc, id)); if (oreader.Read()) { oWeeklyHoliday = 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(oWeeklyHoliday, "Get", id); #endregion return oWeeklyHoliday; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate WeeklyHolidays = _cache["Get", status] as ObjectsTemplate; if (WeeklyHolidays != null) return WeeklyHolidays; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.Get(tc, status)); WeeklyHolidays = 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(WeeklyHolidays, "Get", status); #endregion return WeeklyHolidays; } public ObjectsTemplate GetCompanyEntireHolidays() { #region Cache Header ObjectsTemplate WeeklyHolidays = _cache["GetCompanyEntireHolidays"] as ObjectsTemplate; if (WeeklyHolidays != null) return WeeklyHolidays; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.GetCompanyEntireHolidays(tc)); WeeklyHolidays = 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(WeeklyHolidays, "GetCompanyEntireHolidays"); #endregion return WeeklyHolidays; } public ObjectsTemplate GetByLocation(ID nLocID) { #region Cache Header ObjectsTemplate WeeklyHolidays = _cache["GetByLocation",nLocID] as ObjectsTemplate; if (WeeklyHolidays != null) return WeeklyHolidays; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.GetByLocation(tc,nLocID)); WeeklyHolidays = 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(WeeklyHolidays, "GetByLocation",nLocID); #endregion return WeeklyHolidays; } public ObjectsTemplate GetByEmployee(ID nEmpID) { #region Cache Header ObjectsTemplate WeeklyHolidays = _cache["GetByEmployee", nEmpID] as ObjectsTemplate; if (WeeklyHolidays != null) return WeeklyHolidays; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(WeeklyHolidayDA.GetByEmployee(tc, nEmpID)); WeeklyHolidays = 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(WeeklyHolidays, "GetByEmployee", nEmpID); #endregion return WeeklyHolidays; } public ID Save(WeeklyHoliday oWeeklyHoliday) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oWeeklyHoliday.IsNew) { int id = tc.GenerateID("WeeklyHoliday", "WeeklyHolidayID"); base.SetObjectID(oWeeklyHoliday, ID.FromInteger(id)); int seqNo = tc.GenerateID("WeeklyHoliday", "SequenceNo"); oWeeklyHoliday.Sequence = seqNo; WeeklyHolidayDA.Insert(tc, oWeeklyHoliday); } else { WeeklyHolidayDA.Update(tc, oWeeklyHoliday); } tc.End(); return oWeeklyHoliday.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(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); WeeklyHolidayDA.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 }