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 FSTranDetail Service [Serializable] public class FSTranDetailService : ServiceTemplate, IFSTranDetailService { #region Private functions and declaration Cache _cache = new Cache(typeof(FSTranDetail)); #endregion public FSTranDetailService() { } private void MapObject(FSTranDetail oFSTranDetail, DataReader oReader) { base.SetObjectID(oFSTranDetail, oReader.GetID("FSTranDetailID")); oFSTranDetail.Amount = oReader.GetDouble("ChangeTaxAmount").Value; oFSTranDetail.AmountType = (EnumValueType)oReader.GetInt32("AmountType").Value; oFSTranDetail.ChangedValue = oReader.GetDouble("ChangedValue").Value; oFSTranDetail.Description = oReader.GetString("Description"); oFSTranDetail.FsTranType = (EnumFSTranType)oReader.GetInt32("FsTranType").Value; oFSTranDetail.ItemCode = (EnumFSItemCode)oReader.GetInt32("ItemCode").Value; oFSTranDetail.ItemID = oReader.GetInt16("ItemID").Value; oFSTranDetail.Remarks = oReader.GetString("Remarks"); oFSTranDetail.Side = (EnumSide)oReader.GetInt32("Side").Value; oFSTranDetail.TranID = oReader.GetID("TranID"); oFSTranDetail.CreatedBy = oReader.GetID("CreatedBy"); oFSTranDetail.CreatedDate = oReader.GetDateTime("CreationDate").Value; oFSTranDetail.ModifiedBy = oReader.GetID("ModifiedBy"); oFSTranDetail.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oFSTranDetail, Ease.CoreV35.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { FSTranDetail oFSTranDetail = new FSTranDetail(); MapObject(oFSTranDetail, oReader); return oFSTranDetail as T; } protected FSTranDetail CreateObject(DataReader oReader) { FSTranDetail oFSTranDetail = new FSTranDetail(); MapObject(oFSTranDetail, oReader); return oFSTranDetail; } #region Service implementation Detail public FSTranDetail Get(ID id) { FSTranDetail oFSTranDetail = new FSTranDetail(); #region Cache Header oFSTranDetail = _cache["Get", id] as FSTranDetail; if (oFSTranDetail != null) return oFSTranDetail; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FSTranDetailDA.Get(tc, id)); if (oreader.Read()) { oFSTranDetail = 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(oFSTranDetail, "Get", id); #endregion return oFSTranDetail; } public ObjectsTemplate Get() { #region Cache Header ObjectsTemplate FSTranDetails = _cache["Get"] as ObjectsTemplate; if (FSTranDetails != null) return FSTranDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FSTranDetailDA.Get(tc)); FSTranDetails = 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(FSTranDetails, "Get"); #endregion return FSTranDetails; } public ObjectsTemplate GetDetail(ID nTranID) { #region Cache Header ObjectsTemplate FSTranDetails = _cache["Get", nTranID] as ObjectsTemplate; if (FSTranDetails != null) return FSTranDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FSTranDetailDA.GetDetail(tc, nTranID)); FSTranDetails = 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(FSTranDetails, "Get", nTranID); #endregion return FSTranDetails; } public ObjectsTemplate GetDetailByEmp(int nEmpID) { #region Cache Header ObjectsTemplate FSTranDetails = _cache["GetDetailByEmp", nEmpID] as ObjectsTemplate; if (FSTranDetails != null) return FSTranDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FSTranDetailDA.GetDetailByEmp(tc, nEmpID)); FSTranDetails = 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(FSTranDetails, "GetDetailByEmp", nEmpID); #endregion return FSTranDetails; } public ObjectsTemplate Get(EnumStatus status) { #region Cache Header ObjectsTemplate FSTranDetails = _cache["Get", status] as ObjectsTemplate; if (FSTranDetails != null) return FSTranDetails; #endregion TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FSTranDetailDA.Get(tc, status)); FSTranDetails = 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(FSTranDetails, "Get", status); #endregion return FSTranDetails; } public ID Save(FSTranDetail oFSTranDetail) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //if (oFSTranDetail.IsNew) //{ int id = tc.GenerateID("FSTranDetail", "FSTranDetailID"); base.SetObjectID(oFSTranDetail, ID.FromInteger(id)); FSTranDetailDA.Insert(tc, oFSTranDetail); //} //else //{ // FSTranDetailDA.Update(tc, oFSTranDetail); //} tc.End(); return oFSTranDetail.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(TransactionContext tc,FSTranDetail oFSTranDetail) { try { //tc = TransactionContext.Begin(true); //if (oFSTranDetail.IsNew) //{ int id = tc.GenerateID("FSTranDetail", "FSTranDetailID"); base.SetObjectID(oFSTranDetail, ID.FromInteger(id)); FSTranDetailDA.Insert(tc, oFSTranDetail); //} //else //{ // FSTranDetailDA.Update(tc, oFSTranDetail); //} //tc.End(); return oFSTranDetail.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); FSTranDetailDA.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 }