313 lines
9.3 KiB
C#
313 lines
9.3 KiB
C#
|
|
|||
|
using System;
|
|||
|
using System.Data;
|
|||
|
using System.Linq;
|
|||
|
using Ease.CoreV35;
|
|||
|
using Ease.CoreV35.Model;
|
|||
|
using Ease.CoreV35.DataAccess;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Payroll.BO;
|
|||
|
using Ease.CoreV35.Caching;
|
|||
|
|
|||
|
namespace Payroll.Service
|
|||
|
{
|
|||
|
#region WeeklyHoliday Service
|
|||
|
[Serializable]
|
|||
|
public class WeeklyHolidayService : ServiceTemplate, IWeeklyHolidayService
|
|||
|
{
|
|||
|
#region Private functions and declaration
|
|||
|
Cache _cache = new Cache(typeof(WeeklyHoliday));
|
|||
|
|
|||
|
#endregion
|
|||
|
public WeeklyHolidayService() { }
|
|||
|
|
|||
|
private void MapObject(WeeklyHoliday oWeeklyHoliday, DataReader oReader)
|
|||
|
{
|
|||
|
base.SetObjectID(oWeeklyHoliday, oReader.GetID("WeeklyHolidayID"));
|
|||
|
oWeeklyHoliday.DateType = oReader.GetInt16("DateType").Value;
|
|||
|
oWeeklyHoliday.LocationID = oReader.GetID("LocationID");
|
|||
|
oWeeklyHoliday.Sequence = oReader.GetInt32("SequenceNo").Value;
|
|||
|
oWeeklyHoliday.Status = (EnumStatus)oReader.GetInt32("Status").Value;
|
|||
|
oWeeklyHoliday.CreatedBy = oReader.GetID("CreatedBy");
|
|||
|
oWeeklyHoliday.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
|
|||
|
oWeeklyHoliday.ModifiedBy = oReader.GetID("ModifiedBy");
|
|||
|
oWeeklyHoliday.ModifiedDate = oReader.GetDateTime("ModifiedDate");
|
|||
|
this.SetObjectState(oWeeklyHoliday, Ease.CoreV35.ObjectState.Saved);
|
|||
|
}
|
|||
|
protected override T CreateObject<T>(DataReader oReader)
|
|||
|
{
|
|||
|
WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday();
|
|||
|
MapObject(oWeeklyHoliday, oReader);
|
|||
|
return oWeeklyHoliday as T;
|
|||
|
}
|
|||
|
protected WeeklyHoliday CreateObject(DataReader oReader)
|
|||
|
{
|
|||
|
WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday();
|
|||
|
MapObject(oWeeklyHoliday, oReader);
|
|||
|
return oWeeklyHoliday;
|
|||
|
}
|
|||
|
#region Service implementation
|
|||
|
public WeeklyHoliday Get(ID id)
|
|||
|
{
|
|||
|
WeeklyHoliday oWeeklyHoliday = new WeeklyHoliday();
|
|||
|
#region Cache Header
|
|||
|
oWeeklyHoliday = _cache["Get", id] as WeeklyHoliday;
|
|||
|
if (oWeeklyHoliday != null)
|
|||
|
return oWeeklyHoliday;
|
|||
|
#endregion
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
DataReader oreader = new DataReader(WeeklyHolidayDA.Get(tc, id));
|
|||
|
if (oreader.Read())
|
|||
|
{
|
|||
|
oWeeklyHoliday = this.CreateObject<WeeklyHoliday>(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(oWeeklyHoliday, "Get", id);
|
|||
|
#endregion
|
|||
|
return oWeeklyHoliday;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<WeeklyHoliday> Get(EnumStatus status)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<WeeklyHoliday> WeeklyHolidays = _cache["Get", status] as ObjectsTemplate<WeeklyHoliday>;
|
|||
|
if (WeeklyHolidays != null)
|
|||
|
return WeeklyHolidays;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(WeeklyHolidayDA.Get(tc, status));
|
|||
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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(WeeklyHolidays, "Get", status);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return WeeklyHolidays;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<WeeklyHoliday> GetCompanyEntireHolidays()
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<WeeklyHoliday> WeeklyHolidays = _cache["GetCompanyEntireHolidays"] as ObjectsTemplate<WeeklyHoliday>;
|
|||
|
if (WeeklyHolidays != null)
|
|||
|
return WeeklyHolidays;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(WeeklyHolidayDA.GetCompanyEntireHolidays(tc));
|
|||
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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(WeeklyHolidays, "GetCompanyEntireHolidays");
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return WeeklyHolidays;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<WeeklyHoliday> GetByLocation(ID nLocID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<WeeklyHoliday> WeeklyHolidays = _cache["GetByLocation",nLocID] as ObjectsTemplate<WeeklyHoliday>;
|
|||
|
if (WeeklyHolidays != null)
|
|||
|
return WeeklyHolidays;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(WeeklyHolidayDA.GetByLocation(tc,nLocID));
|
|||
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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(WeeklyHolidays, "GetByLocation",nLocID);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return WeeklyHolidays;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<WeeklyHoliday> GetByEmployee(ID nEmpID)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<WeeklyHoliday> WeeklyHolidays = _cache["GetByEmployee", nEmpID] as ObjectsTemplate<WeeklyHoliday>;
|
|||
|
if (WeeklyHolidays != null)
|
|||
|
return WeeklyHolidays;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader dr = new DataReader(WeeklyHolidayDA.GetByEmployee(tc, nEmpID));
|
|||
|
WeeklyHolidays = this.CreateObjects<WeeklyHoliday>(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(WeeklyHolidays, "GetByEmployee", nEmpID);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return WeeklyHolidays;
|
|||
|
}
|
|||
|
|
|||
|
public ID Save(WeeklyHoliday oWeeklyHoliday)
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
if (oWeeklyHoliday.IsNew)
|
|||
|
{
|
|||
|
|
|||
|
int id = tc.GenerateID("WeeklyHoliday", "WeeklyHolidayID");
|
|||
|
base.SetObjectID(oWeeklyHoliday, ID.FromInteger(id));
|
|||
|
int seqNo = tc.GenerateID("WeeklyHoliday", "SequenceNo");
|
|||
|
oWeeklyHoliday.Sequence = seqNo;
|
|||
|
WeeklyHolidayDA.Insert(tc, oWeeklyHoliday);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
WeeklyHolidayDA.Update(tc, oWeeklyHoliday);
|
|||
|
}
|
|||
|
tc.End();
|
|||
|
return oWeeklyHoliday.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);
|
|||
|
WeeklyHolidayDA.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
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|