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 ProdBonusWorkScheduleService : ServiceTemplate, IProdBonusWorkScheduleService { public ProdBonusWorkScheduleService() { } private void MapObject(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").Value; this.SetObjectState(oProdBonusWorkSchedule, Ease.Core.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(int id) { ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule(); 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 } return oProdBonusWorkSchedule; } public List Get() { List ProdBonusWorkSchedules = null; 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 } return ProdBonusWorkSchedules; } public List GetByLineID(int lineID) { List ProdBonusWorkSchedules = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusWorkScheduleDA.GetByLineID(tc, lineID)); 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 } return ProdBonusWorkSchedules; } public List GetWithSetupID(int nSetupID) { List ProdBonusWorkSchedules = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusWorkScheduleDA.GetBySetupId(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 } return ProdBonusWorkSchedules; } public int Save(ProdBonusWorkSchedule oProdBonusWorkSchedule) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProdBonusWorkSchedule.IsNew) { int id = tc.GenerateID("ProdBonusWorkSchedule", "ProdBonusWorkScheduleID"); base.SetObjectID(oProdBonusWorkSchedule, (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(int 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 } }