EchoTex_Payroll/HRM.DA/Service/PMP/PMPValueBehaviorSettingService.cs

270 lines
8.9 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
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;
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<T>(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<PMPValueBehaviorSetting> oPMPValueBehaviorSettings = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorSettingDA.Get(tc, id));
oPMPValueBehaviorSettings = this.CreateObjects<PMPValueBehaviorSetting>(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<PMPValueBehaviorSetting> Get()
{
List<PMPValueBehaviorSetting> oPMPValueBehaviorSettings = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorSettingDA.Get(tc));
oPMPValueBehaviorSettings = this.CreateObjects<PMPValueBehaviorSetting>(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<PMPValueBehaviorSetting> GetByObjectiveSetID(int objectiveSetId)
{
List<PMPValueBehaviorSetting> oPMPValueBehaviorSettings = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorSettingDA.GetByObjectiveSetID(tc, objectiveSetId));
oPMPValueBehaviorSettings = this.CreateObjects<PMPValueBehaviorSetting>(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<PMPValueBehaviorSetting> 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;
}
#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
}
}
#endregion
#endregion
}
}