475 lines
17 KiB
C#
475 lines
17 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]
|
|||
|
class BudgetComponentService : ServiceTemplate, IBudgetComponentService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(BudgetComponent));
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Object Mapping
|
|||
|
|
|||
|
#region Parent Object Mapping
|
|||
|
private void MapObject(BudgetComponent oBudgetComponent, DataReader oReader)
|
|||
|
{
|
|||
|
SetObjectID(oBudgetComponent, oReader.GetID("BudgetComponentID"));
|
|||
|
oBudgetComponent.BasedOn = (EnumBasedOnPercent)oReader.GetInt32("BasedOn").Value;
|
|||
|
oBudgetComponent.BudgetID = oReader.GetID("BudgetID");
|
|||
|
oBudgetComponent.ComponentType =(EnumBudgetComponent) oReader.GetInt32("ComponentType").Value;
|
|||
|
oBudgetComponent.FlatAmount = oReader.GetDouble("FlatAmount").Value;
|
|||
|
oBudgetComponent.Name = oReader.GetString("Name");
|
|||
|
oBudgetComponent.OriginID = oReader.GetID("OriginID");
|
|||
|
oBudgetComponent.ParameterID = oReader.GetID("ParameterID");
|
|||
|
oBudgetComponent.Percentage = oReader.GetDouble("Percentage").Value;
|
|||
|
oBudgetComponent.Periodicity = oReader.GetDouble("Periodicity").Value;
|
|||
|
oBudgetComponent.Taxable = oReader.GetBoolean("Taxable").Value;
|
|||
|
oBudgetComponent.PayrollTypeID = oReader.GetID("PayrollTypeID");
|
|||
|
oBudgetComponent.IndivisuallyDefined = oReader.GetBoolean("IndivisuallyDefined").Value;
|
|||
|
SetObjectState(oBudgetComponent, ObjectState.Saved);
|
|||
|
oBudgetComponent.OBudgetComponentIndivisuals = new ObjectsTemplate<BudgetComponentIndivisual>();
|
|||
|
oBudgetComponent.OBudgetComponentGrades = new ObjectsTemplate<BudgetComponentGrade>();
|
|||
|
oBudgetComponent.OBudgetComponentIndivisuals = GetBudgetComponentIndivisuals(oBudgetComponent.ID);
|
|||
|
oBudgetComponent.OBudgetComponentGrades = GetBudgetComponentGrades(oBudgetComponent.ID);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader dr)
|
|||
|
{
|
|||
|
BudgetComponent oBudgetComponent = new BudgetComponent();
|
|||
|
MapObject(oBudgetComponent, dr);
|
|||
|
return oBudgetComponent as T;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Child Object Mapping
|
|||
|
|
|||
|
#region BudgetComponentIndivisual Mapping
|
|||
|
|
|||
|
private void MapBudgetComponentIndivisual(BudgetComponentIndivisual oBudgetComponentIndivisual, DataReader oReader)
|
|||
|
{
|
|||
|
SetObjectID(oBudgetComponentIndivisual, oReader.GetID("BudgetComponentIndivisualID"));
|
|||
|
oBudgetComponentIndivisual.Amount = oReader.GetDouble("Amount").Value;
|
|||
|
oBudgetComponentIndivisual.BudgetComponentID = oReader.GetID("BudgetComponentID");
|
|||
|
oBudgetComponentIndivisual.DetailType = (EnumADEmpType)oReader.GetInt32("DetailType").Value;
|
|||
|
oBudgetComponentIndivisual.EmployeeID = oReader.GetID("EmployeeID");
|
|||
|
oBudgetComponentIndivisual.FromDate = oReader.GetDateTime("FromDate").GetValueOrDefault();
|
|||
|
oBudgetComponentIndivisual.ToDate = oReader.GetDateTime("ToDate").GetValueOrDefault();
|
|||
|
oBudgetComponentIndivisual.ValueType = (EnumValueType)oReader.GetInt32("ValueType").Value;
|
|||
|
this.SetObjectState(oBudgetComponentIndivisual, ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
private BudgetComponentIndivisual CreateBudgetComponentIndivisualObject(DataReader oReader)
|
|||
|
{
|
|||
|
BudgetComponentIndivisual oBudgetComponentIndivisual = new BudgetComponentIndivisual();
|
|||
|
MapBudgetComponentIndivisual(oBudgetComponentIndivisual, oReader);
|
|||
|
return oBudgetComponentIndivisual;
|
|||
|
}
|
|||
|
|
|||
|
protected ObjectsTemplate<BudgetComponentIndivisual> CreateBudgetComponentIndivisualObjects(DataReader oReader)
|
|||
|
{
|
|||
|
ObjectsTemplate<BudgetComponentIndivisual> oBudgetComponentIndivisuals = new ObjectsTemplate<BudgetComponentIndivisual>();
|
|||
|
while (oReader.Read())
|
|||
|
{
|
|||
|
BudgetComponentIndivisual item = CreateBudgetComponentIndivisualObject(oReader);
|
|||
|
oBudgetComponentIndivisuals.Add(item);
|
|||
|
}
|
|||
|
return oBudgetComponentIndivisuals;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region BudgetComponentGrade Mapping
|
|||
|
|
|||
|
private void MapBudgetComponentGrade(BudgetComponentGrade oBudgetComponentGrade, DataReader oReader)
|
|||
|
{
|
|||
|
SetObjectID(oBudgetComponentGrade, oReader.GetID("BudgetComponentGradeID"));
|
|||
|
oBudgetComponentGrade.BudgetComponentID = oReader.GetID("BudgetComponentID");
|
|||
|
oBudgetComponentGrade.GradeID = oReader.GetID("GradeID");
|
|||
|
this.SetObjectState(oBudgetComponentGrade, ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
private BudgetComponentGrade CreateBudgetComponentGradeObject(DataReader oReader)
|
|||
|
{
|
|||
|
BudgetComponentGrade oBudgetComponentGrade = new BudgetComponentGrade();
|
|||
|
MapBudgetComponentGrade(oBudgetComponentGrade, oReader);
|
|||
|
return oBudgetComponentGrade;
|
|||
|
}
|
|||
|
|
|||
|
protected ObjectsTemplate<BudgetComponentGrade> CreateBudgetComponentGradeObjects(DataReader oReader)
|
|||
|
{
|
|||
|
ObjectsTemplate<BudgetComponentGrade> oBudgetComponentGrades = new ObjectsTemplate<BudgetComponentGrade>();
|
|||
|
while (oReader.Read())
|
|||
|
{
|
|||
|
BudgetComponentGrade item = CreateBudgetComponentGradeObject(oReader);
|
|||
|
oBudgetComponentGrades.Add(item);
|
|||
|
}
|
|||
|
return oBudgetComponentGrades;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Implementation
|
|||
|
|
|||
|
#region Parent's Service Implementation
|
|||
|
|
|||
|
public BudgetComponent Get(ID nID)
|
|||
|
{
|
|||
|
BudgetComponent oBudgetComponent = new BudgetComponent();
|
|||
|
|
|||
|
#region Cache Header
|
|||
|
oBudgetComponent = _cache["Get", nID] as BudgetComponent;
|
|||
|
if (oBudgetComponent != null)
|
|||
|
return oBudgetComponent;
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetComponentDA.Get(tc, nID));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oBudgetComponent = CreateObject<BudgetComponent>(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(oBudgetComponent, "Get", nID);
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetComponent;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<BudgetComponent> Get()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<BudgetComponent> oBudgetComponents = _cache["Get"] as ObjectsTemplate<BudgetComponent>;
|
|||
|
if (oBudgetComponents != null)
|
|||
|
return oBudgetComponents;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetComponentDA.Get(tc));
|
|||
|
// if (oreader.Read())
|
|||
|
//{
|
|||
|
oBudgetComponents = this.CreateObjects<BudgetComponent>(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(oBudgetComponents, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetComponents;
|
|||
|
}
|
|||
|
public ObjectsTemplate<BudgetComponent> Get(int BudgetID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<BudgetComponent> oBudgetComponents = _cache["Get"] as ObjectsTemplate<BudgetComponent>;
|
|||
|
if (oBudgetComponents != null)
|
|||
|
return oBudgetComponents;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetComponentDA.Get(tc,BudgetID));
|
|||
|
// if (oreader.Read())
|
|||
|
//{
|
|||
|
oBudgetComponents = this.CreateObjects<BudgetComponent>(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(oBudgetComponents, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetComponents;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(BudgetComponent item)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (item.IsNew)
|
|||
|
{
|
|||
|
int id = tc.GenerateID("BudgetComponent", "BudgetComponentID");
|
|||
|
SetObjectID(item, ID.FromInteger(id));
|
|||
|
BudgetComponentDA.Insert(tc, item);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
BudgetComponentDA.Update(tc, item);
|
|||
|
|
|||
|
#region delete childrern
|
|||
|
BudgetComponentDA.Delete(tc, "BudgetComponentIndivisual", "BudgetComponentID", item.ID);
|
|||
|
BudgetComponentDA.Delete(tc, "BudgetComponentGrade", "BudgetComponentID", item.ID);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
#region Insert Children
|
|||
|
|
|||
|
#region BudgetComponentIndivisual
|
|||
|
foreach (BudgetComponentIndivisual oBudgetComponentIndivisual in item.OBudgetComponentIndivisuals)
|
|||
|
{
|
|||
|
oBudgetComponentIndivisual.BudgetComponentID = item.ID;
|
|||
|
this.SetObjectID(oBudgetComponentIndivisual, ID.FromInteger(tc.GenerateID("BudgetComponentIndivisual", "BudgetComponentIndivisualID")));
|
|||
|
BudgetComponentDA.Insert(tc, oBudgetComponentIndivisual);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region BudgetComponentGrade
|
|||
|
foreach (BudgetComponentGrade oBudgetComponentGrade in item.OBudgetComponentGrades)
|
|||
|
{
|
|||
|
oBudgetComponentGrade.BudgetComponentID = item.ID;
|
|||
|
this.SetObjectID(oBudgetComponentGrade, ID.FromInteger(tc.GenerateID("BudgetComponentGrade", "BudgetComponentGradeID")));
|
|||
|
BudgetComponentDA.Insert(tc, oBudgetComponentGrade);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
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(BudgetComponent item,TransactionContext tc)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
int id = tc.GenerateID("BudgetComponent", "BudgetComponentID");
|
|||
|
SetObjectID(item, ID.FromInteger(id));
|
|||
|
item.PayrollTypeID = Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID;
|
|||
|
BudgetComponentDA.Insert(tc, item);
|
|||
|
|
|||
|
#region Insert Children
|
|||
|
|
|||
|
#region BudgetComponentIndivisual
|
|||
|
foreach (BudgetComponentIndivisual oBudgetComponentIndivisual in item.OBudgetComponentIndivisuals)
|
|||
|
{
|
|||
|
oBudgetComponentIndivisual.BudgetComponentID = item.ID;
|
|||
|
this.SetObjectID(oBudgetComponentIndivisual, ID.FromInteger(tc.GenerateID("BudgetComponentIndivisual", "BudgetComponentIndivisualID")));
|
|||
|
BudgetComponentDA.Insert(tc, oBudgetComponentIndivisual);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region BudgetComponentGrade
|
|||
|
foreach (BudgetComponentGrade oBudgetComponentGrade in item.OBudgetComponentGrades)
|
|||
|
{
|
|||
|
oBudgetComponentGrade.BudgetComponentID = item.ID;
|
|||
|
this.SetObjectID(oBudgetComponentGrade, ID.FromInteger(tc.GenerateID("BudgetComponentGrade", "BudgetComponentGradeID")));
|
|||
|
BudgetComponentDA.Insert(tc, oBudgetComponentGrade);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
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);
|
|||
|
|
|||
|
|
|||
|
#region delete childrern
|
|||
|
BudgetComponentDA.Delete(tc, "BudgetComponentIndivisual", "BudgetComponentID", nID);
|
|||
|
BudgetComponentDA.Delete(tc, "BudgetComponentGrade", "BudgetComponentID", nID);
|
|||
|
#endregion
|
|||
|
|
|||
|
BudgetComponentDA.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
|
|||
|
|
|||
|
#region Child's Service Implementation
|
|||
|
|
|||
|
public ObjectsTemplate<BudgetComponentIndivisual> GetBudgetComponentIndivisuals(ID id)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<BudgetComponentIndivisual> oBudgetComponentIndivisuals = _cache["Get"] as ObjectsTemplate<BudgetComponentIndivisual>;
|
|||
|
if (oBudgetComponentIndivisuals != null)
|
|||
|
return oBudgetComponentIndivisuals;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetComponentDA.GetBudgetComponentIndivisuals(tc,id));
|
|||
|
// if (oreader.Read())
|
|||
|
//{
|
|||
|
oBudgetComponentIndivisuals = this.CreateBudgetComponentIndivisualObjects(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(oBudgetComponentIndivisuals, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetComponentIndivisuals;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<BudgetComponentGrade> GetBudgetComponentGrades(ID id)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<BudgetComponentGrade> oBudgetComponentGrades = _cache["Get"] as ObjectsTemplate<BudgetComponentGrade>;
|
|||
|
if (oBudgetComponentGrades != null)
|
|||
|
return oBudgetComponentGrades;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(BudgetComponentDA.GetBudgetComponentGrades(tc,id));
|
|||
|
// if (oreader.Read())
|
|||
|
//{
|
|||
|
oBudgetComponentGrades = this.CreateBudgetComponentGradeObjects(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(oBudgetComponentGrades, "Get");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return oBudgetComponentGrades;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|