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

302 lines
8.9 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 PayScaleDetail Service
[Serializable]
public class PayScaleDetailService : ServiceTemplate, IPayScaleDetailService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(PayScaleDetail));
#endregion
public PayScaleDetailService() { }
private void MapObject(PayScaleDetail oPayScaleDetail, DataReader oReader)
{
base.SetObjectID(oPayScaleDetail, oReader.GetID("PAYSCALEITEMID"));
oPayScaleDetail.PayscaleID = oReader.GetID("PAYSCALEID");
oPayScaleDetail.GradeID = oReader.GetID("GradeID");
oPayScaleDetail.StepNo = oReader.GetInt32("SCALESERIALNO").Value;
oPayScaleDetail.Amount = oReader.GetDouble("AMOUNT").Value;
oPayScaleDetail.StepAmount = oReader.GetDouble("SLABAMOUNT").Value;
oPayScaleDetail.StepIncrement = oReader.GetDouble("StepIncrement").Value;
this.SetObjectState(oPayScaleDetail, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PayScaleDetail oPayScaleDetail = new PayScaleDetail();
MapObject(oPayScaleDetail, oReader);
return oPayScaleDetail as T;
}
protected PayScaleDetail CreateObject(DataReader oReader)
{
PayScaleDetail oPayScaleDetail = new PayScaleDetail();
MapObject(oPayScaleDetail, oReader);
return oPayScaleDetail;
}
#region Service implementation
public PayScaleDetail Get(ID id)
{
PayScaleDetail oPayScaleDetail = new PayScaleDetail();
#region Cache Header
oPayScaleDetail = _cache["Get", id] as PayScaleDetail;
if (oPayScaleDetail != null)
return oPayScaleDetail;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PayScaleDetailDA.Get(tc, id));
if (oreader.Read())
{
oPayScaleDetail = this.CreateObject<PayScaleDetail>(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(oPayScaleDetail, "Get", id);
#endregion
return oPayScaleDetail;
}
public ObjectsTemplate<PayScaleDetail> GetByPayScale(ID payscaleID)
{
#region Cache Header
ObjectsTemplate<PayScaleDetail> payScaleDetails = _cache["GetByPayScale", payscaleID] as ObjectsTemplate<PayScaleDetail>;
if (payScaleDetails != null)
return payScaleDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDetailDA.GetByPayScale(tc, payscaleID));
payScaleDetails = this.CreateObjects<PayScaleDetail>(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(payScaleDetails, "GetByPayScale", payscaleID);
#endregion
return payScaleDetails;
}
public ObjectsTemplate<PayScaleDetail> GetByGradeID(ID nGradeID, ID payrolltypeid)
{
#region Cache Header
ObjectsTemplate<PayScaleDetail> payScaleDetails = _cache["GetByGradeID", nGradeID] as ObjectsTemplate<PayScaleDetail>;
if (payScaleDetails != null)
return payScaleDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDetailDA.GetByGradeID(tc, nGradeID, payrolltypeid));
payScaleDetails = this.CreateObjects<PayScaleDetail>(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(payScaleDetails, "Get", nGradeID);
#endregion
return payScaleDetails;
}
public ObjectsTemplate<PayScaleDetail> Get(ID nGradeID, ID nAllowID)
{
#region Cache Header
ObjectsTemplate<PayScaleDetail> payScaleDetails = _cache["Get", nGradeID,nAllowID] as ObjectsTemplate<PayScaleDetail>;
if (payScaleDetails != null)
return payScaleDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDetailDA.Get(tc, nGradeID, nAllowID));
payScaleDetails = this.CreateObjects<PayScaleDetail>(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(payScaleDetails, "Get",nGradeID,nAllowID);
#endregion
return payScaleDetails;
}
public ObjectsTemplate<PayScaleDetail> Get()
{
#region Cache Header
ObjectsTemplate<PayScaleDetail> payScaleDetails = _cache["Get"] as ObjectsTemplate<PayScaleDetail>;
if (payScaleDetails != null)
return payScaleDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PayScaleDetailDA.Get(tc));
payScaleDetails = this.CreateObjects<PayScaleDetail>(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(payScaleDetails, "Get");
#endregion
return payScaleDetails;
}
public ID Save(PayScaleDetail oPayScaleDetail)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = tc.GenerateID("PayScaleDetail", "PayScaleDetailID");
base.SetObjectID(oPayScaleDetail, ID.FromInteger(id));
PayScaleDetailDA.Insert(tc, oPayScaleDetail);
tc.End();
return oPayScaleDetail.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);
PayScaleDetailDA.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
}