CEL_Payroll/Payroll.Service/Bonus/Service/ProdBonusWorkScheduleService.cs

201 lines
7.2 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
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
{
public class ProdBonusWorkScheduleService: ServiceTemplate, IProdBonusWorkScheduleService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ProdBonusWorkSchedule));
#endregion
public ProdBonusWorkScheduleService() { }
private void MapObject(ProdBonusWorkSchedule oProdBonusWorkSchedule, DataReader oReader)
{
//oProdBonusWorkSchedule.ID = oReader.GetID("ProdBonusWorkScheduleID");
base.SetObjectID(oProdBonusWorkSchedule, oReader.GetID("ProdBonusWorkScheduleID"));
oProdBonusWorkSchedule.ProdBonusSetupID = oReader.GetID("ProdBonusSetupID");
oProdBonusWorkSchedule.ProdBonusLineID = oReader.GetID("ProdBonusLineID");
oProdBonusWorkSchedule.StartDateTime = oReader.GetDateTime("StartDateTime").Value;
//oProdBonusWorkSchedule.EndDateTime = oReader.GetDateTime("EndDateTime").Value;
this.SetObjectState(oProdBonusWorkSchedule,Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule();
MapObject(oProdBonusWorkSchedule, oReader);
return oProdBonusWorkSchedule as T;
}
protected ProdBonusWorkSchedule CreateObject(DataReader oReader)
{
ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule();
MapObject(oProdBonusWorkSchedule, oReader);
return oProdBonusWorkSchedule;
}
#region Service implementation
public ProdBonusWorkSchedule Get(ID id)
{
ProdBonusWorkSchedule oProdBonusWorkSchedule = new ProdBonusWorkSchedule();
#region Cache Header
oProdBonusWorkSchedule = _cache["Get", id] as ProdBonusWorkSchedule;
if (oProdBonusWorkSchedule != null)
return oProdBonusWorkSchedule;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ProdBonusWorkScheduleDA.Get(tc, id));
if (oreader.Read())
{
oProdBonusWorkSchedule = this.CreateObject<ProdBonusWorkSchedule>(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(oProdBonusWorkSchedule, "Get", id);
#endregion
return oProdBonusWorkSchedule;
}
public ObjectsTemplate<ProdBonusWorkSchedule> Get()
{
#region Cache Header
ObjectsTemplate<ProdBonusWorkSchedule> ProdBonusWorkSchedules = _cache["Get"] as ObjectsTemplate<ProdBonusWorkSchedule>;
if (ProdBonusWorkSchedules != null)
return ProdBonusWorkSchedules;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusWorkScheduleDA.Get(tc));
ProdBonusWorkSchedules = this.CreateObjects<ProdBonusWorkSchedule>(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(ProdBonusWorkSchedules, "Get");
#endregion
return ProdBonusWorkSchedules;
}
public ObjectsTemplate<ProdBonusWorkSchedule> Get(int nSetupID)
{
#region Cache Header
ObjectsTemplate<ProdBonusWorkSchedule> ProdBonusWorkSchedules = _cache["Get"] as ObjectsTemplate<ProdBonusWorkSchedule>;
if (ProdBonusWorkSchedules != null)
return ProdBonusWorkSchedules;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusWorkScheduleDA.Get(tc, nSetupID));
ProdBonusWorkSchedules = this.CreateObjects<ProdBonusWorkSchedule>(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(ProdBonusWorkSchedules, "Get");
#endregion
return ProdBonusWorkSchedules;
}
public ID Save(ProdBonusWorkSchedule oProdBonusWorkSchedule)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oProdBonusWorkSchedule.IsNew)
{
int id = tc.GenerateID("ProdBonusWorkSchedule", "ProdBonusWorkScheduleID");
base.SetObjectID(oProdBonusWorkSchedule, ID.FromInteger(id));
int seqNo = tc.GenerateID("ProdBonusWorkSchedule", "SequenceNO");
oProdBonusWorkSchedule.Sequence = seqNo;
ProdBonusWorkScheduleDA.Insert(tc, oProdBonusWorkSchedule);
}
else
{
ProdBonusWorkScheduleDA.Update(tc, oProdBonusWorkSchedule);
}
tc.End();
return oProdBonusWorkSchedule.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);
ProdBonusWorkScheduleDA.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
}
}