CEL_Payroll/Payroll.Service/JV/Service/JVSetupCCService.cs

200 lines
6.8 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region JVSetupCC Service
[Serializable]
public class JVSetupCCService : ServiceTemplate, IJVSetupCCService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(JVSetupCC));
public JVSetupCCService() { }
private void MapObject(JVSetupCC oJVSetupCC, DataReader oReader)
{
base.SetObjectID(oJVSetupCC, ID.FromInteger(oReader.GetInt32("JVSetupCCID").Value));
oJVSetupCC.CCID = oReader.GetString("CCID") == null ? null : ID.FromInteger(oReader.GetInt32("CCID").Value);
oJVSetupCC.JVSetupID = oReader.GetString("JVSetupID") == null ? null : ID.FromInteger(oReader.GetInt32("JVSetupID").Value);
oJVSetupCC.CreatedBy = oReader.GetString("CreatedBy") == null ? null : ID.FromInteger(oReader.GetInt32("CreatedBy").Value);
oJVSetupCC.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oJVSetupCC.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : ID.FromInteger(oReader.GetInt32("ModifiedBy").Value);
oJVSetupCC.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oJVSetupCC, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
JVSetupCC oJVSetupCC = new JVSetupCC();
MapObject(oJVSetupCC, oReader);
return oJVSetupCC as T;
}
protected JVSetupCC CreateObject(DataReader oReader)
{
JVSetupCC oJVSetupCC = new JVSetupCC();
MapObject(oJVSetupCC, oReader);
return oJVSetupCC;
}
#endregion
#region Service implementation
public JVSetupCC Get(ID id)
{
JVSetupCC oJVSetupDetail = new JVSetupCC();
#region Cache Header
oJVSetupDetail = (JVSetupCC)_cache["Get", id];
if (oJVSetupDetail != null)
return oJVSetupDetail;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(JVSetupCCDA.Get(tc, id));
if (oreader.Read())
{
oJVSetupDetail = this.CreateObject<JVSetupCC>(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(oJVSetupDetail, "Get", id);
#endregion
return oJVSetupDetail;
}
public ObjectsTemplate<JVSetupCC> Get()
{
#region Cache Header
ObjectsTemplate<JVSetupCC> oJVSetupDetails = _cache["Get"] as ObjectsTemplate<JVSetupCC>;
if (oJVSetupDetails != null)
return oJVSetupDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(JVSetupCCDA.Get(tc));
oJVSetupDetails = this.CreateObjects<JVSetupCC>(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(oJVSetupDetails, "Get");
#endregion
return oJVSetupDetails;
}
public ObjectsTemplate<JVSetupCC> GetByJVSetup(ID JVSetupID)
{
#region Cache Header
ObjectsTemplate<JVSetupCC> JVSetupDetails = _cache["GetByJVSetup", JVSetupID] as ObjectsTemplate<JVSetupCC>;
if (JVSetupDetails != null)
return JVSetupDetails;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(JVSetupCCDA.GetByJVSetup(tc, JVSetupID));
JVSetupDetails = this.CreateObjects<JVSetupCC>(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(JVSetupDetails, "GetByJVSetup", JVSetupID);
#endregion
return JVSetupDetails;
}
public ID Save(JVSetupCC oJVSetupCC)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oJVSetupCC.IsNew)
{
int id = tc.GenerateID("JVSetupCC", "JVSetupCCID");
base.SetObjectID(oJVSetupCC, ID.FromInteger(id));
JVSetupCCDA.Insert(tc, oJVSetupCC);
}
else
{
JVSetupCCDA.Update(tc, oJVSetupCC);
}
return oJVSetupCC.ID;
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException("Failed to GetJVSetupDetail", e);
#endregion
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
JVSetupCCDA.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
}