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

247 lines
6.9 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 OTSlab Service
[Serializable]
public class OTSlabService : ServiceTemplate, IOTSlabService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(OTSlab));
#endregion
public OTSlabService() { }
private void MapObject(OTSlab oOTSlab, DataReader oReader)
{
base.SetObjectID(oOTSlab, oReader.GetID("OTSlabID"));
oOTSlab.Hours = oReader.GetInt32("hours").Value;
oOTSlab.Amount = oReader.GetInt32("amount").Value;
oOTSlab.TermID = oReader.GetID("TermID");
this.SetObjectState(oOTSlab, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
OTSlab oOTSlab = new OTSlab();
MapObject(oOTSlab, oReader);
return oOTSlab as T;
}
protected OTSlab CreateObject(DataReader oReader)
{
OTSlab oOTSlab = new OTSlab();
MapObject(oOTSlab, oReader);
return oOTSlab;
}
#region Service implementation
public OTSlab Get(ID id)
{
OTSlab oOTSlab = new OTSlab();
#region Cache Header
oOTSlab = _cache["Get", id] as OTSlab;
if (oOTSlab != null)
return oOTSlab;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(OTSlabDA.Get(tc, id));
if (oreader.Read())
{
oOTSlab = this.CreateObject<OTSlab>(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(oOTSlab, "Get", id);
#endregion
return oOTSlab;
}
public ObjectsTemplate<OTSlab> Get()
{
#region Cache Header
ObjectsTemplate<OTSlab> oTSlabs = _cache["Get"] as ObjectsTemplate<OTSlab>;
if (oTSlabs != null)
return oTSlabs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTSlabDA.Get(tc));
oTSlabs = this.CreateObjects<OTSlab>(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(oTSlabs, "Get");
#endregion
return oTSlabs;
}
public ObjectsTemplate<OTSlab> GetByTermID(ID nTermID)
{
#region Cache Header
ObjectsTemplate<OTSlab> oTSlabs = _cache["Get",nTermID] as ObjectsTemplate<OTSlab>;
if (oTSlabs != null)
return oTSlabs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(OTSlabDA.GetByTermID(tc,nTermID));
oTSlabs = this.CreateObjects<OTSlab>(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(oTSlabs, "Get",nTermID);
#endregion
return oTSlabs;
}
public ID Save(OTSlab oOTSlab)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oOTSlab.IsNew)
{
int id = tc.GenerateID("OTSlab", "OTSlabID");
base.SetObjectID(oOTSlab, ID.FromInteger(id));
OTSlabDA.Insert(tc, oOTSlab);
}
else
{
OTSlabDA.Update(tc, oOTSlab);
}
tc.End();
return oOTSlab.ID;
}
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<OTSlab> _OTSlabs)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OTSlabDA.DeleteByTermID(tc, _OTSlabs[0].TermID);
foreach (OTSlab oTSlab in _OTSlabs)
{
if (oTSlab.IsNew)
{
int id = tc.GenerateID("OTSlab", "OTSlabID");
base.SetObjectID(oTSlab, ID.FromInteger(id));
OTSlabDA.Insert(tc, oTSlab);
}
}
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 Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
OTSlabDA.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
}