using System; using Ease.CoreV35.Caching; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Model; using Payroll.BO; using System.Data; namespace Payroll.Service { #region Training Service [Serializable] class TrainingService : ServiceTemplate, ITrainingService { #region Private functions and declaration Cache _cache = new Cache(typeof(Training)); private void MapObject(Training oTraining, DataReader oReader) { base.SetObjectID(oTraining, oReader.GetID("TrainingID")); oTraining.Code = oReader.GetString("Code"); oTraining.Name = oReader.GetString("Name"); oTraining.TrainingTypeID = oReader.GetID("TrainingTypeID"); oTraining.TrainingDuration = oReader.GetDouble("STANDARDDURATION").GetValueOrDefault(); oTraining.StandardCost = oReader.GetDouble("StandardCost").GetValueOrDefault(); oTraining.LearningObjective = oReader.GetString("LearningObjective"); oTraining.CreatedBy = oReader.GetID("CreatedBy"); oTraining.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue?oReader.GetDateTime("CreatedDate").Value:DateTime.Today; oTraining.ModifiedBy = oReader.GetID("ModifiedBy"); oTraining.ModifiedDate = oReader.GetDateTime("ModifiedDate"); this.SetObjectState(oTraining, Ease.CoreV35.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(ID trainingID) { Training oTraining = null; #region CacheHeader oTraining = (Training)_cache["Get", trainingID]; if (oTraining != null) return oTraining; #endregion TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader oreader = new DataReader(TrainingDA.Get(tc, trainingID.Integer)); 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 } #region CacheFooter _cache.Add(oTraining, "Get", trainingID); #endregion return oTraining; } #endregion #region Get Trainings public ObjectsTemplate Get() { ObjectsTemplate oTrainings; #region CacheHeader oTrainings = (ObjectsTemplate)_cache["Get"]; if (oTrainings != null) return oTrainings; #endregion 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 } #region CacheFooter _cache.Add(oTrainings, "Get"); #endregion return oTrainings; } public ObjectsTemplate Get(string query) { ObjectsTemplate oTrainings; #region CacheHeader oTrainings = (ObjectsTemplate)_cache["Get"]; if (oTrainings != null) return oTrainings; #endregion 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 } #region CacheFooter _cache.Add(oTrainings, "Get"); #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, ID 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, ID 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 Save Training public ID 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 = "00" + newID; base.SetObjectID(oTraining, ID.FromInteger(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(ID trainingID) { try { TransactionContext tc = null; try { #region Deleting data tc = TransactionContext.Begin(true); TrainingDA.Delete(tc, trainingID.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 #region ITrainingService Members public DataSet ShowSoftPlanReport(string tYear) { throw new NotImplementedException(); } public DataSet GetEmployeeWiseTrainingReport(string sEmpIDs) { throw new NotImplementedException(); } #endregion } #endregion }