using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Model; using Payroll.BO; namespace Payroll.Service { [Serializable] public class BudgetCostCenterService : ServiceTemplate, IBudgetCostCenterService { #region Private functions and declaration Cache _cache = new Cache(typeof(BudgetGrade)); #endregion #region Object Mapping private void MapObject(BudgetCostCenter oBudgetCostCenter, DataReader oReader) { SetObjectID(oBudgetCostCenter, oReader.GetID("BudgetCostCenterID")); oBudgetCostCenter.CostCenterID = oReader.GetID("CostCenterID"); oBudgetCostCenter.BudgetID = oReader.GetID("BudgetID"); oBudgetCostCenter.EmployeeID = oReader.GetID("EmployeeID"); oBudgetCostCenter.FromMonth = oReader.GetDateTime("FromMonth").Value; oBudgetCostCenter.Percentage = oReader.GetDouble("Percentage").Value; SetObjectState(oBudgetCostCenter, ObjectState.Saved); } protected override T CreateObject(DataReader dr) { BudgetCostCenter oBudgetCostCenter = new BudgetCostCenter(); MapObject(oBudgetCostCenter, dr); return oBudgetCostCenter as T; } #endregion #region Service Implementation public BudgetCostCenter Get(ID nID) { BudgetCostCenter oBudgetCostCenter = new BudgetCostCenter(); #region Cache Header oBudgetCostCenter = _cache["Get", nID] as BudgetCostCenter; if (oBudgetCostCenter != null) return oBudgetCostCenter; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BudgetCostCenterDA.Get(tc, nID)); if (oreader.Read()) { oBudgetCostCenter = 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(oBudgetCostCenter, "Get", nID); #endregion return oBudgetCostCenter; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oBudgetCostCenters = _cache["Get"] as ObjectsTemplate; if (oBudgetCostCenters != null) return oBudgetCostCenters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BudgetCostCenterDA.Get(tc)); // if (oreader.Read()) //{ oBudgetCostCenters = this.CreateObjects(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(oBudgetCostCenters, "Get"); #endregion return oBudgetCostCenters; } public ObjectsTemplate Get(int nID) { #region Cache Header ObjectsTemplate oBudgetCostCenters = _cache["Get"] as ObjectsTemplate; if (oBudgetCostCenters != null) return oBudgetCostCenters; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(BudgetCostCenterDA.Get(tc,nID)); // if (oreader.Read()) //{ oBudgetCostCenters = this.CreateObjects(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(oBudgetCostCenters, "Get"); #endregion return oBudgetCostCenters; } public ID Save(BudgetCostCenter item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("BudgetCostCenter", "BudgetCostCenterID"); SetObjectID(item, ID.FromInteger(id)); BudgetCostCenterDA.Insert(tc, item); } else { BudgetCostCenterDA.Update(tc, item); } tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public ID Save(BudgetCostCenter item,TransactionContext tc) { try { int id = tc.GenerateID("BudgetCostCenter", "BudgetCostCenterID"); SetObjectID(item, ID.FromInteger(id)); BudgetCostCenterDA.Insert(tc, item); return item.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 nID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); BudgetCostCenterDA.Delete(tc, nID); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion } }