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

223 lines
7.0 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 HRM.BO;
using Ease.Core.Utility;
using Ease.Core.Model;
using Ease.Core.DataAccess;
namespace HRM.DA
{
[Serializable]
public class UPDAttendanceService : ServiceTemplate
{
public UPDAttendanceService()
{
}
private void MapObject(UPDAttendance oUPDAttendance, DataReader oReader)
{
base.SetObjectID(oUPDAttendance, (oReader.GetInt32("AttendanceID").Value));
oUPDAttendance.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oUPDAttendance.EmployeeNo = oReader.GetString("EmployeeNo");
oUPDAttendance.AttnDate = oReader.GetDateTime("AttnDate").Value;
oUPDAttendance.InTime = oReader.GetDateTime("InTime");
oUPDAttendance.OutTime = oReader.GetDateTime("OutTime");
oUPDAttendance.UpdStatus = (EnumUPDStatus)oReader.GetInt16("UpdStatus").Value;
oUPDAttendance.ChangeStatus = (EnumUPDStatus)oReader.GetInt16("ChangeStatus").Value;
oUPDAttendance.EmpRemarks = oReader.GetString("EmpRemarks");
oUPDAttendance.LMRemarks = oReader.GetString("LMRemarks");
oUPDAttendance.EmpRemarksDate = oReader.GetDateTime("EmpRemarksDate");
oUPDAttendance.LMRemarksDate = oReader.GetDateTime("LMRemarksDate");
oUPDAttendance.EmpOutsideDutyID = (oReader.GetInt32("EmpOutsideDutyID").Value);
oUPDAttendance.Comment = oReader.GetString("Comment");
oUPDAttendance.LMID = oReader.GetInt32("LMID", 0);
oUPDAttendance.HRID = oReader.GetInt32("HRID", 0);
oUPDAttendance.HRRemarks = oReader.GetString("HRRemarks");
this.SetObjectState(oUPDAttendance, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
UPDAttendance oUPDAttendance = new UPDAttendance();
MapObject(oUPDAttendance, oReader);
return oUPDAttendance as T;
}
protected UPDAttendance CreateObject(DataReader oReader)
{
UPDAttendance oUPDAttendance = new UPDAttendance();
MapObject(oUPDAttendance, oReader);
return oUPDAttendance;
}
#region Service implementation
public UPDAttendance Get(int id)
{
UPDAttendance oUPDAttendance = new UPDAttendance();
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(UPDAttendanceDA.Get(tc, id));
if (oreader.Read())
{
oUPDAttendance = this.CreateObject<UPDAttendance>(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 oUPDAttendance;
}
public List<UPDAttendance> Get(DateTime dt, EnumUPDStatus eType)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UPDAttendanceDA.Get(tc, dt, eType));
var UPDAttendances = this.CreateObjects<UPDAttendance>(dr);
dr.Close();
tc.End();
return UPDAttendances;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<UPDAttendance> Get(DateTime dtFrom, DateTime dtTo, int EmpID, EnumUPDStatus eType)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UPDAttendanceDA.Get(tc, dtFrom, dtTo, EmpID, eType));
var UPDAttendances = this.CreateObjects<UPDAttendance>(dr);
dr.Close();
tc.End();
return UPDAttendances;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public List<UPDAttendance> Get(DateTime dtFrom, DateTime dtTo, EnumUPDStatus eType)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(UPDAttendanceDA.Get(tc, dtFrom, dtTo, eType));
var UPDAttendances = this.CreateObjects<UPDAttendance>(dr);
dr.Close();
tc.End();
return UPDAttendances;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public int Save(UPDAttendance oUPDAttendance)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oUPDAttendance.IsNew)
{
int id = tc.GenerateID("UPDAttendance", "UPDAttendanceID");
base.SetObjectID(oUPDAttendance, (id));
UPDAttendanceDA.Insert(tc, oUPDAttendance);
}
else
{
UPDAttendanceDA.Update(tc, oUPDAttendance);
}
tc.End();
return oUPDAttendance.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);
UPDAttendanceDA.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
}
}