EchoTex_Payroll/HRM.DA/Service/OPI/OpiParameterIndividualService.cs

380 lines
12 KiB
C#
Raw 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
{
#region OpiParameterIndividual Service
public class OpiParameterIndividualService : ServiceTemplate, IOpiParameterIndividualService
{
#region Private functions and declaration
public OpiParameterIndividualService()
{
}
private void MapObject(OpiParameterIndividual oOpiIndividual, DataReader oReader)
{
base.SetObjectID(oOpiIndividual, oReader.GetInt32("OpiParameterIndividualID").Value);
oOpiIndividual.ArrearType = (EnumArrearType)oReader.GetInt32("ArrearType");
oOpiIndividual.EmployeeId =
oReader.GetString("EmployeeId") == null ? 0 : oReader.GetInt32("EmployeeId").Value;
oOpiIndividual.FromDate = oReader.GetDateTime("FromDate").Value;
oOpiIndividual.ToDate = oReader.GetDateTime("ToDate");
oOpiIndividual.IndividualType = (EnumOPIIndivdualType)oReader.GetInt32("IndividualType");
oOpiIndividual.OpiItemId = oReader.GetString("OpiItemId") == null ? 0 : oReader.GetInt32("OpiItemId").Value;
oOpiIndividual.OpiParameterID = oReader.GetString("OpiParameterId") == null
? 0
: oReader.GetInt32("OpiParameterId").Value;
oOpiIndividual.OpiPeriodicity = (EnumOpiPeriodicity)oReader.GetInt32("OpiPeriodicity");
oOpiIndividual.Value = oReader.GetDouble("Value").Value;
oOpiIndividual.employeeNo = oReader.GetString("employeeNo", true, "");
oOpiIndividual.employeeName = oReader.GetString("employeeName", true, "");
oOpiIndividual.ValueType = (EnumValueType)oReader.GetInt32("ValueType");
oOpiIndividual.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oOpiIndividual.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOpiIndividual.ModifiedBy =
oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
oOpiIndividual.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oOpiIndividual.PayrollTypeID = oReader.GetString("PayrollTypeID") == null
? 0
: oReader.GetInt32("PayrollTypeID").Value;
this.SetObjectState(oOpiIndividual, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual();
MapObject(oOpiIndividual, oReader);
return oOpiIndividual as T;
}
protected OpiParameterIndividual CreateObject(DataReader oReader)
{
OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual();
MapObject(oOpiIndividual, oReader);
return oOpiIndividual;
}
#endregion
#region Service implementation
public OpiParameterIndividual Get(int id)
{
OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OpiParameterIndividualDA.Get(tc, id));
if (oreader.Read())
{
oOpiIndividual = this.CreateObject<OpiParameterIndividual>(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 oOpiIndividual;
}
public List<OpiParameterIndividual> Get()
{
List<OpiParameterIndividual> oOpiIndividuals = new List<OpiParameterIndividual>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OpiParameterIndividualDA.Get(tc));
oOpiIndividuals = this.CreateObjects<OpiParameterIndividual>(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 oOpiIndividuals;
}
public List<OpiParameterIndividual> GetByParameterID(int nParamaterID)
{
List< OpiParameterIndividual > items = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
items = this.GetByParameterID(tc, nParamaterID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return items;
}
public List<OpiParameterIndividual> GetByParameterID(TransactionContext tc, int nParamaterID)
{
List<OpiParameterIndividual> oOpiIndividuals = new List<OpiParameterIndividual>();
try
{
DataReader oreader = new DataReader(OpiParameterIndividualDA.GetByParameterID(tc, nParamaterID));
oOpiIndividuals = this.CreateObjects<OpiParameterIndividual>(oreader);
oreader.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oOpiIndividuals;
}
public List<OpiParameterIndividual> Get(DateTime fromDate, DateTime toDate)
{
List<OpiParameterIndividual> opiParameterIndividuals = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterIndividualDA.Get(tc, fromDate, toDate));
opiParameterIndividuals = this.CreateObjects<OpiParameterIndividual>(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 opiParameterIndividuals;
}
public List<OpiParameterIndividual> GetIndividuals(int nOpiPAramID, EnumOPIIndivdualType type)
{
List<OpiParameterIndividual> opiParamIndividuals = new List<OpiParameterIndividual>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterIndividualDA.GetIndividuals(tc, nOpiPAramID, type));
opiParamIndividuals = this.CreateObjects<OpiParameterIndividual>(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 opiParamIndividuals;
}
public OpiParameterIndividual Get(int nOpiPAramID, int EmployeeID, int opiItemID)
{
OpiParameterIndividual opiParameters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterIndividualDA.Get(tc, nOpiPAramID, EmployeeID, opiItemID));
if (dr.Read())
{
opiParameters = this.CreateObject<OpiParameterIndividual>(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 opiParameters;
}
public int Save(OpiParameterIndividual oOpiIndividual)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOpiIndividual.IsNew)
{
int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID");
base.SetObjectID(oOpiIndividual, id);
OpiParameterIndividualDA.Insert(tc, oOpiIndividual);
}
else
{
OpiParameterIndividualDA.Update(tc, oOpiIndividual);
}
return oOpiIndividual.ID;
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetOpiParameterIndividual", e);
#endregion
}
}
public void BulkSave(List<OpiParameterIndividual> oParamIndvdls)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID");
foreach (var oOpiIndividual in oParamIndvdls)
{
if (oOpiIndividual.IsNew)
{
id = id + 1;
base.SetObjectID(oOpiIndividual, id);
OpiParameterIndividualDA.Insert(tc, oOpiIndividual);
}
else
{
OpiParameterIndividualDA.Update(tc, oOpiIndividual);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetOpiParameterIndividual", e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OpiParameterIndividualDA.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
#region IOpiParameterIndividualService Members
#endregion
}
#endregion
}