EchoTex_Payroll/HRM.DA/Service/PF/PFExceptionService.cs

181 lines
5.7 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
using System.Data;
namespace HRM.DA
{
#region PFTransaction Service
public class PFExceptionService : ServiceTemplate
{
#region Private functions and declaration
#endregion
public PFExceptionService()
{
}
private void MapObject(PFException oPFException, DataReader oReader)
{
base.SetObjectID(oPFException, oReader.GetInt32("PFExceptionID").Value);
oPFException.EmployeeID =
oReader.GetString("EmployeeID") == null ? 0 : oReader.GetInt32("EmployeeID").Value;
oPFException.StartDate = oReader.GetDateTime("startDate").Value;
//oPFException.EPFPercent = oReader.GetDouble("epfPercent").Value;
oPFException.EPFPercent =
oReader.GetDouble("epfPercent").HasValue ? oReader.GetDouble("epfPercent").Value : 0;
//oPFException.CPFPercent = oReader.GetDouble("cpfPercent").Value;
oPFException.CPFPercent =
oReader.GetDouble("cpfPercent").HasValue ? oReader.GetDouble("cpfPercent").Value : 0;
//oPFException.EPFAmount = oReader.GetDouble("epfAmount").Value;
oPFException.EPFAmount = oReader.GetDouble("epfAmount").HasValue ? oReader.GetDouble("epfAmount").Value : 0;
//oPFException.CPFAmount = oReader.GetDouble("cpfAmount").Value;
oPFException.CPFAmount = oReader.GetDouble("cpfAmount").HasValue ? oReader.GetDouble("cpfAmount").Value : 0;
oPFException.CreatedBy = oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oPFException.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oPFException.ModifiedBy =
oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
oPFException.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: DateTime.MinValue;
this.SetObjectState(oPFException, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PFException oPFException = new PFException();
MapObject(oPFException, oReader);
return oPFException as T;
}
protected PFException CreateObject(DataReader oReader)
{
PFException oPFException = new PFException();
MapObject(oPFException, oReader);
return oPFException;
}
#region Service implementation
public List<PFException> Get()
{
List<PFException> pFExceptions = new List<PFException>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(PFExceptionDA.Get(tc));
pFExceptions = this.CreateObjects<PFException>(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 pFExceptions;
}
public DataSet Get(DateTime dateTime)
{
DataSet oEmployeesPF = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
oEmployeesPF = PFExceptionDA.Get(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 oEmployeesPF;
}
public PFException Get(int PFExceptionID)
{
throw new NotImplementedException();
}
public void Delete(int PFExceptionID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PFExceptionDA.Delete(tc, PFExceptionID);
tc.End();
}
catch (Exception e)
{
if (tc != null)
{
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
}
}
}
public int Save(PFException oPFException)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPFException.IsNew)
{
int id = tc.GenerateID("PFException", "PFExceptionID");
base.SetObjectID(oPFException, id);
PFExceptionDA.Insert(tc, oPFException);
}
else
{
PFExceptionDA.Update(tc, oPFException);
}
tc.End();
return oPFException.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}