In July, we released the new FlexReport for UWP, and today we'll take you through the steps needed to create and show a FlexReport in a UWP app using SQLite database, and also look at the few differences from the WinForms version of FlexReport.
Unlike some other UWP report generators in which the reports are generated on a server and allow to view or print the server-generated report, FlexReport for UWP generates the report completely on the client UWP system. This has both advantages and disadvantages, depending on the situation. One of the main advantages is that you don't need to set up and run a special dedicated report server—as long as you have your data, you don't need any servers. All work is done on the client. Depending on the complexity of the report, it can also reduce network traffic, as you only need to send data, not the whole report, over the net.
FlexReport for UWP currently supports the following data sources:
To create a report that uses an SQLite data source, you need to do the following, provided that you have your SQLite data source in place:
To use SQLite in the FlexReport Designer App, you need to download and install it on your system. Note that the bitness (32 bit or 64 bit target) of your SQLite installation must match the bitness of the FlexReport Designer app that you want to run. Two versions of the designer app are shipped with C1 Studio:
To use SQLite data sources in the designer app, you need to match the bitness of the SQLite client with the flavor of the C1FlexReportDesigner executable. Once SQLite is installed, the "SQLite Data Provider" should appear in the "Data Provider:" dropdown of the designer's Data Sources dialog: SQLite Data Provider In this example we'll use the C1NWind.db file, which contains our standard sample C1NWind database in SQLite file format. The file is shipped with our UWP samples, or can be downloaded as part of the FlexReportSamples sample where it lives in Resources\C1NWind.db.
You should see a preview similar to this one: ProductList report preview in designer Our sample report is called ProductList. This name will be used in our UWP app when we load the report.
FlexReport connection strings support a special syntax that allows us to specify locations defined by the Environment.SpecialFolder enumeration instead of physical paths. For example, you can specify an Access data source like so:
Data Source=?(SpecialFolder.MyDocuments)\\ComponentOne Samples\\Common\\C1NWind.mdb
This works in WinForms environment but not in UWP, because paths defined by the Environment.SpecialFolder enumeration are not available to a UWP app. To allow using the same syntax in both WinForms and UWP report definitions, two additional constants are supported by FlexReport:
With this in view, we can specify the data source definition in our sample like so:
Data Source=?(SpecialFolder.SystemDefault)\\C1NWind.db
It works both in WinForms environment (e.g in the FlexReport Designer) and in a UWP app.
The following steps allow you to create a simple UWP app that generates the report and shows it in a FlexViewer control (provided that you have the ComponentOne Studio UWP Edition installed):
private async void Page_Loaded(object sender, RoutedEventArgs e)
{
// Copy the SQLite database file from app's Assets to LocalFolder - in a .FLXR report def,
// it can be referenced as ?(SpecialFolder.SystemDefault):
// Data Source=?(SpecialFolder.SystemDefault)\C1NWind.db
// When designing the report, ?(SpecialFolder.SystemDefault) refers to Environment.SpecialFolder.MyDocuments, so you can
// put the report database file in your MyDocuments folder to conveniently design and test run your reports:
var dbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "C1NWind.db");
if (!File.Exists(dbPath))
File.Copy(@"Assets\C1NWind.db", dbPath);
// Create and load the report:
C1FlexReport report = new C1FlexReport();
using (Stream fs = File.OpenRead("Assets/ProductsUWP.flxr"))
report.Load(fs, "ProductList");
// Assign the report to the viewer's DocumentSource - it will be generated automatically
// (asynchronously by default) when the viewer shows it:
this.flexViewer.DocumentSource = report;
}
When you run your app, the FlexViewer will show the report: FlexReport UWP App That's it: we'e created a UWP app that generates and shows a FlexReport. FlexViewer has built-in functionality that allows to view, print or export the report.
The current version of FlexReport for UWP has the following limitations compared to the WinForms version:
In a subsequent post we'll show how to bind a FlexReport for UWP at runtime to an OData Test Service data source using the Simple.OData.Client library installed automatically as a Nuget package.