/// <summary> /// Try to populate the grid with the current result. /// </summary> /// <returns>s false if no detail report is available /// </returns> public Boolean PopulateResultGrid(TSgrdDataGrid ASgGridView) { Boolean ReturnValue; DataTable t; DataRow row; Int32 i; Int32 counter; Int32 columnCounter; string caption; ArrayList sortedList; bool display; ReturnValue = true; FGridView = ASgGridView; // only do this if there are detail reports available // this is to prevent bugs that are still happening (same column caption etc) if (!parameters.Exists("param_detail_report_0")) { return(false); } results.SortChildren(); sortedList = new ArrayList(); results.CreateSortedListByMaster(sortedList, 0); // create columns // todo: header left // todo: indented columns t = new DataTable(); columnCounter = 0; t.Columns.Add("id"); for (i = 0; i <= results.GetMaxDisplayColumns() - 1; i += 1) { if ((!parameters.Get("ColumnCaption", i).IsNil())) { caption = (parameters.Get("ColumnCaption", i).ToString() + ' ' + parameters.Get("ColumnCaption2", i).ToString(false) + ' ' + parameters.Get("ColumnCaption3", i).ToString(false)).Trim(); // todo: add i for preventing same name columns (finance reports, long captions) if (t.Columns.Contains(caption)) { caption = caption + i.ToString(); } } else { caption = "Column" + i.ToString(); } /* if useIndented then * begin * columnCounter := ColumnCounter + 1; * t.Columns.Add(caption + 'Indented'); * end; */ t.Columns.Add(caption); columnCounter = columnCounter + 1; } foreach (TResult element in sortedList) { if (element.display) { row = t.NewRow(); display = false; row[0] = element.code; for (i = 0; i <= results.GetMaxDisplayColumns() - 1; i += 1) { if ((element.column[i] != null) && (!element.column[i].IsNil())) { display = true; row[i + 1] = element.column[i].ToString(); } } if (display) { t.Rows.Add(row); } } } FGridView.Columns.Clear(); FGridView.AddTextColumn(t.Columns[0].ColumnName, t.Columns[0], 0); for (counter = 0; counter <= parameters.Get("MaxDisplayColumns").ToInt() - 1; counter += 1) { FGridView.AddTextColumn(t.Columns[counter + 1].ColumnName, t.Columns[counter + 1]); } FGridView.DataSource = new DevAge.ComponentModel.BoundDataView(new DataView(t)); ((DevAge.ComponentModel.BoundDataView)FGridView.DataSource).AllowEdit = false; ((DevAge.ComponentModel.BoundDataView)FGridView.DataSource).AllowNew = false; ((DevAge.ComponentModel.BoundDataView)FGridView.DataSource).AllowDelete = false; FGridView.AutoSizeCells(); // FGridView.Width := 576; it is necessary to reassign the width because the columns don't take up the maximum width return(ReturnValue); }
/// <summary> /// Export the full result to Excel /// it is a modification of TResult.writeCSV /// /// </summary> /// <returns>void</returns> public void ExportResult() { int i; ArrayList sortedList; bool display; System.Int32 columnCounter; System.Int32 rowCounter; bool useIndented; // write headings rowCounter = 1; columnCounter = 1; SetValue(GetRange(columnCounter, rowCounter), "id"); columnCounter = columnCounter + 1; if (parameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1)) { SetValue(GetRange(columnCounter, rowCounter), parameters.Get("ControlSource", ReportingConsts.HEADERPAGELEFT1).ToString()); columnCounter = columnCounter + 1; } if (parameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2)) { SetValue(GetRange(columnCounter, rowCounter), parameters.Get("ControlSource", ReportingConsts.HEADERPAGELEFT2).ToString()); columnCounter = columnCounter + 1; } if (parameters.Exists("ControlSource", ReportingConsts.HEADERCOLUMN)) { SetValue(GetRange(columnCounter, rowCounter), "header 1"); columnCounter = columnCounter + 1; SetValue(GetRange(columnCounter, rowCounter), "header 0"); columnCounter = columnCounter + 1; } parameters.Add("CurrentSubReport", 0); // otherwise 'indented' cannot be read useIndented = false; for (i = 0; i <= parameters.Get("lowestLevel").ToInt(); i += 1) { if (parameters.Exists("indented", ReportingConsts.ALLCOLUMNS, i)) { useIndented = true; } } for (i = 0; i <= -1; i += 1) { if ((!parameters.Get("ColumnCaption", i).IsNil())) { SetValue(GetRange(columnCounter, rowCounter), (parameters.Get("ColumnCaption", i).ToString() + ' ' + parameters.Get("ColumnCaption2", i).ToString(false) + ' ' + parameters.Get("ColumnCaption3", i).ToString(false)).Trim()); if (useIndented) { columnCounter++; } columnCounter++; } } rowCounter = rowCounter + 1; results.SortChildren(); sortedList = new ArrayList(); results.CreateSortedListByMaster(sortedList, 0); // write each row to CSV file foreach (TResult element in sortedList) { if (element.display) { columnCounter = 1; SetValue(GetRange(columnCounter, rowCounter), element.code); columnCounter++; if (parameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT1)) { SetValue(GetRange(columnCounter, rowCounter), element.descr[0].ToString()); columnCounter++; } if (parameters.Exists("ControlSource", ReportingConsts.HEADERPAGELEFT2)) { SetValue(GetRange(columnCounter, rowCounter), element.descr[1].ToString()); columnCounter++; } if (parameters.Exists("ControlSource", ReportingConsts.HEADERCOLUMN)) { SetValue(GetRange(columnCounter, rowCounter), element.header[1].ToString()); columnCounter++; SetValue(GetRange(columnCounter, rowCounter), element.header[0].ToString()); columnCounter++; } display = false; for (i = 0; i <= results.GetMaxDisplayColumns() - 1; i += 1) { if (parameters.Get("indented", i, element.depth, eParameterFit.eAllColumnFit).ToBool() == true) { columnCounter++; } if ((element.column != null) && (!element.column[i].IsNil())) { display = true; SetValue(GetRange(columnCounter, rowCounter), element.column[i].ToString()); } else { SetValue(GetRange(columnCounter, rowCounter), ""); } if ((parameters.Get("indented", i, element.depth, eParameterFit.eAllColumnFit).ToBool() != true) && useIndented) { columnCounter++; } columnCounter++; } if (display) { rowCounter++; } } } // todo: autofit all columns after the export to Excel // VBA: // Cells.Select // Cells.EntireColumn.AutoFit }