CEL_Payroll/Payroll.Service/Budget/Service/BudgetIndivisualChangeService.cs

250 lines
7.8 KiB
C#
Raw Permalink 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.Caching;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Model;
using Payroll.BO;
namespace Payroll.Service
{
[Serializable]
public class BudgetIndivisualChangeService : ServiceTemplate, IBudgetIndivisualChangeService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(BudgetIndivisualChange));
#endregion
#region Object Mapping
private void MapObject(BudgetIndivisualChange oBudgetIndivisualChange, DataReader oReader)
{
SetObjectID(oBudgetIndivisualChange, oReader.GetID("BudgetIndivisualChangeID"));
oBudgetIndivisualChange.BudgetID = oReader.GetID("BudgetID");
oBudgetIndivisualChange.ButGetIndvChangeType = (EnumBudgetChangeType) oReader.GetInt32("ButGetIndvChangeType").Value;
oBudgetIndivisualChange.EffectDate = oReader.GetDateTime("EffectDate").Value;
oBudgetIndivisualChange.EmployeeID = oReader.GetID("EmployeeID");
oBudgetIndivisualChange.Value = oReader.GetID("Value");
oBudgetIndivisualChange.ChangedBasic = oReader.GetDouble("ChangedBasic").Value;
oBudgetIndivisualChange.ValueType = (EnumValueType)oReader.GetInt32("ValueType").Value;
SetObjectState(oBudgetIndivisualChange, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
BudgetIndivisualChange oBudgetIndivisualChange = new BudgetIndivisualChange();
MapObject(oBudgetIndivisualChange, dr);
return oBudgetIndivisualChange as T;
}
#endregion
#region Service Implementation
public BudgetIndivisualChange Get(ID nID)
{
BudgetIndivisualChange oBudgetIndivisualChange = new BudgetIndivisualChange();
#region Cache Header
oBudgetIndivisualChange = _cache["Get", nID] as BudgetIndivisualChange;
if (oBudgetIndivisualChange != null)
return oBudgetIndivisualChange;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetIndivisualChangeDA.Get(tc, nID));
if (oreader.Read())
{
oBudgetIndivisualChange = CreateObject<BudgetIndivisualChange>(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(oBudgetIndivisualChange, "Get", nID);
#endregion
return oBudgetIndivisualChange;
}
public ObjectsTemplate<BudgetIndivisualChange> Get()
{
#region Cache Header
ObjectsTemplate<BudgetIndivisualChange> oBudgetIndivisualChanges = _cache["Get"] as ObjectsTemplate<BudgetIndivisualChange>;
if (oBudgetIndivisualChanges != null)
return oBudgetIndivisualChanges;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetIndivisualChangeDA.Get(tc));
// if (oreader.Read())
//{
oBudgetIndivisualChanges = this.CreateObjects<BudgetIndivisualChange>(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(oBudgetIndivisualChanges, "Get");
#endregion
return oBudgetIndivisualChanges;
}
public ObjectsTemplate<BudgetIndivisualChange> Get(int nBudID)
{
#region Cache Header
ObjectsTemplate<BudgetIndivisualChange> oBudgetIndivisualChanges = _cache["Get"] as ObjectsTemplate<BudgetIndivisualChange>;
if (oBudgetIndivisualChanges != null)
return oBudgetIndivisualChanges;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetIndivisualChangeDA.Get(tc,nBudID));
// if (oreader.Read())
//{
oBudgetIndivisualChanges = this.CreateObjects<BudgetIndivisualChange>(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(oBudgetIndivisualChanges, "Get");
#endregion
return oBudgetIndivisualChanges;
}
public ID Save(BudgetIndivisualChange item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("BudgetIndivisualChange", "BudgetIndivisualChangeID");
SetObjectID(item, ID.FromInteger(id));
BudgetIndivisualChangeDA.Insert(tc, item);
}
else
{
BudgetIndivisualChangeDA.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(BudgetIndivisualChange item,TransactionContext tc)
{
try
{
int id = tc.GenerateID("BudgetIndivisualChange", "BudgetIndivisualChangeID");
SetObjectID(item, ID.FromInteger(id));
BudgetIndivisualChangeDA.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);
BudgetIndivisualChangeDA.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
}
}