EchoTex_Payroll/HRM.DA/Service/PMP/DevelopmentPlanService.cs

547 lines
17 KiB
C#
Raw Permalink 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 DevelopmentPlanService : ServiceTemplate, IDevelopmentPlanService
{
#region Object Mapping
private void MapObject(DevelopmentPlan oDevelopmentPlan, DataReader oReader)
{
SetObjectID(oDevelopmentPlan, oReader.GetInt32("DevelopmentPlanID", 0));
oDevelopmentPlan.ObjectiveSetID = oReader.GetInt32("ObjectiveSetID").Value;
oDevelopmentPlan.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oDevelopmentPlan.PMPYearID = oReader.GetInt32("PMPYearID").Value;
oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID").HasValue ? oReader.GetInt32("TrainingID").Value : null;
oDevelopmentPlan.TrainingName = oReader.GetString("TrainingName", null);
oDevelopmentPlan.MeasureOfSuccess = oReader.GetString("MeasureOfSuccess", null);
oDevelopmentPlan.FromDate = oReader.GetDateTime("FromDate").HasValue ? oReader.GetDateTime("FromDate").Value : null;
oDevelopmentPlan.ToDate = oReader.GetDateTime("ToDate").Value;
oDevelopmentPlan.TargetRatingID = oReader.GetInt32("TargetRatingID").Value;
oDevelopmentPlan.EmpRemarks = oReader.GetString("EmpRemarks", null);
oDevelopmentPlan.LMRemarks = oReader.GetString("LMRemarks", null);
oDevelopmentPlan.EmployeeID = oReader.GetInt32("EmployeeID", 0);
//oDevelopmentPlan.FuncDevNeeds = oReader.GetString("FuncDevNeeds");
//oDevelopmentPlan.NxtCarrierSteps = oReader.GetString("NxtCarrierSteps");
//oDevelopmentPlan.TimeLine = oReader.GetString("TimeLine");
//oDevelopmentPlan.ObjectiveID = oReader.GetInt32("ObjectiveID", 0);
//oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID", 0);
//oDevelopmentPlan.TrainingID2 = oReader.GetInt32("TrainingID2", 0);
//oDevelopmentPlan.TrainingID3 = oReader.GetInt32("TrainingID3", 0);
//oDevelopmentPlan.CanTravel = oReader.GetBoolean("CanTravel").Value;
//oDevelopmentPlan.Remarks = oReader.GetString("Remarks");
//oDevelopmentPlan.EmployeeID = oReader.GetInt32("EmployeeID", 0);
//oDevelopmentPlan.ObjectiveSetID = oReader.GetInt32("ObjectiveSetID", 0);
this.SetObjectState(oDevelopmentPlan, ObjectState.Saved);
}
private void MapObject(FunctionalDevelopment oDevelopmentPlan, DataReader oReader)
{
SetObjectID(oDevelopmentPlan, oReader.GetInt32("FuncDevelopmentID", 0));
oDevelopmentPlan.DevelopmentPlanID = oReader.GetInt32("DevelopmentPlanID").Value;
oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID").Value;
this.SetObjectState(oDevelopmentPlan, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
DevelopmentPlan oDevelopmentPlan = new DevelopmentPlan();
MapObject(oDevelopmentPlan, oReader);
return oDevelopmentPlan as T;
}
private FunctionalDevelopment CreateFuncDevObject(DataReader oReader)
{
FunctionalDevelopment oDevelopmentPlan = new FunctionalDevelopment();
MapObject(oDevelopmentPlan, oReader);
return oDevelopmentPlan;
}
private List<FunctionalDevelopment> CreateFuncDevObjects(DataReader oReader)
{
List<FunctionalDevelopment> ofuncDevmnts = new List<FunctionalDevelopment>();
while (oReader.Read())
{
ofuncDevmnts.Add(CreateFuncDevObject(oReader));
}
return ofuncDevmnts;
}
#endregion
#region IDevelopmentPlanService Members
#region Get All
public List<DevelopmentPlan> Get()
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.Get(tc));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
public List<DevelopmentPlan> GetByObjectiveSetId(int objectiveSetId)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetByObjectiveSetId(tc, objectiveSetId));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
public List<DevelopmentPlan> GetPreviousYears(int employeeId, int pmpYearId)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetPreviousYears(tc, employeeId, pmpYearId));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
public List<DevelopmentPlan> GetPreviousYears(int employeeId, DateTime pmpYear)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetPreviousYears(tc, employeeId, pmpYear));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
public List<FunctionalDevelopment> GetFunctionalDevelopment(int DevPlanID)
{
List<FunctionalDevelopment> oFunctionalDevelopment = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetFunctionalDevelopment(tc, DevPlanID));
oFunctionalDevelopment = this.CreateFuncDevObjects(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 oFunctionalDevelopment;
}
#endregion
#region GetByEmployeeID
public List<DevelopmentPlan> GetByEmployeeID(int id)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetByEmployeeID(tc, id));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
#endregion
#region GetByPMPYearID
public List<DevelopmentPlan> GetByPMPYearID(int id, string InEmpSQL)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetByPMPYearID(tc, id, InEmpSQL));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
#endregion
#region GetByObjSetID
public List<DevelopmentPlan> GetByObjSetID(int id)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetByObjSetID(tc, id));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
#endregion
#region GetByPmpYearId
public List<DevelopmentPlan> GetByPmpYearId(int id)
{
List<DevelopmentPlan> oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.GetByPmpYearId(tc, id));
oDevelopmentPlan = this.CreateObjects<DevelopmentPlan>(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 oDevelopmentPlan;
}
#endregion
#region Get By ID
public DevelopmentPlan Get(int id)
{
DevelopmentPlan oDevelopmentPlan = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(DevelopmentPlanDA.Get(tc, id));
if (oreader.Read())
{
oDevelopmentPlan = this.CreateObject<DevelopmentPlan>(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 oDevelopmentPlan;
}
#endregion
public DataSet GetTrainingNeedAnalysisCount(int pmpYearId)
{
DataSet dataSet = new DataSet();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
dataSet = DevelopmentPlanDA.GetTrainingNeedAnalysisCount(tc, pmpYearId);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return dataSet;
}
#region Insert
public int Save(DevelopmentPlan item)
{
TransactionContext tc = null;
try
{
int id = 0;
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
id = tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID");
base.SetObjectID(item, (id));
DevelopmentPlanDA.Insert(tc, item);
}
else
{
id = item.ID;
DevelopmentPlanDA.Update(tc, item);
}
tc.End();
return item.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(DevelopmentPlan item, EnumObjectiveFlowStatus DevPlanEmpStatus)
{
TransactionContext tc = null;
try
{
int id = 0;
//var functionalDevelopments = item.FunctionalDevelopments;
//tc = TransactionContext.Begin(true);
//if (item.IsNew)
//{
// id = tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID");
// base.SetObjectID(item, (id));
// DevelopmentPlanDA.Insert(tc, item, DevPlanEmpStatus);
//}
//else
//{
// id = item.ID;
// DevelopmentPlanDA.Update(tc, item, DevPlanEmpStatus);
//}
//DevelopmentPlanDA.DeleteFunctionalDevelopments(tc, id);
//foreach (var fditem in functionalDevelopments)
//{
// int childIid = tc.GenerateID("FuncDevelopment", "FuncDevelopmentID");
// base.SetObjectID(fditem, (childIid));
// fditem.DevelopmentPlanID = id;
// DevelopmentPlanDA.Insert(tc, fditem);
//}
//tc.End();
return item.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void LMSave(DevelopmentPlan item, EnumObjectiveFlowStatus DevPlanLMStatus)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DevelopmentPlanDA.LMUpdate(tc, item, DevPlanLMStatus);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
DevelopmentPlanDA.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
}
}