EchoTex_Payroll/HRM.DA/Service/SearchTools/ReportColumnDefinitionService.cs

343 lines
10 KiB
C#
Raw Permalink Normal View History

2024-10-14 10:01:49 +06:00
using System;
using Ease.Core.Model;
using Ease.Core.DataAccess;
using Ease.Core.Utility;
using System.Collections.Generic;
using HRM.BO;
using System.Data;
namespace HRM.DA
{
public class ReportColumnDefinitionService : ServiceTemplate
{
#region Constructor
public ReportColumnDefinitionService()
{
}
#endregion
private void MapObject(ReportColumnDefinition oReportColumnDefinition, DataReader dr)
{
base.SetObjectID(oReportColumnDefinition, dr.GetInt32("ReportColumnDefinitionId").Value);
oReportColumnDefinition.TableName = dr.GetString("TableName");
oReportColumnDefinition.ColumnName = dr.GetString("ColumnName");
oReportColumnDefinition.ColumnCode = dr.GetString("ColumnCode");
oReportColumnDefinition.Aggregate = dr.GetString("Aggregate");
oReportColumnDefinition.DataType = (ColumnDataTypeEnum)int.Parse(dr.GetString("DataType"));
oReportColumnDefinition.ColumnOrderBy = (OrderByEnum)int.Parse(dr.GetString("ColumnOrderBy"));
this.SetObjectState(oReportColumnDefinition, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
ReportColumnDefinition oReportColumnDefinition = new ReportColumnDefinition();
MapObject(oReportColumnDefinition, dr);
return oReportColumnDefinition as T;
}
#region Comments
#endregion
#region Service Implementation
public void Save(ReportColumnDefinition rc)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (rc.IsNew)
{
int newID = ReportColumnDefinitionDA.GenID(tc);
base.SetObjectID(rc, (newID));
ReportColumnDefinitionDA.Insert(tc, rc);
foreach (PickerDependancy dependancy in rc.Dependancys)
{
int newchildID = ReportColumnDefinitionDA.GenChildID(tc);
base.SetObjectID(dependancy, (newchildID));
ReportColumnDefinitionDA.InsertChild(tc, dependancy);
}
}
else
{
ReportColumnDefinitionDA.Update(tc, rc);
ReportColumnDefinitionDA.DeleteByReportColumnID(tc, rc.ID);
foreach (PickerDependancy dependancy in rc.Dependancys)
{
int newchildID = ReportColumnDefinitionDA.GenChildID(tc);
base.SetObjectID(dependancy, (newchildID));
ReportColumnDefinitionDA.InsertChild(tc, dependancy);
}
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new ServiceException(e.Message, e);
}
}
public void Delete(int columnID)
{
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
ReportColumnDefinitionDA.DeleteByReportColumnID(tc, columnID);
ReportColumnDefinitionDA.Delete(tc, columnID);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
}
catch (Exception e)
{
throw new ServiceException(e.Message, e);
}
}
}
public ReportColumnDefinition Get(int columnID)
{
ReportColumnDefinition column;
TransactionContext tc = null;
try
{
#region Retrieving data
ConnectionContext ctx = new ConnectionContext("reportConnectionHandler1");
tc = TransactionContext.Begin(ctx);
DataReader iReader = new DataReader(ReportColumnDefinitionDA.Get(tc, columnID));
column = this.CreateObject<ReportColumnDefinition>(iReader);
iReader.Close();
iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID));
column.Dependancys = this.CreateObjects<PickerDependancy>(iReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return column;
}
public List<ReportColumnDefinition> Get()
{
List<ReportColumnDefinition> items = null;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(ReportColumnDefinitionDA.Get(tc));
items = this.CreateObjects<ReportColumnDefinition>(iReader);
iReader.Close();
foreach (ReportColumnDefinition column in items)
{
iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID));
column.Dependancys = this.CreateObjects<PickerDependancy>(iReader);
iReader.Close();
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return items;
}
public List<ReportColumnDefinition> SearchRCD(string searchString)
{
List<ReportColumnDefinition> items;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(ReportColumnDefinitionDA.SearchRCD(tc, searchString));
items = this.CreateObjects<ReportColumnDefinition>(iReader);
iReader.Close();
foreach (ReportColumnDefinition column in items)
{
iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID));
column.Dependancys = this.CreateObjects<PickerDependancy>(iReader);
iReader.Close();
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return items;
}
public List<ReportColumnDefinition> GetBySubGroup(int subGroupID)
{
List<ReportColumnDefinition> items;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(ReportColumnDefinitionDA.GetBySubGroup(tc, subGroupID));
items = this.CreateObjects<ReportColumnDefinition>(iReader);
iReader.Close();
foreach (ReportColumnDefinition column in items)
{
iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID));
column.Dependancys = this.CreateObjects<PickerDependancy>(iReader);
iReader.Close();
}
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return items;
}
public List<ReportColumnDefinition> GetByReport(int reportID)
{
List<ReportColumnDefinition> items;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(ReportColumnDefinitionDA.GetByReport(tc, reportID));
items = this.CreateObjects<ReportColumnDefinition>(iReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return items;
}
//public void SetIDOfAllItem(IndexedBusinessObjects objects)
//{
// if (objects.Count > 0)
// {
// int i = 0;
// foreach (BusinessObject bo in objects)
// {
// base.SetObjectID(bo, (++i));
// }
// }
//}
#endregion
}
}