451 lines
14 KiB
C#
451 lines
14 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 PayScale Service
|
|
[Serializable]
|
|
public class PayScaleService : ServiceTemplate, IPayScaleService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(PayScale));
|
|
|
|
#endregion
|
|
public PayScaleService() { }
|
|
|
|
private void MapObject(PayScale oPayScale, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oPayScale, oReader.GetID("PAYSCALEID"));
|
|
oPayScale.GradeID = oReader.GetID("GradeID");
|
|
oPayScale.ItemID = oReader.GetInt32("ALLOWANCEID").Value;
|
|
oPayScale.InitialAmount = oReader.GetDouble("INITIALAMOUNT").Value;
|
|
oPayScale.IncPercentage = oReader.GetDouble("PercentageInc").Value;
|
|
oPayScale.NoOfStep = oReader.GetInt32("NOOFSLABS").Value;
|
|
oPayScale.EffectDate = oReader.GetDateTime("EffectDate").Value;
|
|
oPayScale.ItemType =(EnumPayScaleItemType)oReader.GetInt32("Type").Value;
|
|
this.SetObjectState(oPayScale, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
PayScale oPayScale = new PayScale();
|
|
MapObject(oPayScale, oReader);
|
|
return oPayScale as T;
|
|
}
|
|
protected PayScale CreateObject(DataReader oReader)
|
|
{
|
|
PayScale oPayScale = new PayScale();
|
|
MapObject(oPayScale, oReader);
|
|
return oPayScale;
|
|
}
|
|
#region Service implementation
|
|
public PayScale Get(ID id)
|
|
{
|
|
PayScale oPayScale = new PayScale();
|
|
#region Cache Header
|
|
oPayScale = _cache["Get", id] as PayScale;
|
|
if (oPayScale != null)
|
|
return oPayScale;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(PayScaleDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oPayScale = this.CreateObject<PayScale>(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(oPayScale, "Get", id);
|
|
#endregion
|
|
return oPayScale;
|
|
}
|
|
|
|
public PayScale Get(ID nGradeID, ID nAllowID, DateTime nextPayProcessDate)
|
|
{
|
|
PayScale oPayScale = new PayScale();
|
|
#region Cache Header
|
|
oPayScale = _cache["Get", nGradeID, nAllowID] as PayScale;
|
|
if (oPayScale != null)
|
|
return oPayScale;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(PayScaleDA.Get(tc, nGradeID, nAllowID, nextPayProcessDate));
|
|
if (oreader.Read())
|
|
{
|
|
oPayScale = this.CreateObject<PayScale>(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(oPayScale, "Get", nGradeID, nAllowID);
|
|
#endregion
|
|
return oPayScale;
|
|
}
|
|
public PayScale GetByGrade(ID nGradeID)
|
|
{
|
|
PayScale oPayScale = new PayScale();
|
|
#region Cache Header
|
|
oPayScale = _cache["GetByGrade", nGradeID] as PayScale;
|
|
if (oPayScale != null)
|
|
return oPayScale;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(PayScaleDA.GetByGrade(tc, nGradeID));
|
|
if (oreader.Read())
|
|
{
|
|
oPayScale = this.CreateObject<PayScale>(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(oPayScale, "GetByGrade", nGradeID);
|
|
#endregion
|
|
return oPayScale;
|
|
}
|
|
|
|
public DateTime? GetMaxEffectDate(ID PayrollTypeID)
|
|
{
|
|
TransactionContext tc = null;
|
|
DateTime ?dMaxEffectDate = DateTime.MinValue;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(PayScaleDA.GetMaxEffectDate(tc,PayrollTypeID));
|
|
if (oreader.Read())
|
|
{
|
|
dMaxEffectDate = oreader.GetDateTime(0);
|
|
}
|
|
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 dMaxEffectDate;
|
|
}
|
|
|
|
public ObjectsTemplate<PayScale> GetByAllowance(ID nAllowID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<PayScale> payScales = _cache["GetByAllowance", nAllowID] as ObjectsTemplate<PayScale>;
|
|
if (payScales != null)
|
|
return payScales;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(PayScaleDA.GetByAllowance(tc,nAllowID));
|
|
payScales = this.CreateObjects<PayScale>(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(payScales, "GetByAllowance", nAllowID);
|
|
|
|
#endregion
|
|
|
|
return payScales;
|
|
}
|
|
public ObjectsTemplate<PayScale> Get()
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<PayScale> payScales = _cache["Get"] as ObjectsTemplate<PayScale>;
|
|
if (payScales != null)
|
|
return payScales;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(PayScaleDA.Get(tc));
|
|
payScales = this.CreateObjects<PayScale>(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(payScales, "Get");
|
|
|
|
#endregion
|
|
|
|
return payScales;
|
|
}
|
|
public ObjectsTemplate<PayScale> GetLatest(ID PayrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<PayScale> payScales = _cache["GetLatest"] as ObjectsTemplate<PayScale>;
|
|
if (payScales != null)
|
|
return payScales;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(PayScaleDA.GetLatest(tc, PayrollTypeID));
|
|
payScales = this.CreateObjects<PayScale>(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(payScales, "GetLatest");
|
|
|
|
#endregion
|
|
|
|
return payScales;
|
|
}
|
|
|
|
public ID Save(PayScale oPayScale)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oPayScale.IsNew)
|
|
{
|
|
int id = tc.GenerateID("PayScale", "PAYSCALEID");
|
|
base.SetObjectID(oPayScale, ID.FromInteger(id));
|
|
PayScaleDA.Insert(tc, oPayScale);
|
|
}
|
|
else
|
|
{
|
|
PayScaleDA.Update(tc, oPayScale);
|
|
PayScaleDetailDA.DeleteByPayScaleID(tc, oPayScale.ID);
|
|
}
|
|
foreach (PayScaleDetail detail in oPayScale.PayscaleDetails)
|
|
{
|
|
detail.PayscaleID = oPayScale.ID;
|
|
int id = tc.GenerateID("PAYSCALEITEM", "PAYSCALEITEMID");
|
|
base.SetObjectID(detail, ID.FromInteger(id));
|
|
detail.GradeID = oPayScale.GradeID;
|
|
detail.AllowanceID =ID.FromInteger(oPayScale.ItemID);
|
|
PayScaleDetailDA.Insert(tc, detail);
|
|
}
|
|
tc.End();
|
|
return oPayScale.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public ID Save(TransactionContext tc,PayScale oPayScale)
|
|
{
|
|
try
|
|
{
|
|
if (oPayScale.IsNew)
|
|
{
|
|
int id = tc.GenerateID("PayScale", "PAYSCALEID");
|
|
base.SetObjectID(oPayScale, ID.FromInteger(id));
|
|
PayScaleDA.Insert(tc, oPayScale);
|
|
}
|
|
else
|
|
{
|
|
PayScaleDA.Update(tc, oPayScale);
|
|
PayScaleDetailDA.DeleteByPayScaleID(tc, oPayScale.ID);
|
|
}
|
|
foreach (PayScaleDetail detail in oPayScale.PayscaleDetails)
|
|
{
|
|
detail.PayscaleID = oPayScale.ID;
|
|
int id = tc.GenerateID("PAYSCALEITEM", "PAYSCALEITEMID");
|
|
base.SetObjectID(detail, ID.FromInteger(id));
|
|
detail.GradeID = oPayScale.GradeID;
|
|
detail.AllowanceID = ID.FromInteger(oPayScale.ItemID);
|
|
PayScaleDetailDA.Insert(tc, detail);
|
|
}
|
|
return oPayScale.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);
|
|
PayScaleDA.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
|
|
}
|
|
}
|
|
|
|
public void Save(ObjectsTemplate<PayScale> newPayscale)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
foreach (PayScale scale in newPayscale)
|
|
{
|
|
this.Save(tc,scale);
|
|
}
|
|
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public void DeleteByGradeID(ID id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
PayScaleDA.DeleteByGrade(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
|
|
}
|