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(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(iReader); iReader.Close(); iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID)); column.Dependancys = this.CreateObjects(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 Get() { List items = null; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader iReader = new DataReader(ReportColumnDefinitionDA.Get(tc)); items = this.CreateObjects(iReader); iReader.Close(); foreach (ReportColumnDefinition column in items) { iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID)); column.Dependancys = this.CreateObjects(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 SearchRCD(string searchString) { List items; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader iReader = new DataReader(ReportColumnDefinitionDA.SearchRCD(tc, searchString)); items = this.CreateObjects(iReader); iReader.Close(); foreach (ReportColumnDefinition column in items) { iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID)); column.Dependancys = this.CreateObjects(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 GetBySubGroup(int subGroupID) { List items; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader iReader = new DataReader(ReportColumnDefinitionDA.GetBySubGroup(tc, subGroupID)); items = this.CreateObjects(iReader); iReader.Close(); foreach (ReportColumnDefinition column in items) { iReader = new DataReader(ReportColumnDefinitionDA.GetChild(tc, column.ID)); column.Dependancys = this.CreateObjects(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 GetByReport(int reportID) { List items; TransactionContext tc = null; try { #region Retrieving data tc = TransactionContext.Begin(); DataReader iReader = new DataReader(ReportColumnDefinitionDA.GetByReport(tc, reportID)); items = this.CreateObjects(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 } }