EchoTex_Payroll/HRM.DA/Service/SearchReport/ReportItemService.cs

268 lines
8.6 KiB
C#
Raw Normal View History

2024-10-14 10:01:49 +06:00
using System;
using System.Data;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core;
using System.Collections.Generic;
using Ease.Core.Utility;
using System.IO;
using System.Data.SqlClient;
using HRM.BO;
namespace HRM.DA
{
#region ReportItem Service
public class ReportItemService : ServiceTemplate, IReportItemService
{
public ReportItemService()
{
}
private void MapObject(ReportItem oReportItem, DataReader oReader)
{
base.SetObjectID(oReportItem, (oReader.GetInt32("ReportItemID").Value));
oReportItem.ReportID = oReader.GetInt32("reportID", 0);
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.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.Core.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 = null;
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
}
return oReportItem;
}
public ReportItem Get(int id)
{
ReportItem oReportItem = null;
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
}
return oReportItem;
}
public List<ReportItem> Get()
{
List<ReportItem> reportItems = null;
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin();
DataReader dr = new DataReader(ReportItemDA.Get(tc));
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
}
return reportItems;
}
public bool IsExist(int 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 int Save(ReportItem oReportItem)
{
TransactionContext tc = null;
try
{
tc = TransactionContext.Begin(true);
if (oReportItem.IsNew)
{
int id = tc.GenerateID("ReportItem", "ReportItemID");
base.SetObjectID(oReportItem, (id));
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(int 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
}