EchoTex_Payroll/HRM.DA/Service/RewardStatement/LTIncentivePlanService.cs

214 lines
6.8 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class LTIncentivePlanService : ServiceTemplate, ILTIncentivePlanService
{
private void MapObject(LTIncentivePlan lTIncentivePlan, DataReader oReader)
{
base.SetObjectID(lTIncentivePlan, (oReader.GetInt32("LTIncentivePlanID").Value));
lTIncentivePlan.EmpID = (oReader.GetInt32("EmployeeID").Value);
lTIncentivePlan.LTType = (EnumLTType)oReader.GetInt32("LTType").Value;
lTIncentivePlan.AwardedShare = oReader.GetInt32("AwardedShare").GetValueOrDefault();
lTIncentivePlan.ShareYear = oReader.GetDateTime("ShareYear").Value;
lTIncentivePlan.VestingPercent = oReader.GetDouble("VestingPercent").GetValueOrDefault();
lTIncentivePlan.Remarks = oReader.GetString("Remarks");
lTIncentivePlan.VestedRemarks = oReader.GetString("VestedRemarks");
lTIncentivePlan.IsVestedDSBS = oReader.GetBoolean("IsVestedDSBS").GetValueOrDefault();
lTIncentivePlan.CreatedBy = oReader.GetInt32("CreatedBy", 0);
lTIncentivePlan.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
? oReader.GetDateTime("CreatedDate").Value
: DateTime.MinValue;
lTIncentivePlan.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
lTIncentivePlan.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
this.SetObjectState(lTIncentivePlan, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
LTIncentivePlan lTIncentivePlan = new LTIncentivePlan();
MapObject(lTIncentivePlan, oReader);
return lTIncentivePlan as T;
}
#region Service implementation
public List<LTIncentivePlan> GetLTIP()
{
List<LTIncentivePlan> lTIncentivePlans = new List<LTIncentivePlan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LTIncentivePlanDA.GetLTIP(tc));
lTIncentivePlans = this.CreateObjects<LTIncentivePlan>(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 lTIncentivePlans;
}
public List<LTIncentivePlan> GetDSBS()
{
List<LTIncentivePlan> lTIncentivePlans = new List<LTIncentivePlan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LTIncentivePlanDA.GetDSBS(tc));
lTIncentivePlans = this.CreateObjects<LTIncentivePlan>(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 lTIncentivePlans;
}
public List<LTIncentivePlan> GetLTIP(int empID)
{
List<LTIncentivePlan> lTIncentivePlans = new List<LTIncentivePlan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LTIncentivePlanDA.GetLTIP(tc, empID));
lTIncentivePlans = this.CreateObjects<LTIncentivePlan>(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 lTIncentivePlans;
}
public List<LTIncentivePlan> GetDSBS(int empID)
{
List<LTIncentivePlan> lTIncentivePlans = new List<LTIncentivePlan>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(LTIncentivePlanDA.GetDSBS(tc, empID));
lTIncentivePlans = this.CreateObjects<LTIncentivePlan>(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 lTIncentivePlans;
}
public void Save(LTIncentivePlan lTIncentivePlan)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (lTIncentivePlan.IsNew)
{
int id = tc.GenerateID("LTIncentivePlan", "LTIncentivePlanID");
base.SetObjectID(lTIncentivePlan, (id));
LTIncentivePlanDA.Insert(tc, lTIncentivePlan);
}
else
{
LTIncentivePlanDA.Update(tc, lTIncentivePlan);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new Exception("Failed to Insert. Because " + e.Message, e);
#endregion
}
}
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
LTIncentivePlanDA.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
}
}