247 lines
7.5 KiB
C#
247 lines
7.5 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
|
|
{
|
|
[Serializable]
|
|
public class ReportAuthorizationService : ServiceTemplate, IReportAuthorizationService
|
|
{
|
|
#region Private functions and declaration
|
|
Cache _cache = new Cache(typeof(ReportAuthorization));
|
|
#endregion
|
|
|
|
public ReportAuthorizationService() { }
|
|
|
|
private void MapObject(ReportAuthorization oReportAuthorization, DataReader oReader)
|
|
{
|
|
base.SetObjectID(oReportAuthorization, oReader.GetID("reportID"));
|
|
oReportAuthorization.AuthorizePersionId = oReader.GetID("personID");
|
|
oReportAuthorization.Position = oReader.GetInt32("Position").Value;
|
|
this.SetObjectState(oReportAuthorization, Ease.CoreV35.ObjectState.Saved);
|
|
}
|
|
protected override T CreateObject<T>(DataReader oReader)
|
|
{
|
|
ReportAuthorization oReportAuthorization = new ReportAuthorization();
|
|
MapObject(oReportAuthorization, oReader);
|
|
return oReportAuthorization as T;
|
|
}
|
|
protected ReportAuthorization CreateObject(DataReader oReader)
|
|
{
|
|
ReportAuthorization oReportAuthorization = new ReportAuthorization();
|
|
MapObject(oReportAuthorization, oReader);
|
|
return oReportAuthorization;
|
|
}
|
|
|
|
#region Service implementation
|
|
public ReportAuthorization Get(ID id)
|
|
{
|
|
ReportAuthorization oReportAuthorization = new ReportAuthorization();
|
|
#region Cache Header
|
|
oReportAuthorization = _cache["Get", id] as ReportAuthorization;
|
|
if (oReportAuthorization != null)
|
|
return oReportAuthorization;
|
|
#endregion
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ReportAuthorizationDA.Get(tc, id));
|
|
if (oreader.Read())
|
|
{
|
|
oReportAuthorization = this.CreateObject<ReportAuthorization>(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(oReportAuthorization, "Get", id);
|
|
#endregion
|
|
return oReportAuthorization;
|
|
}
|
|
|
|
public ObjectsTemplate<ReportAuthorization> GetByReportID(ID reportID)
|
|
{
|
|
|
|
#region Cache Header
|
|
ObjectsTemplate<ReportAuthorization> reportAuthorizations = _cache["GetByReportID"] as ObjectsTemplate<ReportAuthorization>;
|
|
if (reportAuthorizations != null)
|
|
return reportAuthorizations;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ReportAuthorizationDA.Get(tc, reportID));
|
|
reportAuthorizations = this.CreateObjects<ReportAuthorization>(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(reportAuthorizations, "GetByReportID");
|
|
|
|
#endregion
|
|
|
|
return reportAuthorizations;
|
|
}
|
|
public ReportAuthorization Get(ID reportID,int position)
|
|
{
|
|
|
|
ReportAuthorization oReportAuthorization = new ReportAuthorization();
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
DataReader oreader = new DataReader(ReportAuthorizationDA.Get(tc, reportID, position));
|
|
if (oreader.Read())
|
|
{
|
|
oReportAuthorization = this.CreateObject<ReportAuthorization>(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 oReportAuthorization;
|
|
}
|
|
|
|
public ObjectsTemplate<ReportAuthorization> Get()
|
|
{
|
|
|
|
#region Cache Header
|
|
ObjectsTemplate<ReportAuthorization> reportAuthorizations = _cache["Get"] as ObjectsTemplate<ReportAuthorization>;
|
|
if (reportAuthorizations != null)
|
|
return reportAuthorizations;
|
|
|
|
#endregion
|
|
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin();
|
|
|
|
DataReader dr = new DataReader(ReportAuthorizationDA.Get(tc));
|
|
reportAuthorizations = this.CreateObjects<ReportAuthorization>(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(reportAuthorizations, "Get");
|
|
|
|
#endregion
|
|
|
|
return reportAuthorizations;
|
|
}
|
|
|
|
|
|
public ID Save(ReportAuthorization oReportAuthorization)
|
|
{
|
|
TransactionContext tc = null;
|
|
try
|
|
{
|
|
tc = TransactionContext.Begin(true);
|
|
|
|
if (oReportAuthorization.IsNew)
|
|
{
|
|
|
|
ReportAuthorizationDA.Insert(tc, oReportAuthorization);
|
|
}
|
|
else
|
|
{
|
|
ReportAuthorizationDA.Update(tc, oReportAuthorization);
|
|
}
|
|
tc.End();
|
|
return oReportAuthorization.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);
|
|
ReportAuthorizationDA.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
|
|
|
|
}
|
|
}
|