using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using Ease.Core.Model; using Ease.Core.DataAccess; using Ease.Core; using Ease.Core.Utility; using HRM.BO; using static iTextSharp.text.pdf.AcroFields; using Microsoft.Data.SqlClient; namespace HRM.DA { public class PMPValueBehaviorSettingService : ServiceTemplate, IPMPValueBehaviorSettingService { #region Object Mapping private void MapObject(PMPValueBehaviorSetting oPMPValueBehaviorSetting, DataReader oReader) { SetObjectID(oPMPValueBehaviorSetting, oReader.GetInt32("PMPValueBehaviorSettingId", 0)); oPMPValueBehaviorSetting.ObjectiveSetID = oReader.GetInt32("ObjectiveSetID", 0); oPMPValueBehaviorSetting.PMPValueBehaviorID = oReader.GetInt32("PMPValueBehaviorID", 0); oPMPValueBehaviorSetting.TargetRating = oReader.GetInt32("TargetRating", 0); oPMPValueBehaviorSetting.EmpComments = oReader.GetString("EmpComments", null); oPMPValueBehaviorSetting.LmComments = oReader.GetString("LMComments", null); oPMPValueBehaviorSetting.EmpCommentsDate = oReader.GetDateTime("EmpCommentsDate"); oPMPValueBehaviorSetting.LmCommentDate = oReader.GetDateTime("LmCommentDate"); oPMPValueBehaviorSetting.MyEmpComments = oReader.GetString("MYEmpComments", null); oPMPValueBehaviorSetting.MyLMComments = oReader.GetString("MYLMComments", null); oPMPValueBehaviorSetting.MyEmpCommentsDate = oReader.GetDateTime("MYEmpCommentsDate"); oPMPValueBehaviorSetting.MyLMCommentDate = oReader.GetDateTime("MYEmpCommentsDate"); oPMPValueBehaviorSetting.YeEmpRating = oReader.GetInt32("YEEmpRating").HasValue ? oReader.GetInt32("YEEmpRating").Value : null; oPMPValueBehaviorSetting.YeLMRating = oReader.GetInt32("YELMRating").HasValue ? oReader.GetInt32("YELMRating").Value : null; oPMPValueBehaviorSetting.YeEmpComments = oReader.GetString("YEEmpComments", null); oPMPValueBehaviorSetting.YeLMComments = oReader.GetString("YELMComments", null); oPMPValueBehaviorSetting.YeEmpCommentsDate = oReader.GetDateTime("YEEmpCommentsDate"); oPMPValueBehaviorSetting.YeLMCommentDate = oReader.GetDateTime("YELMCommentDate"); this.SetObjectState(oPMPValueBehaviorSetting, ObjectState.Saved); } protected override T CreateObject(DataReader oReader) { PMPValueBehaviorSetting oPMPValueBehaviorSetting = new PMPValueBehaviorSetting(); MapObject(oPMPValueBehaviorSetting, oReader); return oPMPValueBehaviorSetting as T; } #endregion #region Service Implementation #region Get By ID public PMPValueBehaviorSetting Get(int id) { List oPMPValueBehaviorSettings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPValueBehaviorSettingDA.Get(tc, id)); oPMPValueBehaviorSettings = 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 (oPMPValueBehaviorSettings.Count == 1) return oPMPValueBehaviorSettings[0]; else return null; } #endregion #region Get All public List Get() { List oPMPValueBehaviorSettings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPValueBehaviorSettingDA.Get(tc)); oPMPValueBehaviorSettings = 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 (oPMPValueBehaviorSettings.Count == 1) return oPMPValueBehaviorSettings[0]; //else return null; return oPMPValueBehaviorSettings; } #endregion #region Get Others public List GetByObjectiveSetID(int objectiveSetId) { List oPMPValueBehaviorSettings = null; TransactionContext tc = null; try { tc = TransactionContext.Begin(); DataReader oreader = new DataReader(PMPValueBehaviorSettingDA.GetByObjectiveSetID(tc, objectiveSetId)); oPMPValueBehaviorSettings = 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 (oPMPValueBehaviorSettings.Count == 1) return oPMPValueBehaviorSettings[0]; //else return null; return oPMPValueBehaviorSettings; } #endregion #region Insert public int Save(PMPValueBehaviorSetting item) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); if (item.IsNew) { int id = tc.GenerateID("PMP_ValueBehavior", "PMPValueBehaviorSettingID"); int sequenceNo = tc.GenerateID("PMP_ValueBehavior", "Sequence"); item.Sequence = sequenceNo; base.SetObjectID(item, (id)); PMPValueBehaviorSettingDA.Insert(tc, item); } else { PMPValueBehaviorSettingDA.Update(tc, item); } tc.End(); return item.ID; } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } public void Save(List items) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); foreach (PMPValueBehaviorSetting item in items) { if (item.IsNew) { PMPValueBehaviorSettingDA.DeleteByPMPValueBehaviorId(tc, item.PMPValueBehaviorID, item.ObjectiveSetID); int id = tc.GenerateID("PMP_ValueBehaviorSetting", "PMPValueBehaviorSettingID"); int sequenceNo = tc.GenerateID("PMP_ValueBehavior", "Sequence"); item.Sequence = sequenceNo; base.SetObjectID(item, (id)); PMPValueBehaviorSettingDA.Insert(tc, item); } else { PMPValueBehaviorSettingDA.Update(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 } return; } public void Save(TransactionContext tc, List items) { try { if(items != null && items.Count > 0) { PMPValueBehaviorSettingDA.DeleteByObjectiveSetID(tc, items[0].ObjectiveSetID); } int id = tc.GenerateID("PMP_ValueBehaviorSetting", "PMPValueBehaviorSettingID"); foreach (PMPValueBehaviorSetting item in items) { if (item.IsNew) { base.SetObjectID(item, (id)); PMPValueBehaviorSettingDA.Insert(tc, item); id++; } else { PMPValueBehaviorSettingDA.Update(tc, item); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } return; } public void SaveBulk(TransactionContext tc, List items) { try { if (items.Count > 0) { int pmpValueBehaviorSettingID = tc.GenerateID("PMP_ValueBehaviorSetting", "PMPValueBehaviorSettingID"); DataTable valueBehaviorSettingTable = new DataTable("PMP_ValueBehaviorSetting"); valueBehaviorSettingTable.Columns.Add(new DataColumn("PMPVALUEBEHAVIORSETTINGID", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("OBJECTIVESETID", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("PMPVALUEBEHAVIORID", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("WEIGHTAGE", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("COMPETENCYLEVEL", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("TARGETRATING", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("EMPCOMMENTS", typeof(string))); valueBehaviorSettingTable.Columns.Add(new DataColumn("LMCOMMENTS", typeof(string))); valueBehaviorSettingTable.Columns.Add(new DataColumn("EMPCOMMENTSDATE", typeof(DateTime))); valueBehaviorSettingTable.Columns.Add(new DataColumn("LMCOMMENTDATE", typeof(DateTime))); valueBehaviorSettingTable.Columns.Add(new DataColumn("MYEMPCOMMENTS", typeof(string))); valueBehaviorSettingTable.Columns.Add(new DataColumn("MYLMCOMMENTS", typeof(string))); valueBehaviorSettingTable.Columns.Add(new DataColumn("MYEMPCOMMENTSDATE", typeof(DateTime))); valueBehaviorSettingTable.Columns.Add(new DataColumn("MYLMCOMMENTDATE", typeof(DateTime))); valueBehaviorSettingTable.Columns.Add(new DataColumn("YEEMPRATING", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("YELMRATING", typeof(int))); valueBehaviorSettingTable.Columns.Add(new DataColumn("YEEMPCOMMENTS", typeof(string))); valueBehaviorSettingTable.Columns.Add(new DataColumn("YELMCOMMENTS", typeof(string))); valueBehaviorSettingTable.Columns.Add(new DataColumn("YEEMPCOMMENTSDATE", typeof(DateTime))); valueBehaviorSettingTable.Columns.Add(new DataColumn("YELMCOMMENTDATE", typeof(DateTime))); valueBehaviorSettingTable.Columns.Add(new DataColumn("ITEMTYPE", typeof(int))); foreach (PMPValueBehaviorSetting item in items) { pmpValueBehaviorSettingID = pmpValueBehaviorSettingID + 1; item.ID = pmpValueBehaviorSettingID; valueBehaviorSettingTable.Rows.Add( pmpValueBehaviorSettingID, item.ObjectiveSetID, item.PMPValueBehaviorID, item.Weightage, item.CompetencyLevel, item.TargetRating, item.EmpComments, item.LmComments, item.EmpCommentsDate, item.MyLMCommentDate, item.MyEmpComments, item.MyLMComments, item.MyEmpCommentsDate, item.MyLMCommentDate, item.YeEmpRating, item.YeLMRating, item.YeEmpComments, item.YeLMComments, item.YeEmpCommentsDate, item.YeLMCommentDate, item.ItemType ); } using (SqlBulkCopy bulkCopy = new SqlBulkCopy((SqlConnection)tc.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)tc.Transaction)) { bulkCopy.BulkCopyTimeout = 6000; // in seconds bulkCopy.ColumnMappings.Add("PMPVALUEBEHAVIORSETTINGID", "PMPVALUEBEHAVIORSETTINGID"); bulkCopy.ColumnMappings.Add("OBJECTIVESETID", "OBJECTIVESETID"); bulkCopy.ColumnMappings.Add("PMPVALUEBEHAVIORID", "PMPVALUEBEHAVIORID"); bulkCopy.ColumnMappings.Add("WEIGHTAGE", "WEIGHTAGE"); bulkCopy.ColumnMappings.Add("COMPETENCYLEVEL", "COMPETENCYLEVEL"); bulkCopy.ColumnMappings.Add("TARGETRATING", "TARGETRATING"); bulkCopy.ColumnMappings.Add("EMPCOMMENTS", "EMPCOMMENTS"); bulkCopy.ColumnMappings.Add("LMCOMMENTS", "LMCOMMENTS"); bulkCopy.ColumnMappings.Add("EMPCOMMENTSDATE", "EMPCOMMENTSDATE"); bulkCopy.ColumnMappings.Add("LMCOMMENTDATE", "LMCOMMENTDATE"); bulkCopy.ColumnMappings.Add("MYEMPCOMMENTS", "MYEMPCOMMENTS"); bulkCopy.ColumnMappings.Add("MYLMCOMMENTS", "MYLMCOMMENTS"); bulkCopy.ColumnMappings.Add("MYEMPCOMMENTSDATE", "MYEMPCOMMENTSDATE"); bulkCopy.ColumnMappings.Add("MYLMCOMMENTDATE", "MYLMCOMMENTDATE"); bulkCopy.ColumnMappings.Add("YEEMPRATING", "YEEMPRATING"); bulkCopy.ColumnMappings.Add("YELMRATING", "YELMRATING"); bulkCopy.ColumnMappings.Add("YEEMPCOMMENTS", "YEEMPCOMMENTS"); bulkCopy.ColumnMappings.Add("YELMCOMMENTS", "YELMCOMMENTS"); bulkCopy.ColumnMappings.Add("YEEMPCOMMENTSDATE", "YEEMPCOMMENTSDATE"); bulkCopy.ColumnMappings.Add("YELMCOMMENTDATE", "YELMCOMMENTDATE"); bulkCopy.ColumnMappings.Add("ITEMTYPE", "ITEMTYPE"); bulkCopy.DestinationTableName = "PMP_ValueBehaviorSetting"; bulkCopy.WriteToServer(valueBehaviorSettingTable); } } } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #region Delete public void Delete(int id) { TransactionContext tc = null; try { tc = TransactionContext.Begin(true); PMPValueBehaviorSettingDA.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 DeleteByObjectiveSetID(TransactionContext tc, int objectiveSetID) { try { PMPValueBehaviorSettingDA.DeleteByObjectiveSetID(tc, objectiveSetID); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } #endregion #endregion } }