EchoTex_Payroll/HRM.DA/Service/Fund/Transaction/TranElementService.cs

270 lines
6.9 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using HRM.BO;
namespace HRM.DA
{
public class TranElementService : ServiceTemplate //, ITranElementService
{
public TranElementService()
{
}
private void MapObject(TranElement tranElement, DataReader dr)
{
base.SetObjectID(tranElement, dr.GetInt32("TranElementID").Value);
tranElement.Name = dr.GetString("TranElementName");
tranElement.Source = dr.GetString("SourceTableName");
tranElement.ElementType = (EnumElementType)(dr.GetInt16("ElementType"));
tranElement.WhereCluse = dr.GetString("WhereCluse");
tranElement.CreatedBy = dr.GetInt32("CreatedBy").Value;
tranElement.CreatedDate = dr.GetDateTime("CreatedDate").Value;
tranElement.ModifiedBy = dr.GetInt32("ModifiedBy");
tranElement.ModifiedDate = dr.GetDateTime("ModifiedDate");
tranElement.ProjectID =
dr.GetInt32("ProjectID")
.Value; //Ease.CoreV35.Model.ID.FromInteger(User.CurrentUser.ProjectID.Integer);
base.SetObjectState(tranElement, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
TranElement tranElement = new TranElement();
MapObject(tranElement, dr);
return tranElement as T;
}
protected TranElement CreateObject(DataReader oReader)
{
TranElement tranElement = new TranElement();
MapObject(tranElement, oReader);
return tranElement;
}
#region Service Implementation
#region Insert
public void Save(TranElement tranElement)
{
TranElement oTranElement = new TranElement();
oTranElement = tranElement;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oTranElement.IsNew)
{
int id = tc.GenerateID("TranElement", "TranElementID");
base.SetObjectID(oTranElement, id);
TranElementDA.Insert(tc, oTranElement);
}
else
{
TranElementDA.Update(tc, oTranElement);
}
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);
TranElementDA.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 TranElementID)
public TranElement Get(int tranElementID)
{
TranElement tranElement = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TranElementDA.Get(tc, tranElementID));
if (dr.Read())
{
tranElement = this.CreateObject<TranElement>(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 tranElement;
}
#endregion
#region Get()
public List<TranElement> Get()
{
List<TranElement> tranElements = new List<TranElement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TranElementDA.Get(tc));
tranElements = this.CreateObjects<TranElement>(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 tranElements;
}
public List<TranElement> Get(string Source)
{
List<TranElement> tranElements = new List<TranElement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TranElementDA.Get(tc, Source));
tranElements = this.CreateObjects<TranElement>(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 tranElements;
}
public List<TranElement> Get(string Source, EnumElementType ntype)
{
List<TranElement> tranElements = new List<TranElement>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TranElementDA.Get(tc, Source, ntype));
tranElements = this.CreateObjects<TranElement>(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 tranElements;
}
#endregion
#region GetTable
public DataTable GetTable()
{
DataTable dTbl = new DataTable("TranElement");
return dTbl;
}
#endregion
#endregion
}
}