CEL_Payroll/Payroll.Service/PF/Service/PFExceptionService.cs

167 lines
5.4 KiB
C#
Raw Permalink 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;
using System.Configuration;
using System.Data.SqlClient;
using System.Reflection;
namespace Payroll.Service
{
#region PFTransaction Service
[Serializable]
public class PFExceptionService : ServiceTemplate, IPFExceptionService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(PFException));
#endregion
public PFExceptionService() { }
private void MapObject(PFException oPFException, DataReader oReader)
{
base.SetObjectID(oPFException, oReader.GetID("PFExceptionID"));
oPFException.EmployeeID = oReader.GetID("employeeID");
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.GetID("CreatedBy");
oPFException.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oPFException.ModifiedBy = oReader.GetID("ModifiedBy");
oPFException.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : DateTime.MinValue;
this.SetObjectState(oPFException, Ease.CoreV35.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 ObjectsTemplate<PFException> Get()
{
#region Cache Header
ObjectsTemplate<PFException> pFExceptions = _cache["Get"] as ObjectsTemplate<PFException>;
if (pFExceptions != null)
return pFExceptions;
#endregion
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
}
#region Cache Footer
_cache.Add(pFExceptions, "Get");
#endregion
return pFExceptions;
}
public PFException Get(ID PFExceptionID)
{
throw new NotImplementedException();
}
public void Delete(ID 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 ID Save(PFException oPFException)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oPFException.IsNew)
{
int id = tc.GenerateID("PFException", "PFExceptionID");
base.SetObjectID(oPFException, ID.FromInteger(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
}