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

223 lines
6.6 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 BudgetIndivisualChangeService : ServiceTemplate, IBudgetIndivisualChangeService
{
#region Object Mapping
private void MapObject(BudgetIndivisualChange oBudgetIndivisualChange, DataReader oReader)
{
SetObjectID(oBudgetIndivisualChange, (oReader.GetInt32("BudgetIndivisualChangeID").Value));
oBudgetIndivisualChange.BudgetID = oReader.GetInt32("BudgetID", 0);
oBudgetIndivisualChange.ButGetIndvChangeType =
(EnumBudgetChangeType)oReader.GetInt32("ButGetIndvChangeType").Value;
oBudgetIndivisualChange.EffectDate = oReader.GetDateTime("EffectDate").Value;
oBudgetIndivisualChange.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oBudgetIndivisualChange.Value = oReader.GetInt32("Value", 0);
oBudgetIndivisualChange.ChangedBasic = oReader.GetDouble("ChangedBasic").Value;
oBudgetIndivisualChange.ValueType = (EnumValueType)oReader.GetInt32("ValueType").Value;
SetObjectState(oBudgetIndivisualChange, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
BudgetIndivisualChange oBudgetIndivisualChange = new BudgetIndivisualChange();
MapObject(oBudgetIndivisualChange, dr);
return oBudgetIndivisualChange as T;
}
#endregion
#region Service Implementation
public BudgetIndivisualChange Get(int nID)
{
BudgetIndivisualChange oBudgetIndivisualChange = new BudgetIndivisualChange();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetIndivisualChangeDA.Get(tc, nID));
if (oreader.Read())
{
oBudgetIndivisualChange = CreateObject<BudgetIndivisualChange>(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 oBudgetIndivisualChange;
}
public List<BudgetIndivisualChange> Get()
{
List<BudgetIndivisualChange> oBudgetIndivisualChanges = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetIndivisualChangeDA.Get(tc));
// if (oreader.Read())
//{
oBudgetIndivisualChanges = this.CreateObjects<BudgetIndivisualChange>(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 oBudgetIndivisualChanges;
}
public List<BudgetIndivisualChange> GetWithBudgetID(int nBudID)
{
List<BudgetIndivisualChange> oBudgetIndivisualChanges = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(BudgetIndivisualChangeDA.Get(tc, nBudID));
// if (oreader.Read())
//{
oBudgetIndivisualChanges = this.CreateObjects<BudgetIndivisualChange>(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 oBudgetIndivisualChanges;
}
public int Save(BudgetIndivisualChange item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("BudgetIndivisualChange", "BudgetIndivisualChangeID");
SetObjectID(item, (id));
BudgetIndivisualChangeDA.Insert(tc, item);
}
else
{
BudgetIndivisualChangeDA.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(BudgetIndivisualChange item, TransactionContext tc)
{
try
{
int id = tc.GenerateID("BudgetIndivisualChange", "BudgetIndivisualChangeID");
SetObjectID(item, (id));
BudgetIndivisualChangeDA.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);
BudgetIndivisualChangeDA.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
}
}