CEL_Payroll/Payroll.Service/Budget/Service/AppraisalPointService.cs

177 lines
5.2 KiB
C#
Raw Normal View History

2024-09-17 14:30:13 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.CoreV35.Model;
using Payroll.BO;
using Ease.CoreV35.DataAccess;
using System.Data;
using Ease.CoreV35;
namespace Payroll.Service
{
public class AppraisalPointService : ServiceTemplate, IAppraisalPointService
{
#region Object Mapping
private void MapObject(AppraisalPoint oAppraisalPoint, DataReader oReader)
{
SetObjectID(oAppraisalPoint, oReader.GetID("AppraisalPointID"));
oAppraisalPoint.Code = oReader.GetString("Code");
oAppraisalPoint.Name = oReader.GetString("Name");
oAppraisalPoint.Status = (EnumStatus)oReader.GetInt32("Status");
if (oReader.GetDateTime("CreatedDate") != null)
{
oAppraisalPoint.CreatedDate = (DateTime)oReader.GetDateTime("CreatedDate");
}
else oAppraisalPoint.CreatedDate = DateTime.MinValue;
if (oReader.GetDateTime("ModifiedDate") != null)
{
oAppraisalPoint.ModifiedDate = (DateTime)oReader.GetDateTime("ModifiedDate");
}
else oAppraisalPoint.ModifiedDate = null;
if (oReader.GetInt32("CreatedBy") != null)
{
oAppraisalPoint.CreatedBy = oReader.GetID("CreatedBy");
}
else oAppraisalPoint.CreatedBy = null;
if (oReader.GetInt32("ModifiedBy") != null)
{
oAppraisalPoint.ModifiedBy = oReader.GetID("ModifiedBy");
}
else oAppraisalPoint.ModifiedBy = null;
this.SetObjectState(oAppraisalPoint,ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
AppraisalPoint oAppraisalPoint = new AppraisalPoint();
MapObject(oAppraisalPoint, oReader);
return oAppraisalPoint as T;
}
#endregion
#region Service Implementation
public ObjectsTemplate<AppraisalPoint> Get(EnumStatus status)
{
ObjectsTemplate<AppraisalPoint> oAppraisalPoint = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(AppraisalPointDA.Get(tc, status));
oAppraisalPoint = this.CreateObjects<AppraisalPoint>(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 oAppraisalPoint;
}
public ID Save(AppraisalPoint item)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (item.IsNew)
{
int id = tc.GenerateID("AppraisalPoint", "AppraisalPointID");
int seqNo = tc.GenerateID("AppraisalPoint", "Sequence");
item.Sequence = seqNo;
SetObjectID(item, ID.FromInteger(id));
AppraisalPointDA.Insert(tc, item);
}
else
{
AppraisalPointDA.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 Delete(ID id)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
AppraisalPointDA.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 bool CheckCode(string code)
{
bool flag = true;
DataSet ds = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ds = AppraisalPointDA.CheckCode(tc, code);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
if (ds.Tables[0].Rows.Count >= 1)
{
flag = false;
}
return flag;
}
#endregion
}
}