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

345 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region LoanParameter Service
[Serializable]
public class LoanParameterService : ServiceTemplate, ILoanParameterService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(LoanParameter));
Cache _loanGrade = new Cache(typeof(LoanGrades));
Cache _loanDocCache = new Cache(typeof(LoanDoc));
#endregion
public LoanParameterService() { }
#region MapObject For LoanParameter
private void MapObject(LoanParameter oLoanParameter, DataReader oReader)
{
base.SetObjectID(oLoanParameter, oReader.GetID("LoanParameterID"));
oLoanParameter.LoanID = oReader.GetID("LoanID");
oLoanParameter.NoOfGross = oReader.GetDouble("NoOfGross").Value;
oLoanParameter.NoOfBasic = oReader.GetDouble("NoOfBasic").Value;
oLoanParameter.MinInstallmentMonth = oReader.GetInt32("MinInstallmentMonth").Value;
oLoanParameter.MaxInstallmentMonth = oReader.GetInt32("MaxInstallmentMonth").Value;
oLoanParameter.MinReconcileMonth = oReader.GetInt32("MinReconcileMonth").Value;
oLoanParameter.CreatedBy = oReader.GetID("CreatedBy");
oLoanParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oLoanParameter.ModifiedBy = oReader.GetID("ModifiedBy");
oLoanParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oLoanParameter.MinFlatAmount = oReader.GetDouble("MinFlatAmount").Value;
oLoanParameter.MaxFlatAmount = oReader.GetDouble("MaxFlatAmount").Value;
this.SetObjectState(oLoanParameter, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LoanParameter oLoanParameter = new LoanParameter();
MapObject(oLoanParameter, oReader);
return oLoanParameter as T;
}
protected LoanParameter CreateObject(DataReader oReader)
{
LoanParameter oLoanParameter = new LoanParameter();
MapObject(oLoanParameter, oReader);
return oLoanParameter;
}
#endregion
#region MapObject For LoanGrades
private void MapLoanGrades(LoanGrades oLoanGrades, DataReader oReader)
{
base.SetObjectID(oLoanGrades, oReader.GetID("LoanGradesID"));
oLoanGrades.LoanID = oReader.GetID("LoanID");
oLoanGrades.LoanParameterID = oReader.GetID("LoanParameterID");
oLoanGrades.GradeID = oReader.GetID("GradeID");
this.SetObjectState(oLoanGrades, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<LoanGrades> CreateLoanGradesObject(DataReader oReader)
{
ObjectsTemplate<LoanGrades> oLoanGrades = new ObjectsTemplate<LoanGrades>();
while (oReader.Read())
{
LoanGrades oLoanGrade = new LoanGrades();
MapLoanGrades(oLoanGrade, oReader);
oLoanGrades.Add(oLoanGrade);
}
return oLoanGrades;
}
#endregion
#region MaoObject For LoanDoc
private void MapLoanDocs(LoanDoc oLoanDocs, DataReader oReader)
{
base.SetObjectID(oLoanDocs, oReader.GetID("LoanDocsID"));
oLoanDocs.HRDocID = oReader.GetID("HRDocID");
oLoanDocs.LoanID = oReader.GetID("LoanID");
oLoanDocs.LoanParameterID = oReader.GetID("LoanParameterID");
this.SetObjectState(oLoanDocs, Ease.CoreV35.ObjectState.Saved);
}
protected ObjectsTemplate<LoanDoc> CreateLoanDocsObject(DataReader oReader)
{
ObjectsTemplate<LoanDoc> oLoanDocs = new ObjectsTemplate<LoanDoc>();
while (oReader.Read())
{
LoanDoc oLoanDoc = new LoanDoc();
MapLoanDocs(oLoanDoc, oReader);
oLoanDocs.Add(oLoanDoc);
}
return oLoanDocs;
}
#endregion
#region Implement LoanParameter Service
public LoanParameter Get(ID id)
{
LoanParameter oLoanParameter = new LoanParameter();
#region Cache Header
oLoanParameter = _cache["Get", id] as LoanParameter;
if (oLoanParameter != null)
return oLoanParameter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(LoanParameterDA.Get(tc, id));
if (oreader.Read())
{
oLoanParameter = this.CreateObject<LoanParameter>(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(oLoanParameter, "Get", id);
#endregion
return oLoanParameter;
}
public ObjectsTemplate<LoanParameter> Get()
{
#region Cache Header
ObjectsTemplate<LoanParameter> LoanParameters = _cache["Get"] as ObjectsTemplate<LoanParameter>;
if (LoanParameters != null)
return LoanParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanParameterDA.Get(tc));
LoanParameters = this.CreateObjects<LoanParameter>(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(LoanParameters, "Get");
#endregion
return LoanParameters;
}
public ID Save(LoanParameter oLoanParameter)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoanParameter.IsNew)
{
int id = tc.GenerateID("LoanParameter", "LoanParameterID");
base.SetObjectID(oLoanParameter, ID.FromInteger(id));
LoanParameterDA.Insert(tc, oLoanParameter);
}
else
{
LoanParameterDA.Update(tc, oLoanParameter);
LoanParameterDA.DeleteLoanGrade(tc, oLoanParameter.ID.Integer);
LoanParameterDA.DeleteLoanDoc(tc,oLoanParameter.ID.Integer);
}
foreach (LoanGrades oLoanGrades in oLoanParameter.LoadGradesTemp)
{
oLoanGrades.LoanParameterID = oLoanParameter.ID;
oLoanGrades.LoanID = oLoanParameter.LoanID;
int loanGradeId = tc.GenerateID("LoanGrades", "LoanGradesID");
base.SetObjectID(oLoanGrades, ID.FromInteger(loanGradeId));
LoanParameterDA.InsertLoadGrades(tc, oLoanGrades);
}
foreach(LoanDoc docItem in oLoanParameter.LoadDocsTemp)
{
docItem.LoanParameterID = oLoanParameter.ID;
docItem.LoanID = oLoanParameter.LoanID;
int loanDocID = tc.GenerateID("LoanDocs", "LoanDocsID");
base.SetObjectID(docItem,ID.FromInteger(loanDocID));
LoanParameterDA.InsertDocItem(tc,docItem);
}
tc.End();
return oLoanParameter.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);
LoanParameterDA.DeleteLoanGrade(tc,id.Integer);
LoanParameterDA.DeleteLoanDoc(tc,id.Integer);
LoanParameterDA.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
#region Implement LoanGrade Service
public ObjectsTemplate<LoanGrades> GetLoanGrades(int loanParameterID)
{
#region Cache Header
ObjectsTemplate<LoanGrades> loanGradess = _loanGrade["Get"] as ObjectsTemplate<LoanGrades>;
if (loanGradess != null)
return loanGradess;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanParameterDA.GetLoanGrades(tc,loanParameterID));
loanGradess = this.CreateLoanGradesObject(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
_loanGrade.Add(loanGradess, "Get");
#endregion
return loanGradess;
}
public ObjectsTemplate<LoanDoc> GetLoanDoc(int loanParameterID)
{
#region Cache Header
ObjectsTemplate<LoanDoc> loanDocs = _loanDocCache["Get"] as ObjectsTemplate<LoanDoc>;
if (loanDocs != null)
return loanDocs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanParameterDA.GetLoanDoc(tc, loanParameterID));
loanDocs = this.CreateLoanDocsObject(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
_loanDocCache.Add(loanDocs, "Get");
#endregion
return loanDocs;
}
#endregion
}
#endregion
}