HRM-10/HRM.DA/Service/Fund/VoucherSetup/RDReportRowService.cs

250 lines
9.6 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
using Ease.Core.DataAccess;
using Ease.Core;
using Ease.Core.Model;
using HRM.BO;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ease.Core.Utility;
namespace HRM.DA
{
public class RDReportRowService : ServiceTemplate, IRDReportRowService
{
public RDReportRowService() { }
private void MapObject(RDReportRow oRDReportRow, DataReader oReader)
{
base.SetObjectID(oRDReportRow, oReader.GetInt32("COLRowID").Value);
oRDReportRow.RowCode = oReader.GetString("RowCode");
oRDReportRow.RowDescription = oReader.GetString("RowDescription");
oRDReportRow.Note = oReader.GetString("Note");
oRDReportRow.ReportID = oReader.GetInt32("ReportID").Value;
oRDReportRow.SerialNo = oReader.GetInt32("SerialNo").Value;
oRDReportRow.RowType = (EnumRowType)oReader.GetInt32("RowType");
oRDReportRow.AmountFrom = (EnumAmountFrom)oReader.GetInt32("AmountFrom");
oRDReportRow.FromOtherSourceType = (EnumFromOtherSourceType)oReader.GetInt32("FromOtherSourceType");
oRDReportRow.FromOtherSourceOperator = (EnumOperator)oReader.GetInt32("FromOtherSourceOperator");
base.SetObjectState(oRDReportRow, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
RDReportRow oRDReportRow = new RDReportRow();
MapObject(oRDReportRow, oReader);
return oRDReportRow as T;
}
public RDReportRow Get(int id)
{
RDReportRow oRDReportRow = new RDReportRow();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(RDReportRowDA.Get(tc, id));
if (oReader.Read())
{
oRDReportRow = CreateObject<RDReportRow>(oReader);
}
oReader.Close();
tc.End();
if (oRDReportRow.ID>0)
{
if (oRDReportRow.AmountFrom == EnumAmountFrom.FromGL)
{
oRDReportRow.RDRowAmountCalItems = new RDRowAmountCalItemService().GetByRowID(oRDReportRow.ID);
}
else
{
oRDReportRow.RowSumCalcItems = new RowSumCalcItemService().GetByRowID(oRDReportRow.ID);
}
}
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetRDReportRow", e);
#endregion
}
return oRDReportRow;
}
public List<RDReportRow> GetByReoprtIDAndFundTypeID(int nReportID, int fundTypeID)
{
List<RDReportRow> oRDReportRows = new List<RDReportRow>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(RDReportRowDA.GetByReoprtIDAndFundTypeID(tc, nReportID, fundTypeID));
oRDReportRows = this.CreateObjects<RDReportRow>(oReader);
oReader.Close();
tc.End();
foreach (RDReportRow oItem in oRDReportRows)
{
if (oItem.AmountFrom == EnumAmountFrom.FromGL)
{
oItem.RDRowAmountCalItems = new RDRowAmountCalItemService().GetByRowID(oItem.ID);
}
else
{
oItem.RowSumCalcItems = new RowSumCalcItemService().GetByRowID(oItem.ID);
}
//oItem.RowSumCalcItems = new RowSumCalcItemService().GetByRowID(oItem.ID);
}
}
catch (Exception e)
{
throw new ServiceException("Failed to Get RDReportRow", e);
}
return oRDReportRows;
}
public List<RDReportRow> GetByReoprtID(int nReportID)
{
List<RDReportRow> oRDReportRows = new List<RDReportRow>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oReader = new DataReader(RDReportRowDA.GetByReoprtID(tc, nReportID));
oRDReportRows = CreateObjects<RDReportRow>(oReader);
foreach (RDReportRow oItem in oRDReportRows)
{
if (oItem.AmountFrom == EnumAmountFrom.FromGL)
{
oItem.RDRowAmountCalItems = new RDRowAmountCalItemService().GetByRowID((int)oItem.ID);
}
else
{
oItem.RowSumCalcItems = new RowSumCalcItemService().GetByRowID(oItem.ID);
}
}
oReader.Close();
tc.End();
}
catch (Exception e)
{
throw new ServiceException("Failed to Get RDReportRow", e);
}
return oRDReportRows;
}
public int Save(RDReportRow oRDReportRow)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oRDReportRow.IsNew)
{
int id = tc.GenerateID("FM_RDReportRow", "COLRowID");
this.SetObjectID(oRDReportRow, id);
oRDReportRow.SerialNo = RDReportRowDA.GetSerialNo(tc);
RDReportRowDA.Insert(tc, oRDReportRow);
RDRowAmountCalItemDA.DeleteByRowID(tc, oRDReportRow.ID);
if (oRDReportRow.RDRowAmountCalItems.Count > 0)
{
foreach (RDRowAmountCalItem oItem in oRDReportRow.RDRowAmountCalItems)
{
oItem.RowID = oRDReportRow.ID;
int rowcalid = tc.GenerateID("FM_RDRowAmountCalItem", "RowAmountCalID");
this.SetObjectID(oItem, rowcalid);
RDRowAmountCalItemDA.Insert(tc, oItem);
}
}
RowSumCalcItemDA.DeleteByRowID(tc, oRDReportRow.ID);
if (oRDReportRow.RowSumCalcItems.Count > 0)
{
foreach (RowSumCalcItem oItem in oRDReportRow.RowSumCalcItems)
{
oItem.CalcRowID = oRDReportRow.ID;
int rowcalSumid = tc.GenerateID("FM_RowSumCalcItem", "RowSumCalcItemID");
this.SetObjectID(oItem, rowcalSumid);
RowSumCalcItemDA.Insert(tc, oItem);
}
}
}
else
{
RDReportRowDA.Update(tc, oRDReportRow);
RDRowAmountCalItemDA.DeleteByRowID(tc, oRDReportRow.ID);
if (oRDReportRow.RDRowAmountCalItems!=null && oRDReportRow.RDRowAmountCalItems.Count > 0)
{
foreach (RDRowAmountCalItem oItem in oRDReportRow.RDRowAmountCalItems)
{
oItem.RowID = oRDReportRow.ID;
int rowcalid = tc.GenerateID("FM_RDRowAmountCalItem", "RowAmountCalID");
this.SetObjectID(oItem, rowcalid);
RDRowAmountCalItemDA.Insert(tc, oItem);
}
}
RowSumCalcItemDA.DeleteByRowID(tc, oRDReportRow.ID);
if (oRDReportRow.RowSumCalcItems != null && oRDReportRow.RowSumCalcItems.Count > 0)
{
foreach (RowSumCalcItem oItem in oRDReportRow.RowSumCalcItems)
{
oItem.CalcRowID = oRDReportRow.ID;
int rowcalSumid = tc.GenerateID("FM_RowSumCalcItem", "RowSumCalcItemID");
this.SetObjectID(oItem, rowcalSumid);
RowSumCalcItemDA.Insert(tc, oItem);
}
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Save RDReportRow", e);
#endregion
}
return oRDReportRow.ID;
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
RDRowAmountCalItemDA.DeleteByRowID(tc, id);
RowSumCalcItemDA.DeleteByRowID(tc, id);
RDReportRowDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Deleste RDReportRow", e);
#endregion
}
}
}
}