HRM-10/HRM.DA/Service/Fund/Basic/FundService.cs

301 lines
7.0 KiB
C#
Raw Normal View History

2026-11-03 13:06:00 +06:00
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class FundService : ServiceTemplate //, IFundService
{
public FundService()
{
}
private void MapObject(FMFund fund, DataReader dr)
{
base.SetObjectID(fund, dr.GetInt32("FundTypeID").Value);
fund.UserObjectName = dr.GetString("UserObjectName");
fund.Code = dr.GetString("Code");
fund.Description = dr.GetString("Description");
fund.CreatedBy = dr.GetInt32("CreatedBy").Value;
fund.CreatedDate = dr.GetDateTime("CreatedDate").Value;
fund.ModifiedBy = dr.GetInt32("ModifiedBy").Value;
fund.ModifiedDate = dr.GetDateTime("ModifiedDate");
fund.FundTypeID = dr.GetInt32("FundTypeID").Value;
base.SetObjectState(fund, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
FMFund fund = new FMFund();
MapObject(fund, dr);
return fund as T;
}
#region Service Implementation
#region Insert
public void Save(FMFund fund)
{
FMFund oFund = new FMFund();
oFund = fund;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oFund.IsNew)
{
int id = tc.GenerateID("Fund", "FundTypeID");
base.SetObjectID(oFund, id);
FMFundDA.Insert(tc, oFund);
}
else
{
FMFundDA.Update(tc, oFund);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
FMFundDA.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
#region Get(By fundID)
public FMFund Get(int fundID)
{
FMFund fund = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FMFundDA.Get(tc, fundID));
if (dr.Read())
{
fund = this.CreateObject<FMFund>(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 fund;
}
#endregion
#region Get()
public List<FMFund> Get()
{
List<FMFund> funds = new List<FMFund>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FMFundDA.Get(tc));
funds = this.CreateObjects<FMFund>(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 funds;
}
#endregion
#region Internal Get()
internal List<FMFund> Get(TransactionContext tc)
{
List<FMFund> funds = new List<FMFund>();
try
{
DataReader dr = new DataReader(FMFundDA.Get(tc));
funds = this.CreateObjects<FMFund>(dr);
dr.Close();
}
catch (Exception e)
{
throw e;
}
return funds;
}
#endregion
#region GetByProjectID
public List<FMFund> GetByProjectID(int ProjectID)
{
List<FMFund> funds = new List<FMFund>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(FMFundDA.GetByProjectID(tc, ProjectID));
funds = this.CreateObjects<FMFund>(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 funds;
}
#endregion
#region GetTable
public DataTable GetTable()
{
DataTable dTbl = new DataTable("Funds");
//TransactionContext tc = null;
//try
//{
// tc = TransactionContext.Begin();
// IDataReader ir = FundDA.Get(tc);
// dTbl.Load(ir);
// ir.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 dTbl;
}
#endregion
#endregion
#region Internal function
internal FMFund Get(TransactionContext tc, string desc)
{
FMFund fund = null;
try
{
DataReader dr = new DataReader(FMFundDA.Get(tc, desc));
if (dr.Read())
{
fund = this.CreateObject<FMFund>(dr);
}
dr.Close();
}
catch (Exception e)
{
throw e;
}
return fund;
}
#endregion
}
}