/// <summary> /// Constructs a MatrixReport /// </summary> /// <param name="reportConstituents">A ReportDefinitionBusinessObject /// encapsulating the input parameters.</param> public MatrixReport(ReportDefinitionBusinessObject reportConstituents, string modelDataSource) { _dataSource = modelDataSource; //switch (model) //{ // case "INES": // _dataSource = "ESF2007"; // break; // case "MI Participant": // _dataSource = "ESFMIBUSINESSDATA"; // break; // case "Managing Authority": // _dataSource = "MANAGINGAUTHORITYDATA"; // break; //} //_dbConnectionString // = ConfigurationManager.ConnectionStrings["BusinessDataConnectionString"].ConnectionString; CurrentDataModel = DataAccessUtilities.RepositoryLocator <IDataModelRepository>().Single(x => x.DatasourceName == _dataSource, "DataTables", "DataTables.DataItems", "DataCategories", "DataTableJoins", "DataTableJoins.DataTableRelationshipJoins", "DataTableJoins.DataTableRelationshipJoins.DataTableRelashionship", "DataTableJoins.DataTableRelationshipJoins.DataTableRelashionship.DataTable", "DataTableJoins.DataTableRelationshipJoins.DataTableRelashionship.DataTable1"); _textboxStyle = new ReportingServicesStyle( ReportingServicesStyle.TextBoxStyle.MatrixReport); _cornerTextboxStyle = new ReportingServicesStyle( ReportingServicesStyle.TextBoxStyle.MatrixReportCorner); _columnTotalDataItemList = reportConstituents.ColumnTotalDataItems; _rowTotalDataItemList = reportConstituents.RowTotalDataItems; if (reportConstituents.IsOuterJoin == false) { _joinMethod = " FULL OUTER JOIN "; } else { _joinMethod = " INNER JOIN "; } // Temporary ArrayList used when instantiating the Dataset List <DataItem> TempGroupList = new List <DataItem>(reportConstituents.RowTotalDataItems); TempGroupList.AddRange(reportConstituents.ColumnTotalDataItems); // Initialise the querywrappers _mainQueryWrapper = new QueryWrapper(reportConstituents.SelectedDataItems, TempGroupList, reportConstituents.FilterList, reportConstituents.ParameterDataItems, false, reportConstituents.JoinList, CurrentDataModel); //30/06/05 LL - TIR0163 Parameter query needs to be build for each data item foreach (DataItem CurrentParameter in reportConstituents.ParameterDataItems) { if (!CurrentParameter.IsValueType) { List <DataItem> ParameterList = new List <DataItem>(); ParameterList.Add(CurrentParameter); _parameterQueryWrapperArrayList.Add(new QueryWrapper(ParameterList, null, null, null, true, null, CurrentDataModel)); } } // Iteration counter used in MatrixRow and MatrixStaticRow instantiations int MatrixRowCount = 0; /* Used when instantiating ColumnGroup and RowGroup lists: * The bools Denote if current item is first in list, so should be set to * false after first item dealt with. * The PrevItemName is the name of the item previous to the current item. */ bool IsFirstInColGroupList = true, IsFirstInRowGroupList = true; string PrevItemName = ""; // MatrixRow foreach (DataItem SelectedItem in reportConstituents.SelectedDataItems) { if (!reportConstituents.RowTotalDataItems.Contains(SelectedItem) && !reportConstituents.ColumnTotalDataItems.Contains(SelectedItem)) { _matrixRowList.Add( new MatrixRow("MatrixRowTextBox" + MatrixRowCount, SelectedItem, CurrentDataModel)); } MatrixRowCount++; } // MatrixDynamicColumnGrouping foreach (DataItem ColumnItem in reportConstituents.ColumnTotalDataItems) { if (IsFirstInColGroupList) { // To ensure drilldown groupname is unique in case of data items with same name, // concatenate the tablename and itemname DataTable SubtotalDataTable = CurrentDataModel.DataTables.Single(x => x.Code == ColumnItem.DataTableCode);//DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(ColumnItem.DataTableCode); string SubtotalTableName = SubtotalDataTable.Name; string SubtotalName = SubtotalTableName + ColumnItem.Name + "Subtotal"; _dynamicColumnGroupingList.Add( new MatrixDynamicColumnGrouping(ColumnItem, SubtotalName, true, CurrentDataModel)); IsFirstInColGroupList = false; } else { _dynamicColumnGroupingList.Add( new MatrixDynamicColumnGrouping(ColumnItem, PrevItemName, false, CurrentDataModel)); } // To ensure field name is unique in case of data items with same name, // concatenate the tablename and itemname DataTable ThisDataTable = CurrentDataModel.DataTables.Single(x => x.Code == ColumnItem.DataTableCode);//DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(ColumnItem.DataTableCode); string TableName = ThisDataTable.Name; PrevItemName = TableName + ColumnItem.Name; } // MatrixDynamicRowGrouping foreach (DataItem RowItem in reportConstituents.RowTotalDataItems) { if (IsFirstInRowGroupList) { // To ensure drilldown groupname is unique in case of data items with same name, // concatenate the tablename and itemname DataTable SubtotalDataTable = CurrentDataModel.DataTables.Single(x => x.Code == RowItem.DataTableCode);//DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(RowItem.DataTableCode); string SubtotalTableName = SubtotalDataTable.Name; string SubtotalName = SubtotalTableName + RowItem.Name + "Subtotal"; _dynamicRowGroupingList.Add( new MatrixDynamicRowGrouping(RowItem, SubtotalName, true, CurrentDataModel)); IsFirstInRowGroupList = false; } else { _dynamicRowGroupingList.Add( new MatrixDynamicRowGrouping(RowItem, PrevItemName, false, CurrentDataModel)); } // To ensure field name is unique in case of data items with same name, // concatenate the tablename and itemname DataTable ThisDataTable = CurrentDataModel.DataTables.Single(x => x.Code == RowItem.DataTableCode);//DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(RowItem.DataTableCode); string TableName = ThisDataTable.Name; PrevItemName = TableName + RowItem.Name; } // MatrixStaticRow MatrixRowCount = 0; foreach (DataItem SelectedItem in reportConstituents.SelectedDataItems) { if (!(reportConstituents.RowTotalDataItems.Contains(SelectedItem)) && !(reportConstituents.ColumnTotalDataItems.Contains(SelectedItem))) { _matrixStaticRowList.Add(new MatrixStaticRow( "MatrixStaticRowTextBox" + MatrixRowCount, SelectedItem, CurrentDataModel)); } MatrixRowCount++; } // Dataset _datasetList.Add(new Dataset(reportConstituents.SelectedDataItems, _matrixDataSetName, _mainQueryWrapper, CurrentDataModel)); //30/06/05 LL - TIR0163 Parameter query needs to be build for each data item int i = 0; foreach (DataItem Item in reportConstituents.ParameterDataItems) { if (!Item.IsValueType) { // We only require a query for the current data item, so put it into // an arraylist to pass to the Dataset constructor. List <DataItem> ParameterList = new List <DataItem>(); ParameterList.Add(Item); // To ensure this parameter's datasetname is unique in case of data items // with same name, concatenate the tablename and itemname DataTable ThisDataTable = CurrentDataModel.DataTables.Single(x => x.Code == Item.DataTableCode);//DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(Item.DataTableCode); string TableName = ThisDataTable.Name; _datasetList.Add(new Dataset(ParameterList, TableName + Item.Name + "Parameter", (QueryWrapper)_parameterQueryWrapperArrayList[i], CurrentDataModel)); _parameterName = TableName + Item.Name; _parameterCaption = Item.Caption; _parameterName = "=\"Selected " + _parameterCaption + " :\"+Parameters!" + _parameterName + ".Value"; _parameterList.Add(_parameterName); i++; } } // ReportParameter foreach (DataItem ParameterItem in reportConstituents.ParameterDataItems) { _reportParameterList.Add(new ReportParameter(ParameterItem, CurrentDataModel)); } //Report Description DBS _reportDescription = "Report Description : " + reportConstituents.ReportDescription + " . Show only data with a common denominator = " + reportConstituents.IsOuterJoin.ToString(); foreach (ReportFilterBusinessObject CurrentFilter in reportConstituents.FilterList) { //TODO: Code Review Issue 11/05/05: Do not use 'my' in variable names. //Choose a meaningful name. Pascal casing for variables. // Done 24/05/2005 Guid DataItemCode = Guid.Parse(CurrentFilter.DataItemCode); DataItem CurrentItem = CurrentDataModel.DataTables.SelectMany(x => x.DataItems).Single(y => y.Code == DataItemCode); //DataAccessUtilities.RepositoryLocator<IDataItemRepository>().GetByCode((CurrentFilter.DataItemCode)); DataTable CurrentTable = CurrentDataModel.DataTables.Single(x => x.Code == CurrentItem.DataTableCode); //DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(CurrentItem.DataTableCode); //25/08/05 LL - TIR0289 convert 'Current Month' to appropriate data format if (CurrentFilter.FilterValue == CURRENTMONTH) { CurrentFilter.FilterValue = DateUtility.GetCurrentYearMonth(); } ReportFilterBusinessObject ReportFilter = new ReportFilterBusinessObject(); ReportFilter.DataItemCaption = CurrentItem.Caption; ReportFilter.Operand = CurrentFilter.Operand; ReportFilter.FilterValue = CurrentFilter.FilterValue; _filterItemList.Add(ReportFilter); } // Initialise the MemoryStream and the XmlWriter _memoryStream = new MemoryStream(); _xmlWriter = new XmlTextWriter( _memoryStream, Encoding.UTF8); // Either of the lines below may be used as alternative outputs for debugging //_stream, Encoding.UTF8); // Console.Out); }
/// <summary> /// Constructs a TabularReport. /// </summary> /// <param name="reportConstituents">A ReportDefinitionBusinessObject /// encapsulating the input parameters.</param> public TabularReport(ReportDefinitionBusinessObject reportConstituents, string modelDataSource) { _dataSource = modelDataSource; //switch (model) //{ // case "INES": // _dataSource = "ESF2007"; // break; // case "MI Participant": // _dataSource = "ESFMIBUSINESSDATA"; // break; // case "Managing Authority": // _dataSource = "MANAGINGAUTHORITYDATA"; // break; //} //_dbConnectionString // = ConfigurationManager.ConnectionStrings["BusinessDataConnectionString"].ConnectionString; // When instantiating the TableGroups, we must record whether we are // instantiating the first group or not AND the name of the group previous // to the one we are currently dealing with. CurrentDataModel = DataAccessUtilities.RepositoryLocator <IDataModelRepository>().Single(x => x.DatasourceName == _dataSource, "DataTables", "DataTables.DataItems", "DataCategories", "DataTableJoins", "DataTableJoins.DataTableRelationshipJoins", "DataTableJoins.DataTableRelationshipJoins.DataTableRelationship", "DataTableJoins.DataTableRelationshipJoins.DataTableRelationship.DataTable", "DataTableJoins.DataTableRelationshipJoins.DataTableRelationship.DataTable1"); bool IsFirstGroup = true; string PreviousGroupName = ""; bool IsDataMapDisplayed = false; IsDataMapDisplayed = reportConstituents.IsDataMapDisplayed; _noOfFilters = reportConstituents.FilterList.Count; //Table Join _isDrillDown = reportConstituents.IsDrillDown; _isPageOnFirstItem = reportConstituents.IsPageBreak; if (reportConstituents.IsOuterJoin == false) { _joinMethod = " FULL OUTER JOIN "; } else { _joinMethod = " INNER JOIN "; } // Get the selectedDataItems _selectedDataItems = reportConstituents.SelectedDataItems; _fieldDataItems = reportConstituents.FieldDataItems; // Instantiate the querywrapper for the main query _mainQueryWrapper = new QueryWrapper(reportConstituents.SelectedDataItems, reportConstituents.RowTotalDataItems, reportConstituents.FilterList, reportConstituents.ParameterDataItems, false, reportConstituents.JoinList, CurrentDataModel); // Instantiate the querywrapper for the parameter query //30/06/05 LL - TIR0163 Parameter query needs to be build for each data item foreach (DataItem CurrentParameter in reportConstituents.ParameterDataItems) { if (!CurrentParameter.IsValueType) { List <DataItem> ParameterList = new List <DataItem>(); ParameterList.Add(CurrentParameter); _parameterQueryWrapperArrayList.Add(new QueryWrapper(ParameterList, null, null, null, true, null, CurrentDataModel)); } } // Call the constructors of each of the report constituents // TableHeader _tableHeader = new TableHeader(reportConstituents.FieldDataItems, DataAccessUtilities.RepositoryLocator <IDataTableRepository>(), CurrentDataModel); // TableFooter #region Join Description Appended //Add any joins in the list that are in the JoinList StringBuilder JoinDescription = new StringBuilder(); foreach (ReportDataTableJoin currentReportJoin in reportConstituents.JoinList) { DataTableJoin currentJoin = CurrentDataModel.DataTableJoins.Single(x => x.Code == currentReportJoin.DataTableJoinCode); string fromTablePlural = currentJoin.FromTable.Substring(currentJoin.FromTable.Length - 1).ToUpper() == "Y" ? currentJoin.FromTable.Substring(0, currentJoin.FromTable.Length - 1) + "ies" : currentJoin.FromTable + "s"; string toTablePlural = currentJoin.ToTable.Substring(currentJoin.ToTable.Length - 1).ToUpper() == "Y" ? currentJoin.ToTable.Substring(0, currentJoin.ToTable.Length - 1) + "ies" : currentJoin.ToTable + "s"; switch (currentReportJoin.JoinType) { case "INNER": JoinDescription.Append("INNER: Select only " + fromTablePlural + " that have related " + toTablePlural + " and " + "select only " + toTablePlural + " that have related " + fromTablePlural + Environment.NewLine); break; case "LEFT": JoinDescription.Append("LEFT: Select all " + fromTablePlural + " and only related " + toTablePlural + Environment.NewLine); break; case "RIGHT": JoinDescription.Append("RIGHT: Select all " + toTablePlural + " and only related " + fromTablePlural + Environment.NewLine); break; case "FULL": JoinDescription.Append("FULL: Select all " + fromTablePlural + " and " + toTablePlural + " with or without relations" + Environment.NewLine); break; } } #endregion _tableFooter = new TableFooter(reportConstituents.ReportDescription + Environment.NewLine + JoinDescription.ToString(), reportConstituents.FieldDataItems.Count.ToString(), reportConstituents.FilterList, CurrentDataModel); // TableGroup // This list contains data items that are not grouped by, but are moved into // being displayed within a group by the TableGroup constructor. List <DataItem> DataItemsPromotedToGroup = new List <DataItem>(); // This list contains the extra groups added by the wrapper. They are ordered, so // each group's index in the list (plus 1) is its grouping level. List <DataItem> NewGroupList = _mainQueryWrapper.NewGroupList; foreach (DataItem Item in reportConstituents.RowTotalDataItems) { if (reportConstituents.IsDrillDown) { if (IsFirstGroup) { _tableGroupList.Add(new TableGroup(reportConstituents.FieldDataItems, reportConstituents.RowTotalDataItems, Item, "", DataItemsPromotedToGroup, _mainQueryWrapper.NewGroupList, IsDataMapDisplayed, CurrentDataModel)); IsFirstGroup = false; } else { _tableGroupList.Add(new TableGroup(reportConstituents.FieldDataItems, reportConstituents.RowTotalDataItems, Item, PreviousGroupName, DataItemsPromotedToGroup, _mainQueryWrapper.NewGroupList, IsDataMapDisplayed, CurrentDataModel)); } } else { _tableGroupList.Add(new TableGroup(reportConstituents.FieldDataItems, reportConstituents.RowTotalDataItems, Item, "", DataItemsPromotedToGroup, _mainQueryWrapper.NewGroupList, IsDataMapDisplayed, CurrentDataModel)); } // To ensure grouping name is unique in case of data items with same name, // concatenate the tablename and itemname DataTable ThisDataTable = CurrentDataModel.DataTables.Single(x => x.Code == Item.DataTableCode); //DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(Item.DataTableCode); string TableName = ThisDataTable.Name; PreviousGroupName = TableName + Item.Name; } // TableDetails if (reportConstituents.IsDrillDown) { _tableDetails = new TableDetails(reportConstituents.FieldDataItems, reportConstituents.RowTotalDataItems, PreviousGroupName, DataItemsPromotedToGroup, IsDataMapDisplayed, CurrentDataModel); } else { _tableDetails = new TableDetails(reportConstituents.FieldDataItems, reportConstituents.RowTotalDataItems, "", DataItemsPromotedToGroup, reportConstituents.IsDataMapDisplayed, CurrentDataModel); } // IsSummaryReport _isSummaryReport = reportConstituents.IsSummaryReport; // Dataset for main query _datasetList.Add(new Dataset(reportConstituents.SelectedDataItems, "Table", _mainQueryWrapper, CurrentDataModel)); //30/06/05 LL - TIR0163 Parameter query needs to be build for each data item int i = 0; foreach (DataItem Item in reportConstituents.ParameterDataItems) { // Add a dataset for each reference-type parameter if (!Item.IsValueType || Item.DataType == "bit") { // We only require a query for the current data item, so put it into // an arraylist to pass to the Dataset constructor. List <DataItem> ParameterList = new List <DataItem>(); ParameterList.Add(Item); // To ensure this parameter's datasetname is unique in case of data items // with same name, concatenate the tablename and itemname DataTable ThisDataTable = CurrentDataModel.DataTables.Single(x => x.Code == Item.DataTableCode);//DataAccessUtilities.RepositoryLocator<IDataTableRepository>().GetByCode(Item.DataTableCode); string TableName = ThisDataTable.Name; if (Item.DataType != "bit") { _datasetList.Add(new Dataset(ParameterList, TableName + Item.Name + "Parameter", (QueryWrapper)_parameterQueryWrapperArrayList[i], CurrentDataModel)); i++; } _parameterName = TableName + Item.Name; _parameterCaption = Item.Caption; _parameterName = "=\"Selected " + _parameterCaption + " :\"+Parameters!" + _parameterName + ".Label"; _parameterList.Add(_parameterName); } // ReportParameter _reportParametersList.Add(new ReportParameter(Item, CurrentDataModel)); } reportConstituents.ChartList = (from x in reportConstituents.ChartList orderby x.SortOrder select x).ToList(); foreach (ReportChartBusinessObject ChartItem in reportConstituents.ChartList) { Guid CategoryDataItemCode = Guid.Parse(ChartItem.CategoryDataItemCode); DataItem CategoryDataItem = CurrentDataModel.DataTables.SelectMany(x => x.DataItems).Single(y => y.Code == CategoryDataItemCode);//DataAccessUtilities.RepositoryLocator<IDataItemRepository>().GetByCode(CategoryDataItemCode); List <DataItem> ChartSeriesDataItems = new List <DataItem>(); ChartItem.ChartSeriesList = (from x in ChartItem.ChartSeriesList orderby x.SortOrder select x).ToList(); foreach (ReportChartSeriesBusinessObject currentSeries in ChartItem.ChartSeriesList) { Guid seriesDataItemCode = Guid.Parse(currentSeries.SeriesDataItemCode); DataItem SeriesDataItem = CurrentDataModel.DataTables.SelectMany(x => x.DataItems).Single(y => y.Code == seriesDataItemCode);//DataAccessUtilities.RepositoryLocator<IDataItemRepository>().GetByCode(seriesDataItemCode); ChartSeriesDataItems.Add(SeriesDataItem); } Chart newChart = new Chart(ChartItem.Type, CategoryDataItem, "TableDataSet", ChartSeriesDataItems[0].DataType, ChartSeriesDataItems, ChartItem.SortOrder, ChartItem.Description, CurrentDataModel); _chartList.Add(newChart); } // Initialise the MemoryStream and the XmlWriter _memoryStream = new MemoryStream(); _xmlWriter = new XmlTextWriter( _memoryStream, Encoding.UTF8); // Either of the lines below may be used as alternative outputs for debugging // _stream, Encoding.UTF8); // Console.Out); }