EchoTex_Payroll/HRM.DA/Service/Fund/Loan/FmLoanScheduleService.cs

255 lines
6.9 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using HRM.BO;
namespace HRM.DA
{
public class FmLoanScheduleService : ServiceTemplate //, ILoanScheduleService
{
public FmLoanScheduleService()
{
}
private void MapObject(FmLoanSchedule loanSchedule, DataReader dr)
{
base.SetObjectID(loanSchedule, dr.GetInt32("LoanScheduleID").Value);
loanSchedule.ActivityID = dr.GetInt32("ActivityID").Value;
loanSchedule.CustomerID = dr.GetInt32("CustomerID").Value;
loanSchedule.EffectiveBalance = dr.GetDouble("EffectiveBalance").Value;
loanSchedule.InstallmentAmount = dr.GetDouble("InstallmentAmount").Value;
loanSchedule.InstallmentInterest = dr.GetDouble("InstallmentInterest").Value;
loanSchedule.InstallmentPrincipal = dr.GetDouble("InstallmentPrincipal").Value;
loanSchedule.LoanCategoryID = dr.GetInt32("LoanCategoryID").Value;
loanSchedule.LoanID = dr.GetInt32("LoanID").Value;
loanSchedule.PayDate = dr.GetDateTime("PayDate").Value;
loanSchedule.ScheduledPayDate = dr.GetDateTime("ScheduledPayDate").Value;
loanSchedule.SerialNo = dr.GetInt32("SerialNo").Value;
loanSchedule.CreatedBy = dr.GetInt32("CreatedBy").Value;
loanSchedule.CreatedDate = dr.GetDateTime("CreatedDate").Value;
loanSchedule.ModifiedBy = dr.GetInt32("ModifiedBy");
loanSchedule.ModifiedDate = dr.GetDateTime("ModifiedDate").Value;
base.SetObjectState(loanSchedule, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
FmLoanSchedule loanSchedule = new FmLoanSchedule();
MapObject(loanSchedule, dr);
return loanSchedule as T;
}
protected FmLoanSchedule CreateObject(DataReader oReader)
{
FmLoanSchedule loanSchedule = new FmLoanSchedule();
MapObject(loanSchedule, oReader);
return loanSchedule;
}
#region Service Implementation
#region Insert
public void Save(FmLoanSchedule loanSchedule)
{
FmLoanSchedule oloanSchedule = new FmLoanSchedule();
oloanSchedule = loanSchedule;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oloanSchedule.IsNew)
{
int id = tc.GenerateID("FmLoan", "LoanID");
base.SetObjectID(oloanSchedule, id);
FmLoanScheduleDA.Insert(tc, oloanSchedule);
}
else
{
FmLoanScheduleDA.Update(tc, oloanSchedule);
}
tc.End();
//return oLoanTransaction.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LoanScheduleDA.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 Get(By loanScheduleID)
public FmLoanSchedule Get(int loanScheduleID)
{
FmLoanSchedule loanSchedule = new FmLoanSchedule();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FmLoanScheduleDA.Get(tc, loanScheduleID));
if (dr.Read())
{
loanSchedule = this.CreateObject<FmLoanSchedule>(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 loanSchedule;
}
#endregion
#region Get()
public List<FmLoanSchedule> Get()
{
List<FmLoanSchedule> loanSchedules = new List<FmLoanSchedule>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanScheduleDA.Get(tc));
loanSchedules = this.CreateObjects<FmLoanSchedule>(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 loanSchedules;
}
#endregion
#region GetTable
public DataTable GetTable()
{
DataTable dTbl = new DataTable("LoanSchedules");
//TransactionContext tc = null;
//try
//{
// tc = TransactionContext.Begin();
// IDataReader ir = LoanScheduleDA.Get(tc);
// dTbl.Load(ir);
// ir.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 dTbl;
}
#endregion
public bool GetSchedule(DateTime month)
{
bool exists = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
exists = FmLoanScheduleDA.GetSchedule(tc, month);
tc.End();
}
catch (Exception e)
{
throw e;
}
return exists;
}
#endregion
}
}