266 lines
6.8 KiB
C#
266 lines
6.8 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 DbColumnService : ServiceTemplate, IDbColumnsService
|
|||
|
{
|
|||
|
#region Constructor
|
|||
|
|
|||
|
public DbColumnService()
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Mapping
|
|||
|
|
|||
|
private void MapObject(DbColumns oDbColumns, DataReader dr)
|
|||
|
{
|
|||
|
base.SetObjectID(oDbColumns, dr.GetInt32("ColumnId").Value);
|
|||
|
oDbColumns.TableId = dr.GetInt32("TableId", 0);
|
|||
|
oDbColumns.TableName = dr.GetString("TableName");
|
|||
|
oDbColumns.ColumnName = dr.GetString("ColumnName");
|
|||
|
oDbColumns.DataType = (ColumnDataTypeEnum)dr.GetInt32("DataType", 0);
|
|||
|
oDbColumns.Size = dr.GetInt32("COLSIZE", 0);
|
|||
|
oDbColumns.AllowNull = dr.GetInt32("AllowNull", 0);
|
|||
|
oDbColumns.TableColumnName = dr.GetString("TableColumnName");
|
|||
|
oDbColumns.UsedAsSearch = dr.GetBoolean("UsedAsSearch", false);
|
|||
|
oDbColumns.SearchName = dr.GetString("SearchName");
|
|||
|
oDbColumns.StaticValue = dr.GetString("StaticValue");
|
|||
|
oDbColumns.Width = dr.GetInt32("Width", 0);
|
|||
|
oDbColumns.ColumnType = (EnumSearchToolColumnType)dr.GetInt32("ColumnType");
|
|||
|
|
|||
|
this.SetObjectState(oDbColumns, Ease.Core.ObjectState.Saved);
|
|||
|
}
|
|||
|
|
|||
|
protected override T CreateObject<T>(DataReader dr)
|
|||
|
{
|
|||
|
DbColumns oDbColumns = new DbColumns();
|
|||
|
MapObject(oDbColumns, dr);
|
|||
|
return oDbColumns as T;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Implementation
|
|||
|
|
|||
|
public void Save(DbColumns group)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Saving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin(true);
|
|||
|
|
|||
|
if (group.IsNew)
|
|||
|
{
|
|||
|
int newID = DbColumnsDA.GenID(tc);
|
|||
|
base.SetObjectID(group, newID);
|
|||
|
DbColumnsDA.Insert(tc, group);
|
|||
|
}
|
|||
|
else
|
|||
|
DbColumnsDA.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);
|
|||
|
|
|||
|
DbColumnsDA.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 DbColumns Get(int groupID)
|
|||
|
{
|
|||
|
DbColumns group;
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader iReader = new DataReader(DbColumnsDA.Get(tc, groupID));
|
|||
|
group = this.CreateObject<DbColumns>(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<DbColumns> Get()
|
|||
|
{
|
|||
|
List<DbColumns> dbColumns = new List<DbColumns>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader iReader = new DataReader(DbColumnsDA.Get(tc));
|
|||
|
dbColumns = this.CreateObjects<DbColumns>(iReader);
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return dbColumns;
|
|||
|
}
|
|||
|
|
|||
|
public List<DbColumns> GetByTableId(int tableId)
|
|||
|
{
|
|||
|
List<DbColumns> dbColumns = new List<DbColumns>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader iReader = new DataReader(DbColumnsDA.GetByTableName(tc, tableId));
|
|||
|
dbColumns = this.CreateObjects<DbColumns>(iReader);
|
|||
|
|
|||
|
tc.End();
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
#region Handle Exception
|
|||
|
|
|||
|
if (tc != null)
|
|||
|
tc.HandleError();
|
|||
|
|
|||
|
throw new ServiceException(e.Message, e);
|
|||
|
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
return dbColumns;
|
|||
|
}
|
|||
|
|
|||
|
public List<DbColumns> GetAll()
|
|||
|
{
|
|||
|
List<DbColumns> dbColumns = new List<DbColumns>();
|
|||
|
|
|||
|
TransactionContext tc = null;
|
|||
|
try
|
|||
|
{
|
|||
|
#region Retrieving data
|
|||
|
|
|||
|
tc = TransactionContext.Begin();
|
|||
|
|
|||
|
DataReader iReader = new DataReader(DbColumnsDA.GetAll(tc));
|
|||
|
dbColumns = this.CreateObjects<DbColumns>(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
|
|||
|
}
|
|||
|
}
|