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

224 lines
6.1 KiB
C#
Raw Permalink 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
{
public class BudgetCostCenterService : ServiceTemplate
{
#region Private functions and declaration
#endregion
#region Object Mapping
private void MapObject(BudgetCostCenter oBudgetCostCenter, DataReader oReader)
{
SetObjectID(oBudgetCostCenter, (oReader.GetInt32("BudgetCostCenterID").Value));
oBudgetCostCenter.CostCenterID = oReader.GetInt32("CostCenterID", 0);
oBudgetCostCenter.BudgetID = oReader.GetInt32("BudgetID", 0);
oBudgetCostCenter.EmployeeID = oReader.GetInt32("EmployeeID", 0);
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(int nID)
{
BudgetCostCenter oBudgetCostCenter = new BudgetCostCenter();
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
}
return oBudgetCostCenter;
}
public List<BudgetCostCenter> Get()
{
List<BudgetCostCenter> oBudgetCostCenters = null;
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
}
return oBudgetCostCenters;
}
public List<BudgetCostCenter> GetWithBudgetID(int nID)
{
List<BudgetCostCenter> oBudgetCostCenters = null;
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
}
return oBudgetCostCenters;
}
public int Save(BudgetCostCenter item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("BudgetCostCenter", "BudgetCostCenterID");
SetObjectID(item, (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 int Save(BudgetCostCenter item, TransactionContext tc)
{
try
{
int id = tc.GenerateID("BudgetCostCenter", "BudgetCostCenterID");
SetObjectID(item, (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(int 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
}
}