CEL_Payroll/Payroll.Service/AllowDeduct/Service/ComponentUploadSetupService.cs

241 lines
8.3 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
{
public class ComponentUploadSetupService : ServiceTemplate, IComponentUploadSetupService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ComponentUploadSetup));
public ComponentUploadSetupService() { }
private void MapObject(ComponentUploadSetup componentSetup, DataReader oReader)
{
base.SetObjectID(componentSetup, ID.FromInteger(oReader.GetInt32("ComponentUploadSetupID").Value));
componentSetup.EmployeeID = oReader.GetInt32("EmployeeID").Value;
componentSetup.ApproverID = oReader.GetInt32("ApproverID").Value;
componentSetup.ItemID = oReader.GetString("ItemID") == null ? null : ID.FromInteger(oReader.GetInt32("ItemID").Value);
componentSetup.ComponentType = (EnumComponentType)oReader.GetInt32("ComponentType");
componentSetup.Description = oReader.GetString("Description");
this.SetObjectState(componentSetup, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ComponentUploadSetup componentSetup = new ComponentUploadSetup();
MapObject(componentSetup, oReader);
return componentSetup as T;
}
private ComponentUploadSetup CreateObject(DataReader oReader)
{
ComponentUploadSetup componentSetup = new ComponentUploadSetup();
MapObject(componentSetup, oReader);
return componentSetup;
}
#endregion
#region Service implementation
public ObjectsTemplate<ComponentUploadSetup> Get()
{
#region Cache Header
ObjectsTemplate<ComponentUploadSetup> componentSetups = _cache["Get"] as ObjectsTemplate<ComponentUploadSetup>;
if (componentSetups != null)
return componentSetups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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
_cache.Add(componentSetups, "Get");
#endregion
return componentSetups;
}
public ObjectsTemplate<ComponentUploadSetup> Get(ID empid)
{
#region Cache Header
ObjectsTemplate<ComponentUploadSetup> componentSetups = _cache["Get"] as ObjectsTemplate<ComponentUploadSetup>;
if (componentSetups != null)
return componentSetups;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.Get(tc, empid));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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
_cache.Add(componentSetups, "Get", empid);
#endregion
return componentSetups;
}
public ObjectsTemplate<ComponentUploadSetup> GetByApproverID(ID apprvrID)
{
ObjectsTemplate<ComponentUploadSetup> componentSetups = _cache["Get"] as ObjectsTemplate<ComponentUploadSetup>;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ComponentUploadSetupDA.GetByApproverID(tc, apprvrID));
componentSetups = this.CreateObjects<ComponentUploadSetup>(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 componentSetups;
}
public DataTable GetUploadedComponentReportData(DateTime fromDate, DateTime toDate)
{
DataTable dtComponentSetups = new DataTable();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataSet ds = ComponentUploadSetupDA.GetUploadedComponentReportData(tc, fromDate, toDate);
dtComponentSetups = (ds != null && (ds.Tables != null && ds.Tables.Count > 0)) ? ds.Tables[0] : new DataTable();
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dtComponentSetups;
}
public void Save(ObjectsTemplate<ComponentUploadSetup> componentSetups)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
int id;
foreach (ComponentUploadSetup componentSetup in componentSetups)
{
if (componentSetup.IsNew)
{
id = tc.GenerateID("ComponentUploadSetup", "ComponentUploadSetupID");
base.SetObjectID(componentSetup, ID.FromInteger(id));
ComponentUploadSetupDA.Insert(tc, componentSetup);
}
else
{
ComponentUploadSetupDA.Update(tc, componentSetup);
}
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new Exception("Failed to Component Upload Setup. Because " + e.Message, e);
#endregion
}
}
public void Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ComponentUploadSetupDA.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 void DeleteSingleComponent(ComponentUploadSetup oComponentUploadSetup)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ComponentUploadSetupDA.DeleteSingleComponent(tc, oComponentUploadSetup.EmployeeID, oComponentUploadSetup.ApproverID, oComponentUploadSetup.ComponentType, oComponentUploadSetup.ItemID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}