248 lines
7.2 KiB
C#
248 lines
7.2 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using Ease.CoreV35;
|
|||
|
using Ease.CoreV35.Caching;
|
|||
|
using Ease.CoreV35.DataAccess;
|
|||
|
using Ease.CoreV35.Model;
|
|||
|
using Payroll.BO;
|
|||
|
|
|||
|
|
|||
|
namespace Payroll.Service
|
|||
|
{
|
|||
|
[Serializable]
|
|||
|
public class BudgetCostCenterService : ServiceTemplate, IBudgetCostCenterService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(BudgetGrade));
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Object Mapping
|
|||
|
|
|||
|
private void MapObject(BudgetCostCenter oBudgetCostCenter, DataReader oReader)
|
|||
|
{
|
|||
|
SetObjectID(oBudgetCostCenter, oReader.GetID("BudgetCostCenterID"));
|
|||
|
oBudgetCostCenter.CostCenterID = oReader.GetID("CostCenterID");
|
|||
|
oBudgetCostCenter.BudgetID = oReader.GetID("BudgetID");
|
|||
|
oBudgetCostCenter.EmployeeID = oReader.GetID("EmployeeID");
|
|||
|
oBudgetCostCenter.FromMonth = oReader.GetDateTime("FromMonth").Value;
|
|||
|
oBudgetCostCenter.Percentage = oReader.GetDouble("Percentage").Value;
|
|||
|
SetObjectState(oBudgetCostCenter, ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader dr)
|
|||
|
{
|
|||
|
BudgetCostCenter oBudgetCostCenter = new BudgetCostCenter();
|
|||
|
MapObject(oBudgetCostCenter, dr);
|
|||
|
return oBudgetCostCenter as T;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Implementation
|
|||
|
|
|||
|
public BudgetCostCenter Get(ID nID)
|
|||
|
{
|
|||
|
BudgetCostCenter oBudgetCostCenter = new BudgetCostCenter();
|
|||
|
|
|||
|
#region Cache Header
|
|||
|
oBudgetCostCenter = _cache["Get", nID] as BudgetCostCenter;
|
|||
|
if (oBudgetCostCenter != null)
|
|||
|
return oBudgetCostCenter;
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetCostCenterDA.Get(tc, nID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oBudgetCostCenter = CreateObject<BudgetCostCenter>(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(oBudgetCostCenter, "Get", nID);
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetCostCenter;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<BudgetCostCenter> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<BudgetCostCenter> oBudgetCostCenters = _cache["Get"] as ObjectsTemplate<BudgetCostCenter>;
|
|||
|
if (oBudgetCostCenters != null)
|
|||
|
return oBudgetCostCenters;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetCostCenterDA.Get(tc));
|
|||
|
// if (oreader.Read())
|
|||
|
//{
|
|||
|
oBudgetCostCenters = this.CreateObjects<BudgetCostCenter>(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(oBudgetCostCenters, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetCostCenters;
|
|||
|
}
|
|||
|
public ObjectsTemplate<BudgetCostCenter> Get(int nID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<BudgetCostCenter> oBudgetCostCenters = _cache["Get"] as ObjectsTemplate<BudgetCostCenter>;
|
|||
|
if (oBudgetCostCenters != null)
|
|||
|
return oBudgetCostCenters;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetCostCenterDA.Get(tc,nID));
|
|||
|
// if (oreader.Read())
|
|||
|
//{
|
|||
|
oBudgetCostCenters = this.CreateObjects<BudgetCostCenter>(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(oBudgetCostCenters, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetCostCenters;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(BudgetCostCenter item)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (item.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("BudgetCostCenter", "BudgetCostCenterID");
|
|||
|
SetObjectID(item, ID.FromInteger(id));
|
|||
|
BudgetCostCenterDA.Insert(tc, item);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
BudgetCostCenterDA.Update(tc, item);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
|
|||
|
return item.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(BudgetCostCenter item,TransactionContext tc)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
int id = tc.GenerateID("BudgetCostCenter", "BudgetCostCenterID");
|
|||
|
SetObjectID(item, ID.FromInteger(id));
|
|||
|
BudgetCostCenterDA.Insert(tc, item);
|
|||
|
|
|||
|
return item.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 nID)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
BudgetCostCenterDA.Delete(tc, nID);
|
|||
|
tc.End();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
ExceptionLog.Write(e);
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|