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 { #region BonusAdjustItem Service [Serializable] public class BonusAdjustItemService : ServiceTemplate, IBonusAdjustItemService { #region Private functions and declaration Cache _cache = new Cache(typeof(BonusAdjustItem)); #endregion public BonusAdjustItemService() { } private void MapObject(BonusAdjustItem oBonusAdjustItem, DataReader oReader) { base.SetObjectID(oBonusAdjustItem, oReader.GetID("BonusAdjustItemID")); oBonusAdjustItem.Code = oReader.GetString("code"); oBonusAdjustItem.Name = oReader.GetString("name"); oBonusAdjustItem.Side = (EnumSide)oReader.GetInt32("side").Value; oBonusAdjustItem.Amount = oReader.GetDouble("Amount").Value; oBonusAdjustItem.Sequence = oReader.GetInt32("SequenceNo").Value; oBonusAdjustItem.Status = (EnumStatus)oReader.GetInt32("Status").Value; oBonusAdjustItem.CreatedBy = oReader.GetID("CreatedBy"); oBonusAdjustItem.CreatedDate = oReader.GetDateTime("CreatedDate").Value; oBonusAdjustItem.ModifiedBy = oReader.GetID("ModifiedBy"); oBonusAdjustItem.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oBonusAdjustItem, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { BonusAdjustItem oBonusAdjustItem = new BonusAdjustItem(); MapObject(oBonusAdjustItem, oReader); return oBonusAdjustItem as T; } protected BonusAdjustItem CreateObject(DataReader oReader) { BonusAdjustItem oBonusAdjustItem = new BonusAdjustItem(); MapObject(oBonusAdjustItem, oReader); return oBonusAdjustItem; } #region Service implementation public BonusAdjustItem Get(ID id) { BonusAdjustItem oBonusAdjustItem = new BonusAdjustItem(); #region Cache Header oBonusAdjustItem = _cache["Get", id] as BonusAdjustItem; if (oBonusAdjustItem != null) return oBonusAdjustItem; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(BonusAdjustItemDA.Get(tc, id)); if (oreader.Read()) { oBonusAdjustItem = 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(oBonusAdjustItem, "Get", id); #endregion return oBonusAdjustItem; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate bonusAdjustItems = _cache["Get",status] as ObjectsTemplate; if (bonusAdjustItems != null) return bonusAdjustItems; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(BonusAdjustItemDA.Get(tc,status)); bonusAdjustItems = 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(bonusAdjustItems, "Get",status); #endregion return bonusAdjustItems; } public ID Save(BonusAdjustItem oBonusAdjustItem) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oBonusAdjustItem.IsNew) { int id = tc.GenerateID("BonusAdjustItem", "BonusAdjustItemID"); base.SetObjectID(oBonusAdjustItem, ID.FromInteger(id)); int seqNo = tc.GenerateID("BonusAdjustItem", "SequenceNo"); oBonusAdjustItem.Sequence = seqNo; BonusAdjustItemDA.Insert(tc, oBonusAdjustItem); } else { BonusAdjustItemDA.Update(tc, oBonusAdjustItem); } tc.End(); return oBonusAdjustItem.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); BonusAdjustItemDA.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 } #endregion }