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

631 lines
18 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 ActivityVoucherSetupService : ServiceTemplate
{
public ActivityVoucherSetupService()
{
}
private void MapObject(ActivityVoucherSetup ActivityVoucherSetup, DataReader dr)
{
base.SetObjectID(ActivityVoucherSetup, dr.GetInt32("SetupID").Value);
ActivityVoucherSetup.ActivityID = dr.GetInt32("ActivityID").Value;
ActivityVoucherSetup.ProjectID = dr.GetInt32("ProjectID").Value;
ActivityVoucherSetup.ProcessID = dr.GetInt32("ProcessID").Value;
ActivityVoucherSetup.IsOptional = dr.GetBoolean("IsOptional").Value;
ActivityVoucherSetup.VoucherType = (VoucherTypeEnum)dr.GetInt16("VoucherType").Value;
ActivityVoucherSetup.IsMultipleDebit = dr.GetBoolean("IsMultipleDebit").Value;
ActivityVoucherSetup.IsMultipleCredit = dr.GetBoolean("IsMultipleCredit").Value;
ActivityVoucherSetup.DebitControl = dr.GetInt32("DebitControl").Value;
ActivityVoucherSetup.CreditControl = dr.GetInt32("CreditControl").Value;
ActivityVoucherSetup.DebitHISeq = dr.GetString("DebitHISeq");
ActivityVoucherSetup.CreditHISeq = dr.GetString("CreditHISeq");
ActivityVoucherSetup.DrGLID = dr.GetInt32("DrGLID").Value;
ActivityVoucherSetup.CrGLID = dr.GetInt32("CrGLID").Value;
ActivityVoucherSetup.DrGLCode = dr.GetString("DrGLCode");
ActivityVoucherSetup.CrGLCode = dr.GetString("CrGLCode");
ActivityVoucherSetup.Status = (EnumVoucherSetupStatus)dr.GetInt16("Status").Value;
ActivityVoucherSetup.Version = dr.GetInt32("Version").Value;
ActivityVoucherSetup.IsReqSubsidiary = dr.GetBoolean("IsReqSubsidiary").Value;
ActivityVoucherSetup.TranElementID = dr.GetInt32("TranElementID").Value;
ActivityVoucherSetup.ValueQuery = dr.GetString("ValueQuery");
ActivityVoucherSetup.SeqNo = dr.GetInt32("SeqNo").HasValue ? dr.GetInt32("SeqNo").Value : 0;
ActivityVoucherSetup.ActivityRelatedID = dr.GetInt32("ActivityRelatedID").Value;
ActivityVoucherSetup.ActivityRelatedValue = dr.GetInt32("ActivityRelatedValue").HasValue
? dr.GetInt32("ActivityRelatedValue").Value
: 0;
ActivityVoucherSetup.IsReqNewUserRecordForCr = dr.GetBoolean("IsReqNewURForCr").Value;
ActivityVoucherSetup.IsReqNewUserRecordForDr = dr.GetBoolean("IsReqNewURForDr").Value;
ActivityVoucherSetup.CreatedBy = dr.GetInt32("CreatedBy").Value;
ActivityVoucherSetup.CreatedDate = dr.GetDateTime("CreatedDate").Value;
ActivityVoucherSetup.ModifiedBy =
dr.GetInt32("ModifiedBy").Value != null ? dr.GetInt32("ModifiedBy").Value : (0);
ActivityVoucherSetup.ModifiedDate = dr.GetDateTime("ModifiedDate") != null
? dr.GetDateTime("ModifiedDate")
: DateTime.MinValue;
base.SetObjectState(ActivityVoucherSetup, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
ActivityVoucherSetup ActivityVoucherSetup = new ActivityVoucherSetup();
MapObject(ActivityVoucherSetup, dr);
return ActivityVoucherSetup as T;
}
#region Service Implementation
#region Insert
public void Save(ActivityVoucherSetup activityVoucherSetup)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (!activityVoucherSetup.IsNew)
{
activityVoucherSetup.Status = EnumVoucherSetupStatus.Inactive;
ActivityVoucherSetupDA.Update(tc, activityVoucherSetup);
}
activityVoucherSetup.Status = EnumVoucherSetupStatus.Active;
activityVoucherSetup.Version = 0;
int id = tc.GenerateID("ActivityVoucherSetup", "SetupID");
base.SetObjectID(activityVoucherSetup, (id));
ActivityVoucherSetupDA.Insert(tc, activityVoucherSetup);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Save(TransactionContext tc, ActivityVoucherSetup activityVoucherSetup)
{
try
{
if (!activityVoucherSetup.IsNew)
{
activityVoucherSetup.Version++;
activityVoucherSetup.ModifiedBy = activityVoucherSetup.CreatedBy;
activityVoucherSetup.ModifiedDate = DateTime.Now;
activityVoucherSetup.Status = EnumVoucherSetupStatus.Inactive;
ActivityVoucherSetupDA.Update(tc, activityVoucherSetup);
}
if (!activityVoucherSetup.IsNew)
{
activityVoucherSetup.Status = EnumVoucherSetupStatus.Active;
activityVoucherSetup.Version = 0;
int id = tc.GenerateID("ActivityVoucherSetup", "SetupID");
base.SetObjectID(activityVoucherSetup, (id));
ActivityVoucherSetupDA.Insert(tc, activityVoucherSetup);
}
}
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);
ActivityVoucherSetupDA.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
public List<ProcessActivity> GetActivityVoucherSetupByProcessActivityID(int ID, int fundtypeid)
{
List<ProcessActivity> items;
//BEGIN : Caching
items = new List<ProcessActivity>();
if (items != null)
{
return items;
}
//END : Caching
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader iReader =
new DataReader(
ActivityVoucherSetupDA.GetActivityVoucherSetupByProcessActivityID(tc, ID, fundtypeid));
items = base.CreateObjects<ProcessActivity>(iReader);
iReader.Close();
tc.End();
}
catch (Exception e)
{
if (tc != null)
{
tc.HandleError();
}
throw new ServiceException(e.Message, e);
}
//FOOTER : Caching
return items;
}
#region Get(By ID)
public ActivityVoucherSetup Get(int ID)
{
#region Cache Header
ActivityVoucherSetup ActivityVoucherSetup = new ActivityVoucherSetup();
if (ActivityVoucherSetup != null)
return ActivityVoucherSetup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityVoucherSetupDA.Get(tc, ID));
if (dr.Read())
{
ActivityVoucherSetup = this.CreateObject<ActivityVoucherSetup>(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 ActivityVoucherSetup;
}
#endregion
#region Get(By string)
public List<ActivityVoucherSetup> Get(string sSearch, int fundtypeid)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetups = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetups != null)
return ActivityVoucherSetups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityVoucherSetupDA.Get(tc, sSearch, fundtypeid));
ActivityVoucherSetups = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetups;
}
#endregion
#region GetbyActivityid(By ID)
public List<ActivityVoucherSetup> GetbyActivityid(int ID, int fundtypeid)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetups = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetups != null)
return ActivityVoucherSetups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityVoucherSetupDA.GetbyActivityid(tc, ID, fundtypeid));
ActivityVoucherSetups = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetups;
}
#endregion
#region GetbyProjectid(By ID)
public List<ActivityVoucherSetup> GetbyProjectid(int ID)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetup = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetup != null)
return ActivityVoucherSetup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityVoucherSetupDA.GetbyProjectid(tc, ID));
ActivityVoucherSetup = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetup;
}
#endregion
#region GetbyProcessid(By ID)
public List<ActivityVoucherSetup> GetbyProcessid(int ID)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetup = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetup != null)
return ActivityVoucherSetup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityVoucherSetupDA.GetbyProcessid(tc, ID));
ActivityVoucherSetup = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetup;
}
#endregion
#region GetbyProcessidActivityid(By ID)
public List<ActivityVoucherSetup> GetbyProcessidActivityid(int Processid, int Activityid, int fundtypeid)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetup = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetup != null)
return ActivityVoucherSetup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr =
new DataReader(
ActivityVoucherSetupDA.GetbyProcessidActivityid(tc, Processid, Activityid, fundtypeid));
ActivityVoucherSetup = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetup;
}
#endregion
#region GetbyActivityProjectProcessID(By ID)
public List<ActivityVoucherSetup> GetbyActivityProjectProcessID(int Activityid, int Projectid, int Processid)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetup = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetup != null)
return ActivityVoucherSetup;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr =
new DataReader(
ActivityVoucherSetupDA.GetbyActivityProjectProcessID(tc, Activityid, Projectid, Processid));
ActivityVoucherSetup = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetup;
}
#endregion
#region Get()
public List<ActivityVoucherSetup> GetbyFundType(int fundtypeid)
{
#region Cache Header
List<ActivityVoucherSetup> ActivityVoucherSetups = new List<ActivityVoucherSetup>();
if (ActivityVoucherSetups != null)
return ActivityVoucherSetups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ActivityVoucherSetupDA.Get(tc, fundtypeid));
ActivityVoucherSetups = this.CreateObjects<ActivityVoucherSetup>(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 ActivityVoucherSetups;
}
#endregion
#region GetTable
public DataTable GetTable(int fundtypeid)
{
DataTable dTbl = new DataTable("ActivityVoucherSetups");
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
IDataReader ir = ActivityVoucherSetupDA.Get(tc, fundtypeid);
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
}
}