HRM-10/HRM.DA/Service/Fund/Basic/FundBranchService.cs

245 lines
6.9 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
using System;
using System.Collections.Generic;
namespace HRM.DA
{
public class FundBranchService : ServiceTemplate, IFundBranchService
{
private void MapObject(FundBranch oFundBranch, DataReader oReader)
{
base.SetObjectID(oFundBranch, oReader.GetInt32("BRANCHID").Value);
oFundBranch.Code = oReader.GetString("BRANCHCODE");
oFundBranch.Name = oReader.GetString("BRANCHNAME");
oFundBranch.Address = oReader.GetString("ADDRESS");
oFundBranch.BankID = oReader.GetInt32("BANKID").Value;
oFundBranch.Telephone = oReader.GetString("CONTACTNO");
oFundBranch.FaxNo = oReader.GetString("FAX");
oFundBranch.RoutingNo = oReader.GetInt32("RoutingNo").Value;
oFundBranch.FundTypeID = oReader.GetInt32("FundTypeID").Value;
}
protected override T CreateObject<T>(DataReader dr)
{
FundBranch oFundBranch = new FundBranch();
MapObject(oFundBranch, dr);
return oFundBranch as T;
}
protected FundBranch CreateObject(DataReader oReader)
{
FundBranch oBranch = new FundBranch();
MapObject(oBranch, oReader);
return oBranch;
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FundBranchDA.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 FundBranch Get(int id)
{
FundBranch oFundBranch = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(FundBranchDA.Get(tc, id));
if (oreader.Read())
{
oFundBranch = this.CreateObject<FundBranch>(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 oFundBranch;
}
public List<FundBranch> GetFundbranches(EnumStatus status)
{
List<FundBranch> oFundBranch = new List<FundBranch>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FundBranchDA.Get(tc));
oFundBranch = this.CreateObjects<FundBranch>(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 oFundBranch;
}
public string GetNextCode()
{
throw new NotImplementedException();
}
public int Save(FundBranch oBranch)
{
TransactionContext tc = null;
try
{
int nID = oBranch.ID;
tc = TransactionContext.Begin(true);
if (oBranch.IsNew)
{
int id = tc.GenerateID("FM_BRANCH", "BranchID");
base.SetObjectID(oBranch, id);
FundBranchDA.Insert(tc, oBranch);
}
else
{
FundBranchDA.Update(tc, oBranch);
}
tc.End();
return oBranch.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<FundBranch> Get()
{
List<FundBranch> banks = new List<FundBranch>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FundBranchDA.Get(tc));
banks = this.CreateObjects<FundBranch>(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 banks;
}
public List<FundBranch> GetBranchByFundTypeID(int fundTypeID)
{
List<FundBranch> banks = new List<FundBranch>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FundBranchDA.GetByFundTypeID(tc,fundTypeID));
banks = this.CreateObjects<FundBranch>(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 banks;
}
public List<FundBranch> GetBranchByBankID(int bankID)
{
List<FundBranch> banks = new List<FundBranch>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FundBranchDA.GetByBankID(tc, bankID));
banks = this.CreateObjects<FundBranch>(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 banks;
}
}
}