CEL_Payroll/Payroll.Service/Budget/Service/BudgetNewJoinerService.cs

354 lines
12 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
{
class BudgetNewJoinerService : ServiceTemplate, IBudgetNewJoinerService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(BudgetNewJoiner));
#endregion
#region Object Mapping
private void MapObject(BudgetNewJoiner oBudgetNewJoiner, DataReader oReader)
{
SetObjectID(oBudgetNewJoiner, oReader.GetID("BudgetNewJoinerID"));
oBudgetNewJoiner.BasicSalary = oReader.GetDouble("BasicSalary").Value;
oBudgetNewJoiner.GrossSalary = oReader.GetDouble("GrossSalary").Value;
oBudgetNewJoiner.BudgetID = oReader.GetID("BudgetID");
oBudgetNewJoiner.DepartmentID = oReader.GetID("DepartmentID");
oBudgetNewJoiner.GradeID = oReader.GetID("GradeID");
oBudgetNewJoiner.CategoryID = oReader.GetID("CategoryID");
oBudgetNewJoiner.IncrementPercentage = oReader.GetDouble("IncrementPercentage").Value;
oBudgetNewJoiner.LocationID = oReader.GetID("LocationID");
oBudgetNewJoiner.NextIncrementalMonth = oReader.GetInt32("NextIncrementalMonth").Value;
oBudgetNewJoiner.NoofEmployee = oReader.GetInt32("NoofEmployee").Value;
oBudgetNewJoiner.FromDate = oReader.GetDateTime("FromDate").Value;
SetObjectState(oBudgetNewJoiner, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
BudgetNewJoiner oBudgetNewJoiner = new BudgetNewJoiner();
MapObject(oBudgetNewJoiner, dr);
return oBudgetNewJoiner as T;
}
#region Child Mapping
private void MapBudgetNewJoinerCrGObject(BudgetNewJoinerCrG oBudgetNewJoinerCrG, DataReader oReader)
{
this.SetObjectID(oBudgetNewJoinerCrG, oReader.GetID("BudgetNewJoinerCrGID"));
oBudgetNewJoinerCrG.BudgetNewJoinerID = oReader.GetID("BudgetNewJoinerID");
oBudgetNewJoinerCrG.CCID = oReader.GetID("CCID");
oBudgetNewJoinerCrG.Percentage = oReader.GetDouble("Percentage").Value;
}
private BudgetNewJoinerCrG CreateBudgetNewJoinerCrG(DataReader oReader)
{
BudgetNewJoinerCrG oBudgetNewJoinerCrG = new BudgetNewJoinerCrG();
MapBudgetNewJoinerCrGObject(oBudgetNewJoinerCrG, oReader);
return oBudgetNewJoinerCrG;
}
protected ObjectsTemplate<BudgetNewJoinerCrG> CreateBudgetNewJoinerCrGs(DataReader oReader)
{
ObjectsTemplate<BudgetNewJoinerCrG> oBudgetNewJoinerCrGs = new ObjectsTemplate<BudgetNewJoinerCrG>();
while (oReader.Read())
{
BudgetNewJoinerCrG item = CreateBudgetNewJoinerCrG(oReader);
oBudgetNewJoinerCrGs.Add(item);
}
return oBudgetNewJoinerCrGs;
}
#endregion
#endregion
#region Implementation of IBudgetNewJoinerService
public BudgetNewJoiner Get(ID nID)
{
BudgetNewJoiner oBudgetNewJoiner = new BudgetNewJoiner();
#region Cache Header
oBudgetNewJoiner = _cache["Get", nID] as BudgetNewJoiner;
if (oBudgetNewJoiner != null)
return oBudgetNewJoiner;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetNewJoinerDA.Get(tc, nID));
if (oreader.Read())
{
oBudgetNewJoiner = CreateObject<BudgetNewJoiner>(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(oBudgetNewJoiner, "Get", nID);
#endregion
return oBudgetNewJoiner;
}
public ObjectsTemplate<BudgetNewJoiner> Get()
{
#region Cache Header
ObjectsTemplate<BudgetNewJoiner> oBudgetNewJoiners = _cache["Get"] as ObjectsTemplate<BudgetNewJoiner>;
if (oBudgetNewJoiners != null)
return oBudgetNewJoiners;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetNewJoinerDA.Get(tc));
// if (oreader.Read())
//{
oBudgetNewJoiners = this.CreateObjects<BudgetNewJoiner>(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(oBudgetNewJoiners, "Get");
#endregion
return oBudgetNewJoiners;
}
public ObjectsTemplate<BudgetNewJoiner> Get(int nBudID)
{
#region Cache Header
ObjectsTemplate<BudgetNewJoiner> oBudgetNewJoiners = _cache["Get"] as ObjectsTemplate<BudgetNewJoiner>;
if (oBudgetNewJoiners != null)
return oBudgetNewJoiners;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetNewJoinerDA.Get(tc,nBudID));
// if (oreader.Read())
//{
oBudgetNewJoiners = this.CreateObjects<BudgetNewJoiner>(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(oBudgetNewJoiners, "Get");
#endregion
return oBudgetNewJoiners;
}
public ID Save(BudgetNewJoiner item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("BudgetNewJoiner", "BudgetNewJoinerID");
SetObjectID(item, ID.FromInteger(id));
BudgetNewJoinerDA.Insert(tc, item);
}
else
{
BudgetNewJoinerDA.Update(tc, item);
#region delete children
BudgetNewJoinerDA.Delete(tc, "BudgetNewJoinerCrG", "BudgetNewJoinerID", item.ID);
#endregion
}
#region Insert Children
foreach (BudgetNewJoinerCrG oBudgetNewJoinerCrG in item.OBudgetNewJoinerCrGs)
{
oBudgetNewJoinerCrG.BudgetNewJoinerID = item.ID;
this.SetObjectID(oBudgetNewJoinerCrG, ID.FromInteger(tc.GenerateID("BudgetNewJoinerCrG", "BudgetNewJoinerCrGID")));
BudgetNewJoinerDA.Insert(tc, oBudgetNewJoinerCrG);
}
#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(BudgetNewJoiner item,TransactionContext tc)
{
try
{
int id =tc.GenerateID("BudgetNewJoiner", "BudgetNewJoinerID");
SetObjectID(item, ID.FromInteger(id));
BudgetNewJoinerDA.Insert(tc, item);
#region Insert Children
foreach (BudgetNewJoinerCrG oBudgetNewJoinerCrG in item.OBudgetNewJoinerCrGs)
{
oBudgetNewJoinerCrG.BudgetNewJoinerID = item.ID;
this.SetObjectID(oBudgetNewJoinerCrG, ID.FromInteger(tc.GenerateID("BudgetNewJoinerCrG", "BudgetNewJoinerCrGID")));
BudgetNewJoinerDA.Insert(tc, oBudgetNewJoinerCrG);
}
#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 children
BudgetNewJoinerDA.Delete(tc, "BudgetNewJoinerCrG", "BudgetNewJoinerID",nID);
#endregion
BudgetNewJoinerDA.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
}
}
#region Child Implementation
public ObjectsTemplate<BudgetNewJoinerCrG> GetBudgetNewJoinerCrGs(ID baseID)
{
ObjectsTemplate<BudgetNewJoinerCrG> oBudgetNewJoinerCrGs;
#region Cache Header
oBudgetNewJoinerCrGs = _cache["GetBudgetNewJoinerCrGs"] as ObjectsTemplate<BudgetNewJoinerCrG>;
if (oBudgetNewJoinerCrGs != null)
return oBudgetNewJoinerCrGs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetNewJoinerDA.GetBudgetNewJoinerCrGs(tc, baseID));
oBudgetNewJoinerCrGs = CreateBudgetNewJoinerCrGs(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(oBudgetNewJoinerCrGs, "GetBudgetNewJoinerCrGs");
#endregion
return oBudgetNewJoinerCrGs;
}
#endregion
#endregion
}
}