Report with dynamic tables

Developer
Aug 6, 2009 at 9:24 AM

Hi hanswolff,

We have decided to use the WPF Reporting Engine project in one of our projects.

We have a request which i guess it could be useful to add to the project. Currently we have implemented it on a dirty way, but we would like to use the trunk version of the open source project in the coming years.


We need to create reports of dynamic tables, that means that the column definition could be modified on execution time.


The final Xaml file would be something like:

 

<TableRowGroup Style="{StaticResource headerFooterRowStyle}">
                    <xrd:TableRowForDynamicHeader TableName="Header"/>                                                          
                </TableRowGroup>
                
                <TableRowGroup Style="{StaticResource dataRowStyle}">
                    <xrd:TableRowForDynamicDataTable TableName="Data"/>                    
                </TableRowGroup>   

 

 

The implementation of the ReportPaginator(dirty/fast way):

 

 

foreach (ITableRowForDynamicDataTable iTableRow in dynamicDataTableRows)
            {
                TableRow tableRow = iTableRow as TableRow;
                if (tableRow == null) continue;

                TableRowGroup tableGroup = tableRow.Parent as TableRowGroup;
                if (tableGroup == null) continue;

                TableRow currentRow = null;

                DataTable table = _data.GetDataTableByName(iTableRow.TableName);

                for (int i = 0; i < table.Rows.Count; i++)
                {
                    currentRow = new TableRow();

                    DataRow dataRow = table.Rows[i];
                    for (int j = 0; j < table.Columns.Count; j++)
                    {
                        string value = dataRow[j].ToString();
                        currentRow.Cells.Add(new TableCell(new Paragraph(new Run(value))));
                    }
                    tableGroup.Rows.Add(currentRow);
                }
            }

            foreach (ITableRowForDynamicHeader iTableRow in dynamicHeaderTableRows)
            {
                TableRow tableRow = iTableRow as TableRow;
                if (tableRow == null) continue;

                DataTable table = _data.GetDataTableByName(iTableRow.TableName);

                foreach (DataRow row in table.Rows)
                {
                    string value = row[0].ToString();
                    TableCell tableCell = new TableCell(new Paragraph(new Run(value)));
                    tableRow.Cells.Add(tableCell);
                }

            }


 

 

Looking forward hearing about the request.

 

Best regards and many thanks.

José Cano

Oct 2, 2009 at 2:13 PM

Jose: I'm interested in your solution also.

The big percentage of the report will have the same template, only changing the tables.

Since I'm new to the project, Do you have more insights in real world use of the project?

 

Developer
Oct 2, 2009 at 2:36 PM

Hi Eddy,

 

We are currently using this feature in order to create a generic report to print the view of list view reports.

 

We used a command to call the report engine, and we pass to the command the required parameters from the view (xaml)

                     

<Button                      
                                Command="{x:Static PrintUserControl.PrintDynamicListViewCommand}" >
                            <Button.CommandParameter>
                                <MultiBinding Converter="{StaticResource multiParameterConverter}">
                                    <MultiBinding.Bindings>
                                        <Binding ElementName="listView"/>
                                        <Binding Path="Titulo"/>
                                    </MultiBinding.Bindings>
                                </MultiBinding>
                            </Button.CommandParameter>
                        </Button>

On the command, we take the Items of listView and create the required ReportData

GridView gridView = listView.View as GridView;

tableHeader = new DataTable("Header");
tableData = new DataTable("Data");
                               
tableHeader.Columns.Add();
foreach (GridViewColumn column in gridView.Columns)
{                    
                    tableHeader.Rows.Add(new object[] { column.Header.ToString() });
                    tableData.Columns.Add();
}

foreach (object item in listView.Items)
{
............. fill up tableData depending on your business logic
............
}

ReportData data = new ReportData();
data.DataTables.Add(tableData);
data.DataTables.Add(tableHeader);
......


In order to get it working, you have to modify ReportPaginator with the lines described on the post above.

I hope it helps.

Coordinator
Oct 2, 2009 at 3:05 PM

Hello guys,

Thank you for your contributions! I'm really busy at the moment and cannot continue the development for now. :-( If you think you have good ideas feel free to improve the reporting engine.

@ppcanodehuelva: I added you to the team, would you please add your suggested changes to the source code?

Regards,

Hans

Oct 2, 2009 at 6:42 PM

Jose: yes, it helps a lot. Thanks!