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 { internal class ProdBonusParameterService : ServiceTemplate, IProdBonusParameterService { #region Private functions and declaration Cache _cache = new Cache(typeof(ProdBonusParameter)); #endregion public ProdBonusParameterService() { } private void MapObject(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); } protected override T CreateObject(DataReader oReader) { ProdBonusParameter oProdBonusParameter = new ProdBonusParameter(); MapObject(oProdBonusParameter, oReader); return oProdBonusParameter as T; } protected ProdBonusParameter CreateObject(DataReader oReader) { ProdBonusParameter oProdBonusParameter = new ProdBonusParameter(); MapObject(oProdBonusParameter, oReader); return oProdBonusParameter; } #region Service implementation public ProdBonusParameter Get(ID id) { ProdBonusParameter oProdBonusParameter = new ProdBonusParameter(); #region Cache Header oProdBonusParameter = _cache["Get", id] as ProdBonusParameter; if (oProdBonusParameter != null) return oProdBonusParameter; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ProdBonusParameterDA.Get(tc, id)); if (oreader.Read()) { oProdBonusParameter = 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(oProdBonusParameter, "Get", id); #endregion return oProdBonusParameter; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate ProdBonusParameters = _cache["Get"] as ObjectsTemplate; if (ProdBonusParameters != null) return ProdBonusParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusParameterDA.Get(tc)); ProdBonusParameters = 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(ProdBonusParameters, "Get"); #endregion return ProdBonusParameters; } public ObjectsTemplate Get(int nSetupID) { #region Cache Header ObjectsTemplate ProdBonusParameters = _cache["Get"] as ObjectsTemplate; if (ProdBonusParameters != null) return ProdBonusParameters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProdBonusParameterDA.Get(tc, nSetupID)); ProdBonusParameters = 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(ProdBonusParameters, "Get"); #endregion return ProdBonusParameters; } public ID Save(ProdBonusParameter oProdBonusParameter) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProdBonusParameter.IsNew) { int id = tc.GenerateID("ProdBonusParameter", "ProdBonusParameterID"); base.SetObjectID(oProdBonusParameter, ID.FromInteger(id)); int seqNo = tc.GenerateID("ProdBonusParameter", "SequenceNO"); oProdBonusParameter.Sequence = seqNo; ProdBonusParameterDA.Insert(tc, oProdBonusParameter); } else { ProdBonusParameterDA.Update(tc, oProdBonusParameter); } tc.End(); return oProdBonusParameter.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); ProdBonusParameterDA.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 } }