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 ProcessItem Service [Serializable] public class ProcessItemService : ServiceTemplate, IProcessItemService { #region Private functions and declaration Cache _cache = new Cache(typeof(ProcessItem)); #endregion public ProcessItemService() { } private void MapObject(ProcessItem oProcessItem, DataReader oReader) { //base.SetObjectID(oProcessItem, oReader.GetID("ProcessItemID")); oProcessItem.ItemCode = oReader.GetInt32("itemCode").Value; oProcessItem.DefaultDescription = oReader.GetString("defaultDescription"); oProcessItem.UserDescription = oReader.GetString("userDescription"); oProcessItem.Position = oReader.GetInt32("position").Value; oProcessItem.ItemGroup = oReader.GetInt32("itemGroup").Value; this.SetObjectState(oProcessItem, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { ProcessItem oProcessItem = new ProcessItem(); MapObject(oProcessItem, oReader); return oProcessItem as T; } protected ProcessItem CreateObject(DataReader oReader) { ProcessItem oProcessItem = new ProcessItem(); MapObject(oProcessItem, oReader); return oProcessItem; } #region Service implementation public ProcessItem Get(ID id) { ProcessItem oProcessItem = new ProcessItem(); #region Cache Header oProcessItem = _cache["Get", id] as ProcessItem; if (oProcessItem != null) return oProcessItem; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ProcessItemDA.Get(tc, id)); if (oreader.Read()) { oProcessItem = 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(oProcessItem, "Get", id); #endregion return oProcessItem; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate processItems = _cache["Get"] as ObjectsTemplate; if (processItems != null) return processItems; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProcessItemDA.Get(tc)); processItems = 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(processItems, "Get"); #endregion return processItems; } public ObjectsTemplate GetForTHeadGroup() { #region Cache Header ObjectsTemplate processItems = _cache["GetForTHeadGroup"] as ObjectsTemplate; if (processItems != null) return processItems; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ProcessItemDA.GetForTHeadGroup(tc)); processItems = 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(processItems, "GetForTHeadGroup"); #endregion return processItems; } public ID Save(ProcessItem oProcessItem) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (oProcessItem.IsNew) { int id = tc.GenerateID("ProcessItem", "ProcessItemID"); base.SetObjectID(oProcessItem, ID.FromInteger(id)); ProcessItemDA.Insert(tc, oProcessItem); } else { ProcessItemDA.Update(tc, oProcessItem); } tc.End(); return oProcessItem.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); ProcessItemDA.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 }