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

279 lines
9.8 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 ReportItem Service
[Serializable]
public class ReportItemService : ServiceTemplate, IReportItemService
{
#region Private functions and declaration
Cache _cache = new Cache(typeof(ReportItem));
#endregion
public ReportItemService() { }
private void MapObject(ReportItem oReportItem, DataReader oReader)
{
base.SetObjectID(oReportItem, oReader.GetID("ReportItemID"));
oReportItem.ReportID = oReader.GetID("reportID");
oReportItem.Name = oReader.GetString("name");
oReportItem.ReportType = oReader.GetString("reportType");
oReportItem.DefaultHeader = oReader.GetString("defaultHeader");
oReportItem.UserHeader1 = oReader.GetString("userHeader1");
oReportItem.UserHeader2 = oReader.GetString("userHeader2");
oReportItem.Chronology = (EnumChronology)oReader.GetInt32("chronology").Value;
oReportItem.SearchFrom = (EnumSearchFrom)oReader.GetInt32("searchFrom").Value;
oReportItem.ItemType = (EnumReportItemType)oReader.GetInt32("itemType").Value;
//Boolean Check[Report Authentications]
oReportItem.IsCompanyInfo = oReader.GetBoolean("isCompanyInfo").Value;
oReportItem.IsDateMonth = oReader.GetBoolean("isDateMonth").Value;
oReportItem.IsSearchCriteria = oReader.GetBoolean("isSearchCriteria").Value;
oReportItem.IsGroupEachPage = oReader.GetBoolean("isGroupEachPage").Value;
oReportItem.IsPageNo = oReader.GetBoolean("isPageNo").Value;
oReportItem.IsDateTime = oReader.GetBoolean("isDateTime").Value;
oReportItem.IsGroupbyCriteria = oReader.GetBoolean("isGroupbyCriteria").Value;
oReportItem.BankNeeded = oReader.GetBoolean("bankNeeded").Value;
oReportItem.ObjectName = oReader.GetString("ObjectName");
oReportItem.FunctionName = oReader.GetString("FunctionName");
oReportItem.Status = (EnumStatus)oReader.GetInt32("Status").Value;
//oReportItem.IsSignatoriesEachPageFooter = oReader.GetBoolean("isPrintSignature").Value;
// oReportItem.CreatedBy = oReader.GetID("CreatedBy");
//oReportItem.CreatedDate = oReader.GetDateTime("CreatedDate").Value;
// oReportItem.ModifiedBy = oReader.GetID("ModifiedBy");
// oReportItem.ModifiedDate = oReader.GetDateTime("ModifiedDate").HasValue ? oReader.GetDateTime("ModifiedDate").Value : (DateTime?)null;
//oReportItem.INSQL = oReader.GetString("iNSQL");
//oReportItem.SearchItems = oReader.GetString("searchItems");
//oReportItem.ProgressBar = oReader.GetInt32("progressBar").Value;
this.SetObjectState(oReportItem, Ease.CoreV35.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader oReader)
{
ReportItem oReportItem = new ReportItem();
MapObject(oReportItem, oReader);
return oReportItem as T;
}
protected ReportItem CreateObject(DataReader oReader)
{
ReportItem oReportItem = new ReportItem();
MapObject(oReportItem, oReader);
return oReportItem;
}
#region Service implementation
public ReportItem GetByReportType(int reportID)
{
ReportItem oReportItem = new ReportItem();
#region Cache Header
oReportItem = _cache["GetByReportType", reportID] as ReportItem;
if (oReportItem != null)
return oReportItem;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ReportItemDA.GetByReportType(tc, reportID));
if (oreader.Read())
{
oReportItem = this.CreateObject<ReportItem>(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(oReportItem, "GetByReportType", reportID);
#endregion
return oReportItem;
}
public ReportItem Get(ID id)
{
ReportItem oReportItem = new ReportItem();
#region Cache Header
oReportItem = _cache["Get", id] as ReportItem;
if (oReportItem != null)
return oReportItem;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader oreader = new DataReader(ReportItemDA.Get(tc, id));
if (oreader.Read())
{
oReportItem = this.CreateObject<ReportItem>(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(oReportItem, "Get", id);
#endregion
return oReportItem;
}
public ObjectsTemplate<ReportItem> Get(EnumStatus eStatus)
{
#region Cache Header
ObjectsTemplate<ReportItem> reportItems = _cache["Get"] as ObjectsTemplate<ReportItem>;
if (reportItems != null)
return reportItems;
#endregion
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ReportItemDA.Get(tc,eStatus));
reportItems = this.CreateObjects<ReportItem>(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(reportItems, "Get");
#endregion
return reportItems;
}
public bool IsExist(ID ReportID)
{
TransactionContext tc = null;
bool IsExist = false;
try
{
tc = TransactionContext.Begin(true);
IsExist = ReportItemDA.IsExist(tc, ReportID);
return IsExist;
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
ExceptionLog.Write(e);
throw new ServiceException(e.Message, e);
#endregion
}
}
public ID Save(ReportItem oReportItem)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oReportItem.IsNew)
{
int id = tc.GenerateID("ReportItem", "ReportItemID");
base.SetObjectID(oReportItem, ID.FromInteger(id));
oReportItem.Status = EnumStatus.Active;
ReportItemDA.Insert(tc, oReportItem);
if (oReportItem.ReportAuthors != null && oReportItem.ReportAuthors.Count>0)
{
foreach (ReportAuthorization oReportAuthor in oReportItem.ReportAuthors)
{
ReportAuthorizationDA.Insert(tc, oReportAuthor);
}
}
}
else
{
ReportItemDA.Update(tc, oReportItem);
if (oReportItem.ReportAuthors != null)
{
foreach (ReportAuthorization oReportAuthor in oReportItem.ReportAuthors)
{
ReportAuthorizationDA.Insert(tc, oReportAuthor);
}
}
}
tc.End();
return oReportItem.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);
ReportItemDA.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
}