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 ProdBonusLineService:ServiceTemplate,IProdBonusLineService { #region Private functions and declaration Cache _cache = new Cache(typeof(ProdBonusLine)); #endregion public ProdBonusLineService() { } private void MapObject(ProdBonusLine oProdBonusLine, DataReader oReader) { //oProdBonusLine.ID = oReader.GetID("ProdBonusLineID"); base.SetObjectID(oProdBonusLine, oReader.GetID("ProdBonusLineID")); oProdBonusLine.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID"); oProdBonusLine.LineName = oReader.GetString("LineName"); oProdBonusLine.LineAchievedPercent = oReader.GetDouble("LineAchievedPercent").GetValueOrDefault(); oProdBonusLine.LineOTHour = oReader.GetDouble("LineOTHour").GetValueOrDefault(); oProdBonusLine.ScheduledHour = oReader.GetDouble("ScheduledHour").GetValueOrDefault(); this.SetObjectState(oProdBonusLine,Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ProdBonusLine oProdBonusLine = new ProdBonusLine(); MapObject(oProdBonusLine, oReader); return oProdBonusLine as T; } protected ProdBonusLine CreateObject(DataReader oReader) { ProdBonusLine oProdBonusLine = new ProdBonusLine(); MapObject(oProdBonusLine, oReader); return oProdBonusLine; } private void MapProdBonusParameterObject(ProdBonusParameter oProdBonusParameter, DataReader oReader) { //oProdBonusParameter.ID = oReader.GetID("ProdBonusParameterID"); base.SetObjectID(oProdBonusParameter, oReader.GetID("ProdBonusParameterID")); oProdBonusParameter.ProdBonusLineID = oReader.GetID("ProdBonusLineID"); oProdBonusParameter.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID"); oProdBonusParameter.ItemID = oReader.GetID("ItemID"); oProdBonusParameter.ItemType = (EnumBonusItemType)oReader.GetInt32("ItemType").Value; oProdBonusParameter.ProdBonusLineID = oReader.GetID("ProdBonusLineID"); this.SetObjectState(oProdBonusParameter, Ease.CoreV35.ObjectState.Saved); } private ProdBonusParameter CreateProdBonusParameterObject(DataReader oReader) { ProdBonusParameter item = new ProdBonusParameter(); MapProdBonusParameterObject(item, oReader); return item; } protected ObjectsTemplate CreateProdBonusParameterObjects(DataReader oReader) { ObjectsTemplate oItems = new ObjectsTemplate(); while (oReader.Read()) { ProdBonusParameter item = CreateProdBonusParameterObject(oReader); oItems.Add(item); } return oItems; } private void MapScheduleObject(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); } private ProdBonusWorkSchedule CreateScheduleObject(DataReader oReader) { ProdBonusWorkSchedule item = new ProdBonusWorkSchedule(); MapScheduleObject(item, oReader); return item; } protected ObjectsTemplate CreateScheduleObjects(DataReader oReader) { ObjectsTemplate oItems = new ObjectsTemplate(); while (oReader.Read()) { ProdBonusWorkSchedule item = CreateScheduleObject(oReader); oItems.Add(item); } return oItems; } private void MapSupervisorObject(ProdBonusSupervisor oProdBonusSupervisor, DataReader oReader) { //oProdBonusWorkSchedule.ID = oReader.GetID("ProdBonusWorkScheduleID"); base.SetObjectID(oProdBonusSupervisor, oReader.GetID("ProdBonusSupervisorID")); oProdBonusSupervisor.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID"); oProdBonusSupervisor.ProdBonusSetupID = oReader.GetID("ProdBonusLineID"); oProdBonusSupervisor.EmployeeID = oReader.GetID("EmployeeID"); oProdBonusSupervisor.BonusPercent = oReader.GetDouble("BonusPercent").GetValueOrDefault(); this.SetObjectState(oProdBonusSupervisor, Ease.CoreV35.ObjectState.Saved); } private ProdBonusSupervisor CreateSupervisorObject(DataReader oReader) { ProdBonusSupervisor item = new ProdBonusSupervisor(); MapSupervisorObject(item, oReader); return item; } protected ObjectsTemplate CreateSupervisorObjects(DataReader oReader) { ObjectsTemplate oItems = new ObjectsTemplate(); while (oReader.Read()) { ProdBonusSupervisor item = CreateSupervisorObject(oReader); oItems.Add(item); } return oItems; } #region Service implementation public ProdBonusLine Get(ID id) { ProdBonusLine oProdBonusLine = new ProdBonusLine(); #region Cache Header oProdBonusLine = _cache["Get", id] as ProdBonusLine; if (oProdBonusLine != null) return oProdBonusLine; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ProdBonusLineDA.Get(tc, id)); if (oreader.Read()) { oProdBonusLine = 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(oProdBonusLine, "Get", id); #endregion return oProdBonusLine; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate ProdBonusLines = _cache["Get"] as ObjectsTemplate; if (ProdBonusLines != null) return ProdBonusLines; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusLineDA.Get(tc)); ProdBonusLines = 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(ProdBonusLines, "Get"); #endregion return ProdBonusLines; } public ObjectsTemplate GetProdBonusParameters(ID iD) { ObjectsTemplate ProdBonusParameters = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusParameters(tc, iD)); ProdBonusParameters = this.CreateProdBonusParameterObjects(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 ProdBonusParameters; } public ObjectsTemplate GetProdBonusWorkSchedules(ID iD) { ObjectsTemplate ProdBonusWorkSchedules = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusWorkSchedules(tc, iD)); ProdBonusWorkSchedules = this.CreateScheduleObjects(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 ProdBonusWorkSchedules; } public ObjectsTemplate GetProdBonusWorkSchedules(TransactionContext tc,ID iD) { ObjectsTemplate ProdBonusWorkSchedules = new ObjectsTemplate(); try { DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusWorkSchedules(tc, iD)); ProdBonusWorkSchedules = this.CreateScheduleObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return ProdBonusWorkSchedules; } public ObjectsTemplate GetProdBonusSupervisors(ID iD) { ObjectsTemplate ProdBonusSupervisors = new ObjectsTemplate(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusSupervisors(tc, iD)); ProdBonusSupervisors = this.CreateSupervisorObjects(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 ProdBonusSupervisors; } public ID Save(ProdBonusLine oProdBonusLine) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProdBonusLine.IsNew) { int id = tc.GenerateID("ProdBonusLines", "ProdBonusLineID"); base.SetObjectID(oProdBonusLine, ID.FromInteger(id)); int seqNo = tc.GenerateID("ProdBonusLines", "SequenceNO"); oProdBonusLine.Sequence = seqNo; ProdBonusLineDA.Insert(tc, oProdBonusLine); } else { ProdBonusLineDA.Update(tc, oProdBonusLine); } tc.End(); return oProdBonusLine.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); ProdBonusLineDA.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 } }