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 ProdBonusAttnService : ServiceTemplate, IProdBonusAttnService { public ProdBonusAttnService() { } private void MapObject(ProdBonusAttn oProdBonusAttn, DataReader oReader) { //oProdBonusAttn.int = oReader.GetInt32("ProdBonusAttnID"); base.SetObjectID(oProdBonusAttn, (oReader.GetInt32("ProdBonusAttnID").Value)); oProdBonusAttn.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0); oProdBonusAttn.BonusScheduleID = oReader.GetInt32("BonusScheduleID", 0); oProdBonusAttn.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0); oProdBonusAttn.EmployeeID = oReader.GetInt32("EmployeeID", 0); oProdBonusAttn.BonusHour = oReader.GetFloat("BonusHour").GetValueOrDefault(); oProdBonusAttn.InTime = oReader.GetDateTime("InTime").Value; oProdBonusAttn.OutTime = oReader.GetDateTime("OutTime").Value; oProdBonusAttn.IsCommon = oReader.GetBoolean("IsCommon").Value; this.SetObjectState(oProdBonusAttn, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ProdBonusAttn oProdBonusAttn = new ProdBonusAttn(); MapObject(oProdBonusAttn, oReader); return oProdBonusAttn as T; } protected ProdBonusAttn CreateObject(DataReader oReader) { ProdBonusAttn oProdBonusAttn = new ProdBonusAttn(); MapObject(oProdBonusAttn, oReader); return oProdBonusAttn; } #region Service implementation public ProdBonusAttn Get(int id) { ProdBonusAttn oProdBonusAttn = new ProdBonusAttn(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ProdBonusAttnDA.Get(tc, id)); if (oreader.Read()) { oProdBonusAttn = 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 oProdBonusAttn; } public List Get() { List ProdBonusAttns = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.Get(tc)); ProdBonusAttns = 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 ProdBonusAttns; } public List Get(int setupID, int ScheduleID) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.Get(tc, setupID, ScheduleID)); ProdBonusAttns = 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 ProdBonusAttns; } public List Get(int setupID, DateTime dateTime) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.Get(tc, setupID, dateTime)); ProdBonusAttns = 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 ProdBonusAttns; } public List GetBySetupLineDate(int setupID, int lineID, DateTime dateTime) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.GetBySetupLineDate(tc, setupID, lineID, dateTime)); ProdBonusAttns = 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 ProdBonusAttns; } public List GetBySetupID(int setupID) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.GetBySetupID(tc, setupID)); ProdBonusAttns = 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 ProdBonusAttns; } public List GetBySetupIDs(string setupIDs) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.GetBySetupIDs(tc, setupIDs)); ProdBonusAttns = 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 ProdBonusAttns; } public List GetByLineID(int lineID) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.GetByLineID(tc, lineID)); ProdBonusAttns = 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 ProdBonusAttns; } public List GetbySetupAndLineID(int setupID, int lineID) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.GetbySetupAndLineID(tc, setupID, lineID)); ProdBonusAttns = 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 ProdBonusAttns; } public List GetbySetupAndLineIDbyInSQL(string setupID, string lineID) { List ProdBonusAttns = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusAttnDA.GetbySetupAndLineIDbyInSQL(tc, setupID, lineID)); ProdBonusAttns = 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 ProdBonusAttns; } public DateTime? GetMaxDate(int setupID, int lineID, DateTime date) { TransactionContext tc = null; try { DateTime? dateValue = null; tc = TransactionContext.Begin(); dateValue = ProdBonusAttnDA.GetMaxDate(tc, setupID, lineID, date); tc.End(); return dateValue; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(ProdBonusAttn oProdBonusAttn) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProdBonusAttn.IsNew) { int id = tc.GenerateID("ProdBonusAttn", "ProdBonusAttnID"); base.SetObjectID(oProdBonusAttn, (id)); ProdBonusAttnDA.Insert(tc, oProdBonusAttn); } else { ProdBonusAttnDA.Update(tc, oProdBonusAttn); } tc.End(); return oProdBonusAttn.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(List oProdBonusAttns, int bSetupID, int scheduleID, DateTime date) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //ProdBonusAttnDA.Delete(tc, bSetupID, scheduleID); ProdBonusAttnDA.Delete(tc, bSetupID, date); if (oProdBonusAttns.Count > 0) { foreach (ProdBonusAttn item in oProdBonusAttns) { int id = tc.GenerateID("ProdBonusAttn", "ProdBonusAttnID"); base.SetObjectID(item, (id)); ProdBonusAttnDA.Insert(tc, item); } } tc.End(); } 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); ProdBonusAttnDA.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 } }