EchoTex_Payroll/HRM.DA/Service/JV/JVSetupDetailService.cs

224 lines
6.6 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using HRM.BO;
using System.Collections.Generic;
using Ease.Core.Utility;
using Payroll.Service;
namespace HRM.DA
{
#region JVSetupDetail Service
public class JVSetupDetailService : ServiceTemplate, IJVSetupDetailService
{
#region Private functions and declaration
public JVSetupDetailService()
{
}
private void MapObject(JVSetupDetail oJVSetupDetail, DataReader oReader)
{
base.SetObjectID(oJVSetupDetail, oReader.GetInt32("JVSetupDetailID").Value);
oJVSetupDetail.ItemID = oReader.GetString("ItemID") == null ? 0 : oReader.GetInt32("ItemID").Value;
oJVSetupDetail.JVItemType = (enumPayrollComponentType)oReader.GetInt32("JVItemType").Value;
oJVSetupDetail.JVSetupID = oReader.GetString("JVSetupID") == null ? 0 : oReader.GetInt32("JVSetupID").Value;
oJVSetupDetail.Name = oReader.GetString("Name");
this.SetObjectState(oJVSetupDetail, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
JVSetupDetail oJVSetupDetail = new JVSetupDetail();
MapObject(oJVSetupDetail, oReader);
return oJVSetupDetail as T;
}
protected JVSetupDetail CreateObject(DataReader oReader)
{
JVSetupDetail oJVSetupDetail = new JVSetupDetail();
MapObject(oJVSetupDetail, oReader);
return oJVSetupDetail;
}
#endregion
#region Service implementation
public JVSetupDetail Get(int id)
{
JVSetupDetail oJVSetupDetail = new JVSetupDetail();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(JVSetupDetailDA.Get(tc, id));
if (oreader.Read())
{
oJVSetupDetail = this.CreateObject<JVSetupDetail>(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 oJVSetupDetail;
}
public List<JVSetupDetail> Get()
{
List<JVSetupDetail> oJVSetupDetails = new List<JVSetupDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(JVSetupDetailDA.Get(tc));
oJVSetupDetails = this.CreateObjects<JVSetupDetail>(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 oJVSetupDetails;
}
public List<JVSetupDetail> GetByJVSetup(int JVSetupID)
{
List<JVSetupDetail> JVSetupDetails = new List<JVSetupDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(JVSetupDetailDA.GetByJVSetup(tc, JVSetupID));
JVSetupDetails = this.CreateObjects<JVSetupDetail>(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 JVSetupDetails;
}
public List<JVSetupDetail> GetLatestSetupByJVType(int payrolltypeid, int jvtypeid)
{
List<JVSetupDetail> JVSetupDetails = new List<JVSetupDetail>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(JVSetupDetailDA.GetLatestSetupByJVType(tc, payrolltypeid, jvtypeid));
JVSetupDetails = this.CreateObjects<JVSetupDetail>(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 JVSetupDetails;
}
public int Save(JVSetupDetail oJVSetupDetail)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oJVSetupDetail.IsNew)
{
int id = tc.GenerateID("JVSetupDetail", "JVSetupDetailID");
base.SetObjectID(oJVSetupDetail, id);
JVSetupDetailDA.Insert(tc, oJVSetupDetail);
}
else
{
JVSetupDetailDA.Update(tc, oJVSetupDetail);
}
return oJVSetupDetail.ID;
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetJVSetupDetail", e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
JVSetupDetailDA.Delete(tc, id);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}