CEL_Payroll/Payroll.Service/Common/Service/ErrorSuccessLogService.cs
2024-09-17 14:30:13 +06:00

417 lines
13 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.Service
{
#region ErrorSuccessLog Service
[Serializable]
public class ErrorSuccessLogService : ServiceTemplate, IErrorSuccessLogService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ErrorSuccessLog));
#endregion
public ErrorSuccessLogService() { }
private void MapObject(ErrorSuccessLog oErrorSuccessLog, DataReader oReader)
{
base.SetObjectID(oErrorSuccessLog, oReader.GetID("ErrorSuccessLogID"));
oErrorSuccessLog.OperationDate = oReader.GetDateTime("OperationDate").Value;
oErrorSuccessLog.ViewName = oReader.GetString("ViewName");
oErrorSuccessLog.ReceiveStatus = (EnumReceiveStatus)oReader.GetInt32("ReceiveStatus").Value;
oErrorSuccessLog.IsLogRead = oReader.GetBoolean("IsLogRead").Value;
this.SetObjectState(oErrorSuccessLog, Ease.CoreV35.ObjectState.Saved);
}
private void MapErrorLogDetailObject(ErrorLogDetail oErrorSuccessLog, DataReader oReader)
{
base.SetObjectID(oErrorSuccessLog, oReader.GetID("ErrorLogDetailID"));
oErrorSuccessLog.ErrorSuccessLogID = oReader.GetID("ErrorSuccessLogID");
oErrorSuccessLog.EmployeePIN = oReader.GetString("EmployeePIN");
oErrorSuccessLog.EmployeeName = oReader.GetString("EmployeeName");
oErrorSuccessLog.ErrorDescription = oReader.GetString("ErrorDescription");
oErrorSuccessLog.ErrorType = (EnumErrorType)oReader.GetInt32("ErrorType").Value;
this.SetObjectState(oErrorSuccessLog, Ease.CoreV35.ObjectState.Saved);
}
private void MapSuccessLogDetailObject(SuccessLogDetail oErrorSuccessLog, DataReader oReader)
{
base.SetObjectID(oErrorSuccessLog, oReader.GetID("SuccessLogDetailID"));
oErrorSuccessLog.ErrorSuccessLogID = oReader.GetID("ErrorSuccessLogID");
oErrorSuccessLog.EmployeePIN = oReader.GetString("EmployeePIN");
oErrorSuccessLog.EmployeeName = oReader.GetString("EmployeeName");
oErrorSuccessLog.SuccessDescription = oReader.GetString("SuccessDescription");
this.SetObjectState(oErrorSuccessLog, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ErrorSuccessLog oErrorSuccessLog = new ErrorSuccessLog();
MapObject(oErrorSuccessLog, oReader);
return oErrorSuccessLog as T;
}
protected ErrorSuccessLog CreateObject(DataReader oReader)
{
ErrorSuccessLog oErrorSuccessLog = new ErrorSuccessLog();
MapObject(oErrorSuccessLog, oReader);
return oErrorSuccessLog;
}
protected ObjectsTemplate<ErrorLogDetail> CreateErrorLogDetailObjects(DataReader oReader)
{
ObjectsTemplate<ErrorLogDetail> oErrorLogDetails = new ObjectsTemplate<ErrorLogDetail>();
while (oReader.Read())
{
ErrorLogDetail oErrorLogDetail = new ErrorLogDetail();
MapErrorLogDetailObject(oErrorLogDetail, oReader);
oErrorLogDetails.Add(oErrorLogDetail);
}
return oErrorLogDetails;
}
protected ObjectsTemplate<SuccessLogDetail> CreateSuccessLogDetailObjects(DataReader oReader)
{
ObjectsTemplate<SuccessLogDetail> oSuccessLogDetails = new ObjectsTemplate<SuccessLogDetail>();
while (oReader.Read())
{
SuccessLogDetail oSuccessLogDetail = new SuccessLogDetail();
MapSuccessLogDetailObject(oSuccessLogDetail, oReader);
oSuccessLogDetails.Add(oSuccessLogDetail);
}
return oSuccessLogDetails;
}
#region Service implementation
public ErrorSuccessLog Get(ID id)
{
ErrorSuccessLog oErrorSuccessLog = new ErrorSuccessLog();
#region Cache Header
oErrorSuccessLog = _cache["Get", id] as ErrorSuccessLog;
if (oErrorSuccessLog != null)
return oErrorSuccessLog;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ErrorSuccessLogDA.Get(tc, id));
if (oreader.Read())
{
oErrorSuccessLog = this.CreateObject<ErrorSuccessLog>(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(oErrorSuccessLog, "Get", id);
#endregion
return oErrorSuccessLog;
}
public ObjectsTemplate<ErrorSuccessLog> Get()
{
#region Cache Header
ObjectsTemplate<ErrorSuccessLog> ErrorSuccessLogs = _cache["Get"] as ObjectsTemplate<ErrorSuccessLog>;
if (ErrorSuccessLogs != null)
return ErrorSuccessLogs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ErrorSuccessLogDA.Get(tc));
ErrorSuccessLogs = this.CreateObjects<ErrorSuccessLog>(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(ErrorSuccessLogs, "Get");
#endregion
return ErrorSuccessLogs;
}
#region Get By Status
public ObjectsTemplate<ErrorSuccessLog> GetByStatus(bool sts)
{
#region Cache Header
ObjectsTemplate<ErrorSuccessLog> ErrorSuccessLogs = _cache["Get"] as ObjectsTemplate<ErrorSuccessLog>;
if (ErrorSuccessLogs != null)
return ErrorSuccessLogs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ErrorSuccessLogDA.GetByStatus(tc, sts));
ErrorSuccessLogs = this.CreateObjects<ErrorSuccessLog>(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(ErrorSuccessLogs, "Get");
#endregion
return ErrorSuccessLogs;
}
public ObjectsTemplate<ErrorSuccessLog> GetByStatus(bool sts, DateTime fromDate, DateTime toDate)
{
#region Cache Header
ObjectsTemplate<ErrorSuccessLog> ErrorSuccessLogs = _cache["Get"] as ObjectsTemplate<ErrorSuccessLog>;
if (ErrorSuccessLogs != null)
return ErrorSuccessLogs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ErrorSuccessLogDA.GetByStatus(tc, sts, fromDate, toDate));
ErrorSuccessLogs = this.CreateObjects<ErrorSuccessLog>(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
}
return ErrorSuccessLogs;
}
#endregion
public ObjectsTemplate<ErrorLogDetail> GetErrorLogDetails(ID nID)
{
#region Cache Header
ObjectsTemplate<ErrorLogDetail> ErrorSuccessLogs = _cache["GetErrorLogDetail"] as ObjectsTemplate<ErrorLogDetail>;
if (ErrorSuccessLogs != null)
return ErrorSuccessLogs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ErrorSuccessLogDA.GetErrorLogDetail(tc, nID));
ErrorSuccessLogs = this.CreateErrorLogDetailObjects(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(ErrorSuccessLogs, "GetErrorLogDetail");
#endregion
return ErrorSuccessLogs;
}
public ObjectsTemplate<SuccessLogDetail> GetSuccessLogDetails(ID nID)
{
#region Cache Header
ObjectsTemplate<SuccessLogDetail> ErrorSuccessLogs = _cache["GetSuccessLogDetail"] as ObjectsTemplate<SuccessLogDetail>;
if (ErrorSuccessLogs != null)
return ErrorSuccessLogs;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ErrorSuccessLogDA.GetSuccessLogDetail(tc, nID));
ErrorSuccessLogs = this.CreateSuccessLogDetailObjects(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(ErrorSuccessLogs, "GetSuccessLogDetail");
#endregion
return ErrorSuccessLogs;
}
public ID Save(ErrorSuccessLog oErrorSuccessLog)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
//if (oErrorSuccessLog.IsNew)
//{
int id = tc.GenerateID("ErrorSuccessLog", "ErrorSuccessLogID");
base.SetObjectID(oErrorSuccessLog, ID.FromInteger(id));
ErrorSuccessLogDA.Insert(tc, oErrorSuccessLog);
foreach (ErrorLogDetail item in oErrorSuccessLog.ErrorLogDetails)
{
int id1 = tc.GenerateID("ErrorLogDetail", "ErrorLogDetailID");
base.SetObjectID(item, ID.FromInteger(id));
item.ErrorSuccessLogID = ID.FromInteger(id);
ErrorSuccessLogDA.Insert(tc, item);
}
foreach (SuccessLogDetail item in oErrorSuccessLog.SuccessLogDetails)
{
int id1 = tc.GenerateID("SuccessLogDetail", "SuccessLogDetailID");
base.SetObjectID(item, ID.FromInteger(id));
item.ErrorSuccessLogID = ID.FromInteger(id);
ErrorSuccessLogDA.Insert(tc, item);
}
// }
tc.End();
return oErrorSuccessLog.ID;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public void Update(ErrorSuccessLog oErrorSuccessLog)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
ErrorSuccessLogDA.Update(tc, oErrorSuccessLog);
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
}