using System; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using System.Collections.Generic; using Ease.Core.Utility; using HRM.BO; namespace HRM.DA { public class DevelopmentPlanService : ServiceTemplate, IDevelopmentPlanService { #region Object Mapping private void MapObject(DevelopmentPlan oDevelopmentPlan, DataReader oReader) { SetObjectID(oDevelopmentPlan, oReader.GetInt32("DevelopmentPlanID", 0)); oDevelopmentPlan.ObjectiveSetID = oReader.GetInt32("ObjectiveSetID").Value; oDevelopmentPlan.EmployeeID = oReader.GetInt32("EmployeeID").Value; oDevelopmentPlan.PMPYearID = oReader.GetInt32("PMPYearID").Value; oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID").HasValue ? oReader.GetInt32("TrainingID").Value : null; oDevelopmentPlan.TrainingName = oReader.GetString("TrainingName", null); oDevelopmentPlan.MeasureOfSuccess = oReader.GetString("MeasureOfSuccess", null); oDevelopmentPlan.FromDate = oReader.GetDateTime("FromDate").HasValue ? oReader.GetDateTime("FromDate").Value : null; oDevelopmentPlan.ToDate = oReader.GetDateTime("ToDate").Value; oDevelopmentPlan.TargetRatingID = oReader.GetInt32("TargetRatingID").Value; oDevelopmentPlan.EmpRemarks = oReader.GetString("EmpRemarks", null); oDevelopmentPlan.LMRemarks = oReader.GetString("LMRemarks", null); oDevelopmentPlan.EmployeeID = oReader.GetInt32("EmployeeID", 0); //oDevelopmentPlan.FuncDevNeeds = oReader.GetString("FuncDevNeeds"); //oDevelopmentPlan.NxtCarrierSteps = oReader.GetString("NxtCarrierSteps"); //oDevelopmentPlan.TimeLine = oReader.GetString("TimeLine"); //oDevelopmentPlan.ObjectiveID = oReader.GetInt32("ObjectiveID", 0); //oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID", 0); //oDevelopmentPlan.TrainingID2 = oReader.GetInt32("TrainingID2", 0); //oDevelopmentPlan.TrainingID3 = oReader.GetInt32("TrainingID3", 0); //oDevelopmentPlan.CanTravel = oReader.GetBoolean("CanTravel").Value; //oDevelopmentPlan.Remarks = oReader.GetString("Remarks"); //oDevelopmentPlan.EmployeeID = oReader.GetInt32("EmployeeID", 0); //oDevelopmentPlan.ObjectiveSetID = oReader.GetInt32("ObjectiveSetID", 0); this.SetObjectState(oDevelopmentPlan, ObjectState.Saved); } private void MapObject(FunctionalDevelopment oDevelopmentPlan, DataReader oReader) { SetObjectID(oDevelopmentPlan, oReader.GetInt32("FuncDevelopmentID", 0)); oDevelopmentPlan.DevelopmentPlanID = oReader.GetInt32("DevelopmentPlanID").Value; oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID").Value; this.SetObjectState(oDevelopmentPlan, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { DevelopmentPlan oDevelopmentPlan = new DevelopmentPlan(); MapObject(oDevelopmentPlan, oReader); return oDevelopmentPlan as T; } private FunctionalDevelopment CreateFuncDevObject(DataReader oReader) { FunctionalDevelopment oDevelopmentPlan = new FunctionalDevelopment(); MapObject(oDevelopmentPlan, oReader); return oDevelopmentPlan; } private List CreateFuncDevObjects(DataReader oReader) { List ofuncDevmnts = new List(); while (oReader.Read()) { ofuncDevmnts.Add(CreateFuncDevObject(oReader)); } return ofuncDevmnts; } #endregion #region IDevelopmentPlanService Members #region Get All public List Get() { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.Get(tc)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } public List GetByObjectiveSetId(int objectiveSetId) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetByObjectiveSetId(tc, objectiveSetId)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } public List GetPreviousYears(int employeeId, int pmpYearId) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetPreviousYears(tc, employeeId, pmpYearId)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } public List GetPreviousYears(int employeeId, DateTime pmpYear) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetPreviousYears(tc, employeeId, pmpYear)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } public List GetFunctionalDevelopment(int DevPlanID) { List oFunctionalDevelopment = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetFunctionalDevelopment(tc, DevPlanID)); oFunctionalDevelopment = this.CreateFuncDevObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oFunctionalDevelopment; } #endregion #region GetByEmployeeID public List GetByEmployeeID(int id) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetByEmployeeID(tc, id)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } #endregion #region GetByPMPYearID public List GetByPMPYearID(int id, string InEmpSQL) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetByPMPYearID(tc, id, InEmpSQL)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } #endregion #region GetByObjSetID public List GetByObjSetID(int id) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetByObjSetID(tc, id)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } #endregion #region GetByPmpYearId public List GetByPmpYearId(int id) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.GetByPmpYearId(tc, id)); oDevelopmentPlan = this.CreateObjects(oreader); oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } #endregion #region Get By ID public DevelopmentPlan Get(int id) { DevelopmentPlan oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(DevelopmentPlanDA.Get(tc, id)); if (oreader.Read()) { oDevelopmentPlan = this.CreateObject(oreader); } oreader.Close(); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oDevelopmentPlan; } #endregion public DataSet GetTrainingNeedAnalysisCount(int pmpYearId) { DataSet dataSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); dataSet = DevelopmentPlanDA.GetTrainingNeedAnalysisCount(tc, pmpYearId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dataSet; } #region Insert public int Save(DevelopmentPlan item) { TransactionContext tc = null; try { int id = 0; tc = TransactionContext.Begin(true); if (item.IsNew) { id = tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"); base.SetObjectID(item, (id)); DevelopmentPlanDA.Insert(tc, item); } else { id = item.ID; DevelopmentPlanDA.Update(tc, item); } tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public int Save(DevelopmentPlan item, EnumObjectiveFlowStatus DevPlanEmpStatus) { TransactionContext tc = null; try { int id = 0; //var functionalDevelopments = item.FunctionalDevelopments; //tc = TransactionContext.Begin(true); //if (item.IsNew) //{ // id = tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"); // base.SetObjectID(item, (id)); // DevelopmentPlanDA.Insert(tc, item, DevPlanEmpStatus); //} //else //{ // id = item.ID; // DevelopmentPlanDA.Update(tc, item, DevPlanEmpStatus); //} //DevelopmentPlanDA.DeleteFunctionalDevelopments(tc, id); //foreach (var fditem in functionalDevelopments) //{ // int childIid = tc.GenerateID("FuncDevelopment", "FuncDevelopmentID"); // base.SetObjectID(fditem, (childIid)); // fditem.DevelopmentPlanID = id; // DevelopmentPlanDA.Insert(tc, fditem); //} //tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void LMSave(DevelopmentPlan item, EnumObjectiveFlowStatus DevPlanLMStatus) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DevelopmentPlanDA.LMUpdate(tc, item, DevPlanLMStatus); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); DevelopmentPlanDA.Delete(tc, id); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #endregion } }