Home Image-Pro Automation (Macros, Apps, Reports)
Options

How to report custom data from a simple App

The following post describes the steps involved for creating a simple App which collects user data and uses it to produce a custom report embedded in the app project.


The project contains 3 modules: the app itself, a code module containing global data and the report.

The main purpose of the Globals module is to expose a DataTable object that will be used to communicate user input to the report engine.
    Private _dataTable As System.Data.DataTable

    ' The data table used in the report is created on demand.
    Public ReadOnly Property DataTable As System.Data.DataTable
        Get
            If _dataTable Is Nothing Then
                _dataTable = New System.Data.DataTable
                _dataTable.Columns.Add("User",GetType(String))
_dataTable.Columns.Add("Batch",GetType(String)) _dataTable.Columns.Add("Sample",GetType(String)) End If Return _dataTable End Get End Property ' This method transfers the data into the data table used by the report Public Sub FillReportData(user As String,batch As String,sample As String) DataTable.Rows.Clear _dataTable.Rows.Add(New Object() {user,batch,sample}) End Sub
This same table is then used in the code behind the report when processing the RefreshSchema event. Note that this event is used both when designing the report template and when creating a report, so that custom fields are visible when editing the template.
Public Class AppReport

    ' This event is used to provide the custom datatable to the report engine
    Private Sub ThisReport_RefreshSchema(ByVal source As Object, ByVal args As MediaCy.Addins.Reporter.ReportEventArgs) Handles ThisReport.RefreshSchema
        args.Report.DataSources.Add("AppData",DataTable)
    End Sub

End Class
Finally the App only has to call FillReportData,
    Private Sub btnReport_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnReport.Click
        FillReportData(txtUser.text,txtBatch.Text,txtSample.Text)
        RunReport(cbOutput.SelectedIndex)
    End Sub
and then use RunReport to create the report using standard reporting commands.
        Case ReportOutput.PreviewEdit
            With Share.ReportCommands.Create(Nothing)
                .Template = "SimpleAppReport>AppReport.iprt"
                .ReadOnly=False
                .Run(New Object(){ThisApplication.ActiveWindow}, Nothing)
            End With
The full project package is attached.



Sign In or Register to comment.