using DocumentFormat.OpenXml.Office2010.Excel; using Ease.Core; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using NPOI.SS.Formula.Functions; using System; using System.Collections.Generic; using System.Data; using System.Linq; 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.PayrollTypeID = oReader.GetInt32("PayrollTypeID", 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.ObjectiveStatus = (EnumObjectiveStatus)oReader.GetInt32("ObjectiveStatus").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.YESecondLMMark = oReader.GetInt32("YE2NDLMMark", 0); oObjective.YESecondLMComments = oReader.GetString("YE2NDLMComments"); oObjective.YEAssessRating = oReader.GetDouble("YEASSESSRATING").HasValue ? oReader.GetDouble("YEASSESSRATING").Value : null; oObjective.YELMAssessRating = oReader.GetInt32("YELMAssessRating").HasValue ? oReader.GetDouble("YELMAssessRating").Value : null; oObjective.KPIType = (EnumObjectiveType)oReader.GetInt32("KPIType").GetValueOrDefault(); oObjective.MasterKpiId = oReader.GetInt32("MASTERKPIID").GetValueOrDefault(); oObjective.GroupID = oReader.GetInt32("GroupID", 0); oObjective.Tier = oReader.GetString("Tier"); oObjective.ProgressStatus = oReader.GetDouble("ProgressStatus", 0); oObjective.ObjectiveSettingRemarksLM = oReader.GetString("ObjectiveSettingRemarksLM", true, ""); oObjective.ObjectiveSettingRemarksLM2 = oReader.GetString("ObjectiveSettingRemarksLM2", true, ""); this.SetObjectState(oObjective, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { Objective oObjective = new Objective(); MapObject(oObjective, oReader); return oObjective as T; } protected ObjectiveAttachment CreateObjectAttachment(DataReader oReader) { ObjectiveAttachment oObjective = new ObjectiveAttachment(); MapObject(oObjective, oReader); return oObjective; } #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 #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; } public Objective Get(TransactionContext tc, int id) { Objective oObjective = null; try { DataReader oreader = new DataReader(ObjectiveDA.Get(tc, id)); if (oreader.Read()) { oObjective = this.CreateObject(oreader); } oreader.Close(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return oObjective; } #endregion 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(); if (oObjectives.Count > 0) { List attachments = new ObjectiveSetService().GetObjectiveAttachments(tc, oObjectives[0].ObjectiveSetID); foreach (var objective in oObjectives) { objective.Attachments = attachments.FindAll(x => x.ObjectiveID == objective.ID); } } 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(int Empid, int PMPID) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByEmployeeID(tc, Empid, PMPID)); //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 GetByPMPYear(int nPMPYearID, int nPayrollTypeID) { List oObjectives = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetByPMPYear(tc, nPMPYearID, nPayrollTypeID)); //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 Insert public int Save(Objective item) { TransactionContext tc = null; try { // ObjectiveSet oObjectiveSet = null; List leadershipObjective = null; ObjectiveSet oObjectiveSet = (new ObjectiveSetService()).GetByEmployeeID(item.EmployeeID, item.PMPYearID); if (oObjectiveSet != null) { item.ObjectiveSetID = oObjectiveSet.ID; } else { Employee oemp = new EmployeeService().Get(item.EmployeeID); PMPProcess pmpYear = new PMPProcessService().GetByPMPProcessID(item.PMPYearID); if (oemp.LineManagerID == null) throw new Exception("line manager not found."); item.LMID = (int)oemp.LineManagerID; oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.lmID = item.LMID; oObjectiveSet.PMPYearID = item.PMPYearID; oObjectiveSet.PayrollTypeID = item.PayrollTypeID; oObjectiveSet.IsEditing = false; oObjectiveSet.OBEmpComplete = EnumObjectiveFlowStatus.Draft; oObjectiveSet.CreatedBy = item.CreatedBy; oObjectiveSet.CreatedDate = DateTime.Today; List obtypes = new ObjectiveTypeService().GetTypeLeadership(EnumStatus.Active, item.PayrollTypeID); List category = new ObjectiveCategoryService().GetByPMPyear(item.PMPYearID); //if (obtypes != null && obtypes.Count > 0) //{ // leadershipObjective = new List(); // foreach (ObjectiveType oObjectiveType in obtypes) // { // if (oObjectiveType.Type == EnumObjectiveType.Leadership) // { // Objective obj = new Objective(); // obj.EmployeeID = item.EmployeeID; // obj.EmployeeNodeID = item.EmployeeNodeID; // obj.LMID = item.LMID; // obj.KPIType = EnumObjectiveType.Leadership; // obj.LMNodeID = item.LMNodeID; // obj.PMPYearID = item.PMPYearID; // obj.PayrollTypeID = item.PayrollTypeID; // obj.ObjectiveType = (int)oObjectiveType.ID; // obj.Description = oObjectiveType.Name; // obj.StartDate = pmpYear.TargetSettingFrom; // obj.EndDate = pmpYear.FinalApprovalTo; // obj.Title = oObjectiveType.Description; // var cat = category.FirstOrDefault(x => x.ObjectiveCategoryGrades.Any(g => g.GradeID == oemp.GradeID) // && x.ObjectiveTypeID == oObjectiveType.ID); // if (cat != null) // { // var cateGrade = cat.ObjectiveCategoryGrades.FirstOrDefault(f => f.GradeID == oemp.GradeID // && f.ObjectiveType == oObjectiveType.ID); // if (cateGrade != null) // obj.Weightages = cateGrade.Percent; // else throw new Exception("System didn't find Leadership Weightages, Contact to System Administrator"); // } // else throw new Exception("System didn't find Leadership Weightages, Contact to System Administrator"); // // obj.MeasuresOfSuccess = oObjectiveType.Description; // leadershipObjective.Add(obj); // } // } //} } tc = TransactionContext.Begin(true); // Set only by the outside-of-settings Add/Edit branches below; used further down to // route any newly-selected attachments to the pending ObjectiveHistory row instead of // the (not-yet-approved) live Objective. int? outsideOfSettingsHistoryId = null; if (oObjectiveSet.IsNew ==true) { int obsetID = tc.GenerateID("ObjectiveSet", "ObjectiveSetID"); base.SetObjectID(oObjectiveSet, (obsetID)); ObjectiveSetDA.Save(tc, oObjectiveSet); item.ObjectiveSetID = (obsetID); ObjectiveSetRemarks oObjectiveSetRemarks = new ObjectiveSetRemarks(); oObjectiveSetRemarks.ObjectiveSetID = obsetID; base.SetObjectID(oObjectiveSetRemarks, (tc.GenerateID("ObjectiveSetRemarks", "ObjectiveSetRemarksID"))); ObjectiveSetRemarksDA.Save(tc, oObjectiveSetRemarks); } if (item.IsNew) { if (item.OutsideOfSettings) { // Fully deferred: nothing written to Objective until the LM approves it. outsideOfSettingsHistoryId = ObjectiveDA.InsertHistoryForNewObjective(tc, oObjectiveSet, item); } else { //List objSet= ObjectiveSetService.GetByEmployeeID(item.EmployeeID, item.PMPYearID); item.ObjectiveStatus = EnumObjectiveStatus.New; int id = tc.GenerateID("Objective", "ObjectiveID"); base.SetObjectID(item, (id)); ObjectiveDA.Insert(tc, item); if (oObjectiveSet.OBEmpComplete == EnumObjectiveFlowStatus.Submit) { //ObjectiveSetDA.updateEditStatus(tc, oObjectiveSet.IsEditing, oObjectiveSet.ID); //item.ObjectiveStatus = EnumObjectiveStatus.Updated; //Objective obold = new ObjectiveService().Get(tc, item.ID); ObjectiveDA.InsertHistory(tc, EnumOperationalStatus.Add, oObjectiveSet, item, null); } } } else if (item.OutsideOfSettings) { // Stage the edit in ObjectiveHistory only. The live row keeps its current content; // it's just flagged Updated so the grid highlights it as pending, same as today's // correction-mode styling. Nothing else about the row (children included) changes // until the LM approves it. Objective obold = new ObjectiveService().Get(tc, item.ID); outsideOfSettingsHistoryId = ObjectiveDA.InsertHistory(tc, EnumOperationalStatus.Edit, oObjectiveSet, obold, item, true); ObjectiveDA.SetObjectiveStatus(tc, item.ID, EnumObjectiveStatus.Updated); } else { #region Delete Child // ObjectiveDA.DeleteObjectiveAttachmentByObjectiveID(tc, item.ID); ObjectiveDA.DeleteLMObjective(tc, item.ID); ObjectiveDA.DeleteDevelopmentPlan(tc, item.ObjectiveSetID); ObjectiveDA.DeleteObjectiveEmployees(tc, item.ID); if (oObjectiveSet.OBEmpComplete == EnumObjectiveFlowStatus.Submit) { ObjectiveSetDA.updateEditStatus(tc, oObjectiveSet.IsEditing, oObjectiveSet.ID); item.ObjectiveStatus = EnumObjectiveStatus.Updated; Objective obold = new ObjectiveService().Get(tc, item.ID); ObjectiveDA.InsertHistory(tc, EnumOperationalStatus.Edit, oObjectiveSet, obold,item); } ObjectiveDA.Update(tc, item); #endregion } #region Insert Child if(leadershipObjective != null && leadershipObjective.Count > 0) { foreach (Objective obj in leadershipObjective) { obj.ObjectiveSetID = item.ObjectiveSetID; obj.ObjectiveStatus = EnumObjectiveStatus.New; int id = tc.GenerateID("Objective", "ObjectiveID"); base.SetObjectID(obj, (id)); ObjectiveDA.Insert(tc, obj); } } // A fully-deferred new KPI (IsNew + OutsideOfSettings) never got a real ObjectiveID // above, so LMObjectives/ObjectiveEmployees (which need one) still can't be carried // through here - those stay dropped, same as before. Attachments are the exception: // they're staged against the ObjectiveHistory row instead (see the else branch below) // and carried through to approval by ApplyOutsideOfSettingsHistory. if (!(item.IsNew && item.OutsideOfSettings)) { if (item.Attachments.Count > 0) { foreach (var obj in item.Attachments) { if (obj.IsNew) { obj.UploadDate = DateTime.Now; obj.PMSStage = EnumPMSStage.KPISettingEmp; // Reaching here with OutsideOfSettings true only ever means the // existing-KPI edit branch above (the IsNew+OutsideOfSettings/fully // deferred case is excluded by the enclosing "if" and handled // separately below) - keep the attachment pending until the LM // decides, same as the KPI edit itself. if (item.OutsideOfSettings && outsideOfSettingsHistoryId.HasValue) { obj.ObjectiveHistoryID = outsideOfSettingsHistoryId; } else { obj.ObjectiveID = item.ID; } ObjectiveDA.InsertObjectiveAttachment(tc, obj); } } } 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); } } } else if (item.OutsideOfSettings && outsideOfSettingsHistoryId.HasValue && item.Attachments.Count > 0) { // Fully-deferred new KPI: stage any selected attachments against the // ObjectiveHistory row (ObjectiveID left at its default 0) so they surface once // the LM approves this proposal, via ApplyOutsideOfSettingsHistory. foreach (var obj in item.Attachments) { if (obj.IsNew) { obj.UploadDate = DateTime.Now; obj.PMSStage = EnumPMSStage.KPISettingEmp; obj.ObjectiveHistoryID = outsideOfSettingsHistoryId; ObjectiveDA.InsertObjectiveAttachment(tc, obj); } } } #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.lmID = item.LMID; 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 if(item.LMObjectives != null) 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) 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 = EnumObjectiveFlowStatus.Submit; objSet.OBEmpCompleteDate = DateTime.Today; objSet.obLmComplete = EnumObjectiveFlowStatus.Agreed; objSet.obLmCompleteDate = DateTime.Today; } else { oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.lmID = item.LMID; oObjectiveSet.PMPYearID = item.PMPYearID; oObjectiveSet.OBEmpComplete = EnumObjectiveFlowStatus.Submit; 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 = EnumObjectiveFlowStatus.Submit; objSet.OBEmpCompleteDate = DateTime.Today; objSet.obLmComplete = EnumObjectiveFlowStatus.Agreed; objSet.obLmCompleteDate = DateTime.Today; } else { oObjectiveSet = new ObjectiveSet(); oObjectiveSet.EmployeeID = item.EmployeeID; oObjectiveSet.lmID = item.LMID; oObjectiveSet.PMPYearID = item.PMPYearID; oObjectiveSet.OBEmpComplete = EnumObjectiveFlowStatus.Submit; 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 Update public void UpdateObjectiveStatus(Objective item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ObjectiveSet oset = new ObjectiveSet(); oset.IsEditing = true; oset.ID = item.ObjectiveSetID; if (item.ObjectiveStatus == EnumObjectiveStatus.Removed && item.OutsideOfSettings) { // Stage the removal: log it, flag the row pending, but leave the live status alone // until the LM approves it. var oldobj = new ObjectiveService().Get(tc, item.ID); oset.EmployeeID = oldobj.EmployeeID; oset.PMPYearID = oldobj.PMPYearID; ObjectiveDA.InsertHistory(tc, EnumOperationalStatus.Delete, oset, oldobj, oldobj, true); ObjectiveDA.SetObjectiveStatus(tc, item.ID, EnumObjectiveStatus.Updated); } else { ObjectiveDA.UpdateObjectiveStatus(tc, item); if (item.ObjectiveStatus == EnumObjectiveStatus.Removed) { var oldobj = new ObjectiveService().Get(tc, item.ID); oset.PMPYearID = oldobj.PMPYearID; ObjectiveDA.InsertHistory(tc, EnumOperationalStatus.Delete, oset, item, item); } } ObjectiveSetDA.UpdateEditMode(tc, oset); 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 UpdateObjectiveHistorySubmitStatus(ObjectiveSet item, bool isSubmitted) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); // isSubmitted == false is the LM's "Approve" action closing out the pending batch. // For rows staged outside of settings, actually apply the proposed change now - // legacy correction-mode rows (OutsideOfSettings = false/NULL) are untouched here, // exactly as before. if (!isSubmitted) { ApplyOutsideOfSettingsHistory(tc, item); } ObjectiveSetDA.UpdateObjectiveHistorySubmitStatus(tc, item, isSubmitted); ObjectiveSetDA.UpdateObjectiveUpdatedWFStatus(tc, item); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } /// /// One pending outside-of-settings history row, fully read into memory. Writes must never /// happen while GetPendingOutsideOfSettingsHistory's DataReader is still open - this /// connection has no MARS, so a second command on the same TransactionContext while a reader /// is open throws "There is already an open DataReader..." - so every caller reads all rows /// first via this list, closes the reader, then loops over the list to write. /// private class PendingHistoryRow { public int HistoryId; public int ChangeType; public int? ObjectiveId; public int EmployeeId; public int ObjectiveTypeId; public string NewTitle; public string NewTarget; public DateTime? NewFromDate; public DateTime? NewToDate; public double? NewWeightage; } private List ReadPendingOutsideOfSettingsHistory(TransactionContext tc, int objectiveSetId, int pmpYearId) { List rows = new List(); DataReader reader = new DataReader(ObjectiveDA.GetPendingOutsideOfSettingsHistory(tc, objectiveSetId, pmpYearId)); while (reader.Read()) { rows.Add(new PendingHistoryRow { HistoryId = reader.GetInt32("ObjectiveHistoryID", 0), ChangeType = reader.GetInt32("ChangeType", 0), ObjectiveId = reader.GetInt32("ObjectiveID"), EmployeeId = reader.GetInt32("EmployeeID", 0), ObjectiveTypeId = reader.GetInt32("ObjectiveTypeID", 0), NewTitle = reader.GetString("NewTitle"), NewTarget = reader.GetString("NewTarget"), NewFromDate = reader.GetDateTime("NewFromDate"), NewToDate = reader.GetDateTime("NewToDate"), NewWeightage = reader.GetDouble("NewWeightage") }); } reader.Close(); return rows; } private void ApplyOutsideOfSettingsHistory(TransactionContext tc, ObjectiveSet item) { List rows = ReadPendingOutsideOfSettingsHistory(tc, item.ID, item.PMPYearID); foreach (PendingHistoryRow row in rows) { if (row.ChangeType == (int)EnumOperationalStatus.Add) { // item.EmployeeID/PayrollTypeID reflect the *acting* (LM) user by the time this // reaches here (see PmpController) - the owning employee only lives on the // history row itself. Objective newObj = new Objective(); newObj.EmployeeID = row.EmployeeId; newObj.EmployeeNodeID = 0; newObj.LMID = item.lmID; newObj.ObjectiveSetID = item.ID; newObj.PMPYearID = item.PMPYearID; newObj.PayrollTypeID = item.PayrollTypeID; newObj.ObjectiveType = row.ObjectiveTypeId; newObj.KPIType = EnumObjectiveType.KPI; newObj.Title = row.NewTitle; newObj.Description = newObj.Title; newObj.MeasuresOfSuccess = row.NewTarget; newObj.StartDate = row.NewFromDate ?? DateTime.Today; newObj.EndDate = row.NewToDate ?? DateTime.Today; newObj.Weightages = row.NewWeightage ?? 0; newObj.ObjectiveStatus = EnumObjectiveStatus.No_Change; int newId = tc.GenerateID("Objective", "ObjectiveID"); base.SetObjectID(newObj, newId); ObjectiveDA.Insert(tc, newObj); ObjectiveDA.UpdateHistoryObjectiveID(tc, row.HistoryId, newId); // Any attachments staged against this history row while it was pending now belong // to the KPI that just came into existence. ObjectiveDA.ReassignObjectiveAttachmentsToObjective(tc, row.HistoryId, newId); } else if (row.ChangeType == (int)EnumOperationalStatus.Edit && row.ObjectiveId.HasValue) { ObjectiveDA.ApplyHistoryEditToObjective(tc, row.ObjectiveId.Value, row.NewTitle, row.NewTarget, row.NewFromDate, row.NewToDate, row.NewWeightage); // Same as above, but the KPI already existed - attachments staged during the edit // move onto it too. ObjectiveDA.ReassignObjectiveAttachmentsToObjective(tc, row.HistoryId, row.ObjectiveId.Value); } else if (row.ChangeType == (int)EnumOperationalStatus.Delete && row.ObjectiveId.HasValue) { ObjectiveDA.SetObjectiveStatus(tc, row.ObjectiveId.Value, EnumObjectiveStatus.Removed); } ObjectiveDA.SetHistoryDecision(tc, row.HistoryId, true, null, item.ModifiedBy.GetValueOrDefault()); } } public void RejectObjectiveHistory(ObjectiveSet item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); List rows = ReadPendingOutsideOfSettingsHistory(tc, item.ID, item.PMPYearID); foreach (PendingHistoryRow row in rows) { // Add rows never touched Objective - nothing to undo. Edit/Delete rows only ever // got their pending "Updated" status flag - clear it, the live content was never // changed. if ((row.ChangeType == (int)EnumOperationalStatus.Edit || row.ChangeType == (int)EnumOperationalStatus.Delete) && row.ObjectiveId.HasValue) { ObjectiveDA.SetObjectiveStatus(tc, row.ObjectiveId.Value, EnumObjectiveStatus.No_Change); } // Whatever was staged (new KPI or an edit) never took effect, so any attachments // staged alongside it - only ever linked via ObjectiveHistoryID, never a real // ObjectiveID - are discarded too. No-op if none were added. ObjectiveDA.DeleteObjectiveAttachmentsByHistoryID(tc, row.HistoryId); ObjectiveDA.SetHistoryDecision(tc, row.HistoryId, false, item.ObjectiveUpdateRejectRemarks, item.ModifiedBy.GetValueOrDefault()); } ObjectiveSetDA.UpdateObjectiveHistorySubmitStatus(tc, item, false); ObjectiveSetDA.UpdateObjectiveUpdatedWFStatus(tc, item); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public DataTable GetObjectiveHistoryStatus(int objectiveSetId) { TransactionContext tc = null; DataTable dt = null; try { tc = TransactionContext.Begin(); dt = ObjectiveDA.GetObjectiveHistoryStatus(tc, objectiveSetId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dt; } public DataTable GetObjectiveHistoryWeightage(int objectiveSetId) { TransactionContext tc = null; DataTable dt = null; try { tc = TransactionContext.Begin(); dt = ObjectiveDA.GetObjectiveHistoryWeightage(tc, objectiveSetId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dt; } public void DismissObjectiveHistory(int objectiveHistoryId) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ObjectiveDA.DismissObjectiveHistory(tc, objectiveHistoryId); 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 { ObjectiveSet obset = new ObjectiveSetService().GetSetByObjectiveID(id); if(obset.OBEmpComplete == EnumObjectiveFlowStatus.Submit) { 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 PMSObjectiveProgressAttachmentDA.DeleteByObjectiveID(tc, id); PMSObjectiveProgressDA.DeleteByObjectiveID(tc, id); 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 DeletebyObjectiveSetIDs(string objectiveSetID) { 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.DeletebyObjectiveSetIDs(tc, objectiveSetID); 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 DeleteObjByEmpIDsAndPMPYear(int yearID, string empIds) { 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.DeleteObjByEmpIDsAndPMPYear(tc, yearID, empIds); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #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 GetObjectiveByYear(int PMPYearID) { DataSet allData = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); allData = ObjectiveDA.GetObjectiveByYear(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 getPMSReportDataByUserType(int pmpYearID, int pmsReportType, string userType, string emps, int userId) { DataSet dataSet = new DataSet(); TransactionContext tc = null; try { tc = TransactionContext.Begin(true); dataSet = ObjectiveDA.getPMSReportDataByUserType(tc, pmpYearID, pmsReportType, userType, emps, userId); 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; } public List GetObjectiveFromHistory(int objectiveSetId) { List updatedObjectives = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(ObjectiveDA.GetObjectiveSet(tc, objectiveSetId)); List oObjectives = this.CreateObjects(oreader); oreader.Close(); oreader = new DataReader(ObjectiveDA.GetObjectiveHistorySubmitted(tc, objectiveSetId)); while (oreader.Read()) { int objectiveId = (int)oreader.GetInt32("ObjectiveID"); Objective obj = oObjectives.Find(o => o.ID == objectiveId); updatedObjectives.Add(obj); } //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 updatedObjectives; } public DataTable GetObjectiveFromHistoryDT(int objectiveSetId) { TransactionContext tc = null; DataTable dt = null; try { tc = TransactionContext.Begin(); dt = ObjectiveDA.GetObjectiveFromHistoryDT(tc, objectiveSetId); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return dt; } public decimal GetYearRating(int employeeId, int pmpYearId) { decimal rating = 0; TransactionContext tc = null; try { tc = TransactionContext.Begin(); object result = ObjectiveDA.GetYearRating(tc, employeeId, pmpYearId); rating = (result == null || result == DBNull.Value) ? 0 : Convert.ToDecimal(result); tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return rating; } #region ObjectiveAttachment private void MapObject(ObjectiveAttachment item, DataReader oReader) { SetObjectID(item, oReader.GetInt32("AttachmentID", 0)); item.ObjectiveID = oReader.GetInt32("ObjectiveID", 0); item.Filetype = oReader.GetString("Filetype"); item.FileName = oReader.GetString("FileName"); item.UploadDate = oReader.GetDateTime("UploadDate").HasValue ? oReader.GetDateTime("UploadDate").Value : DateTime.MinValue; item.FileData = oReader.GetLob("FileData"); item.PMSStage = (EnumPMSStage)oReader.GetInt32("PMSStage").GetValueOrDefault(); item.ObjectiveHistoryID = oReader.GetInt32("ObjectiveHistoryID"); } public List GetObjectiveAttachments(int objectiveId) { List list = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ObjectiveDA.GetObjectiveAttachments(tc, objectiveId)); while (dr.Read()) { ObjectiveAttachment item = new ObjectiveAttachment(); MapObject(item, dr); list.Add(item); } dr.Close(); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } return list; } public List GetObjectiveAttachmentsByHistoryID(int objectiveHistoryId) { List list = new List(); TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(ObjectiveDA.GetObjectiveAttachmentsByHistoryID(tc, objectiveHistoryId)); while (dr.Read()) { ObjectiveAttachment item = new ObjectiveAttachment(); MapObject(item, dr); list.Add(item); } dr.Close(); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } return list; } public int InsertObjectiveAttachment(ObjectiveAttachment item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ObjectiveDA.InsertObjectiveAttachment(tc, item); tc.End(); return item.ID; } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } public ObjectiveAttachment GetObjectiveAttachmentFileData( int attachmentid) { TransactionContext tc = null; ObjectiveAttachment attachment = null; try { tc = TransactionContext.Begin(true); DataReader oreader = new DataReader(ObjectiveDA.GetObjectiveAttachmentFileData(tc, attachmentid)); if (oreader.Read()) { attachment = this.CreateObjectAttachment(oreader); } oreader.Close(); tc.End(); return attachment; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void DeleteObjectiveAttachmentByID(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); ObjectiveDA.DeleteObjectiveAttachmentByID(tc, id); tc.End(); } catch (Exception e) { if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); } } #endregion } }