EchoTex_Payroll/HRM.DA/Service/Attendance/ShiftRotationService.cs

255 lines
7.7 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ease.Core.DataAccess;
using Ease.Core.Model;
using Ease.Core.Utility;
using HRM.BO;
namespace HRM.DA
{
#region ShiftRotation Service
[Serializable]
public class ShiftRotationService : ServiceTemplate, IShiftRotationService
{
public ShiftRotationService()
{
}
private void MapObject(ShiftRotation oShiftRotation, DataReader oReader)
{
base.SetObjectID(oShiftRotation, oReader.GetInt32("ShiftRotationID").Value);
oShiftRotation.ShiftID = oReader.GetInt32("ShiftID", 0);
oShiftRotation.Sequence = oReader.GetInt32("SequenceNo").Value;
oShiftRotation.Status = (EnumStatus)oReader.GetInt32("Status").Value;
oShiftRotation.CreatedBy = oReader.GetInt32("CreatedBy", 0);
oShiftRotation.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
oShiftRotation.ModifiedBy = oReader.GetInt32("ModifiedBy");
oShiftRotation.ModifiedDate = oReader.GetDateTime("ModifiedDate");
oShiftRotation.WorkPlanType = (EnumWorkPlanGroup)oReader.GetInt32("workGroupType");
oShiftRotation.ShiftShortName = oReader.GetString("ShortName", true, "");
this.SetObjectState(oShiftRotation, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ShiftRotation oShiftRotation = new ShiftRotation();
MapObject(oShiftRotation, oReader);
return oShiftRotation as T;
}
protected ShiftRotation CreateObject(DataReader oReader)
{
ShiftRotation oShiftRotation = new ShiftRotation();
MapObject(oShiftRotation, oReader);
return oShiftRotation;
}
#region Service implementation
public List<ShiftRotation> Get(EnumWorkPlanGroup workGroup)
{
List<ShiftRotation> shiftRotations = new List<ShiftRotation>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ShiftRotationDA.Get(tc, workGroup));
shiftRotations = this.CreateObjects<ShiftRotation>(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 shiftRotations;
}
public ShiftRotation Get(int id)
{
ShiftRotation oShiftRotation = new ShiftRotation();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ShiftRotationDA.Get(tc, id));
if (oreader.Read())
{
oShiftRotation = this.CreateObject<ShiftRotation>(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 oShiftRotation;
}
//public List<ShiftRotation> Get(EnumWorkPlanGroup workGroup)
//{
// TransactionContext tc = null;
// try
// {
// tc = TransactionContext.Begin();
// DataReader dr = new DataReader(ShiftRotationDA.Get(tc, workGroup));
// var shiftRotations = this.CreateObjects<ShiftRotation>(dr);
// dr.Close();
// tc.End();
// return shiftRotations;
// }
// catch (Exception e)
// {
// #region Handle Exception
// if (tc != null)
// tc.HandleError();
// ExceptionLog.Write(e);
// throw new ServiceException(e.Message, e);
// #endregion
// }
//}
public ShiftRotation Get(EnumWorkPlanGroup workgrouptype, int sequence)
{
ShiftRotation oShiftRotation = new ShiftRotation();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ShiftRotationDA.Get(tc, workgrouptype, sequence));
if (oreader.Read())
{
oShiftRotation = this.CreateObject<ShiftRotation>(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 oShiftRotation;
}
public int Save(ShiftRotation oShiftRotation)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oShiftRotation.IsNew)
{
int id = tc.GenerateID("ShiftRotation", "ShiftRotationID");
base.SetObjectID(oShiftRotation, (id));
int seqNo = tc.GenerateID("ShiftRotation", "SequenceNO");
oShiftRotation.Sequence = seqNo;
ShiftRotationDA.Insert(tc, oShiftRotation);
}
else
{
ShiftRotationDA.Update(tc, oShiftRotation);
}
tc.End();
return oShiftRotation.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)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ShiftRotationDA.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 List<ShiftRotation> Get(EnumStatus status, int payrolltypeid)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ShiftRotationDA.Get(tc, status, payrolltypeid));
var shiftRotations = this.CreateObjects<ShiftRotation>(dr);
dr.Close();
tc.End();
return shiftRotations;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
#endregion
}