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

194 lines
7.0 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
{
internal class ProdBonusParameterService : ServiceTemplate, IProdBonusParameterService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ProdBonusParameter));
#endregion
public ProdBonusParameterService() { }
private void MapObject(ProdBonusParameter oProdBonusParameter, DataReader oReader)
{
//oProdBonusParameter.ID = oReader.GetID("ProdBonusParameterID");
base.SetObjectID(oProdBonusParameter, oReader.GetID("ProdBonusParameterID"));
oProdBonusParameter.ProdBonusLineID = oReader.GetID("ProdBonusLineID");
oProdBonusParameter.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID");
oProdBonusParameter.ItemID = oReader.GetID("ItemID");
oProdBonusParameter.ItemType = (EnumBonusItemType)oReader.GetInt32("ItemType").Value;
oProdBonusParameter.ProdBonusLineID = oReader.GetID("ProdBonusLineID");
this.SetObjectState(oProdBonusParameter,Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ProdBonusParameter oProdBonusParameter = new ProdBonusParameter();
MapObject(oProdBonusParameter, oReader);
return oProdBonusParameter as T;
}
protected ProdBonusParameter CreateObject(DataReader oReader)
{
ProdBonusParameter oProdBonusParameter = new ProdBonusParameter();
MapObject(oProdBonusParameter, oReader);
return oProdBonusParameter;
}
#region Service implementation
public ProdBonusParameter Get(ID id)
{
ProdBonusParameter oProdBonusParameter = new ProdBonusParameter();
#region Cache Header
oProdBonusParameter = _cache["Get", id] as ProdBonusParameter;
if (oProdBonusParameter != null)
return oProdBonusParameter;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ProdBonusParameterDA.Get(tc, id));
if (oreader.Read())
{
oProdBonusParameter = this.CreateObject<ProdBonusParameter>(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(oProdBonusParameter, "Get", id);
#endregion
return oProdBonusParameter;
}
public ObjectsTemplate<ProdBonusParameter> Get()
{
#region Cache Header
ObjectsTemplate<ProdBonusParameter> ProdBonusParameters = _cache["Get"] as ObjectsTemplate<ProdBonusParameter>;
if (ProdBonusParameters != null)
return ProdBonusParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusParameterDA.Get(tc));
ProdBonusParameters = this.CreateObjects<ProdBonusParameter>(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(ProdBonusParameters, "Get");
#endregion
return ProdBonusParameters;
}
public ObjectsTemplate<ProdBonusParameter> Get(int nSetupID)
{
#region Cache Header
ObjectsTemplate<ProdBonusParameter> ProdBonusParameters = _cache["Get"] as ObjectsTemplate<ProdBonusParameter>;
if (ProdBonusParameters != null)
return ProdBonusParameters;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusParameterDA.Get(tc, nSetupID));
ProdBonusParameters = this.CreateObjects<ProdBonusParameter>(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(ProdBonusParameters, "Get");
#endregion
return ProdBonusParameters;
}
public ID Save(ProdBonusParameter oProdBonusParameter)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oProdBonusParameter.IsNew)
{
int id = tc.GenerateID("ProdBonusParameter", "ProdBonusParameterID");
base.SetObjectID(oProdBonusParameter, ID.FromInteger(id));
int seqNo = tc.GenerateID("ProdBonusParameter", "SequenceNO");
oProdBonusParameter.Sequence = seqNo;
ProdBonusParameterDA.Insert(tc, oProdBonusParameter);
}
else
{
ProdBonusParameterDA.Update(tc, oProdBonusParameter);
}
tc.End();
return oProdBonusParameter.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);
ProdBonusParameterDA.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
}
}