CEL_Payroll/Payroll.Service/TrainingS/Service/TrainingNeedAnalysisService.cs

442 lines
15 KiB
C#
Raw Permalink Normal View History

2024-09-17 14:30:13 +06:00
using System;
using Ease.CoreV35.Caching;
using Ease.CoreV35.DataAccess;
using Ease.CoreV35.Model;
using Payroll.BO;
namespace Payroll.Service
{
#region TrainingNeedAnalysis Service
[Serializable]
class TrainingNeedAnalysisService : ServiceTemplate, ITrainingNeedAnalysisService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TrainingNeedAnalysis));
private void MapObject(TrainingNeedAnalysis oTrainingNeedAnalysis, DataReader oReader)
{
base.SetObjectID(oTrainingNeedAnalysis, oReader.GetID("TrainingNeedAnalysisID"));
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.GetID("CreatedBy");
oTrainingNeedAnalysis.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Today;
oTrainingNeedAnalysis.ModifiedBy = oReader.GetID("ModifiedBy");
oTrainingNeedAnalysis.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oTrainingNeedAnalysis, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingNeedAnalysis oTrainingNeedAnalysis = new TrainingNeedAnalysis();
MapObject(oTrainingNeedAnalysis, oReader);
return oTrainingNeedAnalysis as T;
}
#endregion
#region Implementation of ITrainingNeedAnalysisService
#region Get TrainingNeedAnalysis
public TrainingNeedAnalysis Get(ID TrainingNeedAnalysisID)
{
TrainingNeedAnalysis oTrainingNeedAnalysis = null;
#region CacheHeader
oTrainingNeedAnalysis = (TrainingNeedAnalysis)_cache["Get", TrainingNeedAnalysisID];
if (oTrainingNeedAnalysis != null)
return oTrainingNeedAnalysis;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingNeedAnalysisDA.Get(tc, TrainingNeedAnalysisID.Integer));
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
}
#region CacheFooter
_cache.Add(oTrainingNeedAnalysis, "Get", TrainingNeedAnalysisID);
#endregion
return oTrainingNeedAnalysis;
}
#endregion
#region Get TrainingNeedAnalysiss
public ObjectsTemplate<TrainingNeedAnalysis> Get()
{
ObjectsTemplate<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
#region CacheHeader
oTrainingNeedAnalysiss = (ObjectsTemplate<TrainingNeedAnalysis>)_cache["Get"];
if (oTrainingNeedAnalysiss != null)
return oTrainingNeedAnalysiss;
#endregion
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
}
#region CacheFooter
_cache.Add(oTrainingNeedAnalysiss, "Get");
#endregion
return oTrainingNeedAnalysiss;
}
public ObjectsTemplate<TrainingNeedAnalysis> GetByYear(int year)
{
ObjectsTemplate<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
#region CacheHeader
oTrainingNeedAnalysiss = (ObjectsTemplate<TrainingNeedAnalysis>)_cache["Get"];
if (oTrainingNeedAnalysiss != null)
return oTrainingNeedAnalysiss;
#endregion
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
}
#region CacheFooter
_cache.Add(oTrainingNeedAnalysiss, "Get");
#endregion
return oTrainingNeedAnalysiss;
}
public ObjectsTemplate<TrainingNeedAnalysis> GetByParam(int year, string sDeptIDs, string sDeptForIDs)
{
ObjectsTemplate<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
#region CacheHeader
oTrainingNeedAnalysiss = (ObjectsTemplate<TrainingNeedAnalysis>)_cache["Get"];
if (oTrainingNeedAnalysiss != null)
return oTrainingNeedAnalysiss;
#endregion
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
}
#region CacheFooter
_cache.Add(oTrainingNeedAnalysiss, "Get");
#endregion
return oTrainingNeedAnalysiss;
}
public ObjectsTemplate<TrainingNeedAnalysis> Get(int trainingID, int departmentID, int departmentForID, int trainingType)
{
ObjectsTemplate<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
#region CacheHeader
oTrainingNeedAnalysiss = (ObjectsTemplate<TrainingNeedAnalysis>)_cache["Get"];
if (oTrainingNeedAnalysiss != null)
return oTrainingNeedAnalysiss;
#endregion
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
}
#region CacheFooter
_cache.Add(oTrainingNeedAnalysiss, "Get");
#endregion
return oTrainingNeedAnalysiss;
}
public ObjectsTemplate<TrainingNeedAnalysis> Get(string query)
{
ObjectsTemplate<TrainingNeedAnalysis> oTrainingNeedAnalysiss;
#region CacheHeader
oTrainingNeedAnalysiss = (ObjectsTemplate<TrainingNeedAnalysis>)_cache["Get"];
if (oTrainingNeedAnalysiss != null)
return oTrainingNeedAnalysiss;
#endregion
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
}
#region CacheFooter
_cache.Add(oTrainingNeedAnalysiss, "Get");
#endregion
return oTrainingNeedAnalysiss;
}
#endregion
#region Save TrainingNeedAnalysis
public ID Save(TrainingNeedAnalysis oTrainingNeedAnalysis)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (oTrainingNeedAnalysis.IsNew)
{
ID newID = ID.FromInteger(tc.GenerateID("TrainingNeedAnalysis", "TrainingNeedAnalysisID"));
base.SetObjectID(oTrainingNeedAnalysis, newID);
TrainingNeedAnalysisDA.Insert(tc, oTrainingNeedAnalysis);
foreach (TrainingDepartment item in oTrainingNeedAnalysis.TrainingDepartments)
{
item.TrainingNeedAnalysisID = newID;
(new TrainingDepartmentService()).Save(tc, item);
}
foreach (TrainingNdAnalysisTimeSch item in oTrainingNeedAnalysis.TrainingNdAnalysisTimeSchs)
{
item.TrainingNeedAnalysisID = newID;
(new TrainingNdAnalysisTimeSchService()).Save(tc, item);
}
}
else
{
ObjectsTemplate<TrainingNdAnalysisTimeSch> oTempNdAnalysisTSchs = oTrainingNeedAnalysis.TrainingNdAnalysisTimeSchs;
ObjectsTemplate<TrainingDepartment> oTempTrainingDepts = oTrainingNeedAnalysis.TrainingDepartments;
TrainingDepartmentDA.DeletebyTrainingNeedAnalysisID(tc,oTrainingNeedAnalysis.ID.Integer);
TrainingNdAnalysisTimeSchDA.DeletebyTrainingNeedAnalysisID(tc, oTrainingNeedAnalysis.ID.Integer);
TrainingNeedAnalysisDA.Update(tc, oTrainingNeedAnalysis);
foreach (TrainingDepartment item in oTempTrainingDepts)
{
item.TrainingNeedAnalysisID = oTrainingNeedAnalysis.ID;
int newID = tc.GenerateID("TrainingDepartment", "TrainDepartmentID");
base.SetObjectID(item, ID.FromInteger(newID));
TrainingDepartmentDA.Insert(tc, item);
//TrainingDepartmentDA.Insert(tc, item);
}
foreach (TrainingNdAnalysisTimeSch item in oTempNdAnalysisTSchs)
{
item.TrainingNeedAnalysisID = oTrainingNeedAnalysis.ID;
int newID = tc.GenerateID("TrainingNdAnalysisTimeSch", "TNATimeSchID");
base.SetObjectID(item, ID.FromInteger(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 ServiceException(e.Message, e);
throw new Exception(e.Message, e);
}
return oTrainingNeedAnalysis.ID;
}
#endregion
#region Delete Trainng
public void Delete(ID TrainingNeedAnalysisID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingDepartmentDA.DeletebyTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID.Integer);
TrainingNdAnalysisTimeSchDA.DeletebyTrainingNeedAnalysisID(tc, TrainingNeedAnalysisID.Integer);
TrainingNeedAnalysisDA.Delete(tc, TrainingNeedAnalysisID.Integer);
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
#endregion
}
#endregion
}