206 lines
5.8 KiB
C#
206 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
|
|
{
|
|
#region BudgetDepartment Service
|
|
|
|
public class BudgetDepartmentService : ServiceTemplate
|
|
{
|
|
#region Private functions and declaration
|
|
|
|
#endregion
|
|
|
|
public BudgetDepartmentService()
|
|
{
|
|
}
|
|
|
|
private void MapObject(BudgetDepartment oBudgetDepartment, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oBudgetDepartment, (oReader.GetInt32("BudgetDepartmentID").Value));
|
|
oBudgetDepartment.BudgetudID = oReader.GetInt32("BudgetudID", 0);
|
|
oBudgetDepartment.DepartmentID = oReader.GetInt32("DepartmentID", 0);
|
|
this.SetObjectState(oBudgetDepartment, Ease.Core.ObjectState.Saved);
|
|
}
|
|
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
BudgetDepartment oBudgetDepartment = new BudgetDepartment();
|
|
MapObject(oBudgetDepartment, oReader);
|
|
return oBudgetDepartment as T;
|
|
}
|
|
|
|
protected BudgetDepartment CreateObject(DataReader oReader)
|
|
{
|
|
BudgetDepartment oBudgetDepartment = new BudgetDepartment();
|
|
MapObject(oBudgetDepartment, oReader);
|
|
return oBudgetDepartment;
|
|
}
|
|
|
|
#region Service implementation
|
|
|
|
public BudgetDepartment Get(int id)
|
|
{
|
|
BudgetDepartment oBudgetDepartment = new BudgetDepartment();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(BudgetDepartmentDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oBudgetDepartment = this.CreateObject<BudgetDepartment>(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 oBudgetDepartment;
|
|
}
|
|
|
|
public List<BudgetDepartment> GetWithBudgetID(int nID)
|
|
{
|
|
List<BudgetDepartment> BudgetDepartments = null;
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(BudgetDepartmentDA.Get(tc, nID));
|
|
BudgetDepartments = this.CreateObjects<BudgetDepartment>(dr);
|
|
dr.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 BudgetDepartments;
|
|
}
|
|
|
|
public int Save(BudgetDepartment oBudgetDepartment)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int codeLength = 3;
|
|
if (oBudgetDepartment.IsNew)
|
|
{
|
|
int id = tc.GenerateID("BudgetDepartment", "BudgetDepartmentID");
|
|
base.SetObjectID(oBudgetDepartment, (id));
|
|
|
|
int seqNo = tc.GenerateID("BudgetDepartment", "SequenceNo");
|
|
oBudgetDepartment.Sequence = seqNo;
|
|
BudgetDepartmentDA.Insert(tc, oBudgetDepartment);
|
|
}
|
|
else
|
|
{
|
|
BudgetDepartmentDA.Update(tc, oBudgetDepartment);
|
|
}
|
|
|
|
tc.End();
|
|
return oBudgetDepartment.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(BudgetDepartment oBudgetDepartment, TransactionContext tc)
|
|
{
|
|
try
|
|
{
|
|
//if (oBudgetDepartment.IsNew)
|
|
//{
|
|
|
|
int id = tc.GenerateID("BudgetDepartment", "BudgetDepartmentID");
|
|
base.SetObjectID(oBudgetDepartment, (id));
|
|
BudgetDepartmentDA.Insert(tc, oBudgetDepartment);
|
|
//}
|
|
//else
|
|
//{
|
|
// BudgetDepartmentDA.Update(tc, oBudgetDepartment);
|
|
//}
|
|
return oBudgetDepartment.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 id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
BudgetDepartmentDA.Delete(tc, id);
|
|
tc.End();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
|
|
#endregion
|
|
} |