479 lines
18 KiB
C#
479 lines
18 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 CarFuelParameter Service
|
|
[Serializable]
|
|
public class CarFuelParameterService : ServiceTemplate, ICarFuelParameterService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(CarFuelParameter));
|
|
|
|
public CarFuelParameterService() { }
|
|
|
|
private void MapObject(CarFuelParameter oCarFuelParameter, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oCarFuelParameter, oReader.GetID("CarFuelParameterID"));
|
|
oCarFuelParameter.CarFuelType = (EnumCarFuelType)oReader.GetInt32("CarFuelType").Value;
|
|
oCarFuelParameter.AmountToDistribute = oReader.GetDouble("AmountToDistribute").Value;
|
|
oCarFuelParameter.AvgMonth = oReader.GetInt32("AvgMonth").Value;
|
|
oCarFuelParameter.FlatAmount = oReader.GetDouble("FlatAmount").Value;
|
|
oCarFuelParameter.ProvisionAmount = oReader.GetDouble("ProvisionAmount").Value;
|
|
oCarFuelParameter.MinAmount = oReader.GetDouble("MinAmount") == null ? 0.0 : oReader.GetDouble("MinAmount").Value;
|
|
oCarFuelParameter.MaxAmount = oReader.GetDouble("MaxAmount") == null ? 0.0 : oReader.GetDouble("MaxAmount").Value;
|
|
oCarFuelParameter.FromDate = oReader.GetDateTime("FromDate") == null ? DateTime.MinValue : oReader.GetDateTime("FromDate").Value;
|
|
oCarFuelParameter.ToDate = oReader.GetDateTime("ToDate") == null ? DateTime.MinValue : oReader.GetDateTime("ToDate").Value;
|
|
oCarFuelParameter.Gender = (EnumGender)oReader.GetInt32("Gender");
|
|
oCarFuelParameter.Status = (EnumStatus)oReader.GetInt32("Status");
|
|
//oCarFuelParameter.Sequence = oReader.GetInt32("Sequence").Value;
|
|
oCarFuelParameter.IsActive = oReader.GetBoolean("IsActive").Value;
|
|
oCarFuelParameter.IsEarnedBasic = oReader.GetBoolean("IsEarnedBasic").Value;
|
|
oCarFuelParameter.IsTaxable = oReader.GetBoolean("IsTaxable").Value;
|
|
oCarFuelParameter.IsConfirmed = oReader.GetBoolean("IsConfirmed").Value;
|
|
oCarFuelParameter.IsFractionate = oReader.GetBoolean("IsFractionate").Value;
|
|
oCarFuelParameter.IsWithException = oReader.GetBoolean("IsWithException").Value;
|
|
oCarFuelParameter.CarFuelItemID = oReader.GetID("CarFuelItemID");
|
|
oCarFuelParameter.CarFuelPeriodicity = (EnumCarFuelPeriodicity)oReader.GetInt32("CarFuelPeriodicity");
|
|
oCarFuelParameter.PercentOfBasic = oReader.GetDouble("PercentOfBasic").Value;
|
|
oCarFuelParameter.PercentOfGross = oReader.GetDouble("PercentOfGross").Value;
|
|
oCarFuelParameter.EntitleType = (EnumEntitleType)oReader.GetInt32("EntitleType").Value;
|
|
oCarFuelParameter.CarFuelAvgPayType = (EnumCarFuelAvgPayType)oReader.GetInt32("CarFuelAvgPayType").Value;
|
|
oCarFuelParameter.CarFuelAvgPayItemID = oReader.GetID("CarFuelAvgPayItemID");
|
|
oCarFuelParameter.NoOfMonth = oReader.GetInt32("NoOfMonth").Value;
|
|
oCarFuelParameter.CreatedBy = oReader.GetID("CreatedBy");
|
|
oCarFuelParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oCarFuelParameter.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oCarFuelParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
oCarFuelParameter.PayrollTypeID = oReader.GetString("PayrollTypeID") == null ? null : ID.FromInteger(oReader.GetInt32("PayrollTypeID").Value);
|
|
this.SetObjectState(oCarFuelParameter, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
private void MapParameterGradeObject(CarFuelParameterGrade oGrade, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oGrade, oReader.GetID("CarFuelParameterID"));
|
|
oGrade.CarFuelParameterId = oReader.GetID("CarFuelParameterID");
|
|
oGrade.GradeId = oReader.GetID("GradeID");
|
|
oGrade.CarFuelItemId = oReader.GetID("CarFuelItemId");
|
|
oGrade.PayrollTypeID = oReader.GetString("PayrollTypeID") == null ? null : ID.FromInteger(oReader.GetInt32("PayrollTypeID").Value);
|
|
this.SetObjectState(oGrade, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
CarFuelParameter oCarFuelParameter = new CarFuelParameter();
|
|
MapObject(oCarFuelParameter, oReader);
|
|
return oCarFuelParameter as T;
|
|
}
|
|
protected CarFuelParameter CreateObject(DataReader oReader)
|
|
{
|
|
CarFuelParameter oCarFuelParameter = new CarFuelParameter();
|
|
MapObject(oCarFuelParameter, oReader);
|
|
return oCarFuelParameter;
|
|
}
|
|
protected ObjectsTemplate<CarFuelParameterGrade> CreateParameterGradeObject(DataReader oReader)
|
|
{
|
|
ObjectsTemplate<CarFuelParameterGrade> oGrades = new ObjectsTemplate<CarFuelParameterGrade>();
|
|
while (oReader.Read())
|
|
{
|
|
CarFuelParameterGrade oGrade = new CarFuelParameterGrade();
|
|
MapParameterGradeObject(oGrade, oReader);
|
|
oGrades.Add(oGrade);
|
|
}
|
|
return oGrades;
|
|
}
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
public CarFuelParameter Get(ID id, int payrollTypeID)
|
|
{
|
|
CarFuelParameter oCarFuelParameter = new CarFuelParameter();
|
|
#region Cache Header
|
|
oCarFuelParameter = (CarFuelParameter)_cache["Get", id];
|
|
if (oCarFuelParameter != null)
|
|
return oCarFuelParameter;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(CarFuelParameterDA.Get(tc, id, payrollTypeID));
|
|
if (oreader.Read())
|
|
{
|
|
oCarFuelParameter = this.CreateObject<CarFuelParameter>(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(oCarFuelParameter, "Get", id);
|
|
#endregion
|
|
return oCarFuelParameter;
|
|
}
|
|
public ObjectsTemplate<CarFuelParameter> Get(int payrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<CarFuelParameter> oCarFuelParameters = _cache["Get"] as ObjectsTemplate<CarFuelParameter>;
|
|
if (oCarFuelParameters != null)
|
|
return oCarFuelParameters;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(CarFuelParameterDA.GetCFD(tc, payrollTypeID));
|
|
oCarFuelParameters = this.CreateObjects<CarFuelParameter>(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(oCarFuelParameters, "Get");
|
|
#endregion
|
|
return oCarFuelParameters;
|
|
}
|
|
public ObjectsTemplate<CarFuelParameterGrade> GetGrades(ID CarFuelParameterID, int payrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<CarFuelParameterGrade> oGrade = _cache["Get", CarFuelParameterID] as ObjectsTemplate<CarFuelParameterGrade>;
|
|
if (oGrade != null)
|
|
return oGrade;
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CarFuelParameterDA.GetGrades(tc, CarFuelParameterID, 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", CarFuelParameterID);
|
|
#endregion
|
|
|
|
return oGrade;
|
|
}
|
|
|
|
|
|
|
|
public ObjectsTemplate<CarFuelParameterGrade> GetGrades(int payrollTypeID)
|
|
{
|
|
|
|
ObjectsTemplate<CarFuelParameterGrade> oGrades = null;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CarFuelParameterDA.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<CarFuelParameter> Get(EnumStatus status, int payrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<CarFuelParameter> CarFuelParameters = _cache["Get", status] as ObjectsTemplate<CarFuelParameter>;
|
|
if (CarFuelParameters != null)
|
|
return CarFuelParameters;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CarFuelParameterDA.Get(tc, status, payrollTypeID));
|
|
CarFuelParameters = this.CreateObjects<CarFuelParameter>(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(CarFuelParameters, "Get", status);
|
|
|
|
#endregion
|
|
|
|
return CarFuelParameters;
|
|
}
|
|
public ObjectsTemplate<CarFuelParameter> Get(EnumStatus status, EnumCarFuelType nType, int payrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<CarFuelParameter> CarFuelParameters = _cache["Get", status, nType] as ObjectsTemplate<CarFuelParameter>;
|
|
if (CarFuelParameters != null)
|
|
return CarFuelParameters;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CarFuelParameterDA.Get(tc, status, nType, payrollTypeID));
|
|
CarFuelParameters = this.CreateObjects<CarFuelParameter>(dr);
|
|
foreach (CarFuelParameter oparam in CarFuelParameters)
|
|
{
|
|
oparam.CarFuelParameterGrades = 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(CarFuelParameters, "Get", status, nType);
|
|
|
|
#endregion
|
|
|
|
return CarFuelParameters;
|
|
}
|
|
public ID Save(CarFuelParameter oCarFuelParameter, int payrollTypeID)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oCarFuelParameter.IsNew)
|
|
{
|
|
int id = tc.GenerateID("CarFuelParameter", "CarFuelParameterID");
|
|
base.SetObjectID(oCarFuelParameter, ID.FromInteger(id));
|
|
|
|
CarFuelParameterDA.Insert(tc, oCarFuelParameter);
|
|
}
|
|
else
|
|
{
|
|
oCarFuelParameter.ModifiedDate = DateTime.Now;
|
|
oCarFuelParameter.ModifiedBy = User.CurrentUser.ID;
|
|
CarFuelParameterDA.Update(tc, oCarFuelParameter);
|
|
CarFuelParameterDA.DeleteGrades(tc, oCarFuelParameter.ID, payrollTypeID);
|
|
CarFuelParameterIndividualDA.DeletebyCarFuelParamId(tc, oCarFuelParameter.ID);
|
|
}
|
|
|
|
foreach (CarFuelParameterIndividual CarFuelIndv in oCarFuelParameter.CarFuelParameterIndividuals)
|
|
{
|
|
CarFuelIndv.CarFuelParameterID = oCarFuelParameter.ID;
|
|
int id = tc.GenerateID("CarFuelParameterIndividual", "CarFuelParameterIndividualID");
|
|
base.SetObjectID(CarFuelIndv, ID.FromInteger(id));
|
|
|
|
CarFuelIndv.CreatedDate = DateTime.Now;
|
|
CarFuelIndv.CreatedBy = User.CurrentUser.ID;
|
|
|
|
CarFuelParameterIndividualDA.Insert(tc, CarFuelIndv);
|
|
}
|
|
|
|
foreach (CarFuelParameterGrade oGrade in oCarFuelParameter.CarFuelParameterGrades)
|
|
{
|
|
oGrade.CreatedDate = DateTime.Now;
|
|
oGrade.CreatedBy = User.CurrentUser.ID;
|
|
|
|
oGrade.CarFuelParameterId = oCarFuelParameter.ID;
|
|
oGrade.CarFuelItemId = oCarFuelParameter.CarFuelItemID;
|
|
CarFuelParameterDA.InsertGrade(tc, oGrade);
|
|
}
|
|
|
|
tc.End();
|
|
return oCarFuelParameter.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, int payrollTypeID)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
CarFuelParameterDA.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 ICarFuelParameterService Members
|
|
|
|
|
|
public ObjectsTemplate<CarFuelParameter> Get(EnumStatus enumStatus, EnumCarFuelType enumCarFuelType, EnumEntitleType enumEntitleType, int payrollTypeID)
|
|
{
|
|
|
|
ObjectsTemplate<CarFuelParameter> CarFuelParameters = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CarFuelParameterDA.Get(tc, enumStatus, enumCarFuelType, enumEntitleType, payrollTypeID));
|
|
CarFuelParameters = this.CreateObjects<CarFuelParameter>(dr);
|
|
foreach (CarFuelParameter oparam in CarFuelParameters)
|
|
{
|
|
oparam.CarFuelParameterGrades = 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 CarFuelParameters;
|
|
}
|
|
|
|
public ObjectsTemplate<CarFuelParameter> Get(EnumStatus enumStatus, EnumEntitleType enumEntitleType, int payrollTypeID)
|
|
{
|
|
|
|
ObjectsTemplate<CarFuelParameter> CarFuelParameters = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(CarFuelParameterDA.Get(tc, enumStatus, enumEntitleType, payrollTypeID));
|
|
CarFuelParameters = this.CreateObjects<CarFuelParameter>(dr);
|
|
foreach (CarFuelParameter oparam in CarFuelParameters)
|
|
{
|
|
oparam.CarFuelParameterGrades = 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 CarFuelParameters;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
}
|