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

216 lines
7.1 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 CRGDepartmentLookup Service
[Serializable]
public class CRGDepartmentLookupService : ServiceTemplate, ICRGDepartmentLookupService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(CRGDepartmentLookup));
#endregion
public CRGDepartmentLookupService() { }
private void MapObject(CRGDepartmentLookup oCRGDepartmentLookup, DataReader oReader)
{
base.SetObjectID(oCRGDepartmentLookup, oReader.GetID("CRGDepartmentLookupID"));
oCRGDepartmentLookup.CrgID = oReader.GetID("CrgID");
oCRGDepartmentLookup.DepartmentID = oReader.GetID("DepartmentID");
this.SetObjectState(oCRGDepartmentLookup, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
CRGDepartmentLookup oCRGDepartmentLookup = new CRGDepartmentLookup();
MapObject(oCRGDepartmentLookup, oReader);
return oCRGDepartmentLookup as T;
}
protected CRGDepartmentLookup CreateObject(DataReader oReader)
{
CRGDepartmentLookup oCRGDepartmentLookup = new CRGDepartmentLookup();
MapObject(oCRGDepartmentLookup, oReader);
return oCRGDepartmentLookup;
}
#region Service implementation
public CRGDepartmentLookup Get(ID id)
{
CRGDepartmentLookup oCRGDepartmentLookup = new CRGDepartmentLookup();
#region Cache Header
oCRGDepartmentLookup = _cache["Get", id] as CRGDepartmentLookup;
if (oCRGDepartmentLookup != null)
return oCRGDepartmentLookup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(CRGDepartmentLookupDA.Get(tc, id));
if (oreader.Read())
{
oCRGDepartmentLookup = this.CreateObject<CRGDepartmentLookup>(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(oCRGDepartmentLookup, "Get", id);
#endregion
return oCRGDepartmentLookup;
}
public ObjectsTemplate<CRGDepartmentLookup> Get()
{
#region Cache Header
ObjectsTemplate<CRGDepartmentLookup> oCDLookups = _cache["Get"] as ObjectsTemplate<CRGDepartmentLookup>;
if (oCDLookups != null)
return oCDLookups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(CRGDepartmentLookupDA.Get(tc));
oCDLookups = this.CreateObjects<CRGDepartmentLookup>(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(oCDLookups, "Get");
#endregion
return oCDLookups;
}
public ID Save(CRGDepartmentLookup oCRGDepartmentLookup)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oCRGDepartmentLookup.IsNew)
{
int id = tc.GenerateID("CRGDepartmentLookup", "CRGDepartmentLookupID");
base.SetObjectID(oCRGDepartmentLookup, ID.FromInteger(id));
CRGDepartmentLookupDA.Insert(tc, oCRGDepartmentLookup);
}
else
{
CRGDepartmentLookupDA.Update(tc, oCRGDepartmentLookup);
}
tc.End();
return oCRGDepartmentLookup.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<CRGDepartmentLookup> oCDLookups)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ObjectsTemplate<CRGDepartmentLookup> deleteLookUp = new ObjectsTemplate<CRGDepartmentLookup>();
DataReader dr = new DataReader(CRGDepartmentLookupDA.Get(tc));
deleteLookUp = this.CreateObjects<CRGDepartmentLookup>(dr);
dr.Close();
if (deleteLookUp.Count > 0)
{
CRGDepartmentLookupDA.Delete(tc);
}
foreach (CRGDepartmentLookup lookUp in oCDLookups)
{
this.SetObjectState(lookUp, ObjectState.New);
if (lookUp.IsNew)
{
int id = tc.GenerateID("CRGDepartmentLookup", "CRGDepartmentLookupID");
base.SetObjectID(lookUp, ID.FromInteger(id));
CRGDepartmentLookupDA.Insert(tc, lookUp);
}
else
{
CRGDepartmentLookupDA.Update(tc, lookUp);
}
}
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);
CRGDepartmentLookupDA.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
}