CEL_Payroll/Payroll.Service/FinalSettlement/Service/FSTranDetailService.cs
2024-09-17 14:30:13 +06:00

311 lines
10 KiB
C#

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<T>(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<FSTranDetail>(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<FSTranDetail> Get()
{
#region Cache Header
ObjectsTemplate<FSTranDetail> FSTranDetails = _cache["Get"] as ObjectsTemplate<FSTranDetail>;
if (FSTranDetails != null)
return FSTranDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDetailDA.Get(tc));
FSTranDetails = this.CreateObjects<FSTranDetail>(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<FSTranDetail> GetDetail(ID nTranID)
{
#region Cache Header
ObjectsTemplate<FSTranDetail> FSTranDetails = _cache["Get", nTranID] as ObjectsTemplate<FSTranDetail>;
if (FSTranDetails != null)
return FSTranDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDetailDA.GetDetail(tc, nTranID));
FSTranDetails = this.CreateObjects<FSTranDetail>(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<FSTranDetail> GetDetailByEmp(int nEmpID)
{
#region Cache Header
ObjectsTemplate<FSTranDetail> FSTranDetails = _cache["GetDetailByEmp", nEmpID] as ObjectsTemplate<FSTranDetail>;
if (FSTranDetails != null)
return FSTranDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDetailDA.GetDetailByEmp(tc, nEmpID));
FSTranDetails = this.CreateObjects<FSTranDetail>(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<FSTranDetail> Get(EnumStatus status)
{
#region Cache Header
ObjectsTemplate<FSTranDetail> FSTranDetails = _cache["Get", status] as ObjectsTemplate<FSTranDetail>;
if (FSTranDetails != null)
return FSTranDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FSTranDetailDA.Get(tc, status));
FSTranDetails = this.CreateObjects<FSTranDetail>(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
}