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

260 lines
7.9 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
{
public class InvestmentScheduleService : ServiceTemplate
{
#region Private functions and declaration
public InvestmentScheduleService()
{
}
private void MapObject(InvestmentSchedule oInvestmentSchedule, DataReader oReader)
{
oInvestmentSchedule.FromDate = oReader.GetDateTime("FromDate").Value;
base.SetObjectID(oInvestmentSchedule, oReader.GetInt32("ID").Value);
//BusinessObject.Factory.SetID(oInvestmentSchedule, new ID(oReader.Getint("ID")));
oInvestmentSchedule.InvestmentID = oReader.GetInt32("InvestmentID").Value;
oInvestmentSchedule.ProjectID = oReader.GetInt32("ProjectID").Value;
oInvestmentSchedule.Percentage = oReader.GetFloat("Percentage").Value;
oInvestmentSchedule.RecalculationNeeded = oReader.GetBoolean("RecalculationNeeded").Value;
oInvestmentSchedule.TillDate = oReader.GetDateTime("TillDate").Value;
oInvestmentSchedule.TranDate = oReader.GetDateTime("TranDate").Value;
oInvestmentSchedule.CreatedBy = oReader.GetInt32("CreatedBy").Value;
oInvestmentSchedule.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oInvestmentSchedule.ModifiedBy = oReader.GetInt32("ModifiedBy").Value != null
? oReader.GetInt32("ModifiedBy").Value
: (0);
oInvestmentSchedule.ModifiedDate = oReader.GetDateTime("ModifiedDate") != null
? oReader.GetDateTime("ModifiedDate").Value
: DateTime.MinValue;
base.SetObjectState(oInvestmentSchedule, ObjectState.Modified);
//BusinessObject.Factory.SetObjectState(oInvestmentSchedule, ObjectState.Saved);
}
private InvestmentSchedule CreateObject(DataReader oReader)
{
InvestmentSchedule oInvestmentSchedule = new InvestmentSchedule();
MapObject(oInvestmentSchedule, oReader);
return oInvestmentSchedule;
}
//private InvestmentSchedules CreateObjects(IDataReader oReader)
//{
// InvestmentSchedules oInvestmentSchedules = new InvestmentSchedules();
// DataReader oreader = new DataReader(oReader);
// while (oReader.Read())
// {
// oInvestmentSchedule oItem = CreateObject(oreader);
// oInvestmentSchedules.Add(oItem);
// }
// return oInvestmentSchedules;
//}
#endregion
#region Service implementation
public InvestmentSchedule Get(int id)
{
InvestmentSchedule oInvestmentSchedule = new InvestmentSchedule();
#region Cache Header
oInvestmentSchedule = new InvestmentSchedule();
if (oInvestmentSchedule != null)
return oInvestmentSchedule;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader oreader = InvestmentScheduleDA.Get(tc, id);
DataReader oReader = new DataReader(oreader);
if (oreader.Read())
{
oInvestmentSchedule = 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 GetInvestmentSchedule", e);
#endregion
}
#region Cache Footer
#endregion
return oInvestmentSchedule;
}
public List<InvestmentSchedule> GetbyFundtype(int fundtypeid)
{
#region Cache Header
List<InvestmentSchedule> items = new List<InvestmentSchedule>();
if (items != null)
return items;
#endregion
items = new List<InvestmentSchedule>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dataReader = new DataReader(InvestmentScheduleDA.Getbyfundtype(tc, fundtypeid));
while (dataReader.Read())
{
InvestmentSchedule 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 DataTable GetTable(int fundtypeid)
{
DataTable dataTable = new DataTable("InvestmentSchedule");
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader iDataReader = InvestmentScheduleDA.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;
}
protected override T CreateObject<T>(DataReader dataReader)
{
InvestmentSchedule investmentSchedule = new InvestmentSchedule();
MapObject(investmentSchedule, dataReader);
return investmentSchedule as T;
}
public void Save(InvestmentSchedule oInvestmentSchedule)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oInvestmentSchedule.IsNew)
{
int id = tc.GenerateID("InvestmentSchedule", "ID");
base.SetObjectID(oInvestmentSchedule, (id));
InvestmentScheduleDA.Insert(tc, oInvestmentSchedule);
//BusinessObject.Factory.SetID(oInvestmentSchedule, new ID(DAInvestmentSchedule.GetNewID(tc)));
//InvestmentScheduleDA.Insert(tc, oInvestmentSchedule);
}
else
{
InvestmentScheduleDA.Update(tc, oInvestmentSchedule);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetInvestmentSchedule", e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
InvestmentScheduleDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetInvestmentSchedule", e);
#endregion
}
}
#endregion
}
}