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

1096 lines
35 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 TrainingSchedule Service
public class TrainingScheduleService : ServiceTemplate,ITrainingScheduleService
{
#region Private functions and declaration
#region base Object Functions
private void MapObject(TrainingSchedule oTrainingSchedule, DataReader oReader)
{
base.SetObjectID(oTrainingSchedule, (oReader.GetInt32("TrainingScheduleID").Value));
oTrainingSchedule.TrainingID = oReader.GetInt32("TRAININGID", 0);
oTrainingSchedule.TrainingNatureID = oReader.GetInt32("TrainingNatureID", 0);
oTrainingSchedule.InstituteID = oReader.GetInt32("InstituteID", 0);
oTrainingSchedule.TrainerDescription = oReader.GetString("TrainerDescription");
oTrainingSchedule.EnrolledEndDate = oReader.GetDateTime("EnrolledEndDate");
oTrainingSchedule.EnrolledStartDate = oReader.GetDateTime("EnrolledStartDate");
oTrainingSchedule.IsShowInWeb = oReader.GetBoolean("IsShowInWeb").GetValueOrDefault();
oTrainingSchedule.TNAnalysisID = oReader.GetInt32("TNAnalysisID", 0);
oTrainingSchedule.StartDate = oReader.GetDateTime("StartDate").Value;
oTrainingSchedule.EndDate = oReader.GetDateTime("EndDate").Value;
oTrainingSchedule.Cost = oReader.GetDouble("Cost").GetValueOrDefault();
oTrainingSchedule.MaxParticipants = oReader.GetInt32("MaxParticipants").GetValueOrDefault();
oTrainingSchedule.EnrolledParticipants = oReader.GetInt32("EnrolledParticipants").GetValueOrDefault();
oTrainingSchedule.CourseOutline = oReader.GetString("CourseOutline");
oTrainingSchedule.ScheduleStatus = oReader.GetBoolean("ScheduleStatus").GetValueOrDefault();
oTrainingSchedule.VenueCost = oReader.GetDouble("VenueCost").GetValueOrDefault();
oTrainingSchedule.RefreshmentCost = oReader.GetDouble("RefreshmentCost").GetValueOrDefault();
oTrainingSchedule.TrainerFees = oReader.GetDouble("TrainerFees").GetValueOrDefault();
oTrainingSchedule.OthesCost = oReader.GetDouble("OthesCost").GetValueOrDefault();
oTrainingSchedule.Venue = oReader.GetString("Venue");
oTrainingSchedule.PayrollTypeID = oReader.GetInt32("PAYROLLTYPEID", 0);
oTrainingSchedule.ManDays = oReader.GetDouble("ManDays").GetValueOrDefault();
oTrainingSchedule.ManHour = oReader.GetDouble("ManHour").GetValueOrDefault();
oTrainingSchedule.TrainingName = oReader.GetString("TrainingName",true,null);
oTrainingSchedule.TrainingTypeName = oReader.GetString("TrainingTypeName",true, null);
this.SetObjectState(oTrainingSchedule, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
TrainingSchedule oTrainingSchedule = new TrainingSchedule();
MapObject(oTrainingSchedule, oReader);
return oTrainingSchedule as T;
}
#endregion
#region Child Object Functions
#region TrainingScheduleEmployee Functions
private void MapTrainingScheduleEmployeeObject(TrainingScheduleEmployee oTrainingScheduleEmployee,
DataReader oReader)
{
base.SetObjectID(oTrainingScheduleEmployee, (oReader.GetInt32("TrainingScheduleEmployeeID").Value));
oTrainingScheduleEmployee.TrainingScheduleID = oReader.GetInt32("TrainingScheduleID", 0);
oTrainingScheduleEmployee.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oTrainingScheduleEmployee.ProposedByID = oReader.GetInt32("ProposedByID", 0);
oTrainingScheduleEmployee.ProposedDate = oReader.GetDateTime("ProposedDate").GetValueOrDefault();
oTrainingScheduleEmployee.Remarks = oReader.GetString("Remarks");
oTrainingScheduleEmployee.ScheduleEmpStatus =
(EnumTSStatus)oReader.GetInt32("ScheduleEmpStatus").GetValueOrDefault();
this.SetObjectState(oTrainingScheduleEmployee, Ease.Core.ObjectState.Saved);
}
private TrainingScheduleEmployee CreateTrainingScheduleEmployeeObject(DataReader oReader)
{
TrainingScheduleEmployee oTrainingScheduleEmployee = new TrainingScheduleEmployee();
MapTrainingScheduleEmployeeObject(oTrainingScheduleEmployee, oReader);
return oTrainingScheduleEmployee;
}
private List<TrainingScheduleEmployee> CreateTrainingScheduleEmployeeObjects(DataReader oReader)
{
List<TrainingScheduleEmployee> trainingScheduleEmployees = new List<TrainingScheduleEmployee>();
while (oReader.Read())
{
TrainingScheduleEmployee oTrainingScheduleEmployee = new TrainingScheduleEmployee();
oTrainingScheduleEmployee = CreateTrainingScheduleEmployeeObject(oReader);
trainingScheduleEmployees.Add(oTrainingScheduleEmployee);
}
return trainingScheduleEmployees;
}
#endregion
#region TrainingScheduleDate Functions
private void MapTrainingScheduleDateObject(TrainingScheduleDate oTrainingScheduleDate, DataReader oReader)
{
base.SetObjectID(oTrainingScheduleDate, (oReader.GetInt32("TrainingScheduleDateID").Value));
oTrainingScheduleDate.TrainingScheduleID = oReader.GetInt32("TrainingScheduleID", 0);
oTrainingScheduleDate.ScheduleDate = oReader.GetDateTime("ScheduleDate").Value;
oTrainingScheduleDate.StartTime = oReader.GetDateTime("StartTime").Value;
oTrainingScheduleDate.EndTime = oReader.GetDateTime("EndTime").Value;
oTrainingScheduleDate.Remarks = oReader.GetString("Remarks");
this.SetObjectState(oTrainingScheduleDate, Ease.Core.ObjectState.Saved);
}
private TrainingScheduleDate CreateTrainingScheduleDateObject(DataReader oReader)
{
TrainingScheduleDate oTrainingScheduleDate = new TrainingScheduleDate();
MapTrainingScheduleDateObject(oTrainingScheduleDate, oReader);
return oTrainingScheduleDate;
}
private List<TrainingScheduleDate> CreateTrainingScheduleDateObjects(DataReader oReader)
{
List<TrainingScheduleDate> trainingScheduleDates = new List<TrainingScheduleDate>();
while (oReader.Read())
{
TrainingScheduleDate oTrainingScheduleDate = new TrainingScheduleDate();
oTrainingScheduleDate = CreateTrainingScheduleDateObject(oReader);
trainingScheduleDates.Add(oTrainingScheduleDate);
}
return trainingScheduleDates;
}
#endregion
#endregion
#endregion
#region Implementation of ITrainingScheduleService
#region Get TrainingSchedule
public TrainingSchedule Get(int trainigScheduleID)
{
TrainingSchedule oTrainingSchedule = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.GetTS(tc, trainigScheduleID));
if (oreader.Read())
{
oTrainingSchedule = CreateObject<TrainingSchedule>(oreader);
}
oreader.Close();
if (oTrainingSchedule != null)
{
oreader = new DataReader(TrainingScheduleDA.GetTrainingScheduleEmployees(tc, trainigScheduleID));
oTrainingSchedule.EnrolledTrainingEmployees = CreateTrainingScheduleEmployeeObjects(oreader);
oreader.Close();
if (oTrainingSchedule.EnrolledTrainingEmployees != null)
{
foreach (TrainingScheduleEmployee temp in oTrainingSchedule.EnrolledTrainingEmployees)
{
TrainingSchEmpCostService osvr = new TrainingSchEmpCostService();
temp.TrainingSchEmpCosts = osvr.GetByTrainingScheduleEmpID(tc, temp.EmployeeID, temp.ID);
}
}
oreader = new DataReader(TrainingScheduleDA.GetTrainingScheduleDates(tc, trainigScheduleID));
oTrainingSchedule.TrainingScheduleDates = CreateTrainingScheduleDateObjects(oreader);
oreader.Close();
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedule;
}
#endregion
#region Get TrainingSchedules
public List<TrainingSchedule> GetWithPayrollType(int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(bool active, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, active, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(DateTime today, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, today, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(DateTime fromDate, DateTime toDate, int training, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingScheduleDA.Get(tc, fromDate, toDate, training, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(DateTime fromDate, DateTime toDate, int training, bool active,
int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingScheduleDA.Get(tc, fromDate, toDate, training, active, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> GetTrainingSchedule(int trainingId, int trainingTypeId, DateTime? fromDate, DateTime? toDate)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingScheduleDA.GetTrainingSchedule(tc, trainingId, trainingTypeId, fromDate, toDate));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(int training, int TNAID, bool active, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, training, TNAID, active, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(int training, int TNAID, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, training, TNAID, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(DateTime fromDate, DateTime toDate, bool active, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingScheduleDA.Get(tc, fromDate, toDate, active, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> GetbyStatus(int status, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.GetbyStatus(tc, status, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(DateTime today, int EmpID, int status, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, today, EmpID, status, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public List<TrainingSchedule> Get(DateTime fromDate, DateTime toDate, int payrollTypeID)
{
List<TrainingSchedule> oTrainingSchedules = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(TrainingScheduleDA.Get(tc, fromDate, toDate, payrollTypeID));
oTrainingSchedules = CreateObjects<TrainingSchedule>(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingSchedules;
}
public TrainingScheduleEmployee getScheduleEmp(int SEmpID)
{
TrainingScheduleEmployee oTrainingScheduleEmp = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader dtReader = new DataReader(TrainingScheduleDA.getScheduleEmp(tc, SEmpID));
if (dtReader.Read())
oTrainingScheduleEmp = CreateTrainingScheduleEmployeeObject(dtReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingScheduleEmp;
}
public DataSet Get(string query)
{
TransactionContext tc = null;
DataSet ds = new DataSet();
try
{
tc = TransactionContext.Begin();
ds = TrainingScheduleDA.Get(tc, query);
tc.End();
return ds;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
#region Insert TrainingSchedule
public int Save(TrainingSchedule oTrainingSchedule)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (oTrainingSchedule.IsNew)
{
#region New Schedule Insert
int newID = tc.GenerateID("TrainingSchedule", "TrainingScheduleID");
base.SetObjectID(oTrainingSchedule, (newID));
TrainingScheduleDA.Insert(tc, oTrainingSchedule);
#endregion
}
else
{
#region Old Schedule Update
TrainingScheduleDA.Update(tc, oTrainingSchedule);
//List<TrainingScheduleAttn> tempatt= oTrainingSchedule.TrainingScheduleAttns;
TrainingScheduleDA.DeleteScheduleDetail(tc, oTrainingSchedule.ID);
#region Old Code
//foreach (TrainingScheduleEmployee enrolledTrainingEmployee in oTrainingSchedule.EnrolledTrainingEmployees)
//{
// enrolledTrainingEmployee.TrainingScheduleID = oTrainingSchedule.ID;
// base.SetObjectID(enrolledTrainingEmployee, (tc.GenerateID("TrainingScheduleEmployee", "TrainingScheduleEmployeeID")));
// TrainingScheduleDA.InsertTrainingEmployee(tc, enrolledTrainingEmployee);
//}
//DataReader oreader = new DataReader(TrainingScheduleDA.GetTrainingScheduleDates(tc, oTrainingSchedule.ID));
//List<TrainingScheduleDate> oTempTrainingScheduleDates = CreateTrainingScheduleDateObjects(oreader);
//oreader.Close();
//foreach (TrainingScheduleDate tempTrainingScheduleDate in oTempTrainingScheduleDates)
//{
// bool isExist = false;
// foreach (TrainingScheduleDate trainingSchDate in oTrainingSchedule.TrainingScheduleDates)
// {
// if(tempTrainingScheduleDate.ScheduleDate==trainingSchDate.ScheduleDate)
// {
// isExist = true;
// break;
// }
// }
// if (!isExist)
// TrainingScheduleDA.DeleteTrainingScheduleDate(tc, tempTrainingScheduleDate.ID);
//}
//foreach (TrainingScheduleDate trainingSchDate in oTrainingSchedule.TrainingScheduleDates)
//{
// if(trainingSchDate.IsNew)
// {
// trainingSchDate.TrainingScheduleID = oTrainingSchedule.ID;
// base.SetObjectID(trainingSchDate, (tc.GenerateID("TrainingScheduleDate", "TrainingScheduleDateID")));
// TrainingScheduleDA.InsertTrainingScheduleDate(tc,trainingSchDate);
// }
//}
#endregion Old Code
#endregion
}
foreach (TrainingScheduleEmployee enrolledTrainingEmployee in oTrainingSchedule
.EnrolledTrainingEmployees)
{
enrolledTrainingEmployee.TrainingScheduleID = oTrainingSchedule.ID;
if (enrolledTrainingEmployee.ProposedDate == DateTime.MinValue)
{
enrolledTrainingEmployee.ProposedDate = DateTime.Now;
}
base.SetObjectID(enrolledTrainingEmployee,
(tc.GenerateID("TrainingScheduleEmployee", "TrainingScheduleEmployeeID")));
TrainingScheduleDA.InsertTrainingEmployee(tc, enrolledTrainingEmployee);
if (enrolledTrainingEmployee.TrainingSchEmpCosts != null && enrolledTrainingEmployee.TrainingSchEmpCosts.Count > 0)
{
foreach (TrainingSchEmpCost hcost in enrolledTrainingEmployee.TrainingSchEmpCosts)
{
hcost.TrainSchEmpID = enrolledTrainingEmployee.ID;
base.SetObjectID(hcost, (tc.GenerateID("TrainingSchEmpCost", "TrainingSchEmpCostID")));
hcost.CreatedBy = enrolledTrainingEmployee.CreatedBy;
hcost.CreatedDate = DateTime.Today;
TrainingSchEmpCostDA.Insert(tc, hcost);
}
}
}
foreach (TrainingScheduleDate scheduleDate in oTrainingSchedule.TrainingScheduleDates)
{
scheduleDate.TrainingScheduleID = oTrainingSchedule.ID;
base.SetObjectID(scheduleDate,
(tc.GenerateID("TrainingScheduleDate", "TrainingScheduleDateID")));
TrainingScheduleDA.InsertTrainingScheduleDate(tc, scheduleDate);
}
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 oTrainingSchedule.ID;
}
public int SaveAttnStatus(TrainingSchedule oTrainingSchedule)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
//TrainingScheduleDA.DeleteTrainingEmployees(tc, oTrainingSchedule.ID);
foreach (TrainingScheduleEmployee enrolledTrainingEmployee in oTrainingSchedule
.EnrolledTrainingEmployees)
{
//enrolledTrainingEmployee.TrainingScheduleID = oTrainingSchedule.ID;
//base.SetObjectID(enrolledTrainingEmployee, (tc.GenerateID("TrainingScheduleEmployee", "TrainingScheduleEmployeeID")));
//TrainingScheduleDA.InsertTrainingEmployee(tc, enrolledTrainingEmployee);
TrainingScheduleDA.updateScheduleEmp(tc, enrolledTrainingEmployee.ID,
(int)enrolledTrainingEmployee.ScheduleEmpStatus);
}
TrainingScheduleDA.DeleteTrainingScheduleAttn(tc, oTrainingSchedule.ID);
foreach (TrainingScheduleDate scheduleDate in oTrainingSchedule.TrainingScheduleDates)
{
foreach (TrainingScheduleAttn attn in scheduleDate.TrainingScheduleAttns)
{
base.SetObjectID(attn, (tc.GenerateID("TrainingScheduleAttn", "TSAttnID")));
TrainingScheduleDA.InsertTrainingScheduleAttn(tc, attn);
}
}
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 oTrainingSchedule.ID;
}
public int SaveTrainingEmp(TrainingScheduleEmployee tEmp)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (tEmp.IsNew)
{
base.SetObjectID(tEmp, (tc.GenerateID("TrainingScheduleEmployee", "TrainingScheduleEmployeeID")));
TrainingScheduleDA.InsertTrainingEmployee(tc, tEmp);
}
else
{
TrainingScheduleDA.updateScheduleEmp(tc, tEmp);
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return tEmp.ID;
}
#endregion
#region Delete Training Schedule
public void Delete(int trainingScheduleID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingScheduleAttnDA.DeletebyTrainingScheduleID(tc, trainingScheduleID);
TrainingScheduleDA.DeleteTrainingScheduleDates(tc, trainingScheduleID);
TrainingScheduleDA.DeleteTrainingEmployees(tc, trainingScheduleID);
TrainingScheduleDA.Delete(tc, trainingScheduleID);
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 Child Delete Function
public void DeleteNominatedEmp(int SEmpID)
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
TrainingScheduleDA.DeleteNominatedEmp(tc, SEmpID);
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);
}
}
public void updateScheduleEmp(int SEmpID, int status)
{
try
{
TransactionContext tc = null;
try
{
#region Update data
tc = TransactionContext.Begin(true);
TrainingScheduleDA.updateScheduleEmp(tc, SEmpID, status);
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 Childs Get Functions
public List<TrainingScheduleDate> GetTrainingScheduleDates(int trainingScheduleID)
{
List<TrainingScheduleDate> oTrainingScheduleDates = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingScheduleDA.GetTrainingScheduleDates(tc, trainingScheduleID));
oTrainingScheduleDates = CreateTrainingScheduleDateObjects(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingScheduleDates;
}
public List<TrainingScheduleEmployee> GetTrainingScheduleEmployees(int trainingScheduleID)
{
List<TrainingScheduleEmployee> oTrainingScheduleEmployees = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader oreader =
new DataReader(TrainingScheduleDA.GetTrainingScheduleEmployees(tc, trainingScheduleID));
oTrainingScheduleEmployees = CreateTrainingScheduleEmployeeObjects(oreader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return oTrainingScheduleEmployees;
}
#endregion
#endregion
}
#endregion
}