EchoTex_Payroll/HRM.DA/Service/SearchTools/RelationTableService.cs
2024-10-14 10:01:49 +06:00

201 lines
5.5 KiB
C#

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 RelationTableService : ServiceTemplate
{
#region Constructor
public RelationTableService()
{
}
#endregion
#region Mapping
private void MapObject(RelationTable oRelationTable, DataReader dr)
{
base.SetObjectID(oRelationTable, dr.GetInt32("RelationTableId").Value);
oRelationTable.RelationId = dr.GetInt32("RelationId", 0);
oRelationTable.RelationName = dr.GetString("RelationName");
oRelationTable.MasterTableName = dr.GetString("MasterTableName");
oRelationTable.MasterColumn1Name = dr.GetString("MasterColumn1Name");
oRelationTable.LinkTableName = dr.GetString("LinkTableName");
oRelationTable.LinkColumn1Name = dr.GetString("LinkColumn1Name");
oRelationTable.JoinSql = dr.GetString("JoinSql");
oRelationTable.LinkColumn2Name = dr.GetString("LinkColumn2Name");
oRelationTable.LinkColumn3Name = dr.GetString("LinkColumn3Name");
oRelationTable.LinkColumn4Name = dr.GetString("LinkColumn4Name");
oRelationTable.MasterColumn2Name = dr.GetString("MasterColumn2Name");
oRelationTable.MasterColumn3Name = dr.GetString("MasterColumn3Name");
oRelationTable.MasterColumn4Name = dr.GetString("MasterColumn4Name");
this.SetObjectState(oRelationTable, Ease.Core.ObjectState.Saved);
}
protected override T CreateObject<T>(DataReader dr)
{
RelationTable oRelationTable = new RelationTable();
MapObject(oRelationTable, dr);
return oRelationTable as T;
}
#endregion
#region Service Implementation
public void Save(RelationTable group)
{
try
{
TransactionContext tc = null;
try
{
#region Saving data
tc = TransactionContext.Begin(true);
if (group.IsNew)
{
int newID = RelationTableDA.GenID(tc);
base.SetObjectID(group, newID);
RelationTableDA.Insert(tc, group);
}
else
RelationTableDA.Update(tc, group);
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 groupID)
{
{
try
{
TransactionContext tc = null;
try
{
#region Deleting data
tc = TransactionContext.Begin(true);
RelationTableDA.Delete(tc, groupID);
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 RelationTable Get(int groupID)
{
RelationTable group;
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(RelationTableDA.Get(tc, groupID));
group = this.CreateObject<RelationTable>(iReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return group;
}
public List<RelationTable> Get()
{
List<RelationTable> dbColumns = new List<RelationTable>();
TransactionContext tc = null;
try
{
#region Retrieving data
tc = TransactionContext.Begin();
DataReader iReader = new DataReader(RelationTableDA.Get(tc));
dbColumns = this.CreateObjects<RelationTable>(iReader);
tc.End();
#endregion
}
catch (Exception e)
{
#region Handle Exception
if (tc != null)
tc.HandleError();
throw new ServiceException(e.Message, e);
#endregion
}
return dbColumns;
}
#endregion
}
}