EchoTex_Payroll/HRM.DA/Service/Bonus/ProdBonusLineService.cs

432 lines
14 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 ProdBonusLineService : ServiceTemplate, IProdBonusLineService
{
public ProdBonusLineService()
{
}
private void MapObject(ProdBonusLine oProdBonusLine, DataReader oReader)
{
//oProdBonusLine.int = oReader.GetInt32("ProdBonusLineID");
base.SetObjectID(oProdBonusLine, (oReader.GetInt32("ProdBonusLineID").Value));
oProdBonusLine.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0);
oProdBonusLine.LineName = oReader.GetString("LineName");
oProdBonusLine.LineAchievedPercent = oReader.GetDouble("LineAchievedPercent").GetValueOrDefault();
oProdBonusLine.LineOTHour = oReader.GetDouble("LineOTHour").GetValueOrDefault();
oProdBonusLine.ScheduledHour = oReader.GetDouble("ScheduledHour").GetValueOrDefault();
this.SetObjectState(oProdBonusLine, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ProdBonusLine oProdBonusLine = new ProdBonusLine();
MapObject(oProdBonusLine, oReader);
return oProdBonusLine as T;
}
protected ProdBonusLine CreateObject(DataReader oReader)
{
ProdBonusLine oProdBonusLine = new ProdBonusLine();
MapObject(oProdBonusLine, oReader);
return oProdBonusLine;
}
private void MapProdBonusParameterObject(ProdBonusParameter oProdBonusParameter, DataReader oReader)
{
//oProdBonusParameter.int = oReader.GetInt32("ProdBonusParameterID");
base.SetObjectID(oProdBonusParameter, (oReader.GetInt32("ProdBonusParameterID").Value));
oProdBonusParameter.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0);
oProdBonusParameter.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0);
oProdBonusParameter.ItemID = oReader.GetInt32("ItemID", 0);
oProdBonusParameter.ItemType = (EnumBonusItemType)oReader.GetInt32("ItemType").Value;
oProdBonusParameter.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0);
this.SetObjectState(oProdBonusParameter, Ease.Core.ObjectState.Saved);
}
private ProdBonusParameter CreateProdBonusParameterObject(DataReader oReader)
{
ProdBonusParameter item = new ProdBonusParameter();
MapProdBonusParameterObject(item, oReader);
return item;
}
protected List<ProdBonusParameter> CreateProdBonusParameterObjects(DataReader oReader)
{
List<ProdBonusParameter> oItems = new List<ProdBonusParameter>();
while (oReader.Read())
{
ProdBonusParameter item = CreateProdBonusParameterObject(oReader);
oItems.Add(item);
}
return oItems;
}
private void MapScheduleObject(ProdBonusWorkSchedule oProdBonusWorkSchedule, DataReader oReader)
{
//oProdBonusWorkSchedule.int = oReader.GetInt32("ProdBonusWorkScheduleID");
base.SetObjectID(oProdBonusWorkSchedule, (oReader.GetInt32("ProdBonusWorkScheduleID").Value));
oProdBonusWorkSchedule.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0);
oProdBonusWorkSchedule.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0);
oProdBonusWorkSchedule.StartDateTime = oReader.GetDateTime("StartDateTime").Value;
oProdBonusWorkSchedule.EndDateTime = oReader.GetDateTime("EndDateTime", DateTime.MaxValue);
this.SetObjectState(oProdBonusWorkSchedule, Ease.Core.ObjectState.Saved);
}
private ProdBonusWorkSchedule CreateScheduleObject(DataReader oReader)
{
ProdBonusWorkSchedule item = new ProdBonusWorkSchedule();
MapScheduleObject(item, oReader);
return item;
}
protected List<ProdBonusWorkSchedule> CreateScheduleObjects(DataReader oReader)
{
List<ProdBonusWorkSchedule> oItems = new List<ProdBonusWorkSchedule>();
while (oReader.Read())
{
ProdBonusWorkSchedule item = CreateScheduleObject(oReader);
oItems.Add(item);
}
return oItems;
}
private void MapSupervisorObject(ProdBonusSupervisor oProdBonusSupervisor, DataReader oReader)
{
//oProdBonusWorkSchedule.int = oReader.GetInt32("ProdBonusWorkScheduleID");
base.SetObjectID(oProdBonusSupervisor, (oReader.GetInt32("ProdBonusSupervisorID").Value));
oProdBonusSupervisor.ProdBonusSetupID = oReader.GetInt32("ProdBonusSetupID", 0);
oProdBonusSupervisor.ProdBonusLineID = oReader.GetInt32("ProdBonusLineID", 0);
oProdBonusSupervisor.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oProdBonusSupervisor.BonusPercent = oReader.GetDouble("BonusPercent").GetValueOrDefault();
this.SetObjectState(oProdBonusSupervisor, Ease.Core.ObjectState.Saved);
}
private ProdBonusSupervisor CreateSupervisorObject(DataReader oReader)
{
ProdBonusSupervisor item = new ProdBonusSupervisor();
MapSupervisorObject(item, oReader);
return item;
}
protected List<ProdBonusSupervisor> CreateSupervisorObjects(DataReader oReader)
{
List<ProdBonusSupervisor> oItems = new List<ProdBonusSupervisor>();
while (oReader.Read())
{
ProdBonusSupervisor item = CreateSupervisorObject(oReader);
oItems.Add(item);
}
return oItems;
}
#region Service implementation
public ProdBonusLine Get(int id)
{
ProdBonusLine oProdBonusLine = new ProdBonusLine();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ProdBonusLineDA.Get(tc, id));
if (oreader.Read())
{
oProdBonusLine = this.CreateObject<ProdBonusLine>(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 oProdBonusLine;
}
public List<ProdBonusLine> Get()
{
List<ProdBonusLine> ProdBonusLines = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusLineDA.Get(tc));
ProdBonusLines = this.CreateObjects<ProdBonusLine>(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 ProdBonusLines;
}
public List<ProdBonusLine> GetLines(int id)
{
List<ProdBonusLine> ProdBonusLines = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusLineDA.Get(tc, id));
ProdBonusLines = this.CreateObjects<ProdBonusLine>(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 ProdBonusLines;
}
public List<ProdBonusParameter> GetProdBonusParameters(int iD)
{
List<ProdBonusParameter> ProdBonusParameters = new List<ProdBonusParameter>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusParameters(tc, iD));
ProdBonusParameters = this.CreateProdBonusParameterObjects(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 ProdBonusParameters;
}
public List<ProdBonusWorkSchedule> GetProdBonusWorkSchedules(int iD)
{
List<ProdBonusWorkSchedule> ProdBonusWorkSchedules = new List<ProdBonusWorkSchedule>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusWorkSchedules(tc, iD));
ProdBonusWorkSchedules = this.CreateScheduleObjects(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 ProdBonusWorkSchedules;
}
public List<ProdBonusWorkSchedule> GetProdBonusWorkSchedules(TransactionContext tc, int iD)
{
List<ProdBonusWorkSchedule> ProdBonusWorkSchedules = new List<ProdBonusWorkSchedule>();
try
{
DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusWorkSchedules(tc, iD));
ProdBonusWorkSchedules = this.CreateScheduleObjects(dr);
dr.Close();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return ProdBonusWorkSchedules;
}
public List<ProdBonusSupervisor> GetProdBonusSupervisors(int iD)
{
List<ProdBonusSupervisor> ProdBonusSupervisors = new List<ProdBonusSupervisor>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusLineDA.GetProdBonusSupervisors(tc, iD));
ProdBonusSupervisors = this.CreateSupervisorObjects(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 ProdBonusSupervisors;
}
public List<ProdBonusLine> GetLineBySetupId(int setupID)
{
List<ProdBonusLine> ProdBonusLines = new List<ProdBonusLine>();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ProdBonusLineDA.GetLineBySetupId(tc, setupID));
ProdBonusLines = this.CreateObjects< ProdBonusLine>(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 ProdBonusLines;
}
public int Save(ProdBonusLine oProdBonusLine)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oProdBonusLine.IsNew)
{
int id = tc.GenerateID("ProdBonusLines", "ProdBonusLineID");
base.SetObjectID(oProdBonusLine, (id));
int seqNo = tc.GenerateID("ProdBonusLines", "SequenceNO");
oProdBonusLine.Sequence = seqNo;
ProdBonusLineDA.Insert(tc, oProdBonusLine);
}
else
{
ProdBonusLineDA.Update(tc, oProdBonusLine);
}
tc.End();
return oProdBonusLine.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);
ProdBonusLineDA.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
}
}