219 lines
5.8 KiB
C#
219 lines
5.8 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 BudgetGradeService : ServiceTemplate, IBudgetGradeService
|
|
{
|
|
#region Object Mapping
|
|
|
|
private void MapObject(BudgetGrade oBudgetGrade, DataReader oReader)
|
|
{
|
|
SetObjectID(oBudgetGrade, (oReader.GetInt32("BudgetGradeID").Value));
|
|
oBudgetGrade.BudgetID = oReader.GetInt32("BudgetID", 0);
|
|
oBudgetGrade.ChangedPercentage = oReader.GetDouble("ChangedPercentage").Value;
|
|
oBudgetGrade.FixedAmount = oReader.GetDouble("FixedAmount").Value;
|
|
oBudgetGrade.GradeID = oReader.GetInt32("GradeID", 0);
|
|
SetObjectState(oBudgetGrade, ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader dr)
|
|
{
|
|
BudgetGrade oBudgetGrade = new BudgetGrade();
|
|
MapObject(oBudgetGrade, dr);
|
|
return oBudgetGrade as T;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Service Implementation
|
|
|
|
public BudgetGrade Get(int nID)
|
|
{
|
|
BudgetGrade oBudgetGrade = new BudgetGrade();
|
|
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BudgetGradeDA.Get(tc, nID));
|
|
if (oreader.Read())
|
|
{
|
|
oBudgetGrade = CreateObject<BudgetGrade>(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 oBudgetGrade;
|
|
}
|
|
|
|
public List<BudgetGrade> Get()
|
|
{
|
|
List<BudgetGrade> oBudgetGrades = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BudgetGradeDA.Get(tc));
|
|
// if (oreader.Read())
|
|
//{
|
|
oBudgetGrades = this.CreateObjects<BudgetGrade>(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 oBudgetGrades;
|
|
}
|
|
|
|
public List<BudgetGrade> GetWithBudgetID(int nBudID)
|
|
{
|
|
List<BudgetGrade> oBudgetGrades = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BudgetGradeDA.Get(tc, nBudID));
|
|
// if (oreader.Read())
|
|
//{
|
|
oBudgetGrades = this.CreateObjects<BudgetGrade>(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 oBudgetGrades;
|
|
}
|
|
|
|
public int Save(BudgetGrade item)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (item.IsNew)
|
|
{
|
|
int id = tc.GenerateID("BudgetGrade", "BudgetGradeID");
|
|
SetObjectID(item, (id));
|
|
BudgetGradeDA.Insert(tc, item);
|
|
}
|
|
else
|
|
{
|
|
BudgetGradeDA.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(BudgetGrade item, TransactionContext tc)
|
|
{
|
|
try
|
|
{
|
|
int id = tc.GenerateID("BudgetGrade", "BudgetGradeID");
|
|
SetObjectID(item, (id));
|
|
BudgetGradeDA.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);
|
|
BudgetGradeDA.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
|
|
}
|
|
} |