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; using System.Text; namespace HRM.DA { #region Training Service public class TrainingService : ServiceTemplate, ITrainingService { #region Private functions and declaration private void MapObject(Training oTraining, DataReader oReader) { base.SetObjectID(oTraining, (oReader.GetInt32("TrainingID").Value)); oTraining.Code = oReader.GetString("Code"); oTraining.Name = oReader.GetString("Name"); oTraining.TrainingTypeID = oReader.GetInt32("TrainingTypeID", 0); oTraining.TrainingDuration = oReader.GetDouble("STANDARDDURATION").GetValueOrDefault(); oTraining.StandardCost = oReader.GetDouble("StandardCost").GetValueOrDefault(); oTraining.LearningObjective = oReader.GetString("LearningObjective"); oTraining.CreatedBy = oReader.GetInt32("CreatedBy", 0); oTraining.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue ? oReader.GetDateTime("CreatedDate").Value : DateTime.Today; oTraining.ModifiedBy = oReader.GetInt32("ModifiedBy", 0); oTraining.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTraining, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Training oTraining = new Training(); MapObject(oTraining, oReader); return oTraining as T; } #endregion #region Implementation of ITrainingService #region Get Training public Training Get(int trainingID) { Training oTraining = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingDA.Get(tc, trainingID)); if (oreader.Read()) { oTraining = CreateObject(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 oTraining; } #endregion #region Get Trainings public List Get(EnumStatus status) { List oTrainings = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingDA.Get(tc)); oTrainings = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainings; } public List Get() { List oTrainings = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingDA.Get(tc)); oTrainings = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainings; } public List Get(string query) { List oTrainings = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingDA.Get(tc, query)); oTrainings = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainings; } public List GetbyTypeID(int typeid) { List oTrainings = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingDA.GetbyTypeID(tc, typeid)); oTrainings = CreateObjects(oreader); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oTrainings; } public DataSet GetEmployeeWiseTrainingSummary(string sEmpIDs, DateTime fromDate, DateTime toDate, int tNature, int tTrainingType, int trainingID, int deptID, int instituteID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetEmployeeWiseTrainingSummary(tc, sEmpIDs, fromDate, toDate, tNature, tTrainingType, trainingID, deptID, instituteID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetTrainingWiseReport(string sEmpIDs, int trainingID, DateTime fromDate, DateTime toDate, int nTypeID, int nNatureID, int ndeptID, int instituteID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetTrainingWiseReport(tc, sEmpIDs, trainingID, fromDate, toDate, nTypeID, nNatureID, ndeptID, instituteID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetEmployeeWiseTrainingReport(string sEmpIDs, int nNatureID, int tTrainingTypeID, int ndeptID, int instituteID, int year, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetEmployeeWiseTrainingReport(tc, sEmpIDs, nNatureID, tTrainingTypeID, ndeptID, instituteID, year, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetTrainingAttendenceReport(string sEmpIDs, int trainingID, DateTime dStartDate, DateTime dEndDate, int tTrainingTypeID, int nNatureID, int instituteID, int nScheduleID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetTrainingAttendenceReport(tc, sEmpIDs, trainingID, dStartDate, dEndDate, tTrainingTypeID, nNatureID, instituteID, nScheduleID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetDeptWiseTrainingReport(int dptID, DateTime fromDate, DateTime toDate, int tNatureID, int tTrainingTypeID, int instituteID, int trainingID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetDeptWiseTrainingReport(tc, dptID, fromDate, toDate, tNatureID, tTrainingTypeID, instituteID, trainingID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetEmployeeWiseTrainingDetails(string sEmpIDs, DateTime dStartDate, DateTime dEndDate, int nTypeID, int nNatureID, int instituteID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetEmployeeWiseTrainingDetails(tc, sEmpIDs, dStartDate, dEndDate, nTypeID, nNatureID, instituteID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetTrainingNameWiseDetails(string sEmpIDs, DateTime dStartDate, DateTime dEndDate, int nTyprID, int nNatureID, int instituteID, int trainingID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetTrainingNameWiseDetails(tc, sEmpIDs, dStartDate, dEndDate, nTyprID, nNatureID, instituteID, trainingID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetDepartmentWiseTrainingExpense(string sEmpIDs, int nNatureID, int nTrainingTypeID, int instituteID, int year, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetDepartmentWiseTrainingExpense(tc, sEmpIDs, nNatureID, nTrainingTypeID, instituteID, year, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetTrainingConductedByDeptReport(int dptID, DateTime fromDate, DateTime toDate, int tNature, int tTrainingType, int nTrainingID, int instituteID, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetTrainingConductedByDepartment(tc, dptID, fromDate, toDate, tNature, tTrainingType, nTrainingID, instituteID, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetEntityWiseTrainingSummery(string sEmpIDs, DateTime fromDate, DateTime toDate, int tNature, int tTrainingType, int instituteID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetEntityWiseTrainingSummery(tc, sEmpIDs, fromDate, toDate, tNature, tTrainingType, instituteID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetTrainingCostDetailsReport(string sEmpIDs) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetTrainingCostDetailsReport(tc, sEmpIDs); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } public DataSet GetTrainingCostingInfoReport(string Employees, DateTime dFromDate, DateTime dToDate, int tNature, int instituteID, int tTrainingType, int payrollTypeID) { DataSet oDataSet = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); oDataSet = TrainingDA.GetTrainingCostingInfoReport(tc, Employees, dFromDate, dToDate, tNature, instituteID, tTrainingType, payrollTypeID); tc.End(); #endregion } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); throw new ServiceException(e.Message, e); #endregion } return oDataSet; } #endregion #region Insert Training public string GetNextCode() { TransactionContext tc = null; string _code = ""; try { tc = TransactionContext.Begin(); _code = GlobalFunctionService.GetMaxCode(tc, "Training", "Code"); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return _code; } public int Save(Training oTraining) { try { TransactionContext tc = null; try { #region Saving data tc = TransactionContext.Begin(true); //#region Checking Duplicate Training Code //bool result = false; //result = TrainingDA.IsExists("Training", "Code", oTraining.Code, tc); //if (result & oTraining.IsNew) //{ // throw new ServiceException("Duplicate code is not allowed."); //} //#endregion if (oTraining.IsNew) { int newID = tc.GenerateID("Training", "TrainingID"); oTraining.Code = GlobalFunctionService.GetMaxCode(tc, "Training", "Code"); base.SetObjectID(oTraining, (newID)); TrainingDA.Insert(tc, oTraining); } else TrainingDA.Update(tc, oTraining); 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 oTraining.ID; } #endregion #region Delete Trainng public void Delete(int trainingID) { try { TransactionContext tc = null; try { #region Deleting data tc = TransactionContext.Begin(true); TrainingDA.Delete(tc, trainingID); 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 //#region ITrainingService Members //public DataSet ShowSoftPlanReport(string tYear) //{ // throw new NotImplementedException(); //} //public DataSet GetEmployeeWiseTrainingReport(string sEmpIDs) //{ // throw new NotImplementedException(); //} //public static DataSet GetTrainingAttendenceReport(List Employees, int trainingID, DateTime dStartDate, DateTime dEndDate, int tTrainingTypeID, int nNatureID, int instituteID, int nScheduleID) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetTrainingAttendenceReport(sEmpIDs, trainingID, dStartDate, dEndDate, tTrainingTypeID, nNatureID, instituteID, nScheduleID, SystemInformation.CurrentSysInfo.PayrollTypeID); // return oDataSet; //} //public static DataSet GetEmployeeWiseTrainingDetails(List Employees, DateTime dStartDate, DateTime dEndDate, int nTypeID, int nNatureID, int instituteID) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetEmployeeWiseTrainingDetails(sEmpIDs, dStartDate, dEndDate, nTypeID, nNatureID, instituteID, SystemInformation.CurrentSysInfo.PayrollTypeID); // return oDataSet; //} //public static DataSet GetTrainingNameWiseDetails(List Employees, DateTime dStartDate, DateTime dEndDate, int nTyprID, int nNatureID, int instituteID, int trainingID) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetTrainingNameWiseDetails(sEmpIDs, dStartDate, dEndDate, nTyprID, nNatureID, instituteID, trainingID, SystemInformation.CurrentSysInfo.PayrollTypeID); // return oDataSet; //} //public static DataSet GetDepartmentWiseTrainingExpense(List Employees, int nNatureID, int nTrainingTypeID, int instituteID, int year) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetDepartmentWiseTrainingExpense(sEmpIDs, nNatureID, nTrainingTypeID, instituteID, year, SystemInformation.CurrentSysInfo.PayrollTypeID); // return oDataSet; //} //public static DataSet GetTrainingConductedByDeptReport(int dptID, DateTime fromDate, DateTime toDate, int tNature, int tTrainingType, int nTrainingID, int instituteID) //{ // DataSet oDataSet = new DataSet(); // oDataSet = GetTrainingConductedByDeptReport(dptID, fromDate, toDate, tNature, tTrainingType, nTrainingID, instituteID, SystemInformation.CurrentSysInfo.PayrollTypeID); // return oDataSet; //} //public static DataSet GetEntityWiseTrainingSummery(List Employees, DateTime fromDate, DateTime toDate, int tNature, int tTrainingType, int instituteID) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetEntityWiseTrainingSummery(sEmpIDs, fromDate, toDate, tNature, tTrainingType, instituteID); // return oDataSet; //} //public static DataSet GetTrainingCostDetailsReport(List Employees) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetTrainingCostDetailsReport(sEmpIDs); // return oDataSet; //} //public static DataSet GetTrainingCostingInfoReport(List Employees, DateTime dFromDate, DateTime dToDate, int tNature, int instituteID, int tTrainingType) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetTrainingCostingInfoReport(sEmpIDs, dFromDate, dToDate, tNature, instituteID, tTrainingType, SystemInformation.CurrentSysInfo.PayrollTypeID); // return oDataSet; //} //public static DataSet ShowSoftPlanReport(string year) //{ // string tYear = year.ToString(); // DataSet oDataSet = new DataSet(); // oDataSet = ShowSoftPlanReport(tYear); // return oDataSet; //} //public static DataSet GetEmployeeWiseTrainingSummary(List Employees, DateTime fromDate, DateTime toDate, int tNature, int tTrainingType, int trainingID, List deptIDs, int instituteID) //{ // string sEmpIDs = string.Empty; // if (Employees != null) // { // sEmpIDs = Employees.Aggregate(new StringBuilder(), // (sb, e) => sb.Append(e.EmployeeID.ToString() + ","), // sb => sb.ToString().Trim(',')); // } // DataSet oDataSet = new DataSet(); // oDataSet = GetEmployeeWiseTrainingSummary(sEmpIDs, fromDate, toDate, tNature, tTrainingType, trainingID, deptIDs, instituteID); // return oDataSet; //} //#endregion } #endregion }