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

171 lines
5.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
{
public class PremiumProcessDetailService : ServiceTemplate, IPremiumProcessDetailService
{
private void MapObject(PremiumProcessDetail oPremiumProcess, DataReader oReader)
{
this.SetObjectID(oPremiumProcess, oReader.GetID("PremiumProcessDetailID"));
oPremiumProcess.EmployeeID = oReader.GetID("EmployeeID");
oPremiumProcess.PremiumProcessID = oReader.GetID("PremiumProcessID");
oPremiumProcess.Gross = oReader.GetDouble("Gross").HasValue ? oReader.GetDouble("Gross").Value : 0;
oPremiumProcess.Basic = oReader.GetDouble("Basic").HasValue ? oReader.GetDouble("Basic").Value : 0;
oPremiumProcess.AssuredAmount = oReader.GetDouble("AssuredAmount").HasValue ? oReader.GetDouble("AssuredAmount").Value : 0;
oPremiumProcess.PremiumAmount = oReader.GetDouble("PremiumAmount").HasValue ? oReader.GetDouble("PremiumAmount").Value : 0;
this.SetObjectState(oPremiumProcess, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PremiumProcessDetail oPremiumProcess = new PremiumProcessDetail();
MapObject(oPremiumProcess, oReader);
return oPremiumProcess as T;
}
protected PremiumProcessDetail CreateObject(DataReader oReader)
{
PremiumProcessDetail oPremiumProcess = new PremiumProcessDetail();
MapObject(oPremiumProcess, oReader);
return oPremiumProcess;
}
public PremiumProcessDetail Get(ID id)
{
PremiumProcessDetail oPremiumProcess = new PremiumProcessDetail();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(PremiumProcessDetailDA.Get(tc, id));
if (oReader.Read())
{
oPremiumProcess = 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 oPremiumProcess;
}
public ObjectsTemplate<PremiumProcessDetail> Get()
{
ObjectsTemplate<PremiumProcessDetail> oPremiumProcesses = new ObjectsTemplate<PremiumProcessDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PremiumProcessDetailDA.Get(tc));
oPremiumProcesses = this.CreateObjects<PremiumProcessDetail>(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 oPremiumProcesses;
}
public ID Save(PremiumProcessDetail oPremiumProcess)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPremiumProcess.IsNew)
{
int id = tc.GenerateID("PremiumProcessDetail", "PremiumProcessDetailID");
base.SetObjectID(oPremiumProcess, ID.FromInteger(id));
PremiumProcessDetailDA.Insert(tc, oPremiumProcess);
}
else
{
PremiumProcessDetailDA.Update(tc, oPremiumProcess);
}
tc.End();
return oPremiumProcess.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);
PremiumProcessDetailDA.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 ObjectsTemplate<PremiumProcessDetail> GetDetails(ID id)
{
ObjectsTemplate<PremiumProcessDetail> oPremiumProcesses = new ObjectsTemplate<PremiumProcessDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PremiumProcessDetailDA.GetDetails(tc,id));
oPremiumProcesses = this.CreateObjects<PremiumProcessDetail>(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 oPremiumProcesses;
}
}
}