294 lines
10 KiB
C#
294 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.Caching;
|
|
using Ease.CoreV35.Model;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.BO;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
[Serializable]
|
|
public class BudgetMasterService : ServiceTemplate, IBudgetMasterService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(BudgetMaster));
|
|
#endregion
|
|
|
|
#region Object Mapping
|
|
|
|
private void MapObject(BudgetMaster oBudgetMaster, DataReader oReader)
|
|
{
|
|
SetObjectID(oBudgetMaster, oReader.GetID("BudgetMasterID"));
|
|
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;
|
|
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(ID nID, ID PayrollTypeID)
|
|
{
|
|
BudgetMaster oBudgetMaster = new BudgetMaster();
|
|
|
|
#region Cache Header
|
|
oBudgetMaster = _cache["Get", nID] as BudgetMaster;
|
|
if (oBudgetMaster != null)
|
|
return oBudgetMaster;
|
|
#endregion
|
|
|
|
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
|
|
}
|
|
|
|
#region Cache Footer
|
|
_cache.Add(oBudgetMaster, "Get", nID);
|
|
#endregion
|
|
|
|
return oBudgetMaster;
|
|
|
|
}
|
|
|
|
public ObjectsTemplate<BudgetMaster> Get(ID PayrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<BudgetMaster> oBudgetMasters = _cache["Get"] as ObjectsTemplate<BudgetMaster>;
|
|
if (oBudgetMasters != null)
|
|
return oBudgetMasters;
|
|
|
|
#endregion
|
|
|
|
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
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(oBudgetMasters, "Get");
|
|
|
|
#endregion
|
|
|
|
return oBudgetMasters;
|
|
}
|
|
|
|
public ObjectsTemplate<BudgetMaster> Get(DateTime dtFromDate, DateTime dtToDate, ID PayrollTypeID)
|
|
{
|
|
#region Cache Header
|
|
|
|
ObjectsTemplate<BudgetMaster> oBudgetMasters = _cache["Get"] as ObjectsTemplate<BudgetMaster>;
|
|
if (oBudgetMasters != null)
|
|
return oBudgetMasters;
|
|
|
|
#endregion
|
|
|
|
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
|
|
}
|
|
|
|
#region Cache Footer
|
|
|
|
_cache.Add(oBudgetMasters, "Get");
|
|
|
|
#endregion
|
|
|
|
return oBudgetMasters;
|
|
}
|
|
|
|
public ID Save(BudgetMaster item, ProgressBar pbar, ID PayrollTypeID)
|
|
{
|
|
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.IsUnassigned)
|
|
{
|
|
BudgetMasterDA.DeleteAll(tc, item.ID, PayrollTypeID);
|
|
}
|
|
int id = tc.GenerateID("BudgetMaster", "BudgetMasterID");
|
|
SetObjectID(item, ID.FromInteger(id));
|
|
BudgetMasterDA.Insert(tc, item, PayrollTypeID);
|
|
|
|
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();
|
|
oBudProsMonthService.BulkSave(item.BudgetProcessMonthlys, tc, item.ID.Integer);
|
|
//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(ID nID, ID 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
|
|
}
|
|
}
|