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 ObjectiveService : ServiceTemplate, IObjectiveService { #region Object Mapping private void MapObject(Objective oObjective, DataReader oReader) { SetObjectID(oObjective, oReader.GetInt32("ObjectiveID", 0)); oObjective.ObjectiveSetID = oReader.GetInt32("ObjectiveSetID", 0); oObjective.PMPYearID = oReader.GetInt32("PMPYearID", 0); oObjective.Title = oReader.GetString("Title"); oObjective.Description = oReader.GetString("Description"); oObjective.Activities = oReader.GetString("Activities"); oObjective.MeasuresOfSuccess = oReader.GetString("MeasuresOfSuccess"); oObjective.MeasuresOfSuccess2 = oReader.GetString("MeasuresOfSuccess2"); oObjective.Weightages = oReader.GetDouble("Weightages").Value; oObjective.EmployeeID = oReader.GetInt32("EmployeeID", 0); oObjective.EmployeeNodeID = oReader.GetInt32("EmployeeNodeID", 0); oObjective.ObjectiveDate = oReader.GetDateTime("ObjectiveDate").HasValue ? oReader.GetDateTime("ObjectiveDate").Value : DateTime.MinValue; oObjective.LMID = oReader.GetInt32("LMID", 0); oObjective.LMNodeID = oReader.GetInt32("LMNodeID", 0); oObjective.LMRatingID = oReader.GetInt32("LMRatingID").GetValueOrDefault(); oObjective.RagingDate = oReader.GetDateTime("RagingDate").HasValue ? oReader.GetDateTime("RagingDate").Value : DateTime.MinValue; oObjective.MYEmployeeComments = oReader.GetString("MYEmployeeComments"); oObjective.MYLMComments = oReader.GetString("MYLMComments"); oObjective.ObjComment = oReader.GetString("ObjComment"); oObjective.StartDate = oReader.GetDateTime("StartDate").HasValue ? oReader.GetDateTime("StartDate").Value : DateTime.MinValue; oObjective.EndDate = oReader.GetDateTime("EndDate").HasValue ? oReader.GetDateTime("EndDate").Value : DateTime.MinValue; oObjective.IsDraft = oReader.GetBoolean("IsDraft").Value; oObjective.IsOldObjective = oReader.GetBoolean("IsOldObjective").Value; oObjective.ObjectiveType = oReader.GetInt32("ObjectiveType").Value; oObjective.YEEmployeeComments = oReader.GetString("YEEmployeeComments"); oObjective.YELMComments = oReader.GetString("YELMComments"); oObjective.MYAssessRating = (EnumAssessment)oReader.GetInt32("MYAssessRating").GetValueOrDefault(); oObjective.MYLMAssessRating = (EnumAssessment)oReader.GetInt32("MYLMAssessRating").GetValueOrDefault(); oObjective.MYStatus = (EnumObjectiveStatus)oReader.GetInt32("MYStatus").GetValueOrDefault(); oObjective.YEStatus = (EnumObjectiveStatus)oReader.GetInt32("YEStatus").GetValueOrDefault(); oObjective.PriorityPercent = oReader.GetDouble("PriorityPercent").Value; oObjective.YEEmpMark = oReader.GetDouble("YEEmpMark").Value; oObjective.YELMMark = oReader.GetInt32("YELMMark", 0); oObjective.YEAssessRating = oReader.GetDouble("YEASSESSRATING").HasValue ? oReader.GetDouble("YEASSESSRATING").Value : null; oObjective.YELMAssessRating = oReader.GetInt32("YELMAssessRating").HasValue ? oReader.GetDouble("YELMAssessRating").Value : null; oObjective.KPIType = oReader.GetInt32("KPIType").GetValueOrDefault(); oObjective.MasterKpiId = oReader.GetInt32("MASTERKPIID").GetValueOrDefault(); oObjective.GroupID = oReader.GetInt32("GroupID", 0); oObjective.Tier = oReader.GetString("Tier"); this.SetObjectState(oObjective, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Objective oObjective = new Objective(); MapObject(oObjective, oReader); return oObjective as T; } #endregion #region Child Mapping #region LMObjective private List CreateLMObjectives(DataReader oReader) { List oLMObjectives = new List(); while (oReader.Read()) { LMObjective oLMObjective = new LMObjective(); MapLMObjectiveObject(oLMObjective, oReader); oLMObjectives.Add(oLMObjective); } return oLMObjectives; } private void MapLMObjectiveObject(LMObjective oLMObjective, DataReader oReader) { base.SetObjectID(oLMObjective, oReader.GetInt32("LMObjectiveID", 0)); oLMObjective.ObjectiveID = oReader.GetInt32("ObjectiveID", 0); this.SetObjectState(oLMObjective, Ease.Core.ObjectState.Saved); } #endregion #region ObjectiveEmployees private List CreateObjectiveEmployeess(DataReader oReader) { List oObjectiveEmployeess = new List(); while (oReader.Read()) { ObjectiveEmployees oObjectiveEmployees = new ObjectiveEmployees(); MapoObjectiveEmployeesObject(oObjectiveEmployees, oReader); oObjectiveEmployeess.Add(oObjectiveEmployees); } return oObjectiveEmployeess; } private void MapoObjectiveEmployeesObject(ObjectiveEmployees oObjectiveEmployees, DataReader oReader) { base.SetObjectID(oObjectiveEmployees, oReader.GetInt32("ObjectiveEmployeesID", 0)); oObjectiveEmployees.ObjectiveID = oReader.GetInt32("ObjectiveID", 0); oObjectiveEmployees.EmployeeID = oReader.GetInt32("EmployeeID", 0); oObjectiveEmployees.ObjectiveNodeID = oReader.GetInt32("ObjectiveNodeID", 0); this.SetObjectState(oObjectiveEmployees, Ease.Core.ObjectState.Saved); } #endregion #region DevelopmentPlan private List CreateDevelopmentPlans(DataReader oReader) { List oDevelopmentPlans = new List(); while (oReader.Read()) { DevelopmentPlan oDevelopmentPlan = new DevelopmentPlan(); MapDevelopmentPlansObject(oDevelopmentPlan, oReader); oDevelopmentPlans.Add(oDevelopmentPlan); } return oDevelopmentPlans; } private void MapDevelopmentPlansObject(DevelopmentPlan oDevelopmentPlan, DataReader oReader) { base.SetObjectID(oDevelopmentPlan, oReader.GetInt32("DevelopmentPlanID").Value); //oDevelopmentPlan.FuncDevNeeds = oReader.GetString("Activities"); //oDevelopmentPlan.NxtCarrierSteps = oReader.GetString("MeasuresOfSuccess"); //oDevelopmentPlan.TimeLine = oReader.GetString("TimeLine"); //oDevelopmentPlan.ObjectiveID = oReader.GetInt32("ObjectiveID", 0); //oDevelopmentPlan.TrainingID = oReader.GetInt32("TrainingID", 0); //oDevelopmentPlan.Remarks = oReader.GetString("Remarks"); this.SetObjectState(oDevelopmentPlan, ObjectState.Saved); } #endregion #endregion #region IObjectiveService Members #region Get All public List Get() { List oObjective = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.Get(tc)); oObjective = 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 oObjective; } #endregion #region Get By ID public Objective Get(int id) { Objective oObjective = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.Get(tc, id)); if (oreader.Read()) { oObjective = 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 oObjective; } #endregion #region Get By Line Manager ID public Objective GetByLMID(int id) { Objective oObjective = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByLMID(tc, id)); if (oreader.Read()) { oObjective = this.CreateObject(oreader); } //oObjective = 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 oObjective; } #endregion #region Get Draft Objective public List GetObjectives(int id, int draft) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetDraftObjectives(tc, id, draft)); //if (oreader.Read()) //{ // oObjectives = this.CreateObjects(oreader); //} oObjectives = 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 oObjectives; } #endregion #region Get By Employee ID public List GetByEmployeeID(int Empid, int PMPID, bool IsDrafted) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByEmployeeID(tc, Empid, PMPID, IsDrafted)); //if (oreader.Read()) //{ // oObjectives = this.CreateObjects(oreader); //} oObjectives = 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 oObjectives; } public List GetForValidation(int empId, int pmpYearId, int objectiveTypeId) { List items = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dataReader = new DataReader(ObjectiveDA.GetForValidation(tc, empId, pmpYearId, objectiveTypeId)); items = this.CreateObjects(dataReader); dataReader.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 items; } public List GetLMObjs(int Empid, int PMPYID, int nLMID) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetLMObjs(tc, Empid, PMPYID, nLMID)); //if (oreader.Read()) //{ // oObjectives = this.CreateObjects(oreader); //} oObjectives = 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 oObjectives; } public List GetByEmployeeID(string Empids, int PMPID, bool IsDrafted) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByEmployeeID(tc, Empids, PMPID, IsDrafted)); //if (oreader.Read()) //{ // oObjectives = this.CreateObjects(oreader); //} oObjectives = 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 oObjectives; } public List GetByPMPYearID(int id, string InEmpSQL) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByPMPYearID(tc, id, InEmpSQL)); //if (oreader.Read()) //{ // oObjectives = this.CreateObjects(oreader); //} oObjectives = 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 oObjectives; } public List GetByStatus(EnumPMPStatus estatus, bool IsFinalized) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByStatus(tc, estatus, IsFinalized)); //if (oreader.Read()) //{ // oObjectives = this.CreateObjects(oreader); //} oObjectives = 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 oObjectives; } #endregion #region Get Development Plans public List GetDevelopmentPlans(int iD) { List oDevelopmentPlan = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetDevelopmentPlans(tc, iD)); oDevelopmentPlan = this.CreateDevelopmentPlans(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 LMObjectives public List GetLMObjectives(int iD) { List oLMObjective = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetLMObjectives(tc, iD)); oLMObjective = this.CreateLMObjectives(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 oLMObjective; } #endregion #region Get Objective Employees public List GetObjectiveEmployees(int iD) { List oObjectiveEmployees = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetObjectiveEmployees(tc, iD)); oObjectiveEmployees = this.CreateObjectiveEmployeess(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 oObjectiveEmployees; } #endregion #region Get Line Manager Objective public Objective GetLineManager(int id) { Objective oObjective = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetLineManager(tc, id)); if (oreader.Read()) { oObjective = this.CreateObject(oreader); } //oObjective = 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 oObjective; } #endregion #region Insert public int Save(Objective item) { TransactionContext tc = null; try { ObjectiveSet oObjectiveSet = null; ObjectiveSet objSet = (new ObjectiveSetService()).GetByEmployeeID(item.EmployeeID, item.PMPYearID); if (objSet != null) { item.ObjectiveSetID = objSet.ID; } else { oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.EmployeeNodeID = item.EmployeeNodeID; oObjectiveSet.LMID = item.LMID; oObjectiveSet.LMNodeID = item.LMNodeID; oObjectiveSet.PMPYearID = item.PMPYearID; } tc = TransactionContext.Begin(true); if (oObjectiveSet != null) { int obsetID = tc.GenerateID("ObjectiveSet", "ObjectiveSetID"); base.SetObjectID(oObjectiveSet, (obsetID)); ObjectiveSetDA.Save(tc, oObjectiveSet); item.ObjectiveSetID = (obsetID); } if (item.IsNew) { //List objSet= ObjectiveSetService.GetByEmployeeID(item.EmployeeID, item.PMPYearID); int id = tc.GenerateID("Objective", "ObjectiveID"); base.SetObjectID(item, (id)); ObjectiveDA.Insert(tc, item); } else { ObjectiveDA.Update(tc, item); #region Delete Child ObjectiveDA.DeleteLMObjective(tc, item.ID); ObjectiveDA.DeleteDevelopmentPlan(tc, item.ID); ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); #endregion } #region Insert Child if (item.LMObjectives != null && item.LMObjectives.Count > 0) { foreach (LMObjective lMObjective in item.LMObjectives) { lMObjective.ParentID = item.ID; base.SetObjectID(lMObjective, (tc.GenerateID("LMObjective", "LMObjectiveID"))); LMObjectiveDA.Save(tc, lMObjective); } } //foreach (DevelopmentPlan dDevelopmentPlan in item.DevelopmentPlans) //{ // dDevelopmentPlan.ObjectiveID = item.ID; // base.SetObjectID(dDevelopmentPlan, (tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"))); // DevelopmentPlanDA.Insert(tc, dDevelopmentPlan, EnumObjectiveFlowStatus.Draft); //} if (item.ObjectiveEmployees != null && item.ObjectiveEmployees.Count > 0) { foreach (ObjectiveEmployees oObjectiveEmployees in item.ObjectiveEmployees) { oObjectiveEmployees.ObjectiveID = item.ID; base.SetObjectID(oObjectiveEmployees, (tc.GenerateID("ObjectiveEmployees", "ObjectiveEmployeesID"))); ObjectiveEmployeesDA.Save(tc, oObjectiveEmployees); } } #endregion 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 Save(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("Objective", "ObjectiveID"); int obsetID = tc.GenerateID("ObjectiveSet", "ObjectiveSetID"); foreach (Objective item in items) { ObjectiveSet oObjectiveSet = null; ObjectiveSet objSet = (new ObjectiveSetService()).GetByEmployeeID(tc, item.EmployeeID, item.PMPYearID); if (objSet != null) { item.ObjectiveSetID = objSet.ID; } else { oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.EmployeeNodeID = item.EmployeeNodeID; oObjectiveSet.LMID = item.LMID; oObjectiveSet.LMNodeID = item.LMNodeID; oObjectiveSet.PMPYearID = item.PMPYearID; } if (oObjectiveSet != null) { base.SetObjectID(oObjectiveSet, (obsetID)); ObjectiveSetDA.Save(tc, oObjectiveSet); item.ObjectiveSetID = (obsetID); obsetID++; } if (item.IsNew) { //List objSet= ObjectiveSetService.GetByEmployeeID(item.EmployeeID, item.PMPYearID); base.SetObjectID(item, (id)); ObjectiveDA.Insert(tc, item); id++; } else { ObjectiveDA.Update(tc, item); #region Delete Child ObjectiveDA.DeleteLMObjective(tc, item.ID); ObjectiveDA.DeleteDevelopmentPlan(tc, item.ID); ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); #endregion } #region Insert Child foreach (LMObjective lMObjective in item.LMObjectives) { lMObjective.ParentID = item.ID; base.SetObjectID(lMObjective, (tc.GenerateID("LMObjective", "LMObjectiveID"))); LMObjectiveDA.Save(tc, lMObjective); } //foreach (DevelopmentPlan dDevelopmentPlan in item.DevelopmentPlans) //{ // dDevelopmentPlan.ObjectiveID = item.ID; // base.SetObjectID(dDevelopmentPlan, (tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"))); // DevelopmentPlanDA.Insert(tc, dDevelopmentPlan, EnumObjectiveFlowStatus.Draft); //} foreach (ObjectiveEmployees oObjectiveEmployees in item.ObjectiveEmployees) { oObjectiveEmployees.ObjectiveID = item.ID; base.SetObjectID(oObjectiveEmployees, (tc.GenerateID("ObjectiveEmployees", "ObjectiveEmployeesID"))); ObjectiveEmployeesDA.Save(tc, oObjectiveEmployees); } #endregion //return item.ID; } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void SaveForUpload(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("Objective", "ObjectiveID"); int obsetID = tc.GenerateID("ObjectiveSet", "ObjectiveSetID"); foreach (Objective item in items) { ObjectiveSet oObjectiveSet = null; ObjectiveSet objSet = (new ObjectiveSetService()).GetByEmployeeID(tc, item.EmployeeID, item.PMPYearID); if (objSet != null) { item.ObjectiveSetID = objSet.ID; objSet.OBEmpComplete = true; objSet.OBEmpCompleteDate = DateTime.Today; objSet.OBLMComplete = EnumObjectiveFlowStatus.Agreed; objSet.OBLMCompleteDate = DateTime.Today; } else { oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.EmployeeNodeID = item.EmployeeNodeID; oObjectiveSet.LMID = item.LMID; oObjectiveSet.LMNodeID = item.LMNodeID; oObjectiveSet.PMPYearID = item.PMPYearID; oObjectiveSet.OBEmpComplete = true; oObjectiveSet.OBEmpCompleteDate = DateTime.Today; oObjectiveSet.OBLMComplete = EnumObjectiveFlowStatus.Agreed; oObjectiveSet.OBLMCompleteDate = DateTime.Today; } if (oObjectiveSet != null) { base.SetObjectID(oObjectiveSet, (obsetID)); ObjectiveSetDA.Save(tc, oObjectiveSet); item.ObjectiveSetID = (obsetID); obsetID++; } else { ObjectiveSetDA.Update(tc, objSet); } if (item.IsNew) { //List objSet= ObjectiveSetService.GetByEmployeeID(item.EmployeeID, item.PMPYearID); base.SetObjectID(item, (id)); ObjectiveDA.Insert(tc, item); id++; } else { ObjectiveDA.Update(tc, item); #region Delete Child ObjectiveDA.DeleteLMObjective(tc, item.ID); ObjectiveDA.DeleteDevelopmentPlan(tc, item.ID); ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); #endregion } //#region Insert Child //foreach (LMObjective lMObjective in item.LMObjectives) //{ // lMObjective.ParentID = item.ID; // base.SetObjectID(lMObjective, (tc.GenerateID("LMObjective", "LMObjectiveID"))); // LMObjectiveDA.Insert(tc, lMObjective); //} //foreach (DevelopmentPlan dDevelopmentPlan in item.DevelopmentPlans) //{ // dDevelopmentPlan.ObjectiveID = item.ID; // base.SetObjectID(dDevelopmentPlan, (tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"))); // DevelopmentPlanDA.Insert(tc, dDevelopmentPlan); //} //foreach (ObjectiveEmployees oObjectiveEmployees in item.ObjectiveEmployees) //{ // oObjectiveEmployees.ObjectiveID = item.ID; // base.SetObjectID(oObjectiveEmployees, (tc.GenerateID("ObjectiveEmployees", "ObjectiveEmployeesID"))); // ObjectiveEmployeesDA.Insert(tc, oObjectiveEmployees); //} //#endregion //return item.ID; } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void SaveForSalesUpload(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); int id = tc.GenerateID("Objective", "ObjectiveID"); int obsetID = tc.GenerateID("ObjectiveSet", "ObjectiveSetID"); foreach (Objective item in items) { ObjectiveSet oObjectiveSet = null; ObjectiveSet objSet = (new ObjectiveSetService()).GetByEmployeeID(tc, item.EmployeeID, item.PMPYearID); if (objSet != null) { item.ObjectiveSetID = objSet.ID; objSet.OBEmpComplete = true; objSet.OBEmpCompleteDate = DateTime.Today; objSet.OBLMComplete = EnumObjectiveFlowStatus.Agreed; objSet.OBLMCompleteDate = DateTime.Today; } else { oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.EmployeeNodeID = item.EmployeeNodeID; oObjectiveSet.LMID = item.LMID; oObjectiveSet.LMNodeID = item.LMNodeID; oObjectiveSet.PMPYearID = item.PMPYearID; oObjectiveSet.OBEmpComplete = true; oObjectiveSet.OBEmpCompleteDate = DateTime.Today; oObjectiveSet.OBLMComplete = EnumObjectiveFlowStatus.Agreed; oObjectiveSet.OBLMCompleteDate = DateTime.Today; } if (oObjectiveSet != null) { base.SetObjectID(oObjectiveSet, (obsetID)); ObjectiveSetDA.Save(tc, oObjectiveSet); item.ObjectiveSetID = (obsetID); obsetID++; } else { ObjectiveSetDA.Update(tc, objSet); } if (item.IsNew) { //List objSet= ObjectiveSetService.GetByEmployeeID(item.EmployeeID, item.PMPYearID); base.SetObjectID(item, (id)); ObjectiveDA.Insert(tc, item); id++; } else { ObjectiveDA.Update(tc, item); #region Delete Child ObjectiveDA.DeleteLMObjective(tc, item.ID); ObjectiveDA.DeleteDevelopmentPlan(tc, item.ID); ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); #endregion } //#region Insert Child //foreach (LMObjective lMObjective in item.LMObjectives) //{ // lMObjective.ParentID = item.ID; // base.SetObjectID(lMObjective, (tc.GenerateID("LMObjective", "LMObjectiveID"))); // LMObjectiveDA.Insert(tc, lMObjective); //} //foreach (DevelopmentPlan dDevelopmentPlan in item.DevelopmentPlans) //{ // dDevelopmentPlan.ObjectiveID = item.ID; // base.SetObjectID(dDevelopmentPlan, (tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"))); // DevelopmentPlanDA.Insert(tc, dDevelopmentPlan); //} //foreach (ObjectiveEmployees oObjectiveEmployees in item.ObjectiveEmployees) //{ // oObjectiveEmployees.ObjectiveID = item.ID; // base.SetObjectID(oObjectiveEmployees, (tc.GenerateID("ObjectiveEmployees", "ObjectiveEmployeesID"))); // ObjectiveEmployeesDA.Insert(tc, oObjectiveEmployees); //} //#endregion //return item.ID; } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Update(List items) { string sError = string.Empty; TransactionContext tc = null; try { tc = TransactionContext.Begin(); foreach (Objective item in items) { ObjectiveDA.Update(tc, item); ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); foreach (ObjectiveEmployees oObjectiveEmployees in item.ObjectiveEmployees) { oObjectiveEmployees.ObjectiveID = item.ID; base.SetObjectID(oObjectiveEmployees, (tc.GenerateID("ObjectiveEmployees", "ObjectiveEmployeesID"))); ObjectiveEmployeesDA.Save(tc, oObjectiveEmployees); } } tc.End(); } catch (Exception e) { throw new Exception(sError); } } //public string Save2(Objective item, List UpdateHistory) //{ // string sError = string.Empty; // TransactionContext tc = null; // try // { // ObjectiveSet oObjectiveSet = null; // sError += "error code:30"; // ObjectiveSet objSet = (new ObjectiveSetService()).GetByEmployeeID(item.EmployeeID, item.PMPYearID); // if (objSet != null) // { // item.ObjectiveSetID = objSet.ID; // //objSet.OBLMComplete = EnumObjectiveFlowStatus.Not_yet_Agreed; // //objSet.OBEmpComplete = false; // objSet.LMID = item.LMID; // objSet.LMNodeID = item.LMNodeID; // } // else // { // oObjectiveSet = new ObjectiveSet(); // oObjectiveSet.EmployeeID = item.EmployeeID; // oObjectiveSet.EmployeeNodeID = item.EmployeeNodeID; // oObjectiveSet.LMID = item.LMID; // oObjectiveSet.LMNodeID = item.LMNodeID; // oObjectiveSet.PMPYearID = item.PMPYearID; // } // sError += "error code:04"; // tc = TransactionContext.Begin(true); // if (oObjectiveSet != null) // { // int obsetID = tc.GenerateID("ObjectiveSet", "ObjectiveSetID"); // base.SetObjectID(oObjectiveSet, (obsetID)); // ObjectiveSetDA.Insert(tc, oObjectiveSet); // item.ObjectiveSetID = (obsetID); // } // else // { // ObjectiveSetDA.Update(tc, objSet); // } // sError += "error code:05"; // if (item.IsNew) // { // //List objSet= ObjectiveSetService.GetByEmployeeID(item.EmployeeID, item.PMPYearID); // int id = tc.GenerateID("Objective", "ObjectiveID"); // base.SetObjectID(item, (id)); // ObjectiveDA.Insert(tc, item); // } // else // { // ObjectiveDA.Update(tc, item); // #region Delete Child // ObjectiveDA.DeleteLMObjective(tc, item.ID); // ObjectiveDA.DeleteDevelopmentPlan(tc, item.ID); // ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); // #endregion // } // #region Insert Child // sError += "error code:06"; // foreach (LMObjective lMObjective in item.LMObjectives) // { // lMObjective.ParentID = item.ID; // base.SetObjectID(lMObjective, (tc.GenerateID("LMObjective", "LMObjectiveID"))); // LMObjectiveDA.Insert(tc, lMObjective); // } // sError += "error code:07"; // foreach (DevelopmentPlan dDevelopmentPlan in item.DevelopmentPlans) // { // dDevelopmentPlan.ObjectiveID = item.ID; // base.SetObjectID(dDevelopmentPlan, (tc.GenerateID("DevelopmentPlan", "DevelopmentPlanID"))); // DevelopmentPlanDA.Insert(tc, dDevelopmentPlan,EnumObjectiveFlowStatus.Draft); // } // sError += "error code:08"; // foreach (ObjectiveEmployees oObjectiveEmployees in item.ObjectiveEmployees) // { // oObjectiveEmployees.ObjectiveID = item.ID; // base.SetObjectID(oObjectiveEmployees, (tc.GenerateID("ObjectiveEmployees", "ObjectiveEmployeesID"))); // ObjectiveEmployeesDA.Insert(tc, oObjectiveEmployees); // } // #endregion // foreach (PMSUpdateHistory uph in UpdateHistory) // { // base.SetObjectID(uph, (tc.GenerateID("PMSUpdateHistory", "PMSUpdateHistoryID"))); // uph.CreatedBy = item.EmployeeID; // uph.CreatedDate = DateTime.Today; // uph.Sequence = PMSUpdateHistoryDA.GetSequence(tc, uph.PmpStatus, uph.ChangeType, uph.ActorType); // PMSUpdateHistoryDA.Insert(tc, uph); // } // tc.End(); // } // catch (Exception e) // { // throw new Exception(sError); // } // return sError; //} #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { ObjectiveSet obset = new ObjectiveSetService().GetSetByObjectiveID(id); if(obset.OBEmpComplete ==true) { throw new Exception(" Delete is not allowed after objective submit"); } tc = TransactionContext.Begin(true); //#region Delete Child //ObjectiveDA.DeleteLMObjective(tc, id); //ObjectiveDA.DeleteDevelopmentPlan(tc, id); //ObjectiveDA.DeleteObjectiveEmployees(tc, id); //#endregion ObjectiveDA.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 } } public void DeleteAllCompanyObj(int yearID) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); //#region Delete Child //ObjectiveDA.DeleteLMObjective(tc, id); //ObjectiveDA.DeleteDevelopmentPlan(tc, id); //ObjectiveDA.DeleteObjectiveEmployees(tc, id); //#endregion ObjectiveDA.DeleteAllCompanyObj(tc, yearID); 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 public DataSet GetComObjAssignedEmpID(int PMPYearID) { DataSet allData = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); allData = ObjectiveDA.GetComObjAssignedEmpID(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 allData; } public DataSet GetEmpObjectiveData(int year) { DataSet allData = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); allData = new DataSet(); //ObjectiveDA.GetEmpObjectiveData(tc,year); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return allData; } public DataSet GetEmpFreezedObjectiveData() { DataSet allData = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); allData = new DataSet(); //ObjectiveDA.GetEmpFreezedObjectiveData(tc); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return allData; } public DataSet GetPmsDataEmployeeWise(int pmpYearId, string empIds) { DataSet dataSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); dataSet = ObjectiveDA.GetPmsDataEmployeeWise(tc, pmpYearId, empIds); 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; } public DataSet GetPmsLmGoalReport(int pmpYearId, int empId) { DataSet dataSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); dataSet = ObjectiveDA.GetPmsLmGoalReport(tc, pmpYearId, empId); 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; } public DataSet GetPmsIndividualGoalData(int pmpYearId, int empId) { DataSet dataSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); dataSet = ObjectiveDA.GetPmsIndividualGoalData(tc, pmpYearId, empId); 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; } public DataSet getPMSReportData(int pmpYearID, int pmsReportType, string emps) { DataSet dataSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); dataSet = ObjectiveDA.getPMSReportData(tc, pmpYearID, pmsReportType, emps); 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; } } }