using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class ProdBonusLineService : ServiceTemplate, IProdBonusLineService { public ProdBonusLineService() { } private void MapObject(ProdBonusLine oProdBonusLine, DataReader oReader) { //oProdBonusLine.int = oReader.GetInt32("ProdBonusLineID"); base.SetObjectID(oProdBonusLine, (oReader.GetInt32("ProdBonusLineID").Value)); oProdBonusLine.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0); 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.Core.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.int = oReader.GetInt32("ProdBonusParameterID"); base.SetObjectID(oProdBonusParameter, (oReader.GetInt32("ProdBonusParameterID").Value)); oProdBonusParameter.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0); oProdBonusParameter.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0); oProdBonusParameter.ItemID = oReader.GetInt32("ItemID", 0); oProdBonusParameter.ItemType = (EnumBonusItemType)oReader.GetInt32("ItemType").Value; oProdBonusParameter.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0); this.SetObjectState(oProdBonusParameter, Ease.Core.ObjectState.Saved); } private ProdBonusParameter CreateProdBonusParameterObject(DataReader oReader) { ProdBonusParameter item = new ProdBonusParameter(); MapProdBonusParameterObject(item, oReader); return item; } protected List CreateProdBonusParameterObjects(DataReader oReader) { List oItems = new List(); while (oReader.Read()) { ProdBonusParameter item = CreateProdBonusParameterObject(oReader); oItems.Add(item); } return oItems; } private void MapScheduleObject(ProdBonusWorkSchedule oProdBonusWorkSchedule, DataReader oReader) { //oProdBonusWorkSchedule.int = oReader.GetInt32("ProdBonusWorkScheduleID"); base.SetObjectID(oProdBonusWorkSchedule, (oReader.GetInt32("ProdBonusWorkScheduleID").Value)); oProdBonusWorkSchedule.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0); oProdBonusWorkSchedule.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0); oProdBonusWorkSchedule.StartDateTime = oReader.GetDateTime("StartDateTime").Value; oProdBonusWorkSchedule.EndDateTime = oReader.GetDateTime("EndDateTime", DateTime.MaxValue); this.SetObjectState(oProdBonusWorkSchedule, Ease.Core.ObjectState.Saved); } private ProdBonusWorkSchedule CreateScheduleObject(DataReader oReader) { ProdBonusWorkSchedule item = new ProdBonusWorkSchedule(); MapScheduleObject(item, oReader); return item; } protected List CreateScheduleObjects(DataReader oReader) { List oItems = new List(); while (oReader.Read()) { ProdBonusWorkSchedule item = CreateScheduleObject(oReader); oItems.Add(item); } return oItems; } private void MapSupervisorObject(ProdBonusSupervisor oProdBonusSupervisor, DataReader oReader) { //oProdBonusWorkSchedule.int = oReader.GetInt32("ProdBonusWorkScheduleID"); base.SetObjectID(oProdBonusSupervisor, (oReader.GetInt32("ProdBonusSupervisorID").Value)); oProdBonusSupervisor.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0); oProdBonusSupervisor.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0); oProdBonusSupervisor.EmployeeID = oReader.GetInt32("EmployeeID", 0); oProdBonusSupervisor.BonusPercent = oReader.GetDouble("BonusPercent").GetValueOrDefault(); this.SetObjectState(oProdBonusSupervisor, Ease.Core.ObjectState.Saved); } private ProdBonusSupervisor CreateSupervisorObject(DataReader oReader) { ProdBonusSupervisor item = new ProdBonusSupervisor(); MapSupervisorObject(item, oReader); return item; } protected List CreateSupervisorObjects(DataReader oReader) { List oItems = new List(); while (oReader.Read()) { ProdBonusSupervisor item = CreateSupervisorObject(oReader); oItems.Add(item); } return oItems; } #region Service implementation public ProdBonusLine Get(int id) { ProdBonusLine oProdBonusLine = new ProdBonusLine(); 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 } return oProdBonusLine; } public List Get() { List ProdBonusLines = null; 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 } return ProdBonusLines; } public List GetLines(int id) { List ProdBonusLines = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusLineDA.Get(tc, id)); 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 } return ProdBonusLines; } public List GetProdBonusParameters(int iD) { List ProdBonusParameters = new List(); 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 List GetProdBonusWorkSchedules(int iD) { List ProdBonusWorkSchedules = new List(); 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 List GetProdBonusWorkSchedules(TransactionContext tc, int iD) { List ProdBonusWorkSchedules = new List(); 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 List GetProdBonusSupervisors(int iD) { List ProdBonusSupervisors = new List(); 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 List GetLineBySetupId(int setupID) { List ProdBonusLines = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusLineDA.GetLineBySetupId(tc, setupID)); ProdBonusLines = this.CreateObjects< ProdBonusLine>(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 ProdBonusLines; } public int Save(ProdBonusLine oProdBonusLine) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProdBonusLine.IsNew) { int id = tc.GenerateID("ProdBonusLines", "ProdBonusLineID"); base.SetObjectID(oProdBonusLine, (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(int 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 } }