EchoTex_Payroll/HRM.DA/Service/Fund/VoucherSetup/ActivityRelatedSourceService.cs

245 lines
6.4 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
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;
using HRM.DA;
//using HRM.BO.Fund;
namespace HRM.DA.Fund
{
public class ActivityRelatedSourceService : ServiceTemplate
{
public ActivityRelatedSourceService()
{
}
private void MapObject(ActivityRelatedSource activityRelatedSource, DataReader dr)
{
base.SetObjectID(activityRelatedSource, dr.GetInt32("ActivityRelatedID").Value);
activityRelatedSource.SourceTable = dr.GetString("SourceTable");
activityRelatedSource.ValueField = dr.GetString("ValueField");
activityRelatedSource.ObjectType = dr.GetString("ObjectType");
activityRelatedSource.ObjectTypeSubsidiary = dr.GetString("ObjectTypeSubsidiary");
activityRelatedSource.CreatedBy = dr.GetInt32("CreatedBy").Value;
activityRelatedSource.CreatedDate = dr.GetDateTime("CreatedDate").Value;
activityRelatedSource.ModifiedBy = dr.GetInt32("ModifiedBy").Value;
activityRelatedSource.ModifiedDate = dr.GetDateTime("ModifiedDate");
base.SetObjectState(activityRelatedSource, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
ActivityRelatedSource activityRelatedSource = new ActivityRelatedSource();
MapObject(activityRelatedSource, dr);
return activityRelatedSource as T;
}
#region Service Implementation
#region Insert
public void Save(ActivityRelatedSource activityRelatedSource)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (activityRelatedSource.IsNew)
{
int id = tc.GenerateID("ActivityRelatedSource", "ActivityRelatedID");
base.SetObjectID(activityRelatedSource, (id));
ActivityRelatedSourceDA.Insert(tc, activityRelatedSource);
}
else
{
ActivityRelatedSourceDA.Update(tc, activityRelatedSource);
}
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);
ActivityRelatedSourceDA.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 ID)
public ActivityRelatedSource Get(int ID)
{
#region Cache Header
ActivityRelatedSource activityRelatedSource = new ActivityRelatedSource();
if (activityRelatedSource != null)
return activityRelatedSource;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityRelatedSourceDA.Get(tc, ID));
if (dr.Read())
{
activityRelatedSource = this.CreateObject<ActivityRelatedSource>(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
}
#region Cache Footer
#endregion
return activityRelatedSource;
}
#endregion
#region Get()
public List<ActivityRelatedSource> GetbyFundtype(int fundtypeid)
{
#region Cache Header
List<ActivityRelatedSource> activityRelatedSources = new List<ActivityRelatedSource>();
if (activityRelatedSources != null)
return activityRelatedSources;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityRelatedSourceDA.GetbyFundtype(tc, fundtypeid));
activityRelatedSources = this.CreateObjects<ActivityRelatedSource>(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
}
#region Cache Footer
#endregion
return activityRelatedSources;
}
#endregion
#region GetTable
//public DataTable GetTable()
//{
// DataTable dTbl = new DataTable("ActivityRelatedSources");
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// IDataReader ir = ActivityRelatedSourceDA.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
}
}