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

190 lines
5.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 Ease.CoreV35.DataAccess;
using HRM.BO;
namespace HRM.DA
{
public class EmpFieldTrackService : ServiceTemplate, IEmpFieldTrackService
{
public EmpFieldTrackService()
{
}
private void MapObject(EmpFieldTrack oEmpFieldTrack, DataReader oReader)
{
base.SetObjectID(oEmpFieldTrack, oReader.GetInt32("EmpFieldTrackID").Value);
oEmpFieldTrack.EmployeeID = oReader.GetInt32("EmployeeID", 0);
oEmpFieldTrack.IMENumber = oReader.GetString("IMENO");
oEmpFieldTrack.NearLocation = oReader.GetString("NearLocation");
oEmpFieldTrack.Client = oReader.GetString("Client");
oEmpFieldTrack.Remarks = oReader.GetString("Remarks");
oEmpFieldTrack.Zipcode = oReader.GetString("Zipcode");
oEmpFieldTrack.Latitude = oReader.GetDecimal("Latitude").Value;
oEmpFieldTrack.Longitude = oReader.GetDecimal("Longitude").Value;
oEmpFieldTrack.TranDateTime = oReader.GetDateTime("TranDateTime").HasValue
? oReader.GetDateTime("TranDateTime").Value
: DateTime.MinValue;
this.SetObjectState(oEmpFieldTrack, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
EmpFieldTrack attendanceTrack = new EmpFieldTrack();
MapObject(attendanceTrack, dr);
return attendanceTrack as T;
}
#region IUserLocationService Members
public List<EmpFieldTrack> Get()
{
TransactionContext tc = null;
List<EmpFieldTrack> listEmpFieldTrack = new List<EmpFieldTrack>();
;
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(EmpFieldTrackDA.Get(tc));
listEmpFieldTrack = this.CreateObjects<EmpFieldTrack>(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 listEmpFieldTrack;
}
public List<EmpFieldTrack> Get(DateTime tranDate)
{
TransactionContext tc = null;
List<EmpFieldTrack> listEmpFieldTrack = new List<EmpFieldTrack>();
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(EmpFieldTrackDA.Get(tc, tranDate));
listEmpFieldTrack = this.CreateObjects<EmpFieldTrack>(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 listEmpFieldTrack;
}
public EmpFieldTrack Get(int nID)
{
TransactionContext tc = null;
EmpFieldTrack empFieldTrack = new EmpFieldTrack();
try
{
tc = TransactionContext.Begin(true);
DataReader oreader = new DataReader(EmpFieldTrackDA.Get(tc, nID));
if (oreader.Read())
{
empFieldTrack = this.CreateObject<EmpFieldTrack>(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 empFieldTrack;
}
public int Save(EmpFieldTrack obj)
{
TransactionContext tc = null;
int oId = 0;
try
{
tc = TransactionContext.Begin(true);
if (obj.IsNew)
{
int id = tc.GenerateID("EMPFIELDTRACK", "EmpFieldTrackID");
base.SetObjectID(obj, (id));
oId = EmpFieldTrackDA.Insert(tc, obj);
}
else
{
}
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
return oId;
}
public void Delete(int obj)
{
TransactionContext tc = null;
//ID oId = null;
try
{
tc = TransactionContext.Begin(true);
EmpFieldTrackDA.Delete(tc, obj);
tc.End();
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
#endregion
}
}