using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { #region FSTranDetail Service public class FSTranDetailService : ServiceTemplate, IFSTranDetailService { #region Private functions and declaratio #endregion public FSTranDetailService() { } private void MapObject(FSTranDetail oFSTranDetail, DataReader oReader) { base.SetObjectID(oFSTranDetail, (oReader.GetInt32("FSTranDetailID").Value)); 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.GetInt32("ItemID"); oFSTranDetail.Remarks = oReader.GetString("Remarks"); oFSTranDetail.Side = (EnumSide)oReader.GetInt32("Side").Value; oFSTranDetail.TranID = oReader.GetInt32("TranID", 0); oFSTranDetail.CreatedBy = oReader.GetInt32("CreatedBy", 0); oFSTranDetail.CreatedDate = oReader.GetDateTime("CREATIONDATE").HasValue ? oReader.GetDateTime("CREATIONDATE").Value : DateTime.MinValue; oFSTranDetail.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oFSTranDetail.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null; this.SetObjectState(oFSTranDetail, Ease.Core.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(int id) { FSTranDetail oFSTranDetail = new FSTranDetail(); 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 } return oFSTranDetail; } public List Get() { List FSTranDetails = new List(); 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 } return FSTranDetails; } public FSTranDetail GetGratuity(int id) { FSTranDetail oFSTranDetail = new FSTranDetail(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FSTranDetailDA.GetGratuity(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 } return oFSTranDetail; } public FSTranDetail GetFinalSettlement(int id) { FSTranDetail oFSTranDetail = new FSTranDetail(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(FSTranDetailDA.GetFinalSettlement(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 } return oFSTranDetail; } public List GetDetail(int nTranID) { List FSTranDetails = new List(); 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 } return FSTranDetails; } public List GetDetail(TransactionContext tc, int nTranID) { List FSTranDetails = new List(); try { DataReader dr = new DataReader(FSTranDetailDA.GetDetail(tc, nTranID)); FSTranDetails = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return FSTranDetails; } public List GetDetailAmountType(int nTranID) { List FSTranDetails = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(FSTranDetailDA.GetDetailAmountType(tc, nTranID)); FSTranDetails = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return FSTranDetails; } public List GetDetail(TransactionContext tc, DateTime fromDate, DateTime toDate) { List FSTranDetails = new List(); try { DataReader dr = new DataReader(FSTranDetailDA.GetDetail(tc, fromDate, toDate)); FSTranDetails = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return FSTranDetails; } public List GetDetailsBytranIDs(TransactionContext tc,string ids) { List FSTranDetails = new List(); try { DataReader dr = new DataReader(FSTranDetailDA.GetDetail(tc, ids)); FSTranDetails = this.CreateObjects(dr); dr.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return FSTranDetails; } public List GetDetailByEmp(int nEmpID) { List FSTranDetails = new List(); 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 } return FSTranDetails; } public List Get(EnumStatus status) { List FSTranDetails = new List(); 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 } return FSTranDetails; } public int Save(FSTranDetail oFSTranDetail) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //if (oFSTranDetail.IsNew) //{ int id = tc.GenerateID("FSTranDetail", "FSTranDetailID"); base.SetObjectID(oFSTranDetail, (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 int Save(TransactionContext tc, FSTranDetail oFSTranDetail) { try { //tc = TransactionContext.Begin(true); //if (oFSTranDetail.IsNew) //{ int id = tc.GenerateID("FSTranDetail", "FSTranDetailID"); base.SetObjectID(oFSTranDetail, (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(int 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 } } public void DeleteByUserId(int trandId, int userId) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); FSTranDetailDA.DeleteByUserId(tc, trandId, userId); 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 }