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

479 lines
17 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 OpiParameter Service
[Serializable]
public class OpiParameterService : ServiceTemplate, IOpiParameterService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OpiParameter));
public OpiParameterService() { }
private void MapObject(OpiParameter oOpiParameter, DataReader oReader)
{
base.SetObjectID(oOpiParameter, oReader.GetID("OpiParameterID"));
oOpiParameter.OpiType = (EnumOpiType)oReader.GetInt32("OpiType").Value;
oOpiParameter.AmountToDistribute = oReader.GetDouble("AmountToDistribute").Value;
oOpiParameter.AvgMonth = oReader.GetInt32("AvgMonth").Value;
oOpiParameter.FlatAmount = oReader.GetDouble("FlatAmount").Value;
oOpiParameter.ProvisionAmount = oReader.GetDouble("ProvisionAmount").Value;
oOpiParameter.MinAmount = oReader.GetDouble("MinAmount") == null ? 0.0 : oReader.GetDouble("MinAmount").Value;
oOpiParameter.MaxAmount = oReader.GetDouble("MaxAmount") == null ? 0.0 : oReader.GetDouble("MaxAmount").Value;
oOpiParameter.FromDate = oReader.GetDateTime("FromDate") == null ? DateTime.MinValue : oReader.GetDateTime("FromDate").Value;
oOpiParameter.ToDate = oReader.GetDateTime("ToDate") == null ? DateTime.MinValue : oReader.GetDateTime("ToDate").Value;
oOpiParameter.Gender = (EnumGender)oReader.GetInt32("Gender");
oOpiParameter.Status = (EnumStatus)oReader.GetInt32("Status");
//oOpiParameter.Sequence = oReader.GetInt32("Sequence").Value;
oOpiParameter.IsActive = oReader.GetBoolean("IsActive").Value;
oOpiParameter.IsEarnedBasic = oReader.GetBoolean("IsEarnedBasic").Value;
oOpiParameter.IsTaxable = oReader.GetBoolean("IsTaxable").Value;
oOpiParameter.IsConfirmed = oReader.GetBoolean("IsConfirmed").Value;
oOpiParameter.IsFractionate = oReader.GetBoolean("IsFractionate").Value;
oOpiParameter.IsWithException = oReader.GetBoolean("IsWithException").Value;
oOpiParameter.OpiItemID = oReader.GetID("OpiItemID");
oOpiParameter.OpiPeriodicity = (EnumOpiPeriodicity)oReader.GetInt32("OpiPeriodicity");
oOpiParameter.PercentOfBasic = oReader.GetDouble("PercentOfBasic").Value;
oOpiParameter.PercentOfGross = oReader.GetDouble("PercentOfGross").Value;
oOpiParameter.EntitleType = (EnumEntitleType)oReader.GetInt32("EntitleType").Value;
oOpiParameter.OpiAvgPayType = (EnumOpiAvgPayType)oReader.GetInt32("OpiAvgPayType").Value;
oOpiParameter.OpiAvgPayItemID = oReader.GetID("OpiAvgPayItemID");
oOpiParameter.NoOfMonth = oReader.GetInt32("NoOfMonth").Value;
oOpiParameter.CreatedBy = oReader.GetID("CreatedBy");
oOpiParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oOpiParameter.ModifiedBy = oReader.GetID("ModifiedBy");
oOpiParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oOpiParameter.AnnualGrossPerBand = oReader.GetDouble("ANNUALGROSSPERBAND").Value;
oOpiParameter.PerformanceAchievement = oReader.GetDouble("PERFORMANCEACHIEVEMENT").Value;
this.SetObjectState(oOpiParameter, Ease.CoreV35.ObjectState.Saved);
}
private void MapParameterGradeObject(OpiParameterGrade oGrade, DataReader oReader)
{
base.SetObjectID(oGrade, oReader.GetID("OpiParameterID"));
oGrade.OpiParameterId = oReader.GetID("OpiParameterID");
oGrade.GradeId = oReader.GetID("GradeID");
oGrade.OpiItemId = oReader.GetID("OpiItemId");
this.SetObjectState(oGrade, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OpiParameter oOpiParameter = new OpiParameter();
MapObject(oOpiParameter, oReader);
return oOpiParameter as T;
}
protected OpiParameter CreateObject(DataReader oReader)
{
OpiParameter oOpiParameter = new OpiParameter();
MapObject(oOpiParameter, oReader);
return oOpiParameter;
}
protected ObjectsTemplate<OpiParameterGrade> CreateParameterGradeObject(DataReader oReader)
{
ObjectsTemplate<OpiParameterGrade> oGrades = new ObjectsTemplate<OpiParameterGrade>();
while (oReader.Read())
{
OpiParameterGrade oGrade = new OpiParameterGrade();
MapParameterGradeObject(oGrade, oReader);
oGrades.Add(oGrade);
}
return oGrades;
}
#endregion
#region Service implementation
public OpiParameter Get(ID id)
{
OpiParameter oOpiParameter = new OpiParameter();
#region Cache Header
oOpiParameter = (OpiParameter)_cache["Get", id];
if (oOpiParameter != null)
return oOpiParameter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OpiParameterDA.Get(tc, id));
if (oreader.Read())
{
oOpiParameter = this.CreateObject<OpiParameter>(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(oOpiParameter, "Get", id);
#endregion
return oOpiParameter;
}
public ObjectsTemplate<OpiParameter> GetByPayrollTypeID(ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OpiParameter> oOpiParameters = _cache["Get"] as ObjectsTemplate<OpiParameter>;
if (oOpiParameters != null)
return oOpiParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OpiParameterDA.Get(tc, payrollTypeID));
oOpiParameters = this.CreateObjects<OpiParameter>(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(oOpiParameters, "Get");
#endregion
return oOpiParameters;
}
public ObjectsTemplate<OpiParameterGrade> GetGrades(ID opiParameterID, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OpiParameterGrade> oGrade = _cache["Get", opiParameterID] as ObjectsTemplate<OpiParameterGrade>;
if (oGrade != null)
return oGrade;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterDA.GetGrades(tc, opiParameterID, payrollTypeID));
oGrade = this.CreateParameterGradeObject(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(oGrade, "Get", opiParameterID);
#endregion
return oGrade;
}
public ObjectsTemplate<OpiParameterGrade> GetGrades(ID payrollTypeID)
{
ObjectsTemplate<OpiParameterGrade> oGrades = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterDA.GetGrades(tc, payrollTypeID));
oGrades = this.CreateParameterGradeObject(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 oGrades;
}
public ObjectsTemplate<OpiParameter> Get(EnumStatus status, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OpiParameter> opiParameters = _cache["Get", status] as ObjectsTemplate<OpiParameter>;
if (opiParameters != null)
return opiParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterDA.Get(tc, status, payrollTypeID));
opiParameters = this.CreateObjects<OpiParameter>(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(opiParameters, "Get", status);
#endregion
return opiParameters;
}
public ObjectsTemplate<OpiParameter> Get(EnumStatus status, EnumOpiType nType, ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<OpiParameter> opiParameters = _cache["Get", status, nType] as ObjectsTemplate<OpiParameter>;
if (opiParameters != null)
return opiParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterDA.Get(tc, status, nType, payrollTypeID));
opiParameters = this.CreateObjects<OpiParameter>(dr);
foreach (OpiParameter oparam in opiParameters)
{
oparam.OpiParameterGrades = this.GetGrades(oparam.ID, payrollTypeID);
}
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(opiParameters, "Get", status, nType);
#endregion
return opiParameters;
}
public ID Save(OpiParameter oOpiParameter, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOpiParameter.IsNew)
{
int id = tc.GenerateID("OpiParameter", "OpiParameterID");
base.SetObjectID(oOpiParameter, ID.FromInteger(id));
OpiParameterDA.Insert(tc, oOpiParameter, payrollTypeID);
}
else
{
oOpiParameter.ModifiedDate = DateTime.Now;
oOpiParameter.ModifiedBy = User.CurrentUser.ID;
OpiParameterDA.Update(tc, oOpiParameter, payrollTypeID);
OpiParameterDA.DeleteGrades(tc, oOpiParameter.ID, payrollTypeID);
OpiParameterIndividualDA.DeletebyOpiParamId(tc, oOpiParameter.ID);
}
foreach (OpiParameterIndividual opiIndv in oOpiParameter.OpiParameterIndividuals)
{
opiIndv.OpiParameterID = oOpiParameter.ID;
int id = tc.GenerateID("OpiParameterIndividual", "OpiParameterIndividualID");
base.SetObjectID(opiIndv, ID.FromInteger(id));
opiIndv.CreatedDate = DateTime.Now;
opiIndv.CreatedBy = User.CurrentUser.ID;
OpiParameterIndividualDA.Insert(tc, opiIndv, payrollTypeID);
}
foreach (OpiParameterGrade oGrade in oOpiParameter.OpiParameterGrades)
{
oGrade.CreatedDate = DateTime.Now;
oGrade.CreatedBy = User.CurrentUser.ID;
oGrade.OpiParameterId = oOpiParameter.ID;
oGrade.OpiItemId = oOpiParameter.OpiItemID;
OpiParameterDA.InsertGrade(tc, oGrade, payrollTypeID);
}
tc.End();
return oOpiParameter.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(ID id, ID payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OpiParameterDA.Delete(tc, id, payrollTypeID);
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 IOpiParameterService Members
public ObjectsTemplate<OpiParameter> Get(EnumStatus enumStatus, EnumOpiType enumOpiType, EnumEntitleType enumEntitleType, ID payrollTypeID)
{
ObjectsTemplate<OpiParameter> opiParameters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterDA.Get(tc, enumStatus, enumOpiType, enumEntitleType, payrollTypeID));
opiParameters = this.CreateObjects<OpiParameter>(dr);
foreach (OpiParameter oparam in opiParameters)
{
oparam.OpiParameterGrades = this.GetGrades(oparam.ID, payrollTypeID);
}
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 ObjectsTemplate<OpiParameter> Get(EnumStatus enumStatus, EnumEntitleType enumEntitleType, ID payrollTypeID)
{
ObjectsTemplate<OpiParameter> opiParameters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OpiParameterDA.Get(tc, enumStatus, enumEntitleType, payrollTypeID));
opiParameters = this.CreateObjects<OpiParameter>(dr);
foreach (OpiParameter oparam in opiParameters)
{
oparam.OpiParameterGrades = this.GetGrades(oparam.ID, payrollTypeID);
}
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;
}
#endregion
}
#endregion
}