270 lines
7.6 KiB
C#
270 lines
7.6 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 class DivisionService
|
|
public class DivisionService : ServiceTemplate, IDivisionService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(Division));
|
|
#endregion
|
|
|
|
#region constructor
|
|
public DivisionService() { }
|
|
#endregion
|
|
|
|
#region Object
|
|
|
|
private void MapObject(Division oDivision, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oDivision, oReader.GetID("DIVISIONID"));
|
|
oDivision.Code = oReader.GetString("CODE");
|
|
oDivision.Name = oReader.GetString("NAME");
|
|
oDivision.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|
oDivision.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|
oDivision.CreatedBy = oReader.GetID("CreatedBy");
|
|
oDivision.CreatedDate = oReader.GetDateTime("CreationDate").Value;
|
|
oDivision.ModifiedBy = oReader.GetID("ModifiedBy");
|
|
oDivision.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|
|
|
this.SetObjectState(oDivision, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
Division oDivision = new Division();
|
|
MapObject(oDivision, oReader);
|
|
return oDivision as T;
|
|
}
|
|
|
|
protected Division CreateObject(DataReader oReader)
|
|
{
|
|
Division oDivision = new Division();
|
|
MapObject(oDivision, oReader);
|
|
return oDivision;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service implementation
|
|
|
|
public Division Get(ID id)
|
|
{
|
|
Division oDivision = new Division();
|
|
#region Cache Header
|
|
oDivision = _cache["Get", id] as Division;
|
|
if (oDivision != null)
|
|
return oDivision;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(DivisionDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oDivision = this.CreateObject<Division>(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(oDivision, "Get", id);
|
|
#endregion
|
|
return oDivision;
|
|
}
|
|
|
|
public Division Get(string sCode)
|
|
{
|
|
Division oDivision = new Division();
|
|
#region Cache Header
|
|
oDivision = _cache["Get", sCode] as Division;
|
|
if (oDivision != null)
|
|
return oDivision;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(DivisionDA.Get(tc, sCode));
|
|
if (oreader.Read())
|
|
{
|
|
oDivision = this.CreateObject<Division>(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(oDivision, "Get", sCode);
|
|
#endregion
|
|
return oDivision;
|
|
}
|
|
|
|
public ObjectsTemplate<Division> Get()
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Division> countries = _cache["Get"] as ObjectsTemplate<Division>;
|
|
if (countries != null)
|
|
return countries;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DivisionDA.Get(tc));
|
|
countries = this.CreateObjects<Division>(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(countries, "Get");
|
|
|
|
#endregion
|
|
|
|
return countries;
|
|
}
|
|
|
|
public ObjectsTemplate<Division> Get(EnumStatus status)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<Division> countries = _cache["Get"] as ObjectsTemplate<Division>;
|
|
if (countries != null)
|
|
return countries;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(DivisionDA.Get(tc, status));
|
|
countries = this.CreateObjects<Division>(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(countries, "Get", status);
|
|
|
|
#endregion
|
|
|
|
return countries;
|
|
}
|
|
|
|
public ID Save(Division oDivision)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oDivision.IsNew)
|
|
{
|
|
int id = tc.GenerateID("DIVISION", "DIVISIONID");
|
|
base.SetObjectID(oDivision, ID.FromInteger(id));
|
|
DivisionDA.Insert(tc, oDivision);
|
|
}
|
|
else
|
|
{
|
|
DivisionDA.Update(tc, oDivision);
|
|
}
|
|
tc.End();
|
|
return oDivision.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);
|
|
DivisionDA.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
|
|
}
|