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

279 lines
8.3 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
public class PMPValueBehaviorService : ServiceTemplate, IPMPValueBehaviorService
{
#region Object Mapping
private void MapObject(PMPValueBehavior oPMPValueBehavior, DataReader oReader)
{
SetObjectID(oPMPValueBehavior, oReader.GetInt32("PMPValueBehaviorID", 0));
oPMPValueBehavior.Name = oReader.GetString("Name");
oPMPValueBehavior.Code = oReader.GetString("Code");
oPMPValueBehavior.Description = oReader.GetString("Description");
oPMPValueBehavior.Question = oReader.GetString("Question",true,null);
oPMPValueBehavior.ParentID = oReader.GetInt32("ParentID");
oPMPValueBehavior.Tier = oReader.GetInt32("Tire", 0);
oPMPValueBehavior.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oPMPValueBehavior.CreatedDate = oReader.GetDateTime("CreatedDate").HasValue
? oReader.GetDateTime("CreatedDate").Value
: DateTime.MinValue;
oPMPValueBehavior.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oPMPValueBehavior.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue
? oReader.GetDateTime("ModifiedDate").Value
: (DateTime?)null;
oPMPValueBehavior.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oPMPValueBehavior.Sequence = oReader.GetInt32("Sequence").Value;
this.SetObjectState(oPMPValueBehavior, ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
PMPValueBehavior oPMPValueBehavior = new PMPValueBehavior();
MapObject(oPMPValueBehavior, oReader);
return oPMPValueBehavior as T;
}
#endregion
#region Service Implementation
#region Get By Status
public List<PMPValueBehavior> Get(EnumStatus status)
{
List<PMPValueBehavior> oPMPValueBehaviors = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorDA.Get(tc, status));
oPMPValueBehaviors = this.CreateObjects<PMPValueBehavior>(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 oPMPValueBehaviors;
}
public List<PMPValueBehavior> Get(EnumStatus status, int payrollTypeID)
{
List<PMPValueBehavior> oPMPValueBehaviors = new List<PMPValueBehavior>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorDA.Get(tc, status, payrollTypeID));
oPMPValueBehaviors = this.CreateObjects<PMPValueBehavior>(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 oPMPValueBehaviors;
}
#endregion
#region Get By ID
public PMPValueBehavior Get(int id)
{
List<PMPValueBehavior> oPMPValueBehaviors = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorDA.Get(tc, id));
oPMPValueBehaviors = this.CreateObjects<PMPValueBehavior>(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 (oPMPValueBehaviors.Count == 1) return oPMPValueBehaviors[0];
else return null;
}
#endregion
#region Get All
public List<PMPValueBehavior> Get()
{
List<PMPValueBehavior> oPMPValueBehaviors = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(PMPValueBehaviorDA.Get(tc));
oPMPValueBehaviors = this.CreateObjects<PMPValueBehavior>(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 (oPMPValueBehaviors.Count == 1) return oPMPValueBehaviors[0];
//else return null;
return oPMPValueBehaviors;
}
#endregion
#region Insert
public int Save(PMPValueBehavior item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("PMP_ValueBehavior", "PMPValueBehaviorID");
int sequenceNo = tc.GenerateID("PMP_ValueBehavior", "Sequence");
item.Sequence = sequenceNo;
base.SetObjectID(item, (id));
PMPValueBehaviorDA.Insert(tc, item);
}
else
{
PMPValueBehaviorDA.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 string GetNextCode(int tier, int parentid)
{
TransactionContext tc = null;
string code = "";
string parentCode = "";
try
{
if (parentid != -1)
{
PMPValueBehavior parent = this.Get((int)parentid);
if (parent != null)
parentCode = parent.Code;
}
tc = TransactionContext.Begin();
code = GlobalFunctionService.GetMaxCodeofTree(tc, "Competency", "codeautogenerate", "Competency",
"Code", "CompetencyID", "PARENTID", parentCode, tier);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return code;
}
#endregion
#region Delete
public void Delete(int id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
PMPValueBehaviorDA.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
}
}