EchoTex_Payroll/HRM.DA/Service/TrainingS/TrainingNeedAnalysisService.cs

734 lines
24 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using System.Data;
using Ease.Core;
using System.Linq;
namespace HRM.DA
{
#region TrainingNeedAnalysis Service
class TrainingNeedAnalysisService : ServiceTemplate
{
#region Private functions and declaration
#region TrainingNeedAnalysis Mapping
private void MapObject(TrainingNeedAnalysis oTrainingNeedAnalysis, DataReader oReader)
{
base.SetObjectID(oTrainingNeedAnalysis, oReader.GetInt32("TrainingNeedAnalysisID").Value);
oTrainingNeedAnalysis.TrainingYear = oReader.GetInt32("TrainingYear").Value;
oTrainingNeedAnalysis.Name = oReader.GetString("Name");
oTrainingNeedAnalysis.EmployeeID = oReader.GetInt32("EmployeeID").GetValueOrDefault();
oTrainingNeedAnalysis.DepartmentID = oReader.GetInt32("DepartmentID").GetValueOrDefault();
oTrainingNeedAnalysis.TrainingID = oReader.GetInt32("TrainingID").Value;
oTrainingNeedAnalysis.Description = oReader.GetString("Description");
oTrainingNeedAnalysis.MaxParticipent = oReader.GetInt32("MaxParticipent").GetValueOrDefault();
oTrainingNeedAnalysis.Conduct_Required = oReader.GetInt32("Conduct_Required").Value;
// oTrainingNeedAnalysis.Schedule = oReader.GetString("Schedule");
oTrainingNeedAnalysis.CreatedBy =
oReader.GetString("CreatedBy") == null ? 0 : oReader.GetInt32("CreatedBy").Value;
oTrainingNeedAnalysis.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oTrainingNeedAnalysis.ModifiedBy =
oReader.GetString("ModifiedBy") == null ? 0 : oReader.GetInt32("ModifiedBy").Value;
;
oTrainingNeedAnalysis.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oTrainingNeedAnalysis, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingNeedAnalysis oTrainingNeedAnalysis = new TrainingNeedAnalysis();
MapObject(oTrainingNeedAnalysis, oReader);
return oTrainingNeedAnalysis as T;
}
#endregion
#region Subordinate Mapping
private void MapSubordinateTraineeObject(SubordinateTrainee oSubordinateTrainee, DataReader oReader)
{
base.SetObjectID(oSubordinateTrainee, oReader.GetInt32("SubordinateTraineeID").Value);
oSubordinateTrainee.TrainingNeedAnalysisID = oReader.GetInt32("TrainingNeedAnalysisID").Value;
oSubordinateTrainee.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oSubordinateTrainee.Remarks = oReader.GetString("Remarks");
//oSubordinateTrainee.CreatedBy = oReader.GetString("CreatedBy") == null ? null : oReader.GetInt32("CreatedBy").Value);
//oSubordinateTrainee.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Today;
//oSubordinateTrainee.ModifiedBy = oReader.GetString("ModifiedBy") == null ? null : oReader.GetInt32("ModifiedBy").Value);
//oSubordinateTrainee.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oSubordinateTrainee, Ease.Core.ObjectState.Saved);
}
//protected override T CreateObject<T>(DataReader oReader)
//{
// SubordinateTrainee oSubordinateTrainee = new SubordinateTrainee();
// MapSubordinateTraineeObject(oSubordinateTrainee, oReader);
// return oSubordinateTrainee as T;
//}
private SubordinateTrainee CreateSubordinateTraineeObject(DataReader oReader)
{
SubordinateTrainee oSubordinateTrainee = new SubordinateTrainee();
MapSubordinateTraineeObject(oSubordinateTrainee, oReader);
return oSubordinateTrainee;
}
protected List<SubordinateTrainee> CreateSubordinateTraineeObjects(DataReader oReader)
{
List<SubordinateTrainee> oSubordinateTrainee = new List<SubordinateTrainee>();
while (oReader.Read())
{
SubordinateTrainee item = CreateSubordinateTraineeObject(oReader);
oSubordinateTrainee.Add(item);
}
return oSubordinateTrainee;
}
#endregion
#endregion
#region Implementation of ITrainingNeedAnalysisService
#region Get TrainingNeedAnalysis
public TrainingNeedAnalysis Get(int TrainingNeedAnalysisID)
{
TrainingNeedAnalysis oTrainingNeedAnalysis = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.Get(tc, TrainingNeedAnalysisID));
if (oreader.Read())
{
oTrainingNeedAnalysis = CreateObject<TrainingNeedAnalysis>(oreader);
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysis;
}
#endregion
#region GetByEmployeeID
public TrainingNeedAnalysis GetByEmployeeID(string employeeNo)
{
TrainingNeedAnalysis oTrainingNeedAnalysis = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.GetByEmployeeID(tc, employeeNo));
if (oreader.Read())
{
oTrainingNeedAnalysis = CreateObject<TrainingNeedAnalysis>(oreader);
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysis;
}
#endregion
#region Get TrainingNeedAnalysiss
public List<TrainingNeedAnalysis> Get()
{
List<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.Get(tc));
oTrainingNeedAnalysiss = CreateObjects<TrainingNeedAnalysis>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysiss;
}
public List<TrainingNeedAnalysis> GetByYear(int year)
{
List<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.GetByYear(tc, year));
oTrainingNeedAnalysiss = CreateObjects<TrainingNeedAnalysis>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysiss;
}
public List<TrainingNeedAnalysis> GetByParam(int year, string sDeptIDs, string sDeptForIDs)
{
List<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.GetByParam(tc, year, sDeptIDs, sDeptForIDs));
oTrainingNeedAnalysiss = CreateObjects<TrainingNeedAnalysis>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysiss;
}
public List<TrainingNeedAnalysis> Get(int trainingID, int departmentID, int departmentForID, int trainingType)
{
List<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingNeedAnalysisDA.Get(tc, trainingID, departmentID, departmentForID,
trainingType));
oTrainingNeedAnalysiss = CreateObjects<TrainingNeedAnalysis>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysiss;
}
public List<TrainingNeedAnalysis> Get(string query)
{
List<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.Get(tc, query));
oTrainingNeedAnalysiss = CreateObjects<TrainingNeedAnalysis>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysiss;
}
#endregion
#region IsExist
public TrainingNeedAnalysis IsExist(int trainingID)
{
TrainingNeedAnalysis oTrainingNeedAnalysis = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.IsExist(tc, trainingID));
if (oreader.Read())
{
oTrainingNeedAnalysis = CreateObject<TrainingNeedAnalysis>(oreader);
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingNeedAnalysis;
}
#endregion
#region Insert TrainingNeedAnalysis
public int Save(TrainingNeedAnalysis oTrainingNeedAnalysis)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (oTrainingNeedAnalysis.IsNew)
{
int newID = tc.GenerateID("TrainingNeedAnalysis", "TrainingNeedAnalysisID");
base.SetObjectID(oTrainingNeedAnalysis, newID);
TrainingNeedAnalysisDA.Insert(tc, oTrainingNeedAnalysis);
foreach (SubordinateTrainee item in oTrainingNeedAnalysis.TrainingEmployee)
{
item.TrainingNeedAnalysisID = newID;
(new TrainingNeedAnalysisService()).SaveSubordinate(tc, item);
}
foreach (TrainingNdAnalysisTimeSch item in oTrainingNeedAnalysis.TrainingNdAnalysisTimeSchs)
{
item.TrainingNeedAnalysisID = newID;
(new TrainingNdAnalysisTimeSchService()).Save(tc, item);
}
}
else
{
List<TrainingNdAnalysisTimeSch> oTempNdAnalysisTSchs =
oTrainingNeedAnalysis.TrainingNdAnalysisTimeSchs;
List<TrainingDepartment> oTempTrainingDepts = oTrainingNeedAnalysis.TrainingDepartments;
TrainingDepartmentDA.DeletebyTrainingNeedAnalysisID(tc, oTrainingNeedAnalysis.ID);
TrainingNdAnalysisTimeSchDA.DeletebyTrainingNeedAnalysisID(tc, oTrainingNeedAnalysis.ID);
TrainingNeedAnalysisDA.Update(tc, oTrainingNeedAnalysis);
foreach (TrainingDepartment item in oTempTrainingDepts)
{
item.TrainingNeedAnalysisID = oTrainingNeedAnalysis.ID;
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
base.SetObjectID(item, newID);
TrainingDepartmentDA.Insert(tc, item);
}
foreach (TrainingNdAnalysisTimeSch item in oTempNdAnalysisTSchs)
{
item.TrainingNeedAnalysisID = oTrainingNeedAnalysis.ID;
int newID = tc.GenerateID("TrainingNdAnalysisTimeSch", "TNATimeSchID");
base.SetObjectID(item, newID);
TrainingNdAnalysisTimeSchDA.Insert(tc, item);
}
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
return oTrainingNeedAnalysis.ID;
}
#endregion
#region Delete Trainng
public void Delete(int TrainingNeedAnalysisID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingDepartmentDA.DeletebyTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID);
TrainingNdAnalysisTimeSchDA.DeletebyTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID);
TrainingNeedAnalysisDA.Delete(tc, TrainingNeedAnalysisID);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new ServiceException(e.Message, e);
}
}
#endregion
#region Subordinate Implementation
public SubordinateTrainee SubordinateGet(int id)
{
SubordinateTrainee oSubordinateTrainee = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.SubordinateGet(tc, id));
if (oreader.Read())
{
oSubordinateTrainee = CreateObject<SubordinateTrainee>(oreader);
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oSubordinateTrainee;
}
public List<SubordinateTrainee> SubordinateGet()
{
List<SubordinateTrainee> oSubordinateTrainee = new List<SubordinateTrainee>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(TrainingNeedAnalysisDA.GetSubordinate(tc));
oSubordinateTrainee = this.CreateSubordinateTraineeObjects(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 oSubordinateTrainee;
}
public List<SubordinateTrainee> GetByTrainingNeedAnalysisID(int TrainingNeedAnalysisID)
{
List<SubordinateTrainee> SubordinateTrainees = new List<SubordinateTrainee>();
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingNeedAnalysisDA.GetByTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID));
SubordinateTrainees = CreateSubordinateTraineeObjects(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return SubordinateTrainees;
}
#endregion
#endregion
private void SaveSubordinate(TransactionContext tc, SubordinateTrainee oSubordinateTrainee)
{
try
{
try
{
#region Saving data
if (oSubordinateTrainee.IsNew)
{
int newID = tc.GenerateID("SubordinateTrainee", "SubordinateTraineeID");
base.SetObjectID(oSubordinateTrainee, newID);
TrainingNeedAnalysisDA.Insert(tc, oSubordinateTrainee);
}
else
TrainingNeedAnalysisDA.Update(tc, oSubordinateTrainee);
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
internal void SaveCollection(TransactionContext tc, List<TrainingNeedAnalysis> _trainingNeedAnalysises)
{
try
{
try
{
#region Saving data
foreach (var oTrainingNeedAnalysis in _trainingNeedAnalysises)
{
if (oTrainingNeedAnalysis.IsNew)
{
int newID = tc.GenerateID("TrainingNeedAnalysis", "TrainingNeedAnalysisID");
base.SetObjectID(oTrainingNeedAnalysis, newID);
TrainingNeedAnalysisDA.Insert(tc, oTrainingNeedAnalysis);
foreach (SubordinateTrainee item in oTrainingNeedAnalysis.TrainingEmployee)
{
item.TrainingNeedAnalysisID = newID;
(new TrainingNeedAnalysisService()).SaveSubordinate(tc, item);
}
foreach (TrainingNdAnalysisTimeSch item in oTrainingNeedAnalysis.TrainingNdAnalysisTimeSchs)
{
item.TrainingNeedAnalysisID = newID;
(new TrainingNdAnalysisTimeSchService()).Save(tc, item);
}
}
else
{
List<TrainingNdAnalysisTimeSch> oTempNdAnalysisTSchs =
oTrainingNeedAnalysis.TrainingNdAnalysisTimeSchs;
List<TrainingDepartment> oTempTrainingDepts = oTrainingNeedAnalysis.TrainingDepartments;
TrainingDepartmentDA.DeletebyTrainingNeedAnalysisID(tc, oTrainingNeedAnalysis.ID);
TrainingNdAnalysisTimeSchDA.DeletebyTrainingNeedAnalysisID(tc, oTrainingNeedAnalysis.ID);
TrainingNeedAnalysisDA.Update(tc, oTrainingNeedAnalysis);
foreach (TrainingDepartment item in oTempTrainingDepts)
{
item.TrainingNeedAnalysisID = oTrainingNeedAnalysis.ID;
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
base.SetObjectID(item, newID);
TrainingDepartmentDA.Insert(tc, item);
}
foreach (TrainingNdAnalysisTimeSch item in oTempNdAnalysisTSchs)
{
item.TrainingNeedAnalysisID = oTrainingNeedAnalysis.ID;
int newID = tc.GenerateID("TrainingNdAnalysisTimeSch", "TNATimeSchID");
base.SetObjectID(item, newID);
TrainingNdAnalysisTimeSchDA.Insert(tc, item);
}
}
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new Exception(e.Message, e);
}
}
}
#endregion
}