EchoTex_Payroll/HRM.DA/Service/Budget/BudgetMasterService.cs
2024-10-14 10:01:49 +06:00

279 lines
9.5 KiB
C#

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 BudgetMasterService : ServiceTemplate
{
#region Object Mapping
private void MapObject(BudgetMaster oBudgetMaster, DataReader oReader)
{
SetObjectID(oBudgetMaster, (oReader.GetInt32("BudgetMasterID").Value));
oBudgetMaster.BasedOn = (EnumBasedOnPercent)oReader.GetInt32("BasedOn");
oBudgetMaster.EffectMonth = oReader.GetDateTime("EffectMonth").Value;
oBudgetMaster.FromDate = oReader.GetDateTime("FromDate").Value;
oBudgetMaster.Name = oReader.GetString("Name");
oBudgetMaster.OverAllPercentage = oReader.GetDouble("OverAllPercentage").Value;
oBudgetMaster.ToDate = oReader.GetDateTime("ToDate").Value;
oBudgetMaster.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 0);
SetObjectState(oBudgetMaster, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
BudgetMaster oBudgetMaster = new BudgetMaster();
MapObject(oBudgetMaster, dr);
return oBudgetMaster as T;
}
#endregion
#region IBudgetMasterService Implementation
public BudgetMaster Get(int nID, int payrollTypeID)
{
BudgetMaster oBudgetMaster = new BudgetMaster();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetMasterDA.Get(tc, nID, payrollTypeID));
if (oreader.Read())
{
oBudgetMaster = CreateObject<BudgetMaster>(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 oBudgetMaster;
}
public List<BudgetMaster> Get(int payrollTypeID)
{
List<BudgetMaster> oBudgetMasters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetMasterDA.Get(tc, payrollTypeID));
// if (oreader.Read())
//{
oBudgetMasters = this.CreateObjects<BudgetMaster>(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 oBudgetMasters;
}
public List<BudgetMaster> Get(DateTime dtFromDate, DateTime dtToDate, int payrollTypeID)
{
List<BudgetMaster> oBudgetMasters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetMasterDA.Get(tc, dtFromDate, dtToDate, payrollTypeID));
// if (oreader.Read())
//{
oBudgetMasters = this.CreateObjects<BudgetMaster>(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 oBudgetMasters;
}
public int Save(BudgetMaster item)
{
//pbar.Value = 0;
//pbar.Maximum = item.BudgetDepartments.Count + item.BudgetGrades.Count + item.BudgetCCs.Count + item.Individualchanges.Count + item.NewJoiners.Count + item.Components.Count + item.BudgetProcessMonthlys.Count;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.ID != 0)
{
BudgetMasterDA.DeleteAll(tc, item.ID, item.PayrollTypeID);
BudgetMasterDA.DeleteBudgetCostCenter(tc, item.ID);
BudgetMasterDA.DeleteBudgetGrade(tc, item.ID);
BudgetMasterDA.DeleteBudgetIndivisualChange(tc, item.ID);
BudgetMasterDA.DeleteBudgetNewJoiner(tc, item.ID);
BudgetMasterDA.DeleteBudgetProcessMonthly(tc, item.ID, item.PayrollTypeID);
BudgetMasterDA.DeleteBudgetComponent(tc, item.ID);
BudgetMasterDA.DeleteBudgetMaster(tc, item.ID, item.PayrollTypeID);
}
int id = tc.GenerateID("BudgetMaster", "BudgetMasterID");
SetObjectID(item, (id));
BudgetMasterDA.Insert(tc, item);
BudgetDepartmentService oBudDept = new BudgetDepartmentService();
foreach (BudgetDepartment bd in item.BudgetDepartments)
{
bd.BudgetudID = item.ID;
oBudDept.Save(bd, tc);
}
//pbar.Value += item.BudgetDepartments.Count;
//pbar.Refresh();
BudgetGradeService oBudGradeService = new BudgetGradeService();
foreach (BudgetGrade oBudGrade in item.BudgetGrades)
{
oBudGrade.BudgetID = item.ID;
oBudGradeService.Save(oBudGrade, tc);
}
//pbar.Value += item.BudgetGrades.Count;
//pbar.Refresh();
BudgetCostCenterService oBudCCService = new BudgetCostCenterService();
foreach (BudgetCostCenter oBudCC in item.BudgetCCs)
{
oBudCC.BudgetID = item.ID;
oBudCCService.Save(oBudCC, tc);
}
//pbar.Value += item.BudgetCCs.Count;
//pbar.Refresh();
BudgetIndivisualChangeService oBudIndvChangeService = new BudgetIndivisualChangeService();
foreach (BudgetIndivisualChange oBudIndvChg in item.Individualchanges)
{
oBudIndvChg.BudgetID = item.ID;
oBudIndvChangeService.Save(oBudIndvChg, tc);
}
//pbar.Value += item.Individualchanges.Count;
//pbar.Refresh();
BudgetNewJoinerService oBudNewJoinerService = new BudgetNewJoinerService();
foreach (BudgetNewJoiner oBudNewJoiner in item.NewJoiners)
{
oBudNewJoiner.BudgetID = item.ID;
oBudNewJoinerService.Save(oBudNewJoiner, tc);
}
//pbar.Value += item.NewJoiners.Count;
//pbar.Refresh();
BudgetComponentService oBudComponentService = new BudgetComponentService();
foreach (BudgetComponent oBudCom in item.Components)
{
oBudCom.BudgetID = item.ID;
oBudComponentService.Save(oBudCom, tc);
}
//pbar.Value += item.Components.Count;
//pbar.Refresh();
BudgetProcessMonthlyService oBudProsMonthService = new BudgetProcessMonthlyService();
foreach (BudgetProcessMonthly oBudMonthly in item.BudgetProcessMonthlys)
{
oBudMonthly.BudgetID = item.ID;
oBudProsMonthService.Save(oBudMonthly, tc);
//pbar.Value += 1;
//pbar.Refresh();
}
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 void Delete(int nID, int payrollTypeID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
BudgetMasterDA.DeleteAll(tc, nID, payrollTypeID);
BudgetMasterDA.DeleteBudgetCostCenter(tc, nID);
BudgetMasterDA.DeleteBudgetGrade(tc, nID);
BudgetMasterDA.DeleteBudgetIndivisualChange(tc, nID);
BudgetMasterDA.DeleteBudgetNewJoiner(tc, nID);
BudgetMasterDA.DeleteBudgetProcessMonthly(tc, nID, payrollTypeID);
BudgetMasterDA.DeleteBudgetComponent(tc, nID);
BudgetMasterDA.DeleteBudgetMaster(tc, nID, payrollTypeID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}