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

297 lines
7.7 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class LoanCustomerService : ServiceTemplate //, ILoanCustomerService
{
public LoanCustomerService()
{
}
private void MapObject(LoanCustomer loanCustomer, DataReader dr)
{
base.SetObjectID(loanCustomer, dr.GetInt32("CustomerID").Value);
loanCustomer.AccNo = dr.GetString("AccNo");
loanCustomer.Address = dr.GetString("Address");
loanCustomer.DateOfBirth = dr.GetDateTime("DateOfBirth").Value;
loanCustomer.DateOfJoining = dr.GetDateTime("DateOfJoining").Value;
loanCustomer.EmpCode = dr.GetString("EmpCode");
loanCustomer.IsMember = dr.GetBoolean("IsMember").Value;
loanCustomer.MemberShipNo = dr.GetString("MemberShipNo");
loanCustomer.Name = dr.GetString("Name");
loanCustomer.CreatedBy = dr.GetInt32("CreatedBy").Value;
loanCustomer.CreatedDate = dr.GetDateTime("CreatedDate").Value;
loanCustomer.ModifiedBy = dr.GetInt32("ModifiedBy");
loanCustomer.ModifiedDate = dr.GetDateTime("ModifiedDate");
loanCustomer.ProjectID = dr.GetInt32("ProjectID").Value;
loanCustomer.MemberID = dr.GetInt32("MemberID").Value;
loanCustomer.MembershipDate = dr.GetDateTime("MembershipDate");
loanCustomer.Email = dr.GetString("Email");
base.SetObjectState(loanCustomer, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
LoanCustomer loanCustomer = new LoanCustomer();
MapObject(loanCustomer, dr);
return loanCustomer as T;
}
protected LoanCustomer CreateObject(DataReader oReader)
{
LoanCustomer loanCustomer = new LoanCustomer();
MapObject(loanCustomer, oReader);
return loanCustomer;
}
#region Service Implementation
#region IsExist
public bool IsExist(int memberID)
{
bool exists = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
exists = LoanCustomerDA.IsExist(tc, memberID);
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to Check by ID" + e.Message, e);
}
return exists;
}
#endregion
#region Insert
public void Save(LoanCustomer loanCustomer)
{
LoanCustomer oLoanCustomer = new LoanCustomer();
oLoanCustomer = loanCustomer;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oLoanCustomer.IsNew)
{
int id = tc.GenerateID("LoanCustomer", "LoanCustomerID");
base.SetObjectID(oLoanCustomer, id);
LoanCustomerDA.Insert(tc, oLoanCustomer);
}
else
{
LoanCustomerDA.Update(tc, oLoanCustomer);
}
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 Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LoanCustomerDA.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 LoanCustomerID)
public LoanCustomer Get(int loanCustomerID)
{
LoanCustomer loanCustomer = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanCustomerDA.Get(tc, loanCustomerID));
if (dr.Read())
{
loanCustomer = this.CreateObject<LoanCustomer>(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 loanCustomer;
}
#endregion
#region Get()
public List<LoanCustomer> Get()
{
List<LoanCustomer> loanCustomers = new List<LoanCustomer>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanCustomerDA.Get(tc));
loanCustomers = this.CreateObjects<LoanCustomer>(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 loanCustomers;
}
#endregion
#region Get Customer By MemberID
public LoanCustomer GetByMemberID(int memberID)
{
LoanCustomer loanCustomer = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LoanCustomerDA.GetByMemberID(tc, memberID));
if (dr.Read())
{
loanCustomer = this.CreateObject<LoanCustomer>(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 loanCustomer;
}
#endregion
#region GetTable
public DataTable GetTable()
{
DataTable dTbl = new DataTable("LoanCustomers");
//TransactionContext tc = null;
//try
//{
// tc = TransactionContext.Begin();
// IDataReader ir = LoanCustomerDA.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
#endregion
}
}