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 ProdBonusWorkScheduleService: ServiceTemplate, IProdBonusWorkScheduleService { #region Private functions and declaration Cache _cache = new Cache(typeof(ProdBonusWorkSchedule)); #endregion public ProdBonusWorkScheduleService() { } private void MapObject(ProdBonusWorkSchedule oProdBonusWorkSchedule, DataReader oReader) { //oProdBonusWorkSchedule.ID = oReader.GetID("ProdBonusWorkScheduleID"); base.SetObjectID(oProdBonusWorkSchedule, oReader.GetID("ProdBonusWorkScheduleID")); oProdBonusWorkSchedule.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID"); oProdBonusWorkSchedule.ProdBonusLineID = oReader.GetID("ProdBonusLineID"); oProdBonusWorkSchedule.StartDateTime = oReader.GetDateTime("StartDateTime").Value; //oProdBonusWorkSchedule.EndDateTime = oReader.GetDateTime("EndDateTime").Value; this.SetObjectState(oProdBonusWorkSchedule,Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule(); MapObject(oProdBonusWorkSchedule, oReader); return oProdBonusWorkSchedule as T; } protected ProdBonusWorkSchedule CreateObject(DataReader oReader) { ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule(); MapObject(oProdBonusWorkSchedule, oReader); return oProdBonusWorkSchedule; } #region Service implementation public ProdBonusWorkSchedule Get(ID id) { ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule(); #region Cache Header oProdBonusWorkSchedule = _cache["Get", id] as ProdBonusWorkSchedule; if (oProdBonusWorkSchedule != null) return oProdBonusWorkSchedule; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ProdBonusWorkScheduleDA.Get(tc, id)); if (oreader.Read()) { oProdBonusWorkSchedule = 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(oProdBonusWorkSchedule, "Get", id); #endregion return oProdBonusWorkSchedule; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate ProdBonusWorkSchedules = _cache["Get"] as ObjectsTemplate; if (ProdBonusWorkSchedules != null) return ProdBonusWorkSchedules; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusWorkScheduleDA.Get(tc)); ProdBonusWorkSchedules = 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(ProdBonusWorkSchedules, "Get"); #endregion return ProdBonusWorkSchedules; } public ObjectsTemplate Get(int nSetupID) { #region Cache Header ObjectsTemplate ProdBonusWorkSchedules = _cache["Get"] as ObjectsTemplate; if (ProdBonusWorkSchedules != null) return ProdBonusWorkSchedules; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusWorkScheduleDA.Get(tc, nSetupID)); ProdBonusWorkSchedules = 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(ProdBonusWorkSchedules, "Get"); #endregion return ProdBonusWorkSchedules; } public ID Save(ProdBonusWorkSchedule oProdBonusWorkSchedule) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProdBonusWorkSchedule.IsNew) { int id = tc.GenerateID("ProdBonusWorkSchedule", "ProdBonusWorkScheduleID"); base.SetObjectID(oProdBonusWorkSchedule, ID.FromInteger(id)); int seqNo = tc.GenerateID("ProdBonusWorkSchedule", "SequenceNO"); oProdBonusWorkSchedule.Sequence = seqNo; ProdBonusWorkScheduleDA.Insert(tc, oProdBonusWorkSchedule); } else { ProdBonusWorkScheduleDA.Update(tc, oProdBonusWorkSchedule); } tc.End(); return oProdBonusWorkSchedule.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); ProdBonusWorkScheduleDA.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 } }