240 lines
8.7 KiB
C#
240 lines
8.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Ease.CoreV35.Caching;
|
|
using Payroll.BO;
|
|
using Ease.CoreV35.DataAccess;
|
|
using Payroll.Service.Attendence.DA;
|
|
using Ease.CoreV35.Model;
|
|
using Payroll.BO;
|
|
|
|
namespace Payroll.Service
|
|
{
|
|
[Serializable]
|
|
public class UPDAttendanceService : ServiceTemplate, IUPDAttendanceService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(UPDAttendance));
|
|
|
|
#endregion
|
|
public UPDAttendanceService() { }
|
|
|
|
private void MapObject(UPDAttendance oUPDAttendance, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oUPDAttendance, oReader.GetID("AttendanceID"));
|
|
oUPDAttendance.EmployeeID = oReader.GetID("EmployeeID");
|
|
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.GetID("EmpOutsideDutyID");
|
|
oUPDAttendance.Comment = oReader.GetString("Comment");
|
|
oUPDAttendance.LMID = oReader.GetID("LMID");
|
|
oUPDAttendance.HRID = oReader.GetID("HRID");
|
|
oUPDAttendance.HRRemarks = oReader.GetString("HRRemarks");
|
|
this.SetObjectState(oUPDAttendance, Ease.CoreV35.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(ID id)
|
|
{
|
|
UPDAttendance oUPDAttendance = new UPDAttendance();
|
|
#region Cache Header
|
|
oUPDAttendance = _cache["Get", id] as UPDAttendance;
|
|
if (oUPDAttendance != null)
|
|
return oUPDAttendance;
|
|
#endregion
|
|
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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(oUPDAttendance, "Get", id);
|
|
#endregion
|
|
return oUPDAttendance;
|
|
}
|
|
|
|
|
|
|
|
public ObjectsTemplate<UPDAttendance> Get(DateTime dt, EnumUPDStatus eType)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<UPDAttendance> UPDAttendances = _cache["Get",dt,eType] as ObjectsTemplate<UPDAttendance>;
|
|
if (UPDAttendances != null)
|
|
return UPDAttendances;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(UPDAttendanceDA.Get(tc,dt,eType));
|
|
UPDAttendances = this.CreateObjects<UPDAttendance>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(UPDAttendances, "Get",dt,eType);
|
|
#endregion
|
|
return UPDAttendances;
|
|
}
|
|
public ObjectsTemplate<UPDAttendance> Get(DateTime dtFrom, DateTime dtTo, int EmpID, EnumUPDStatus eType)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<UPDAttendance> UPDAttendances = _cache["Get", dtFrom, dtTo, EmpID,eType] as ObjectsTemplate<UPDAttendance>;
|
|
if (UPDAttendances != null)
|
|
return UPDAttendances;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(UPDAttendanceDA.Get(tc, dtFrom, dtTo, EmpID,eType));
|
|
UPDAttendances = this.CreateObjects<UPDAttendance>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(UPDAttendances, "Get", dtFrom, dtTo, EmpID,eType);
|
|
#endregion
|
|
return UPDAttendances;
|
|
}
|
|
public ObjectsTemplate<UPDAttendance> Get(DateTime dtFrom, DateTime dtTo, EnumUPDStatus eType)
|
|
{
|
|
#region Cache Header
|
|
ObjectsTemplate<UPDAttendance> UPDAttendances = _cache["Get", dtFrom, dtTo, eType] as ObjectsTemplate<UPDAttendance>;
|
|
if (UPDAttendances != null)
|
|
return UPDAttendances;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader dr = new DataReader(UPDAttendanceDA.Get(tc, dtFrom, dtTo, eType));
|
|
UPDAttendances = this.CreateObjects<UPDAttendance>(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
|
|
}
|
|
#region Cache Footer
|
|
_cache.Add(UPDAttendances, "Get", dtFrom, dtTo, eType);
|
|
#endregion
|
|
return UPDAttendances;
|
|
}
|
|
|
|
|
|
|
|
public ID Save(UPDAttendance oUPDAttendance)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
if (oUPDAttendance.IsNew)
|
|
{
|
|
int id = tc.GenerateID("UPDAttendance", "UPDAttendanceID");
|
|
base.SetObjectID(oUPDAttendance, ID.FromInteger(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(ID 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
|
|
}
|
|
}
|