using System; using System.Collections.Generic; using System.Linq; using System.Text; using Payroll.BO; using Ease.CoreV35.DataAccess; using Ease.CoreV35.Model; using Ease.CoreV35; using System.Data; namespace Payroll.Service { public class PMPProcessService : ServiceTemplate, IPMPProcessService { #region Object Mapping #region PMPProcess Object Mapping private void MapPMPProcessObject(PMPProcess oPMPProcess, DataReader oReader) { SetObjectID(oPMPProcess, oReader.GetID("PMPProcessID")); oPMPProcess.PmpYear = oReader.GetDateTime("PmpYear").Value; oPMPProcess.Description = oReader.GetString("Description"); oPMPProcess.TargetSettingFrom = oReader.GetDateTime("TargetSettingFrom").Value; oPMPProcess.TargetSettingTo = oReader.GetDateTime("TargetSettingTo").Value; oPMPProcess.MedianAppraisalFrom = oReader.GetDateTime("MedianAppraisalFrom").Value; oPMPProcess.MedianAppraisalTo = oReader.GetDateTime("MedianAppraisalTo").Value; oPMPProcess.FinalApprovalFrom = oReader.GetDateTime("FinalApprovalFrom").Value; oPMPProcess.FinalApprovalTo = oReader.GetDateTime("FinalApprovalTo").Value; oPMPProcess.IsFinalize = oReader.GetBoolean("IsFinalize").Value; oPMPProcess.CreatedBy = oReader.GetID("CreadtedBy"); oPMPProcess.CreatedDate = oReader.GetDateTime("CreationDate").Value; oPMPProcess.ModifiedBy = oReader.GetID("ModifiedBy") == null ? null : oReader.GetID("ModifiedBy"); oPMPProcess.ModifiedDate = oReader.GetDateTime("ModifiedDate") == null ? DateTime.MinValue : oReader.GetDateTime("ModifiedDate"); oPMPProcess.Status = (EnumStatus)oReader.GetInt32("Status"); oPMPProcess.Sequence = (int)oReader.GetInt32("Sequence"); oPMPProcess.PmpStatus = (PMPStatus)oReader.GetInt32("PmpStatus"); this.SetObjectState(oPMPProcess, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PMPProcess oPMPProcess = new PMPProcess(); MapPMPProcessObject(oPMPProcess, oReader); return oPMPProcess as T; } #endregion #region PMPTargetSetting Object Mapping private void MapPMPTargetSettingObject(PMPTargetSetting oPMPTargetSetting, DataReader oReader) { SetObjectID(oPMPTargetSetting, oReader.GetID("PMPTargetSettingId")); oPMPTargetSetting.PmpEmployeeRatingID = oReader.GetID("PmpEmployeeRatingID") == null ? null : oReader.GetID("PmpEmployeeRatingID"); oPMPTargetSetting.PmpProcessId = oReader.GetID("PmpProcessId"); oPMPTargetSetting.EmployeeID = oReader.GetID("EmployeeID"); oPMPTargetSetting.Objective = oReader.GetString("Objective"); oPMPTargetSetting.ObjectivePercent = oReader.GetDouble("ObjectivePercent").Value; if (oReader.GetDateTime("TargetDate") == null) { oPMPTargetSetting.TargetDate = DateTime.MinValue; } else oPMPTargetSetting.TargetDate = oReader.GetDateTime("TargetDate").Value; oPMPTargetSetting.SelfComments = oReader.GetString("SelfComments") == null ? String.Empty : oReader.GetString("SelfComments"); oPMPTargetSetting.SelfRatingID = oReader.GetID("SelfRatingID") == null ? null : oReader.GetID("SelfRatingID"); //oPMPTargetSetting.Sequence = oReader.GetInt32("Sequence").Value; oPMPTargetSetting.EvaluationCriteria = oReader.GetString("EvaluationCriteria") == null ? String.Empty : oReader.GetString("EvaluationCriteria"); oPMPTargetSetting.ApprovarID = oReader.GetID("ApprovarID") == null ? null : oReader.GetID("ApprovarID"); oPMPTargetSetting.ApprovarComments = oReader.GetString("ApprovarComments") == null ? String.Empty : oReader.GetString("ApprovarComments"); oPMPTargetSetting.ApprovarRatingID = oReader.GetID("ApprovarRatingID") == null ? null : oReader.GetID("ApprovarRatingID"); this.SetObjectState(oPMPTargetSetting, ObjectState.Saved); } protected ObjectsTemplate CreatePMPTargetSettingObject(DataReader oReader) { ObjectsTemplate allPMPTargetSettings = new ObjectsTemplate(); while (oReader.Read()) { PMPTargetSetting oPMPTargetSetting = new PMPTargetSetting(); MapPMPTargetSettingObject(oPMPTargetSetting, oReader); allPMPTargetSettings.Add(oPMPTargetSetting); } return allPMPTargetSettings; } #endregion #region PMPValueBehaviorRating Object Mapping private void MapPMPValueBehaviorRatingObject(PMPValueBehaviorRating oPMPValueBehaviorRating, DataReader oReader) { SetObjectID(oPMPValueBehaviorRating, oReader.GetID("PMPValueBehaviorRatingId")); oPMPValueBehaviorRating.PmpEmployeeRatingID = oReader.GetID("PmpEmployeeRatingID"); oPMPValueBehaviorRating.PMPValueBehaviorID = oReader.GetID("PMPValueBehaviorID") == null ? null : oReader.GetID("PMPValueBehaviorID"); oPMPValueBehaviorRating.EmployeeID = oReader.GetID("EmployeeID"); oPMPValueBehaviorRating.SelfComments = oReader.GetString("SelfComments") == null ? string.Empty : oReader.GetString("SelfComments"); oPMPValueBehaviorRating.SelfRatingID = oReader.GetID("SelfRatingID") == null ? null : oReader.GetID("SelfRatingID"); oPMPValueBehaviorRating.ApprovarComments = oReader.GetString("ApprovarComments") == null ? string.Empty : oReader.GetString("ApprovarComments"); oPMPValueBehaviorRating.ApprovarRatingID = oReader.GetID("ApprovarRatingID") == null ? null : oReader.GetID("ApprovarRatingID"); oPMPValueBehaviorRating.PmpProcessId = oReader.GetID("PmpProcessID") == null ? null : oReader.GetID("PmpProcessID"); this.SetObjectState(oPMPValueBehaviorRating, ObjectState.Saved); } protected ObjectsTemplate CreatePMPValueBehaviorRatingObject(DataReader oReader) { ObjectsTemplate allPMPValueBehaviorRatings = new ObjectsTemplate(); while (oReader.Read()) { PMPValueBehaviorRating oPMPValueBehaviorRating = new PMPValueBehaviorRating(); MapPMPValueBehaviorRatingObject(oPMPValueBehaviorRating, oReader); allPMPValueBehaviorRatings.Add(oPMPValueBehaviorRating); } return allPMPValueBehaviorRatings; } #endregion #region PMPEmployeeRating Object Mapping private void MapPMPEmployeeRatingObject(PMPEmployeeRating oPMPEmployeeRating, DataReader oReader) { SetObjectID(oPMPEmployeeRating, oReader.GetID("PMPEmployeeRatingId")); oPMPEmployeeRating.HrValueBehaValueBehaviorRatingID = oReader.GetID("HrValueBehaValueBehaviorRatingID") == null ? null : oReader.GetID("HrValueBehaValueBehaviorRatingID"); oPMPEmployeeRating.HrTargetSettingRatingID = oReader.GetID("HrTargetSettingRatingID") == null ? null : oReader.GetID("HrTargetSettingRatingID"); oPMPEmployeeRating.PmpProcessID = oReader.GetID("PmpProcessID"); oPMPEmployeeRating.EmployeeID = oReader.GetID("EmployeeID"); oPMPEmployeeRating.SelfObjectRatingID = oReader.GetID("SelfObjectRatingID") == null ? null : oReader.GetID("SelfObjectRatingID"); oPMPEmployeeRating.ApprovarObjectRatingID = oReader.GetID("ApprovarObjectRatingID") == null ? null : oReader.GetID("ApprovarObjectRatingID"); oPMPEmployeeRating.ApprovarID = oReader.GetID("ApprovarID") == null ? null : oReader.GetID("ApprovarID"); oPMPEmployeeRating.SelfValueBehaviorRatingID = oReader.GetID("SelfValueBehaviorRatingID") == null ? null : oReader.GetID("SelfValueBehaviorRatingID"); oPMPEmployeeRating.AppValueBehaviorRatingID = oReader.GetID("AppValueBehaviorRatingID") == null ? null : oReader.GetID("AppValueBehaviorRatingID"); oPMPEmployeeRating.IsTargetSettingDone = oReader.GetBoolean("IsTargetSettingDone").Value; oPMPEmployeeRating.IsMedianDone = oReader.GetBoolean("IsMedianDone").Value; oPMPEmployeeRating.IsValueBehaviorDone = oReader.GetBoolean("IsValueBehaviorDone").Value; oPMPEmployeeRating.PmpStatus = (PMPStatus)oReader.GetInt32("PmpStatus"); if (oReader.GetInt32("PmpWFStatus") != null) oPMPEmployeeRating.PmpWFStatus = (PMPWFStatus)oReader.GetInt32("PmpWFStatus"); oPMPEmployeeRating.RemarksByHR = oReader.GetString("RemarksByHR") == null ? String.Empty : oReader.GetString("RemarksByHR"); oPMPEmployeeRating.IncrementedPercentByHR = oReader.GetDouble("IncrementedPercentByHR") == null ? Double.MinValue : oReader.GetDouble("IncrementedPercentByHR").Value; oPMPEmployeeRating.IsFinalized = oReader.GetBoolean("IsFinalized") == null ? false : oReader.GetBoolean("IsFinalized").Value; this.SetObjectState(oPMPEmployeeRating, ObjectState.Saved); } protected ObjectsTemplate CreatePMPEmployeeRatingObject(DataReader oReader) { ObjectsTemplate allPMPEmployeeRatings = new ObjectsTemplate(); while (oReader.Read()) { PMPEmployeeRating oPMPEmployeeRating = new PMPEmployeeRating(); MapPMPEmployeeRatingObject(oPMPEmployeeRating, oReader); allPMPEmployeeRatings.Add(oPMPEmployeeRating); } return allPMPEmployeeRatings; } #endregion #endregion #region IPMPProcessService Members #region Save PMPProcess public ID Save(PMPProcess item) { PMPProcess Prvmpm = null; if (item.IsNew == false) { Prvmpm = PMPProcess.GetByPMPProcessID(item.ID); } TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("PMP_Process", "PMPProcessID"); int sequenceNo = tc.GenerateID("PMP_Process", "Sequence"); item.Sequence = sequenceNo; base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPProcessItem(tc, item); } else { PMPProcessDA.UpdatePMPProcessItem(tc, item); if (Prvmpm.PmpStatus != item.PmpStatus) { PMPProcessDA.UpdatePMPStatus(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 } } #endregion #region Save PMPEmployeeRating Object public ID SavePMPEmployeeRating(PMPEmployeeRating item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("PMP_EmployeeRating", "PMPEmployeeRatingId"); base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPEmployeeRatingItem(tc, item); } else { PMPProcessDA.UpdatePMPEmployeeRatingItem(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 } } #endregion #region Save PMPTargetSetting Object public ID SavePMPTargetSetting(PMPTargetSetting item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("PMP_TargetSetting", "PMPTargetSettingId"); base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPTargetSettingItem(tc, item); } else { PMPProcessDA.UpdatePMPTargetSettingItem(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 } } #endregion #region SaveSinglePMPEmployeeRatingObject // public void SaveSinglePMPEmployeeRatingObject(PMPEmployeeRating obPmpempRating) { TransactionContext tc = null; try { ID obID = null; tc = TransactionContext.Begin(true); if (obPmpempRating.IsNew) { int id = tc.GenerateID("PMP_EmployeeRating", "PMPEmployeeRatingId"); obID = ID.FromInteger(id); base.SetObjectID(obPmpempRating, ID.FromInteger(id)); PMPProcessDA.InsertPMPEmployeeRatingItem(tc, obPmpempRating); } else { obID = obPmpempRating.ID; PMPProcessDA.UpdatePMPEmployeeRatingItem(tc,obPmpempRating); PMPProcessDA.DeleteAllPmpTargetSetting(tc, obPmpempRating.EmployeeID, obPmpempRating.PmpProcessID); PMPProcessDA.DeleteValueBehaviorRating(tc, obPmpempRating.EmployeeID, obPmpempRating.PmpProcessID); } // PMPProcessDA.DeleteAllPmpTargetSetting(tc,obPmpempRating.EmployeeID, obPmpempRating.PmpProcessID); ObjectsTemplate allSettings = obPmpempRating.OPMPTargetSettings; ObjectsTemplate allValueBehaviorRatings = obPmpempRating.OPMPValueBehaviorRatings; if (allSettings != null ) { foreach (PMPTargetSetting item in allSettings) { //if (item.IsNew) //{ int id = tc.GenerateID("PMP_TargetSetting", "PMPTargetSettingId"); base.SetObjectID(item, ID.FromInteger(id)); item.PmpEmployeeRatingID = obPmpempRating.ID; PMPProcessDA.InsertPMPTargetSettingItem(tc, item); //} //else //{ // item.PmpEmployeeRatingID = obID; // PMPProcessDA.UpdatePMPTargetSettingItem(tc, item); //} } } if (allValueBehaviorRatings!=null ) { foreach (PMPValueBehaviorRating item in allValueBehaviorRatings) { //if (item.IsNew) //{ int id = tc.GenerateID("PMP_ValueBehaviorRating", "PMPValueBehaviorRatingId"); base.SetObjectID(item, ID.FromInteger(id)); item.PmpEmployeeRatingID = obPmpempRating.ID; PMPProcessDA.InsertPMPValueBehaviorRatingItem(tc, item); //} //else //{ // item.PmpEmployeeRatingID = obID; // PMPProcessDA.UpdatePMPValueBehaviorRatingItem(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 } } #endregion #region SaveAllPMPTargetSettings public void SaveAllPMPTargetSettings(ObjectsTemplate allSettings) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (PMPTargetSetting item in allSettings) { if (item.IsNew) { int id = tc.GenerateID("PMP_TargetSetting", "PMPTargetSettingId"); base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPTargetSettingItem(tc, item); } else { PMPProcessDA.UpdatePMPTargetSettingItem(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 } } #endregion #region SavePMPValueBehaviorRating Object public ID SavePMPValueBehaviorRating(PMPValueBehaviorRating item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("PMP_ValueBehaviorRating", "PMPValueBehaviorRatingId"); base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPValueBehaviorRatingItem(tc, item); } else { PMPProcessDA.UpdatePMPValueBehaviorRatingItem(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 } } #endregion #region SaveAllPMPValueBehaviorRaings public void SaveAllPMPValueBehaviorRaings(ObjectsTemplate allValueBehaviorRatings) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (PMPValueBehaviorRating item in allValueBehaviorRatings) { if (item.IsNew) { int id = tc.GenerateID("PMP_ValueBehaviorRating", "PMPValueBehaviorRatingId"); base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPValueBehaviorRatingItem(tc, item); } else { PMPProcessDA.UpdatePMPValueBehaviorRatingItem(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 } } #endregion #region Update public void Update(PMPProcess item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PMPProcessDA.Delete(tc, 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 } } #endregion #region Delete public void Delete(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PMPProcessDA.DeletePmpTargetSettingsByPMPId(id,tc); PMPProcessDA.DeletePmpValueBehaviorRatingByPMPId(id, tc); PMPProcessDA.DeletePmpEmployeeRatingByPMPIDd(id, tc); PMPProcessDA.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 #region GetPMPEmployeeRatingByPMPProcessID public PMPEmployeeRating GetPMPEmployeeRatingByPMPProcessID(ID id) { ObjectsTemplate allPMPEmployeeRatings= null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetEmployeeRatingById(tc,id)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 } if (allPMPEmployeeRatings.Count == 1) return allPMPEmployeeRatings[0]; else return null; } #endregion #region GetPmpEmployeeRatingByEmployeeIdAndPmpProcessId public PMPEmployeeRating GetPmpEmployeeRatingByEmployeeIdAndPmpProcessId(ID empId, ID pmpProcessId) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetPmpEmployeeRatingByEmployeeIdAndPmpProcessId(tc, empId, pmpProcessId)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 } if (allPMPEmployeeRatings.Count == 1) return allPMPEmployeeRatings[0]; else return null; } #endregion #region GetPmpTargetSettingByPmpTargetSettingId public PMPTargetSetting GetPmpTargetSettingByPmpTargetSettingId(ID Id) { ObjectsTemplate allPMPTargetSettings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetPmpTargetSettingByPmpTargetSettingId(tc, Id)); allPMPTargetSettings = this.CreatePMPTargetSettingObject(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 } if (allPMPTargetSettings.Count == 1) return allPMPTargetSettings[0]; else return null; } #endregion #region GetPMPTargetSettingsByEmployeeId public ObjectsTemplate GetPMPTargetSettingsByEmployeeIdAndPMPProcessID(ID id,ID pmpProcessID) { ObjectsTemplate allPMPTargetSettings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetPMPTargetSettingsByEmployeeIdAndPMPProcessID(tc, id, pmpProcessID)); allPMPTargetSettings = this.CreatePMPTargetSettingObject(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 allPMPTargetSettings; } #endregion #region GetAllPMPTargetSettings public ObjectsTemplate GetAllPMPTargetSettings() { ObjectsTemplate allPMPTargetSettings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetAllPMPTargetSettings(tc)); allPMPTargetSettings = this.CreatePMPTargetSettingObject(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 allPMPTargetSettings; } #endregion #region GetPmpValueBehaviorRatingById public PMPValueBehaviorRating GetPmpValueBehaviorRatingById(ID Id) { ObjectsTemplate allPMPValueBehaviorRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetPmpValueBehaviorRatingById(tc, Id)); allPMPValueBehaviorRatings = this.CreatePMPValueBehaviorRatingObject(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 } if (allPMPValueBehaviorRatings.Count == 1) return allPMPValueBehaviorRatings[0]; else return null; } #endregion #region GetValueBehaviorRatingsByEmployeeIdAndPmpProcessId public ObjectsTemplate GetValueBehaviorRatingsByEmployeeIdAndPmpProcessId(ID empId, ID pmpProcessId) { ObjectsTemplate allPMPValueBehaviorRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetValueBehaviorRatingsByEmployeeIdAndPmpProcessId(tc, empId, pmpProcessId)); allPMPValueBehaviorRatings = this.CreatePMPValueBehaviorRatingObject(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 } if (allPMPValueBehaviorRatings.Count > 0) return allPMPValueBehaviorRatings; else return null; } #endregion #region GetAllPmpProcess public ObjectsTemplate Get(EnumStatus status) { ObjectsTemplate oPMPProcesses = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.Get(tc, status)); oPMPProcesses = 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 oPMPProcesses; } #endregion #region GetPmpProcessByPmpProcesId public PMPProcess GetPmpProcessByPmpProcesId(ID id) { ObjectsTemplate oPMPProcesses = null; TransactionContext tc = null; PMPProcess obPMPProcess = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetByPMPProcessId(tc, id)); oPMPProcesses = 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 } if (oPMPProcesses.Count == 1) { return oPMPProcesses[0]; } else return obPMPProcess; } #endregion #region DeletePMPTargetSettingById public void DeletePMPTargetSettingById(ID id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PMPProcessDA.DeletePMPTargetSettingById(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 #region GetByPMPProcessID public PMPProcess GetByPMPProcessID(ID id) { ObjectsTemplate allPMPProcesses = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetByPMPProcessID(tc, id)); allPMPProcesses = 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 allPMPProcesses[0]; } public PMPProcess Get(DateTime pmpYear) { ObjectsTemplate allPMPProcesses = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.Get(tc, pmpYear)); allPMPProcesses = 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 allPMPProcesses[0]; } #endregion #region GetPmpEmployeeRatingByRatingId public PMPEmployeeRating GetPmpEmployeeRatingByRatingId(ID ratingId) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetPmpEmployeeRatingByRatingId(tc, ratingId)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 } if (allPMPEmployeeRatings.Count == 1) return allPMPEmployeeRatings[0]; else return null; } #endregion #region GetEmployeeRating public ObjectsTemplate GetEmployeeRating(ID processID) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetEmployeeRating(tc, processID)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 allPMPEmployeeRatings; } #endregion #region GetEmployeeRating public PMPEmployeeRating GetEmployeeRating(ID employeeID, ID processID) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetPmpEmployeeRatingByEmployeeIdAndPmpProcessId(tc, employeeID, processID)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 } if (allPMPEmployeeRatings.Count == 1) return allPMPEmployeeRatings[0]; else return null; } #endregion #region DeleteAllPmpTargetSettings public void DeleteAllPmpTargetSettings(ObjectsTemplate allSettings) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (PMPTargetSetting obDelObj in allSettings) { if (!obDelObj.IsNew) PMPProcessDA.DeletePMPTargetSettingById(tc, obDelObj.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 #region GetEmployeeRating public ObjectsTemplate GetEmployeeRating(ID pmpProcessId, PMPStatus pmpStatus, PMPWFStatus status) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetEmployeeRating(tc, pmpProcessId, pmpStatus, status)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 allPMPEmployeeRatings; } #endregion #region GetEmployeeRatingForDraft public ObjectsTemplate GetEmployeeRatingForDraft(ID pmpProcessId) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPProcessDA.GetEmployeeRatingForDraft(tc, pmpProcessId)); allPMPEmployeeRatings = this.CreatePMPEmployeeRatingObject(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 allPMPEmployeeRatings; } #endregion #region GetEmployeeRatingForNotInitiate public ObjectsTemplate GetEmployeeRatingForNotInitiate(ID pmpProcessId, PMPStatus pmpStatus) { ObjectsTemplate allPMPEmployeeRatings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataSet ds = PMPProcessDA.GetEmployeeRatingForNotInitiate(tc, pmpProcessId, pmpStatus); if (ds.Tables[0].Rows.Count >= 1) allPMPEmployeeRatings = new ObjectsTemplate(); foreach (DataRow dr in ds.Tables[0].Rows) { PMPEmployeeRating obEmpRating = new PMPEmployeeRating(); obEmpRating.EmployeeID = ID.FromInteger(Convert.ToInt32(dr["EmployeeID"])); obEmpRating.PmpProcessID = pmpProcessId; allPMPEmployeeRatings.Add(obEmpRating); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return allPMPEmployeeRatings; } #endregion #region SavePMPEmployeeRatingObject(PMPEmployeeRating obPmpempRating) public void SavePMPEmployeeRatingObject(PMPEmployeeRating obPmpempRating) { TransactionContext tc = null; try { ID obID = null; tc = TransactionContext.Begin(true); ObjectsTemplate allSettings = obPmpempRating.OPMPTargetSettings; ObjectsTemplate allValueBehaviorRatings = obPmpempRating.OPMPValueBehaviorRatings; if (obPmpempRating.IsNew) { int id = tc.GenerateID("PMP_EmployeeRating", "PMPEmployeeRatingId"); obID = ID.FromInteger(id); base.SetObjectID(obPmpempRating, ID.FromInteger(id)); PMPProcessDA.InsertPMPEmployeeRatingItem(tc, obPmpempRating); } else { obID = obPmpempRating.ID; PMPProcessDA.UpdatePMPEmployeeRatingItem(tc, obPmpempRating); if(allSettings != null)PMPProcessDA.DeleteAllPmpTargetSetting(tc, obPmpempRating.EmployeeID, obPmpempRating.PmpProcessID); if(allValueBehaviorRatings != null)PMPProcessDA.DeleteValueBehaviorRating(tc, obPmpempRating.EmployeeID, obPmpempRating.PmpProcessID); } // PMPProcessDA.DeleteAllPmpTargetSetting(tc,obPmpempRating.EmployeeID, obPmpempRating.PmpProcessID); if (allSettings != null) { foreach (PMPTargetSetting item in allSettings) { //if (item.IsNew) //{ int id = tc.GenerateID("PMP_TargetSetting", "PMPTargetSettingId"); base.SetObjectID(item, ID.FromInteger(id)); item.PmpEmployeeRatingID = obPmpempRating.ID; PMPProcessDA.InsertPMPTargetSettingItem(tc, item); //} //else //{ // item.PmpEmployeeRatingID = obID; // PMPProcessDA.UpdatePMPTargetSettingItem(tc, item); //} } } if (allValueBehaviorRatings != null) { foreach (PMPValueBehaviorRating item in allValueBehaviorRatings) { //if (item.IsNew) //{ int id = tc.GenerateID("PMP_ValueBehaviorRating", "PMPValueBehaviorRatingId"); base.SetObjectID(item, ID.FromInteger(id)); item.PmpEmployeeRatingID = obPmpempRating.ID; PMPProcessDA.InsertPMPValueBehaviorRatingItem(tc, item); //} //else //{ // item.PmpEmployeeRatingID = obID; // PMPProcessDA.UpdatePMPValueBehaviorRatingItem(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 } } #endregion #region SavePMPValueBehaviorRating(PMPValueBehaviorRating item) public void SavePMPValueBehaviorRatingItem(PMPValueBehaviorRating item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if(item.IsNew) { int id = tc.GenerateID("PMP_ValueBehaviorRating", "PMPValueBehaviorRatingId"); base.SetObjectID(item, ID.FromInteger(id)); PMPProcessDA.InsertPMPValueBehaviorRatingItem(tc, item); } else { PMPProcessDA.UpdatePMPValueBehaviorRatingItem(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 } } #endregion #endregion } }