EchoTex_Payroll/HRM.DA/Service/Claim/ClaimPaymentService.cs
2024-10-14 10:01:49 +06:00

297 lines
11 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using Ease.Core.Utility;
namespace Payroll.Service
{
#region ClaimPaymentService Service
public class ClaimPaymentService : ServiceTemplate, IClaimPaymentService
{
public ClaimPaymentService() { }
private void MapObject(ClaimPayment oClaimPayment, DataReader oReader)
{
base.SetObjectID(oClaimPayment,oReader.GetInt32("ClaimPaymentID").Value);
oClaimPayment.IsAnnualDisbursment = oReader.GetBoolean("IsAnnualDisbursment", false);
oClaimPayment.IsActualPayment = oReader.GetBoolean("IsActualPayment", false);
oClaimPayment.IsNotMaximum = oReader.GetBoolean("IsNotMaximum", false);
oClaimPayment.ClaimType = (EnumClaimType)oReader.GetInt32("ClaimType").Value;
oClaimPayment.MaxServiceLength = oReader.GetDouble("MaxServiceLength") == null ? 0.0 : oReader.GetDouble("MaxServiceLength").Value;
oClaimPayment.MonthDifference = oReader.GetInt32("MonthDifference").Value;
oClaimPayment.NoOfDependent = oReader.GetInt32("NoOfDependent").Value;
oClaimPayment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oClaimPayment.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oClaimPayment.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oClaimPayment.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value;
oClaimPayment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oClaimPayment.PayrollTypeID = oReader.GetString("PayrollTypeID") == null ? null : oReader.GetInt32("PayrollTypeID").Value;
this.SetObjectState(oClaimPayment, Ease.Core.ObjectState.Saved);
}
private void MapChildObject(ClaimPaymentGrades oClaimPaymentGrade, DataReader oReader)
{
base.SetObjectID(oClaimPaymentGrade, oReader.GetInt32("ClaimPaymentGradesID").Value);
oClaimPaymentGrade.ClaimPaymentID = oReader.GetInt32("ClaimPaymentID") == null ? 0 : oReader.GetInt32("ClaimPaymentID").Value;
oClaimPaymentGrade.GradeID = oReader.GetInt32("GradeID") == null ? 0 : oReader.GetInt32("GradeID").Value;
oClaimPaymentGrade.Amount = oReader.GetDouble("Amount") == null ? 0.0 : oReader.GetDouble("Amount").Value;
this.SetObjectState(oClaimPaymentGrade, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ClaimPayment oClaimPayment = new ClaimPayment();
MapObject(oClaimPayment, oReader);
return oClaimPayment as T;
}
protected ClaimPayment CreateObject(DataReader oReader)
{
ClaimPayment oClaimPayment = new ClaimPayment();
MapObject(oClaimPayment, oReader);
return oClaimPayment;
}
private List<ClaimPaymentGrades> CreateChilds(DataReader oReader)
{
List<ClaimPaymentGrades> oClaimPaymentGrades = new List<ClaimPaymentGrades>();
ClaimPaymentGrades oClaimPaymentGrade;
while (oReader.Read())
{
oClaimPaymentGrade = new ClaimPaymentGrades();
oClaimPaymentGrade = CreateChild(oReader);
oClaimPaymentGrades.Add(oClaimPaymentGrade);
}
return oClaimPaymentGrades;
}
private ClaimPaymentGrades CreateChild(DataReader oReader)
{
ClaimPaymentGrades oClaimPaymentGrades = new ClaimPaymentGrades();
MapChildObject(oClaimPaymentGrades, oReader);
return oClaimPaymentGrades;
}
#region Service implementation
public ClaimPayment Get(int id)
{
ClaimPayment oClaimPayment = new ClaimPayment();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ClaimPaymentDA.Get(tc, id));
if (oreader.Read())
{
oClaimPayment = this.CreateObject<ClaimPayment>(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 oClaimPayment;
}
public List<ClaimPayment> Get(EnumStatus status, int payrollTypeID)
{
#region Cache Header
List<ClaimPayment> attnNationalHolidays =null;
//if (attnNationalHolidays != null)
// return attnNationalHolidays;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimPaymentDA.Get(tc, status, payrollTypeID));
attnNationalHolidays = this.CreateObjects<ClaimPayment>(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 attnNationalHolidays;
}
public List<ClaimPaymentGrades> GetClaimPaymentGrades(int attnNationalHolidayID)
{
List<ClaimPaymentGrades> oClaimPaymentGrades = new List<ClaimPaymentGrades>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ClaimPaymentDA.GetChild(tc, attnNationalHolidayID));
oClaimPaymentGrades = this.CreateChilds(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 oClaimPaymentGrades;
}
public void Save(List<ClaimPayment> oClaimPayments)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int ClaimPaymentID = tc.GenerateID("ClaimPayment", "ClaimPaymentID");
int ClaimPaymentGradesID = tc.GenerateID("ClaimPaymentGrades", "ClaimPaymentGradesID");
foreach (ClaimPayment oClaimPayment in oClaimPayments)
{
if (oClaimPayment.IsNew)
{
base.SetObjectID(oClaimPayment, ClaimPaymentID);
ClaimPaymentDA.Insert(tc, oClaimPayment);
ClaimPaymentID++;
}
else
{
ClaimPaymentDA.Update(tc, oClaimPayment);
ClaimPaymentDA.DeleteChild(tc, oClaimPayment.ID);
}
foreach (ClaimPaymentGrades item in oClaimPayment.ClaimPaymentGrades)
{
base.SetObjectID(item, ClaimPaymentGradesID);
item.ClaimPaymentID = oClaimPayment.ID;
ClaimPaymentDA.InsertChild(tc, item);
ClaimPaymentGradesID++;
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(ClaimPayment oClaimPayment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oClaimPayment.IsNew)
{
int id = tc.GenerateID("ClaimPayment", "ClaimPaymentID");
base.SetObjectID(oClaimPayment, id);
ClaimPaymentDA.Insert(tc, oClaimPayment);
}
else
{
ClaimPaymentDA.Update(tc, oClaimPayment);
ClaimPaymentDA.DeleteChild(tc, oClaimPayment.ID);
}
foreach (ClaimPaymentGrades item in oClaimPayment.ClaimPaymentGrades)
{
int id = tc.GenerateID("ClaimPaymentGrades", "ClaimPaymentGradesID");
base.SetObjectID(item, id);
item.ClaimPaymentID = oClaimPayment.ID;
ClaimPaymentDA.InsertChild(tc, item);
}
tc.End();
return oClaimPayment.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void DeleteByType(EnumClaimType claimType)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ClaimPaymentDA.DeleteChildByType(tc, claimType);
ClaimPaymentDA.DeleteByType(tc, claimType);
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 Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ClaimPaymentDA.DeleteChild(tc, id);
ClaimPaymentDA.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
}