using System; using System.Collections.Generic; using System.Text; using Ease.Core.DataAccess; using Ease.Core.Model; using Ease.Core.Utility; using HRM.BO; using HRM.BO.SearchTools; using HRM.DA.DA.SearchTools; namespace HRM.DA.Service.SearchTools { public class QueryToolService : ServiceTemplate, IQueryToolService { public QueryToolService() { } private void MapObject(QueryTool item, DataReader dataReader) { base.SetObjectID(item, dataReader.GetInt32("QueryToolID").Value); item.SearchString = dataReader.GetString("SearchString"); item.Name = dataReader.GetString("Name"); item.Description = dataReader.GetString("Description"); item.SQL = dataReader.GetString("SQL"); item.QTModuleType = (EnumQTModuleType)dataReader.GetInt32("QTModuleType"); this.SetObjectState(item, Ease.Core.ObjectState.Saved); } protected override T CreateObject(DataReader dataReader) { QueryTool item = new QueryTool(); MapObject(item, dataReader); return item as T; } protected QueryTool CreateObject(DataReader dataReader) { QueryTool item = new QueryTool(); MapObject(item, dataReader); return item; } // QTColumn private void MapObjectQTColumn(QTColumn item, DataReader dataReader) { base.SetObjectID(item, dataReader.GetInt32("QTColumnID").Value); item.QueryToolID = dataReader.GetInt32("QueryToolID").Value; item.ColumnID = dataReader.GetInt32("ColumnID").Value; item.Alignment = (ColumnAlignmentEnum)dataReader.GetInt32("Alignment").Value; item.Aggregate = dataReader.GetString("Aggregate"); item.Format = dataReader.GetString("Format"); item.Caption = dataReader.GetString("Caption"); this.SetObjectState(item, Ease.Core.ObjectState.Saved); } private QTColumn CreateComponentQtColumn(DataReader dataReader) { QTColumn item = new QTColumn(); MapObjectQTColumn(item, dataReader); return item; } private List CreateComponentsQTColumn(DataReader dataReader) { List items = new List(); while (dataReader.Read()) { QTColumn item = new QTColumn(); item = CreateComponentQtColumn(dataReader); items.Add(item); } return items; } // QTSearchColumn private void MapObjectQTSearchColumn(QTSearchColumn item, DataReader dataReader) { base.SetObjectID(item, dataReader.GetInt32("QTSearchColumnID").Value); item.QueryToolID = dataReader.GetInt32("QueryToolID").Value; item.ColumnID = dataReader.GetInt32("ColumnID").Value; item.Caption = dataReader.GetString("Caption"); this.SetObjectState(item, Ease.Core.ObjectState.Saved); } private QTSearchColumn CreateComponentQTSearchColumn(DataReader dataReader) { QTSearchColumn item = new QTSearchColumn(); MapObjectQTSearchColumn(item, dataReader); return item; } private List CreateComponentsQTSearchColumn(DataReader dataReader) { List items = new List(); while (dataReader.Read()) { QTSearchColumn item = new QTSearchColumn(); item = CreateComponentQTSearchColumn(dataReader); items.Add(item); } return items; } // QTAuthorization private void MapObjectQTAuthorization(QTAuthorization item, DataReader dataReader) { base.SetObjectID(item, dataReader.GetInt32("QTAuthorizationID").Value); item.QueryToolID = dataReader.GetInt32("QueryToolID").Value; item.EmployeeID = dataReader.GetInt32("EmployeeID").Value; item.AuthorizeDate = dataReader.GetDateTime("AuthorizeDate").Value; item.Count = dataReader.GetInt32("Count").Value; this.SetObjectState(item, Ease.Core.ObjectState.Saved); } private QTAuthorization CreateComponentQTAuthorization(DataReader dataReader) { QTAuthorization item = new QTAuthorization(); MapObjectQTAuthorization(item, dataReader); return item; } private List CreateComponentsQTAuthorization(DataReader dataReader) { List items = new List(); while (dataReader.Read()) { QTAuthorization item = new QTAuthorization(); item = CreateComponentQTAuthorization(dataReader); items.Add(item); } return items; } public List GetAll() { TransactionContext tc = null; List items = new List(); List qtColumnList = new List(); List qtSearchColumnsList = new List(); List qtAuthorizationsList = new List(); try { tc = TransactionContext.Begin(); DataReader dr = new DataReader(QueryToolDA.GetAllQueryTool(tc)); items = this.CreateObjects(dr); dr.Close(); foreach (QueryTool queryTool in items) { DataReader dr2 = new DataReader(QueryToolDA.GetQTColumns(tc, queryTool.ID)); queryTool.DataColumns = this.CreateComponentsQTColumn(dr2); dr2.Close(); DataReader dr3 = new DataReader(QueryToolDA.GetQTSearchColumn(tc, queryTool.ID)); queryTool.SearchColumns = this.CreateComponentsQTSearchColumn(dr3); dr3.Close(); DataReader dr4 = new DataReader(QueryToolDA.GetQTAuthorization(tc, queryTool.ID)); queryTool.QtAuthorizations = this.CreateComponentsQTAuthorization(dr4); dr4.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 items; } public void SaveQueryTool(QueryTool item) { TransactionContext tc = null; try { int QueryToolID = 0; tc = TransactionContext.Begin(true); if (item.IsNew) { QueryToolID = tc.GenerateID("QueryTool", "QueryToolID"); base.SetObjectID(item, QueryToolID); QueryToolDA.Insert(tc, item); } else { QueryToolDA.Update(tc, item); QueryToolDA.DeleteChildData(tc, QueryToolID, "QTColumn"); QueryToolDA.DeleteChildData(tc, QueryToolID, "QTSearchColumn"); QueryToolDA.DeleteChildData(tc, QueryToolID, "QTAuthorization"); } foreach (QTColumn itemDataColumn in item.DataColumns) { int id = tc.GenerateID("QTColumn", "QTColumnID"); base.SetObjectID(itemDataColumn, id); /*this.SetObjectID(item, (QueryToolDA.GetNewID(tc, "QTColumn", "QTColumnID")));*/ itemDataColumn.QueryToolID = QueryToolID; QueryToolDA.Insert(tc, itemDataColumn); } foreach (QTSearchColumn itemSearchColumn in item.SearchColumns) { int id = tc.GenerateID("QTSearchColumn", "QTSearchColumnID"); base.SetObjectID(itemSearchColumn, id); /*this.SetObjectID(item, (QueryToolDA.GetNewID(tc, "QTSearchColumn", "QTSearchColumnID")));*/ itemSearchColumn.QueryToolID = QueryToolID; QueryToolDA.Insert(tc, itemSearchColumn); } foreach (QTAuthorization itemQtAuthorization in item.QtAuthorizations) { int id = tc.GenerateID("QTAuthorization", "QTAuthorizationID"); base.SetObjectID(itemQtAuthorization, id); /*this.SetObjectID(item, (QueryToolDA.GetNewID(tc, "QTAuthorization", "QTAuthorizationID")));*/ itemQtAuthorization.QueryToolID = QueryToolID; QueryToolDA.Insert(tc, itemQtAuthorization); } tc.End(); } catch (Exception e) { #region Handle Exception if (tc != null) tc.HandleError(); ExceptionLog.Write(e); throw new ServiceException(e.Message, e); #endregion } } } }