EchoTex_Payroll/HRM.DA/Service/Basic/ApproveFinantialDataService.cs

258 lines
7.8 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using HRM.BO;
namespace HRM.DA
{
public class ApproveFinantialDataService : ServiceTemplate, IApproveFinantialDataService
{
public ApproveFinantialDataService()
{
}
private void MapObject(ApproveFinantialData oApproveFinantialData, DataReader oReader)
{
base.SetObjectID(oApproveFinantialData, oReader.GetInt32("ApproveID").Value);
oApproveFinantialData.FinantialDataType =
(EnumApprovalFinancialData)oReader.GetInt32("FinanatialDataType");
oApproveFinantialData.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oApproveFinantialData.ObjectID = oReader.GetInt32("ObjectID").GetValueOrDefault();
oApproveFinantialData.SalaryMonth = oReader.GetDateTime("SalaryMonth").GetValueOrDefault();
oApproveFinantialData.Approvedby = oReader.GetInt32("Approvedby").GetValueOrDefault();
oApproveFinantialData.ApprovedDate = oReader.GetDateTime("ApprovedDate").GetValueOrDefault();
this.SetObjectState(oApproveFinantialData, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ApproveFinantialData oApproveFinantialData = new ApproveFinantialData();
MapObject(oApproveFinantialData, oReader);
return oApproveFinantialData as T;
}
#region Service implementation
public ApproveFinantialData Get(int EmpID, DateTime dt)
{
ApproveFinantialData oApproveFinantialData = new ApproveFinantialData();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ApproveFinantialDataDA.Get(tc, EmpID, dt));
if (oreader.Read())
{
oApproveFinantialData = this.CreateObject<ApproveFinantialData>(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 oApproveFinantialData;
}
public List<ApproveFinantialData> Get(int id)
{
List<ApproveFinantialData> ApproveFinantialDatas = new List<ApproveFinantialData>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ApproveFinantialDataDA.Get(tc, id));
ApproveFinantialDatas = this.CreateObjects<ApproveFinantialData>(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 ApproveFinantialDatas;
}
public List<ApproveFinantialData> GetByMonth(DateTime dtStart, DateTime dtEnd)
{
List<ApproveFinantialData> ApproveFinantialDatas = new List<ApproveFinantialData>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ApproveFinantialDataDA.GetByMonth(tc, dtStart, dtEnd));
ApproveFinantialDatas = this.CreateObjects<ApproveFinantialData>(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 ApproveFinantialDatas;
}
public List<ApproveFinantialData> Get()
{
List<ApproveFinantialData> ApproveFinantialDatas = new List<ApproveFinantialData>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ApproveFinantialDataDA.Get(tc));
ApproveFinantialDatas = this.CreateObjects<ApproveFinantialData>(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 ApproveFinantialDatas;
}
public void Save(List<ApproveFinantialData> items)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (ApproveFinantialData item in items)
{
int id = tc.GenerateID("ApproveFinantialData", "ApproveID");
base.SetObjectID(item, id);
ApproveFinantialDataDA.Insert(tc, item);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(ApproveFinantialData item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ApproveFinantialDataDA.Delete(tc, item);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(List<ApproveFinantialData> items)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (var item in items)
{
ApproveFinantialDataDA.Delete(tc, item);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
public List<ApproveFinantialData> GetByType(int selectedType)
{
List<ApproveFinantialData> ApproveFinantialDatas = new List<ApproveFinantialData>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ApproveFinantialDataDA.GetByType(tc, selectedType));
ApproveFinantialDatas = this.CreateObjects<ApproveFinantialData>(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 ApproveFinantialDatas;
}
}
}