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

331 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;
using System.Text;
namespace Payroll.Service
{
#region TermParameter Service
[Serializable]
public class TermParameterService : ServiceTemplate, ITermParameterService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TermParameter));
#endregion
public TermParameterService() { }
private void MapObject(TermParameter oTermParameter, DataReader oReader)
{
base.SetObjectID(oTermParameter, oReader.GetID("TermParameterID"));
oTermParameter.TermID = oReader.GetID("termID");
oTermParameter.EffectDate = oReader.GetDateTime("effectDate").Value;
oTermParameter.Amount = oReader.GetDouble("amount").Value;
oTermParameter.Type = (EnumOverTimeType)oReader.GetInt32("type").Value;
oTermParameter.CreatedBy = oReader.GetID("CreatedBy");
oTermParameter.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oTermParameter.ModifiedBy = oReader.GetID("ModifiedBy");
oTermParameter.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oTermParameter, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TermParameter oTermParameter = new TermParameter();
MapObject(oTermParameter, oReader);
return oTermParameter as T;
}
protected TermParameter CreateObject(DataReader oReader)
{
TermParameter oTermParameter = new TermParameter();
MapObject(oTermParameter, oReader);
return oTermParameter;
}
private void MapObjectForTEGrade(TermParameter.TermEntityGrade oTermEGrade, DataReader oReader)
{
base.SetObjectID(oTermEGrade, oReader.GetID("TermentityID"));
oTermEGrade.TermEntityID = oReader.GetID("TermentityID");
oTermEGrade.GradeID = oReader.GetID("GRADEID");
this.SetObjectState(oTermEGrade, Ease.CoreV35.ObjectState.Saved);
}
//protected override T CreateObject1<T>(DataReader oReader)
//{
// TermEntityGrade oTermEGrade = new TermEntityGrade();
// MapObjectForTEGrade(oTermEGrade, oReader);
// return oTermEGrade as T;
//}
protected TermParameter.TermEntityGrade CreateObjectForTEGrade(DataReader oReader)
{
TermParameter.TermEntityGrade oTermEGrade = new TermParameter.TermEntityGrade();
MapObjectForTEGrade(oTermEGrade, oReader);
return oTermEGrade;
}
private ObjectsTemplate<TermParameter.TermEntityGrade> FillChildren(DataReader dr)
{
ObjectsTemplate<TermParameter.TermEntityGrade> _TerEGrades = new ObjectsTemplate<TermParameter.TermEntityGrade>();
while (dr.Read())
{
TermParameter.TermEntityGrade item = this.CreateObjectForTEGrade(dr);
_TerEGrades.Add(item);
}
return _TerEGrades;
}
#region Service implementation
public TermParameter Get(ID id)
{
TermParameter oTermParameter = new TermParameter();
#region Cache Header
oTermParameter = _cache["Get", id] as TermParameter;
if (oTermParameter != null)
return oTermParameter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TermParameterDA.Get(tc, id));
if (oreader.Read())
{
oTermParameter = this.CreateObject<TermParameter>(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(oTermParameter, "Get", id);
#endregion
return oTermParameter;
}
public ObjectsTemplate<TermParameter> Get2(ID payrollTypeID)
{
#region Cache Header
ObjectsTemplate<TermParameter> termParams = _cache["Get"] as ObjectsTemplate<TermParameter>;
if (termParams != null)
return termParams;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TermParameterDA.Get2(tc, payrollTypeID));
termParams = this.CreateObjects<TermParameter>(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(termParams, "Get");
#endregion
return termParams;
}
public ObjectsTemplate<TermParameter> GetByGradeID(ID nGradeID)
{
#region Cache Header
ObjectsTemplate<TermParameter> termParams = _cache["Get",nGradeID] as ObjectsTemplate<TermParameter>;
if (termParams != null)
return termParams;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TermParameterDA.GetByGradeID(tc,nGradeID));
termParams = this.CreateObjects<TermParameter>(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(termParams, "Get",nGradeID);
#endregion
return termParams;
}
public ObjectsTemplate<TermParameter.TermEntityGrade> GetGrades(ID nID)
{
#region Cache Header
ObjectsTemplate<TermParameter.TermEntityGrade> termEntityGrades = _cache["Get", nID] as ObjectsTemplate<TermParameter.TermEntityGrade>;
if (termEntityGrades != null)
return termEntityGrades;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TermParameterDA.GetGrades(tc, nID));
termEntityGrades=FillChildren(dr);
//termEntityGrades = this.CreateObjects<TermEntityGrade>(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(termEntityGrades, "Get", nID);
#endregion
return termEntityGrades;
}
public ID Save(TermParameter oTermParameter)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTermParameter.IsNew)
{
int id = tc.GenerateID("TermParameter", "TermParameterID");
base.SetObjectID(oTermParameter, ID.FromInteger(id));
TermParameterDA.Insert(tc, oTermParameter);
}
else
{
TermParameterDA.Update(tc, oTermParameter);
TermParameterDA.DeleteGrade(tc, oTermParameter.ID);
}
foreach (TermParameter.TermEntityGrade teGrade in oTermParameter.TermEntityGrades)
{
teGrade.TermEntityID = oTermParameter.ID;
TermParameterDA.Insert(tc, teGrade);
}
SetupDetailService sdetailService = new SetupDetailService();
sdetailService.Save(tc, EnumParameterSetup.OT,
oTermParameter.SetupDetails, oTermParameter.ID);
//Newly Added by ashek 20 dec 2015
// Update oteligible property of employee table
if (oTermParameter.SetupDetails != null && oTermParameter.SetupDetails.Count > 0)
{
string sIDs = oTermParameter.SetupDetails
.Aggregate(new StringBuilder(),
(sb, item) => sb.Append(item.TranID.Integer + ","),
s => s.ToString().Trim(','));
EmployeeDA.UpdateOTFlag(tc, sIDs);
}
tc.End();
return oTermParameter.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)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
SetupDetailService sd = new SetupDetailService();
sd.Delete(tc, EnumParameterSetup.OT, id);
TermParameterDA.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
}