CEL_Payroll/Payroll.Service/TrainingS/Service/TrainingSchEmpCostService.cs

420 lines
13 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 TrainingSchEmpCost Service
[Serializable]
class TrainingSchEmpCostService : ServiceTemplate, ITrainingSchEmpCostService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(TrainingSchEmpCost));
private void MapObject(TrainingSchEmpCost oTrainingSchEmpCost, DataReader oReader)
{
base.SetObjectID(oTrainingSchEmpCost, oReader.GetID("TrainingSchEmpCostID"));
oTrainingSchEmpCost.CostHdID = oReader.GetInt32("CostHdID").Value;
oTrainingSchEmpCost.Amount = oReader.GetDouble("Amount").Value;
oTrainingSchEmpCost.TrunDate = oReader.GetDateTime("TrunDate").Value;
oTrainingSchEmpCost.Remarks = oReader.GetString("Remarks");
oTrainingSchEmpCost.EmployeeID = oReader.GetInt32("EmployeeID").Value;
oTrainingSchEmpCost.TrainSchEmpID = oReader.GetInt32("TrainSchEmpID").Value;
oTrainingSchEmpCost.CreatedBy = oReader.GetID("CreatedBy");
oTrainingSchEmpCost.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Today;
oTrainingSchEmpCost.ModifiedBy = oReader.GetID("ModifiedBy");
oTrainingSchEmpCost.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oTrainingSchEmpCost, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingSchEmpCost oTrainingSchEmpCost = new TrainingSchEmpCost();
MapObject(oTrainingSchEmpCost, oReader);
return oTrainingSchEmpCost as T;
}
#endregion
#region Implementation of ITrainingSchEmpCostService
#region Get TrainingSchEmpCost
public TrainingSchEmpCost Get(ID TrainingSchEmpCostID)
{
TrainingSchEmpCost oTrainingSchEmpCost = null;
#region CacheHeader
oTrainingSchEmpCost = (TrainingSchEmpCost)_cache["Get", TrainingSchEmpCostID];
if (oTrainingSchEmpCost != null)
return oTrainingSchEmpCost;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingSchEmpCostDA.Get(tc, TrainingSchEmpCostID.Integer));
oreader.Read();
oTrainingSchEmpCost = CreateObject<TrainingSchEmpCost>(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(oTrainingSchEmpCost, "Get", TrainingSchEmpCostID);
#endregion
return oTrainingSchEmpCost;
}
#endregion
#region Get TrainingSchEmpCosts
public ObjectsTemplate<TrainingSchEmpCost> Get()
{
ObjectsTemplate<TrainingSchEmpCost> oTrainingSchEmpCosts;
#region CacheHeader
oTrainingSchEmpCosts = (ObjectsTemplate<TrainingSchEmpCost>)_cache["Get"];
if (oTrainingSchEmpCosts != null)
return oTrainingSchEmpCosts;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingSchEmpCostDA.Get(tc));
oTrainingSchEmpCosts = CreateObjects<TrainingSchEmpCost>(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(oTrainingSchEmpCosts, "Get");
#endregion
return oTrainingSchEmpCosts;
}
public ObjectsTemplate<TrainingSchEmpCost> GetByTrainingScheduleEmpID(TransactionContext tc, ID empID, ID trainSchEmpID)
{
ObjectsTemplate<TrainingSchEmpCost> trainingSchEmpCosts;
#region CacheHeader
trainingSchEmpCosts = (ObjectsTemplate<TrainingSchEmpCost>)_cache["Get"];
if (trainingSchEmpCosts != null)
return trainingSchEmpCosts;
#endregion
try
{
#region Retrieving data
DataReader oreader = new DataReader(TrainingSchEmpCostDA.GetByTrainingScheduleEmpID(tc, empID, trainSchEmpID));
trainingSchEmpCosts = CreateObjects<TrainingSchEmpCost>(oreader);
oreader.Close();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
#region CacheFooter
_cache.Add(trainingSchEmpCosts, "Get");
#endregion
return trainingSchEmpCosts;
}
public ObjectsTemplate<TrainingSchEmpCost> GetByTrainingScheduleEmpID(ID empID, ID trainSchEmpID)
{
ObjectsTemplate<TrainingSchEmpCost> trainingSchEmpCosts;
#region CacheHeader
trainingSchEmpCosts = (ObjectsTemplate<TrainingSchEmpCost>)_cache["Get"];
if (trainingSchEmpCosts != null)
return trainingSchEmpCosts;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingSchEmpCostDA.GetByTrainingScheduleEmpID(tc, empID, trainSchEmpID));
trainingSchEmpCosts = CreateObjects<TrainingSchEmpCost>(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(trainingSchEmpCosts, "Get");
#endregion
return trainingSchEmpCosts;
}
public ObjectsTemplate<TrainingSchEmpCost> GetCostWithoutParent()
{
ObjectsTemplate<TrainingSchEmpCost> trainingSchEmpCosts;
#region CacheHeader
trainingSchEmpCosts = (ObjectsTemplate<TrainingSchEmpCost>)_cache["Get"];
if (trainingSchEmpCosts != null)
return trainingSchEmpCosts;
#endregion
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingSchEmpCostDA.GetCostWithoutParent(tc));
trainingSchEmpCosts = CreateObjects<TrainingSchEmpCost>(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(trainingSchEmpCosts, "Get");
#endregion
return trainingSchEmpCosts;
}
#endregion
#region Save TrainingSchEmpCost
public ID Save(TrainingSchEmpCost oTrainingSchEmpCost)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
#region Checking Duplicate TrainingSchEmpCost Code
//bool result = false;
//result = TrainingSchEmpCostDA.IsExists("TrainingSchEmpCost", "Code", oTrainingSchEmpCost.Code, tc);
//if ( oTrainingSchEmpCost.IsNew)
//{
// throw new ServiceException("Duplicate code is not allowed.");
//}
#endregion
if (oTrainingSchEmpCost.IsNew)
{
int newID = tc.GenerateID("TrainingSchEmpCost", "TrainingSchEmpCostID");
base.SetObjectID(oTrainingSchEmpCost, ID.FromInteger(newID));
TrainingSchEmpCostDA.Insert(tc, oTrainingSchEmpCost);
}
else
TrainingSchEmpCostDA.Update(tc, oTrainingSchEmpCost);
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 oTrainingSchEmpCost.ID;
}
public void SaveTrainingSheduleCost(ObjectsTemplate<TrainingSchEmpCost> tsec)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
//TrainingScheduleDA.DeleteTrainingEmployees(tc, oTrainingSchedule.ID.Integer);
foreach (TrainingSchEmpCost item in tsec)
{
//enrolledTrainingEmployee.TrainingScheduleID = oTrainingSchedule.ID;
//base.SetObjectID(enrolledTrainingEmployee, ID.FromInteger(tc.GenerateID("TrainingScheduleEmployee", "TrainingScheduleEmployeeID")));
//TrainingScheduleDA.InsertTrainingEmployee(tc, enrolledTrainingEmployee);
int newID = tc.GenerateID("TrainingSchEmpCost", "TrainingSchEmpCostID");
base.SetObjectID(item, ID.FromInteger(newID));
item.CreatedBy = User.CurrentUser.ID;
item.CreatedDate = DateTime.Today;
TrainingSchEmpCostDA.Insert(tc, item);
}
TrainingSchEmpCostDA.DeleteCommonUpdateUncommon(tc);
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
#region Delete Trainng
public void Delete(ID TrainingSchEmpCostID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingSchEmpCostDA.Delete(tc, TrainingSchEmpCostID.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
}