229 lines
6.3 KiB
C#
229 lines
6.3 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using Ease.CoreV35;
|
|
using Ease.CoreV35.DataAccess;
|
|
using System.Collections.Generic;
|
|
using Payroll.BO;
|
|
using Ease.Core.Model;
|
|
using HRM.BO;
|
|
using Ease.Core.DataAccess;
|
|
using Ease.Core.Utility;
|
|
using HRM.DA;
|
|
using static iTextSharp.text.pdf.AcroFields;
|
|
using System.Data.Common;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
#region ClaimBasic Service
|
|
public class PRBKpiService : ServiceTemplate, IPRBKpiService
|
|
{
|
|
public PRBKpiService() { }
|
|
|
|
private void MapObject(PRBKpi oPRBKpi, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oPRBKpi, oReader.GetInt32("KpiID").Value);
|
|
oPRBKpi.Serial = oReader.GetString("targetSerial",true,null);
|
|
oPRBKpi.KpiName = oReader.GetString("kpiName", true, null);
|
|
oPRBKpi.PRBMonth = oReader.GetDateTime("PRBMonth").Value;
|
|
oPRBKpi.Description = oReader.GetString("Description", true, null);
|
|
this.SetObjectState(oPRBKpi, Ease.Core.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
PRBKpi oPRBKpi = new PRBKpi();
|
|
MapObject(oPRBKpi, oReader);
|
|
return oPRBKpi as T;
|
|
}
|
|
protected PRBKpi CreateObject(DataReader oReader)
|
|
{
|
|
PRBKpi oPrbKpi = new PRBKpi();
|
|
MapObject(oPrbKpi, oReader);
|
|
return oPrbKpi;
|
|
}
|
|
|
|
#region Service implementation
|
|
|
|
public List<PRBKpi> GetAll()
|
|
{
|
|
List<PRBKpi> prbCals = new List<PRBKpi>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(PRBKpiDA.Get(tc));
|
|
prbCals = this.CreateObjects<PRBKpi>(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 prbCals;
|
|
}
|
|
|
|
public List<PRBKpi> GetKpiByPrbMonth(DateTime prbmonth)
|
|
{
|
|
List<PRBKpi> prbCals = new List<PRBKpi>();
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(PRBKpiDA.GetKpiByPrbMonth(tc, prbmonth));
|
|
prbCals = this.CreateObjects<PRBKpi>(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 prbCals;
|
|
}
|
|
|
|
public bool IsKpiByPrbMonth(DateTime prbmonth)
|
|
{
|
|
List<PRBKpi> prbCals = new List<PRBKpi>();
|
|
bool isKpiByPrb = false;
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(PRBKpiDA.GetKpiByPrbMonth(tc, prbmonth));
|
|
prbCals = this.CreateObjects<PRBKpi>(dr);
|
|
dr.Close();
|
|
tc.End();
|
|
|
|
if(prbCals.Count > 0)
|
|
{
|
|
isKpiByPrb = true;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
#region Handle Exception
|
|
|
|
if (tc != null)
|
|
tc.HandleError();
|
|
ExceptionLog.Write(e);
|
|
|
|
throw new ServiceException(e.Message, e);
|
|
|
|
#endregion
|
|
}
|
|
|
|
return isKpiByPrb;
|
|
}
|
|
|
|
|
|
public void Save(PRBKpi oprbkpi)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int id = tc.GenerateID("PRBKpi", "KpiId");
|
|
if (oprbkpi.IsNew)
|
|
{
|
|
base.SetObjectID(oprbkpi, id);
|
|
PRBKpiDA.Insert(tc, oprbkpi);
|
|
}
|
|
else
|
|
{
|
|
PRBKpiDA.Update(tc, oprbkpi);
|
|
}
|
|
|
|
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 Save(List<PRBKpi> prbKpiList)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
int id = tc.GenerateID("PRBKpi", "KpiId");
|
|
foreach (PRBKpi item in prbKpiList)
|
|
{
|
|
if (item.IsNew)
|
|
{
|
|
base.SetObjectID(item, id);
|
|
PRBKpiDA.Insert(tc, item);
|
|
id++;
|
|
}
|
|
else
|
|
{
|
|
PRBKpiDA.Update(tc, item);
|
|
}
|
|
}
|
|
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 Delete(int id)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
PRBKpiDA.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
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|