EchoTex_Payroll/HRM.DA/Service/Budget/BudgetNewJoinerService.cs

336 lines
10 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
class BudgetNewJoinerService : ServiceTemplate, IBudgetNewJoinerService
{
#region Private functions and declaration
#endregion
#region Object Mapping
private void MapObject(BudgetNewJoiner oBudgetNewJoiner, DataReader oReader)
{
SetObjectID(oBudgetNewJoiner, (oReader.GetInt32("BudgetNewJoinerID").Value));
oBudgetNewJoiner.BasicSalary = oReader.GetDouble("BasicSalary").Value;
oBudgetNewJoiner.GrossSalary = oReader.GetDouble("GrossSalary").Value;
oBudgetNewJoiner.BudgetID = oReader.GetInt32("BudgetID", 0);
oBudgetNewJoiner.DepartmentID = oReader.GetInt32("DepartmentID", 0);
oBudgetNewJoiner.GradeID = oReader.GetInt32("GradeID", 0);
oBudgetNewJoiner.CategoryID = oReader.GetInt32("CategoryID", 0);
oBudgetNewJoiner.IncrementPercentage = oReader.GetDouble("IncrementPercentage").Value;
oBudgetNewJoiner.LocationID = oReader.GetInt32("LocationID", 0);
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.GetInt32("BudgetNewJoinerCrGID").Value));
oBudgetNewJoinerCrG.BudgetNewJoinerID = oReader.GetInt32("BudgetNewJoinerID", 0);
oBudgetNewJoinerCrG.CCID = oReader.GetInt32("CCID", 0);
oBudgetNewJoinerCrG.Percentage = oReader.GetDouble("Percentage").Value;
}
private BudgetNewJoinerCrG CreateBudgetNewJoinerCrG(DataReader oReader)
{
BudgetNewJoinerCrG oBudgetNewJoinerCrG = new BudgetNewJoinerCrG();
MapBudgetNewJoinerCrGObject(oBudgetNewJoinerCrG, oReader);
return oBudgetNewJoinerCrG;
}
protected List<BudgetNewJoinerCrG> CreateBudgetNewJoinerCrGs(DataReader oReader)
{
List<BudgetNewJoinerCrG> oBudgetNewJoinerCrGs = new List<BudgetNewJoinerCrG>();
while (oReader.Read())
{
BudgetNewJoinerCrG item = CreateBudgetNewJoinerCrG(oReader);
oBudgetNewJoinerCrGs.Add(item);
}
return oBudgetNewJoinerCrGs;
}
#endregion
#endregion
#region Implementation of IBudgetNewJoinerService
public BudgetNewJoiner Get(int nID)
{
BudgetNewJoiner oBudgetNewJoiner = new BudgetNewJoiner();
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
}
return oBudgetNewJoiner;
}
public List<BudgetNewJoiner> Get()
{
List<BudgetNewJoiner> oBudgetNewJoiners = null;
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
}
return oBudgetNewJoiners;
}
public List<BudgetNewJoiner> GetWithBudgetID(int nBudID)
{
List<BudgetNewJoiner> oBudgetNewJoiners = null;
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
}
return oBudgetNewJoiners;
}
public int Save(BudgetNewJoiner item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("BudgetNewJoiner", "BudgetNewJoinerID");
SetObjectID(item, (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,
(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 int Save(BudgetNewJoiner item, TransactionContext tc)
{
try
{
int id = tc.GenerateID("BudgetNewJoiner", "BudgetNewJoinerID");
SetObjectID(item, (id));
BudgetNewJoinerDA.Insert(tc, item);
#region Insert Children
foreach (BudgetNewJoinerCrG oBudgetNewJoinerCrG in item.OBudgetNewJoinerCrGs)
{
oBudgetNewJoinerCrG.BudgetNewJoinerID = item.ID;
this.SetObjectID(oBudgetNewJoinerCrG,
(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(int 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 List<BudgetNewJoinerCrG> GetBudgetNewJoinerCrGs(int baseID)
{
List<BudgetNewJoinerCrG> oBudgetNewJoinerCrGs;
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
}
return oBudgetNewJoinerCrGs;
}
#endregion
#endregion
}
}