CEL_Payroll/Payroll.Service/OPI/Service/OpiParameterIndividualService.cs
2024-09-17 14:30:13 +06:00

319 lines
11 KiB
C#

using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region OpiParameterIndividual Service
[Serializable]
public class OpiParameterIndividualService : ServiceTemplate, IOpiParameterIndividualService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OpiParameterIndividual));
public OpiParameterIndividualService() { }
private void MapObject(OpiParameterIndividual oOpiIndividual, DataReader oReader)
{
base.SetObjectID(oOpiIndividual, oReader.GetID("OpiParameterIndividualID"));
oOpiIndividual.ArrearType = (EnumArrearType)oReader.GetInt32("ArrearType");
oOpiIndividual.EmployeeId = oReader.GetID("EmployeeId");
oOpiIndividual.FromDate = oReader.GetDateTime("FromDate").Value;
oOpiIndividual.ToDate = oReader.GetDateTime("ToDate");
oOpiIndividual.IndividualType = (EnumOPIIndivdualType)oReader.GetInt32("IndividualType");
oOpiIndividual.OpiItemId = oReader.GetID("OpiItemId");
oOpiIndividual.OpiParameterID = oReader.GetID("OpiParameterId");
oOpiIndividual.OpiPeriodicity = (EnumOpiPeriodicity)oReader.GetInt32("OpiPeriodicity");
oOpiIndividual.Value = oReader.GetDouble("Value").Value;
oOpiIndividual.ValueType = (EnumValueType)oReader.GetInt32("ValueType");
oOpiIndividual.CreatedBy = oReader.GetID("CreatedBy");
oOpiIndividual.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOpiIndividual.ModifiedBy = oReader.GetID("ModifiedBy");
oOpiIndividual.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oOpiIndividual, Ease.CoreV35.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(ID id)
{
OpiParameterIndividual oOpiIndividual = new OpiParameterIndividual();
#region Cache Header
oOpiIndividual = (OpiParameterIndividual)_cache["Get", id];
if (oOpiIndividual != null)
return oOpiIndividual;
#endregion
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
}
#region Cache Footer
_cache.Add(oOpiIndividual, "Get", id);
#endregion
return oOpiIndividual;
}
public ObjectsTemplate<OpiParameterIndividual> Get()
{
#region Cache Header
ObjectsTemplate<OpiParameterIndividual> oOpiIndividuals = _cache["Get"] as ObjectsTemplate<OpiParameterIndividual>;
if (oOpiIndividuals != null)
return oOpiIndividuals;
#endregion
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
}
#region Cache Footer
_cache.Add(oOpiIndividuals, "Get");
#endregion
return oOpiIndividuals;
}
public ObjectsTemplate<OpiParameterIndividual> GetByParameterID(ID nParamaterID)
{
#region Cache Header
ObjectsTemplate<OpiParameterIndividual> oOpiIndividuals = _cache["GetByParameterID"] as ObjectsTemplate<OpiParameterIndividual>;
if (oOpiIndividuals != null)
return oOpiIndividuals;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OpiParameterIndividualDA.GetByParameterID(tc, nParamaterID));
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
}
#region Cache Footer
_cache.Add(oOpiIndividuals, "GetByParameterID");
#endregion
return oOpiIndividuals;
}
public ObjectsTemplate<OpiParameterIndividual> Get(DateTime fromDate, DateTime toDate)
{
ObjectsTemplate<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 ObjectsTemplate<OpiParameterIndividual> GetIndividuals(ID nOpiPAramID, EnumOPIIndivdualType type)
{
#region Cache Header
ObjectsTemplate<OpiParameterIndividual> opiParamIndividuals = _cache["GetIndividuals", nOpiPAramID, type] as ObjectsTemplate<OpiParameterIndividual>;
if (opiParamIndividuals != null)
return opiParamIndividuals;
#endregion
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
}
#region Cache Footer
_cache.Add(opiParamIndividuals, "GetIndividuals", nOpiPAramID, type);
#endregion
return opiParamIndividuals;
}
public ID Save(OpiParameterIndividual oOpiIndividual, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOpiIndividual.IsNew)
{
int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID");
base.SetObjectID(oOpiIndividual, ID.FromInteger(id));
OpiParameterIndividualDA.Insert(tc, oOpiIndividual, payrollTypeID);
}
else
{
OpiParameterIndividualDA.Update(tc, oOpiIndividual, payrollTypeID);
}
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(ObjectsTemplate<OpiParameterIndividual> oParamIndvdls, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
foreach (var oOpiIndividual in oParamIndvdls)
{
if (oOpiIndividual.IsNew)
{
int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID");
base.SetObjectID(oOpiIndividual, ID.FromInteger(id));
OpiParameterIndividualDA.Insert(tc, oOpiIndividual, payrollTypeID);
}
else
{
OpiParameterIndividualDA.Update(tc, oOpiIndividual, payrollTypeID);
}
}
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(ID 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
}