209 lines
6.6 KiB
C#
209 lines
6.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 BudgetDepartment Service
|
|
[Serializable]
|
|
public class BudgetDepartmentService : ServiceTemplate, IBudgetDepartmentService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(BudgetDepartment));
|
|
|
|
#endregion
|
|
public BudgetDepartmentService() { }
|
|
|
|
private void MapObject(BudgetDepartment oBudgetDepartment, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oBudgetDepartment, oReader.GetID("BudgetDepartmentID"));
|
|
oBudgetDepartment.BudgetudID = oReader.GetID("BudgetID");
|
|
oBudgetDepartment.DepartmentID = oReader.GetID("DepartmentID");
|
|
this.SetObjectState(oBudgetDepartment, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
BudgetDepartment oBudgetDepartment = new BudgetDepartment();
|
|
MapObject(oBudgetDepartment, oReader);
|
|
return oBudgetDepartment as T;
|
|
}
|
|
protected BudgetDepartment CreateObject(DataReader oReader)
|
|
{
|
|
BudgetDepartment oBudgetDepartment = new BudgetDepartment();
|
|
MapObject(oBudgetDepartment, oReader);
|
|
return oBudgetDepartment;
|
|
}
|
|
#region Service implementation
|
|
|
|
public BudgetDepartment Get(ID id)
|
|
{
|
|
BudgetDepartment oBudgetDepartment = new BudgetDepartment();
|
|
#region Cache Header
|
|
oBudgetDepartment = _cache["Get", id] as BudgetDepartment;
|
|
if (oBudgetDepartment != null)
|
|
return oBudgetDepartment;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BudgetDepartmentDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBudgetDepartment = this.CreateObject<BudgetDepartment>(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(oBudgetDepartment, "Get", id);
|
|
#endregion
|
|
return oBudgetDepartment;
|
|
}
|
|
|
|
public ObjectsTemplate<BudgetDepartment> Get(int nID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<BudgetDepartment> BudgetDepartments = _cache["Get"] as ObjectsTemplate<BudgetDepartment>;
|
|
if (BudgetDepartments != null)
|
|
return BudgetDepartments;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BudgetDepartmentDA.Get(tc, nID));
|
|
BudgetDepartments = this.CreateObjects<BudgetDepartment>(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(BudgetDepartments, "Get");
|
|
|
|
#endregion
|
|
|
|
return BudgetDepartments;
|
|
}
|
|
public ID Save(BudgetDepartment oBudgetDepartment)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int codeLength = 3;
|
|
if (oBudgetDepartment.IsNew)
|
|
{
|
|
|
|
int id = tc.GenerateID("BudgetDepartment", "BudgetDepartmentID");
|
|
base.SetObjectID(oBudgetDepartment, ID.FromInteger(id));
|
|
|
|
int seqNo = tc.GenerateID("BudgetDepartment", "SequenceNo");
|
|
oBudgetDepartment.Sequence = seqNo;
|
|
BudgetDepartmentDA.Insert(tc, oBudgetDepartment);
|
|
}
|
|
else
|
|
{
|
|
BudgetDepartmentDA.Update(tc, oBudgetDepartment);
|
|
}
|
|
tc.End();
|
|
return oBudgetDepartment.ID;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
public ID Save(BudgetDepartment oBudgetDepartment,TransactionContext tc)
|
|
{
|
|
try
|
|
{
|
|
//if (oBudgetDepartment.IsNew)
|
|
//{
|
|
|
|
int id = tc.GenerateID("BudgetDepartment", "BudgetDepartmentID");
|
|
base.SetObjectID(oBudgetDepartment, ID.FromInteger(id));
|
|
BudgetDepartmentDA.Insert(tc, oBudgetDepartment);
|
|
//}
|
|
//else
|
|
//{
|
|
// BudgetDepartmentDA.Update(tc, oBudgetDepartment);
|
|
//}
|
|
return oBudgetDepartment.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);
|
|
BudgetDepartmentDA.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
|
|
}
|
|
|