EchoTex_Payroll/HRM.DA/Service/Fund/Investment/InvestmentTranService.cs

345 lines
9.6 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
using HRM.DA;
namespace HRM.DA.Fund
{
#region InvestmentTran Service
[Serializable]
public class InvestmentTranService : ServiceTemplate
{
#region Private functions and declaration
public InvestmentTranService()
{
}
private void MapObject(InvestmentTran oInvestmentTran, DataReader oReader)
{
oInvestmentTran.ActivityID = oReader.GetInt32("ActivityID").Value;
oInvestmentTran.TranTypeID = oReader.GetInt32("TranTypeID").Value;
oInvestmentTran.CategoryID = oReader.GetInt32("CategoryID").Value;
oInvestmentTran.InvestmentID = oReader.GetInt32("InvestmentID").Value;
oInvestmentTran.TemplateVoucherID = oReader.GetInt32("TemplateVoucherID").Value;
oInvestmentTran.ProjectID = oReader.GetInt32("ProjectID").Value;
oInvestmentTran.TranDate = oReader.GetDateTime("TranDate").Value;
oInvestmentTran.PrincipalAmount = oReader.GetDouble("Amount").Value;
base.SetObjectID(oInvestmentTran, oReader.GetInt32("TranID").Value);
//BusinessObject.Factory.SetID(oInvestmentTran, new ID(oReader.Getint("TranID")));
oInvestmentTran.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oInvestmentTran.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oInvestmentTran.ModifiedBy = oReader.GetInt32("ModifiedBy").Value != null
? oReader.GetInt32("ModifiedBy").Value
: (0);
oInvestmentTran.ModifiedDate = oReader.GetDateTime("ModifiedDate") != null
? oReader.GetDateTime("ModifiedDate").Value
: DateTime.MinValue;
base.SetObjectState(oInvestmentTran, ObjectState.Modified);
//BusinessObject.Factory.SetObjectState(oInvestmentTran, ObjectState.Saved);
}
private InvestmentTran CreateObject(DataReader oReader)
{
InvestmentTran oInvestmentTran = new InvestmentTran();
MapObject(oInvestmentTran, oReader);
return oInvestmentTran;
}
#endregion
#region Service implementation
public InvestmentTran Get(int id)
{
InvestmentTran oInvestmentTran = new InvestmentTran();
#region Cache Header
oInvestmentTran = new InvestmentTran();
if (oInvestmentTran != null)
return oInvestmentTran;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader oreader = InvestmentTranDA.Get(tc, id);
DataReader oReader = new DataReader(oreader);
if (oreader.Read())
{
oInvestmentTran = CreateObject(oReader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetInvestmentTran", e);
#endregion
}
#region Cache Footer
#endregion
return oInvestmentTran;
}
public List<InvestmentTran> Get(InvestmentInfo investmentInfo)
{
#region Cache Header
List<InvestmentTran> items = new List<InvestmentTran>();
if (items != null)
return items;
#endregion
items = new List<InvestmentTran>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(InvestmentTranDA.Get(tc, investmentInfo));
while (dataReader.Read())
{
InvestmentTran item = this.CreateObject(dataReader);
items.Add(item);
}
dataReader.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
#endregion
return items;
}
public List<InvestmentTran> Get(TransactionContext tc, InvestmentInfo investmentInfo)
{
#region Cache Header
List<InvestmentTran> items = new List<InvestmentTran>();
if (items != null)
return items;
#endregion
items = new List<InvestmentTran>();
try
{
DataReader dataReader = new DataReader(InvestmentTranDA.Get(tc, investmentInfo));
while (dataReader.Read())
{
InvestmentTran item = this.CreateObject(dataReader);
items.Add(item);
}
dataReader.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
#region Cache Footer
#endregion
return items;
}
public DataTable GetTable(int fundtypeid)
{
DataTable dataTable = new DataTable("InvestmentTran");
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader iDataReader = InvestmentTranDA.Get(tc, fundtypeid);
dataTable.Load(iDataReader);
iDataReader.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 dataTable;
}
public List<InvestmentTran> Getbyfundtype(int fundtypeid)
{
#region Cache Header
List<InvestmentTran> items = new List<InvestmentTran>();
if (items != null)
return items;
#endregion
items = new List<InvestmentTran>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(InvestmentTranDA.Get(tc, fundtypeid));
while (dataReader.Read())
{
InvestmentTran item = this.CreateObject(dataReader);
items.Add(item);
}
dataReader.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
#endregion
return items;
}
protected override T CreateObject<T>(DataReader dataReader)
{
InvestmentTran oInvestmentTran = new InvestmentTran();
MapObject(oInvestmentTran, dataReader);
return oInvestmentTran as T;
}
public void Save(InvestmentTran oInvestmentTran)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oInvestmentTran.IsNew)
{
int id = tc.GenerateID("InvestmentTran", "ID");
base.SetObjectID(oInvestmentTran, (id));
InvestmentTranDA.Insert(tc, oInvestmentTran);
//BusinessObject.Factory.SetID(oInvestmentTran, new ID(DAInvestmentTran.GetNewID(tc)));
//DAInvestmentTran.Insert(tc, oInvestmentTran);
}
else
{
InvestmentTranDA.Update(tc, oInvestmentTran);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetInvestmentTran", e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
InvestmentTranDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetInvestmentTran", e);
#endregion
}
}
#endregion
}
#endregion
}