EchoTex_Payroll/HRM.DA/Service/Gratuity/ESBProvisionService.cs
2024-10-14 10:01:49 +06:00

297 lines
8.4 KiB
C#

using System;
using System.Data;
using System.Linq;
using System.Collections.Generic;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region ESBProvision Service
public class ESBProvisionService : ServiceTemplate
{
public ESBProvisionService()
{
}
private void MapObject(ESBProvision oESBProvision, DataReader oReader)
{
oESBProvision.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oESBProvision.SalaryMonthlyID = oReader.GetInt32("SalaryMonthlyID").Value;
oESBProvision.UserID = oReader.GetInt32("UserID").Value;
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.Core.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(int id)
{
ESBProvision oESBProvision = new ESBProvision();
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
}
return oESBProvision;
}
public List<ESBProvision> GetProvision(DateTime dFromDate, DateTime dToDate)
{
List<ESBProvision> oESBProvisions = new List<ESBProvision>();
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
}
return oESBProvisions;
}
public List<ESBProvision> GetProvision(int EmployeeID, DateTime dFromDate, DateTime dToDate)
{
List<ESBProvision> oESBProvisions = new List<ESBProvision>();
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
}
return oESBProvisions;
}
public List<ESBProvision> GetProvision(string sEmpID, DateTime GratuityMonth)
{
List<ESBProvision> oESBProvisions = new List<ESBProvision>();
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
}
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 int 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 int 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(int nEmpID, int 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
}