EchoTex_Payroll/HRM.DA/Service/Basic/GradeSegmentService.cs

259 lines
7.4 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using HRM.BO;
using HRM.DA;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using System;
using System.Collections.Generic;
namespace HRM.DA
{
public class GradeSegmentService : ServiceTemplate, IGradeSegmentService
{
public GradeSegmentService()
{
}
private void MapObject(GradeSegment oGradeSegment, DataReader oReader)
{
base.SetObjectID(oGradeSegment, oReader.GetInt32("GradeSegmentID").Value);
oGradeSegment.Code = oReader.GetString("code");
oGradeSegment.Name = oReader.GetString("description");
oGradeSegment.BasicPer = oReader.GetDouble("BasicPer").Value;
oGradeSegment.Sequence = oReader.GetInt32("SequenceNo").Value;
oGradeSegment.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oGradeSegment.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oGradeSegment.CreatedDate = oReader.GetDateTime("CreationDate").Value;
oGradeSegment.ModifiedBy = oReader.GetInt32("ModifiedBy", 0);
oGradeSegment.ModifiedDate = oReader.GetDateTime("ModifiedDate");
this.SetObjectState(oGradeSegment, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
GradeSegment oGradeSegment = new GradeSegment();
MapObject(oGradeSegment, oReader);
return oGradeSegment as T;
}
#region Service implementation
public string GetNextCode()
{
TransactionContext tc = null;
string _code = "";
try
{
tc = TransactionContext.Begin();
//#### _code = GlobalFunctionService.GetMaxCode(tc, "gradesegment", "codeautogenerate", "GradeSegment", "Code");
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;
}
public GradeSegment Get(int id)
{
GradeSegment oGradeSegment = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(GradeSegmentDA.Get(tc, id));
if (oreader.Read())
{
oGradeSegment = this.CreateObject<GradeSegment>(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 oGradeSegment;
}
public GradeSegment Get(string sCode)
{
GradeSegment oGradeSegment = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(GradeSegmentDA.Get(tc, sCode));
if (oreader.Read())
{
oGradeSegment = this.CreateObject<GradeSegment>(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 oGradeSegment;
}
public List<GradeSegment> Get(EnumStatus status)
{
List<GradeSegment> gradeSegments = new List<GradeSegment>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(GradeSegmentDA.Get(tc, status));
gradeSegments = this.CreateObjects<GradeSegment>(dr);
dr.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 gradeSegments;
}
public int Save(GradeSegment oGradeSegment)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oGradeSegment.IsNew)
{
int id = tc.GenerateID("GradeSegment", "GradeSegmentID");
base.SetObjectID(oGradeSegment, id);
int seqNo = tc.GenerateID("GradeSegment", "SequenceNO");
oGradeSegment.Sequence = seqNo;
GradeSegmentDA.Insert(tc, oGradeSegment);
}
else
{
GradeSegmentDA.Update(tc, oGradeSegment);
}
tc.End();
return oGradeSegment.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(int id, int UserID)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
GradeSegmentDA.Delete(tc, id, UserID);
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 Delete(int id)
{
throw new NotImplementedException();
}
public List<GradeSegment> GetAllGradeSegment(int payrollTypeID, EnumStatus status, string code, string name)
{
List<GradeSegment> gradeSegments = new List<GradeSegment>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr =
new DataReader(GradeSegmentDA.GetAllGradeSegment(tc, payrollTypeID, status, code, name));
gradeSegments = this.CreateObjects<GradeSegment>(dr);
dr.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 gradeSegments;
}
#endregion
}
}