CEL_Payroll/Payroll.Service/Gratuity/Service/ESBProvisionService.cs
2024-09-17 14:30:13 +06:00

322 lines
10 KiB
C#

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 ESBProvision Service
[Serializable]
public class ESBProvisionService : ServiceTemplate, IESBProvisionService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ESBProvision));
#endregion
public ESBProvisionService() { }
private void MapObject(ESBProvision oESBProvision, DataReader oReader)
{
oESBProvision.EmployeeID = oReader.GetID("EmployeeID");
oESBProvision.SalaryMonthlyID = oReader.GetID("SalaryMonthlyID");
oESBProvision.UserID = oReader.GetID("UserID");
oESBProvision.ProcessMonthDate = oReader.GetDateTime("ProcessMonthDate").Value;
oESBProvision.Provision = oReader.GetDouble("Provision").Value;
oESBProvision.ProvisionOne = oReader.GetDouble("ProvisionOne").Value;
oESBProvision.ProvisionTwo = oReader.GetDouble("ProvisionTwo").Value;
this.SetObjectState(oESBProvision,Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ESBProvision oESBProvision = new ESBProvision();
MapObject(oESBProvision, oReader);
return oESBProvision as T;
}
protected ESBProvision CreateObject(DataReader oReader)
{
ESBProvision oESBProvision = new ESBProvision();
MapObject(oESBProvision, oReader);
return oESBProvision;
}
#region Service implementation
public ESBProvision Get(ID id)
{
ESBProvision oESBProvision = new ESBProvision();
#region Cache Header
oESBProvision = _cache["Get", id] as ESBProvision;
if (oESBProvision != null)
return oESBProvision;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ESBProvisionDA.Get(tc, id));
if (oreader.Read())
{
oESBProvision = this.CreateObject<ESBProvision>(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
}
#region Cache Footer
_cache.Add(oESBProvision, "Get", id);
#endregion
return oESBProvision;
}
public ObjectsTemplate<ESBProvision> GetProvision(DateTime dFromDate, DateTime dToDate)
{
#region Cache Header
ObjectsTemplate<ESBProvision> oESBProvisions = _cache["GetProvision", dFromDate, dToDate] as ObjectsTemplate<ESBProvision>;
if (oESBProvisions != null)
return oESBProvisions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ESBProvisionDA.GetProvision(tc, dFromDate, dToDate));
oESBProvisions = this.CreateObjects< ESBProvision>(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(oESBProvisions, "GetProvision", dFromDate, dToDate);
#endregion
return oESBProvisions;
}
public ObjectsTemplate<ESBProvision> GetProvision(int EmployeeID, DateTime dFromDate, DateTime dToDate)
{
#region Cache Header
ObjectsTemplate<ESBProvision> oESBProvisions = _cache["GetProvision",EmployeeID, dFromDate, dToDate] as ObjectsTemplate<ESBProvision>;
if (oESBProvisions != null)
return oESBProvisions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ESBProvisionDA.GetProvision(tc,EmployeeID, dFromDate, dToDate));
oESBProvisions = this.CreateObjects<ESBProvision>(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(oESBProvisions, "GetProvision",EmployeeID, dFromDate, dToDate);
#endregion
return oESBProvisions;
}
public ObjectsTemplate<ESBProvision> GetProvision(string sEmpID, DateTime GratuityMonth)
{
#region Cache Header
ObjectsTemplate<ESBProvision> oESBProvisions = _cache["GetProvision", sEmpID, GratuityMonth] as ObjectsTemplate<ESBProvision>;
if (oESBProvisions != null)
return oESBProvisions;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ESBProvisionDA.GetProvision(tc, sEmpID, GratuityMonth));
oESBProvisions = this.CreateObjects<ESBProvision>(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(oESBProvisions, "GetProvision", sEmpID, GratuityMonth);
#endregion
return oESBProvisions;
}
public double GetOpeningBalance(int employeeId, DateTime fromDate)
{
double amount = 0;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
amount = ESBProvisionDA.GetOpeningBalance(tc, employeeId,fromDate);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return amount;
}
public DataSet GetCumulativeProv(DateTime dateTime)
{
DataSet oCumulativeProvss = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oCumulativeProvss = ESBProvisionDA.GetCumulativeProv(tc, dateTime);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oCumulativeProvss;
}
public ID Save(ESBProvision oESBProvision)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ESBProvisionDA.Delete(tc,oESBProvision.EmployeeID, oESBProvision.SalaryMonthlyID);
ESBProvisionDA.Insert(tc, oESBProvision);
tc.End();
return oESBProvision.EmployeeID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID Save(TransactionContext tc,ESBProvision oESBProvision)
{
try
{
ESBProvisionDA.Delete(tc, oESBProvision.EmployeeID, oESBProvision.SalaryMonthlyID);
ESBProvisionDA.Insert(tc, oESBProvision);
return oESBProvision.EmployeeID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Delete(ID nEmpID, ID nSalaryMonthlyID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ESBProvisionDA.Delete(tc, nEmpID, nSalaryMonthlyID);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}