CEL_Payroll/Payroll.Service/SetupManager/Service/SetupDetailService.cs

372 lines
11 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Data;
using System.Linq;
using Ease.CoreV35;
using Ease.CoreV35.Model;
using Ease.CoreV35.DataAccess;
using System.Collections.Generic;
using Payroll.BO;
using Ease.CoreV35.Caching;
namespace Payroll.Service
{
#region SetupDetail Service
[Serializable]
public class SetupDetailService : ServiceTemplate, ISetupDetailService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(SetupDetail));
#endregion
public SetupDetailService() { }
private void MapObject(SetupDetail oSetupDetail, DataReader oReader)
{
base.SetObjectID(oSetupDetail, oReader.GetID("DetailID"));
oSetupDetail.SetupID = oReader.GetID("SetupID");
oSetupDetail.TranID = oReader.GetID("tranID");
oSetupDetail.TranType = (EnmSetupManagerTranType)oReader.GetInt32("tranType").Value;
this.SetObjectState(oSetupDetail, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
SetupDetail oSetupDetail = new SetupDetail();
MapObject(oSetupDetail, oReader);
return oSetupDetail as T;
}
protected SetupDetail CreateObject(DataReader oReader)
{
SetupDetail oSetupDetail = new SetupDetail();
MapObject(oSetupDetail, oReader);
return oSetupDetail;
}
#region Service implementation
public ObjectsTemplate<SetupDetail> GetParameters(EnumParameterSetup setup)
{
ObjectsTemplate<SetupDetail> setupDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SetupDetailDA.GetParameters(tc, setup));
setupDetails = this.CreateObjects<SetupDetail>(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 setupDetails;
}
public DataSet GetParameters(EnumParameterSetup setup,
List<string> sqlRelation, string InEmpSQL)
{
TransactionContext tc = null;
DataSet odataset;
try
{
tc = TransactionContext.Begin();
EmployeeSetupParameter empsetup = new EmployeeSetupParameter(setup);
odataset = SetupDetailDA.GetParameters(tc, setup, sqlRelation,InEmpSQL);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return odataset;
}
public ObjectsTemplate<SetupDetail> GetParameters(
EnumParameterSetup setup, int setupID)
{
ObjectsTemplate<SetupDetail> setupDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SetupDetailDA.GetParameters(tc, setupID, setup));
setupDetails = this.CreateObjects<SetupDetail>(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 setupDetails;
}
public ObjectsTemplate<SetupDetail> GetUsedParameters(
EnumParameterSetup setup, int setupID, int parameterID)
{
ObjectsTemplate<SetupDetail> setupDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SetupDetailDA.GetUsedParameters(tc, setup, setupID, parameterID));
setupDetails = this.CreateObjects<SetupDetail>(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 setupDetails;
}
public ObjectsTemplate<SetupDetail> GetOTDetail(EnumParameterSetup setup, EnmSetupManagerTranType enmSetupManagerTranType)
{
ObjectsTemplate<SetupDetail> setupDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SetupDetailDA.GetOTDetail(tc, setup, enmSetupManagerTranType));
setupDetails = this.CreateObjects<SetupDetail>(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 setupDetails;
}
public List<EnmSetupManagerTranType> GetTypes(
EnumParameterSetup setup)
{
List<EnmSetupManagerTranType> types = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet dataset = SetupDetailDA.GetTypes(tc, setup);
types = new List<EnmSetupManagerTranType>();
foreach (DataRow orow in dataset.Tables[0].Rows)
{
types.Add((EnmSetupManagerTranType)Convert.ToInt32(orow[0]));
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return types;
}
public List<int> GetParameterID(
EnumParameterSetup setup, EnmSetupManagerTranType type, ID TranID)
{
List<int> parameters = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet dataset = SetupDetailDA.GetParameters(tc, setup, type, TranID);
parameters = new List<int>();
foreach (DataRow orow in dataset.Tables[0].Rows)
{
parameters.Add(Convert.ToInt32(orow[0]));
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return parameters;
}
public ObjectsTemplate<SetupDetail> GetUsedParameters(
EnumParameterSetup setup, int parameterID)
{
ObjectsTemplate<SetupDetail> setupDetails = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(SetupDetailDA.GetUsedParameters(tc, setup, parameterID));
setupDetails = this.CreateObjects<SetupDetail>(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 setupDetails;
}
public void Save(TransactionContext tc, EnumParameterSetup setup,
ObjectsTemplate<SetupDetail> Details, ID SetupID)
{
try
{
this.Delete(tc, setup, SetupID);
foreach (SetupDetail item in Details)
{
item.SetupID = SetupID;
this.Save(tc, setup, item);
}
}
catch (Exception Ex)
{
throw new ServiceException(Ex.Message);
}
}
public ID Save(TransactionContext tc, EnumParameterSetup setup, SetupDetail oSetupDetail)
{
try
{
//tc = TransactionContext.Begin(true);
if (oSetupDetail.IsNew)
{
int id = SetupDetailDA.GenerateID( tc, setup);
base.SetObjectID(oSetupDetail, ID.FromInteger(id));
SetupDetailDA.Insert(tc, oSetupDetail,setup);
}
else
{
SetupDetailDA.Update(tc, oSetupDetail,setup);
}
// tc.End();
return oSetupDetail.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(TransactionContext tc, EnumParameterSetup setup, ID setupID)
{
try
{
SetupDetailDA.Delete(tc, setup, setupID);
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}