HRM-10/HRM.DA/Service/Fund/VoucherSetup/RDReportService.cs
Mohaimen Hasan 838b8d4480 first commit
2026-11-03 13:06:00 +06:00

247 lines
7.5 KiB
C#

using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using Ease.Core;
using HRM.BO;
using System;
using System.Collections.Generic;
using System.Data;
using static HRM.BO.RDReport;
namespace HRM.DA
{
public class RDReportService : ServiceTemplate, IRDReportService
{
#region Private functions and declaration
public RDReportService() { }
private void MapObject(RDReport oRDReport, DataReader oReader)
{
this.SetObjectID(oRDReport,oReader.GetInt32("REPORTID").Value);
oRDReport.ReportCode = oReader.GetString("REPORTCODE");
oRDReport.ReportName = oReader.GetString("REPORTNAME");
oRDReport.ReportType = (EnumReportTypes)oReader.GetInt32("REPORTTYPE");
this.SetObjectState(oRDReport, ObjectState.Saved);
}
//private RDReport CreateObject(DataReader oReader)
//{
// RDReport oRDReport = new RDReport();
// MapObject(oRDReport, oReader);
// return oRDReport;
//}
protected override T CreateObject<T>(DataReader oReader)
{
RDReport oRDReport = new RDReport();
MapObject(oRDReport, oReader);
return oRDReport as T;
}
#endregion
#region Service implementation
public bool IsExistCode(string code,int fundTypeID)
{
bool exist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
exist = RDReportDA.IsExistCode(tc, code, fundTypeID);
tc.End();
}
catch (Exception e)
{
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
}
return exist;
}
public bool IsExistType(EnumReportType reportType, int fundTypeID)
{
bool exist = false;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
exist = RDReportDA.IsExistType(tc, reportType, fundTypeID);
tc.End();
}
catch (Exception e)
{
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
}
return exist;
}
public RDReport Get(int id)
{
RDReport oRDReport = new RDReport();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
IDataReader oreader = RDReportDA.Get(tc, id);
DataReader oReader = new DataReader(oreader);
if (oreader.Read())
{
oRDReport = this.CreateObject<RDReport>(oReader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetRDReport", e);
#endregion
}
return oRDReport;
}
public RDReport GetByReportType(EnumReportType reportType)
{
RDReport oRDReport = new RDReport();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
IDataReader oreader = RDReportDA.Get(tc, reportType);
DataReader oReader = new DataReader(oreader);
if (oreader.Read())
{
oRDReport = this.CreateObject<RDReport>(oReader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetRDReport", e);
#endregion
}
return oRDReport;
}
public List<RDReport> GetByFundTypeID(int fundTypeID)
{
List<RDReport> oRDReports = new List<RDReport>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DataReader oReader =new DataReader(RDReportDA.GetByFundType(tc, fundTypeID));
oRDReports = CreateObjects<RDReport>(oReader);
oReader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Get RDReport", e);
#endregion
}
return oRDReports;
}
public int Save(RDReport oRDReport, int fundTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oRDReport.IsNew)
{
this.SetObjectID(oRDReport, (RDReportDA.GetNewID(tc)));
RDReportDA.Insert(tc, oRDReport, fundTypeID);
}
else
{
RDReportDA.Update(tc, oRDReport, fundTypeID);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Save RDReport", e);
#endregion
}
return oRDReport.ID;
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
RDReportDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to Delete RDReport", e);
#endregion
}
}
public RDReport GetByReportTypeAndFundTypeID(EnumReportTypes reportType, int fundTypeID)
{
RDReport oRDReport = new RDReport();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
IDataReader oreader = RDReportDA.GetByReportTypeAndFundTypeID(tc, reportType, fundTypeID);
DataReader oReader = new DataReader(oreader);
if (oreader.Read())
{
oRDReport = this.CreateObject<RDReport>(oReader);
}
oreader.Close();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetRDReport", e);
#endregion
}
return oRDReport;
}
#endregion
}
}