EchoTex_Payroll/HRM.DA/Service/Basic/AutoObjectService.cs

154 lines
4.2 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.Data;
using HRM.BO;
namespace HRM.DA
{
public class AutoObjectService : ServiceTemplate, IAutoObjectService
{
public AutoObjectService()
{
}
private void MapObject(AutoObject oAutoObject, DataReader oReader)
{
base.SetObjectID(oAutoObject, oReader.GetInt32("TableID").Value);
oAutoObject.Name = oReader.GetString("FormName");
oAutoObject.MenuKey = oReader.GetString("MenuKey");
this.SetObjectState(oAutoObject, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
AutoObject oAutoObject = new AutoObject();
MapObject(oAutoObject, oReader);
return oAutoObject as T;
}
protected AutoObject CreateObject(DataReader oReader)
{
AutoObject oAutoObject = new AutoObject();
MapObject(oAutoObject, oReader);
return oAutoObject;
}
#region Service implementation
public AutoObject Get(string sFormName)
{
AutoObject oAutoObject = new AutoObject();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AutoObjectDA.Get(tc, sFormName));
if (oreader.Read())
{
oAutoObject = this.CreateObject<AutoObject>(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 oAutoObject;
}
public int Save(AutoObject oAutoObject)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oAutoObject.IsNew)
{
int id = tc.GenerateID("AutoObjectName", "AutoObjectID");
base.SetObjectID(oAutoObject, id);
AutoObjectDA.Insert(tc, oAutoObject);
}
else
{
AutoObjectDA.Update(tc, oAutoObject);
}
tc.End();
return oAutoObject.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);
AutoObjectDA.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
}
}
public static DataSet GetInformation(DateTime FromDate, DateTime ToDate, string sTableName)
{
DataSet ds = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
ds = AutoObjectDA.GetInformation(tc, FromDate, ToDate, sTableName);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return ds;
}
#endregion
}
}