Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / WPF
Article

Best Practices for a Visual Studio Report Generator

Rate me:
Please Sign up or sign in to vote.
4.33/5 (4 votes)
6 Feb 2023CPOL6 min read 7.6K   10  
This article provides an overview of Visual Studio's integration of combit's report generator List & Label.

This article is a sponsored article. Articles such as these are intended to provide you with information on products and services that we consider useful and of value to developers

When it comes to writing Windows and Web Apps, using Microsoft's Visual Studio certainly is a no brainer. Therefore, component vendors are making sure to support the Visual Studio ecosystem. This article provides an overview of Visual Studio's integration of combit's report generator List & Label. Feel free to check out the free and fully-functional trial.

Reporting with Visual Studio

Every .NET application handling data will sooner or later require an option to display said data in a user friendly manner. That's where report generators come to play. They offer quick and convenient ways to connect to different data source types, straight from within Visual Studio. With the report designer, layout templates are created and adapted and finally printed to a wide selection of different export formats like PDF, XHTML, Microsoft Excel or Microsoft Word. In many cases, it's desired to have the designer made available to the application's end users as well. 

Binding to Common .NET Data Sources

Before starting with a report, data need to be available. Since the application usually uses data in a specific format, the component should be able to go right from there. This requires the broadest possible support for a wide variety of data formats.

Image 1

Choose data source for reports and analyses

Binding to standard .NET data sources

ADO.NET provides a unified driver model to connect Visual Studio to .NET data sources. List & Label supports all standard sources such as Microsoft SQL Server, PostgreSQL, MySql or SQLite. Also, cloud-based data sources, like Azure CosmosDB or REST are directly supported. Of course, standard ADO data objects such as DataSet, DataTable or DataViewManager can't be left out.

The support is made possible by a separate interface, IDataProvider. This abstraction layer also enables users to contribute their own extra data providers for previously unsupported data sources. combit also promotes this as part of open source projects, e.g. on GitHub. The ecosystem around List & Label is open and invites the community to participate and expand. 

Binding to .NET business objects

In addition to the above data sources, List & Label uses Reflection to support binding to business objects. This also provides important extra flexibility. Users can thus work with objects and classes they also use in their Visual Studio code. .NET offers a number of interfaces, such as IBindingListView or IQueryable/LINQ, that support extended binding with sorting and filtering. It is crucial to provide the broadest possible support here - after all, the component should adapt to the existing data, not the other way around.

Binding to Entity Framework data

The Entity Framework, or - more generally - ORM (object relational mapper) tools abstract the serialization of business objects into a database. The usual CRUD operations can be performed at object level, while the ORM tool provides the necessary persistence. Respectively, binding to EF objects is nothing else than binding to business objects. For performance reasons, a component should take care of supporting existing lateload techniques of the respective ORM framework to avoid unnecessary database traffic and memory consumption. List & Label supports these scenarios.

Starting the Report Designer from Visual Studio

Once the connection to the data source is established, the report designer can be called from within Visual Studio. The best possible support for various project types such as WinForms, WPF or ASP.NET must be ensured. Reports should be interchangeable between these types, to support easy cloud migrations of desktop applications. That's what List & Label does.

Windows apps

In Windows applications - for both WPF and WinForms - the Designer can be launched as a separate window. Many report generators offer a direct Visual Studio designer here. List & Label takes a different approach by offering the designer as an independent window. The advantage: all editors, dialogs, etc. can be individually adapted and optimized for end-user convenience. Also, it does not require a Visual Studio shell at the end user's site. The report designer is the same for the developer and the end user. Functionalities can be deliberately restricted, if the user is not supposed to have all possibilities.

The actual call to the designer is then a method of the ListLabel class. The minimal code to connect to an SQL data source and the subsequent design looks like this:

C#
// build the connection srtring
var builder = new SqlConnectionStringBuilder();
builder.DataSource = "dbserver";
builder.InitialCatalog = "CustomerData";

// initialize the connection to the database
var connection = new SqlConnection(builder.ConnectionString);

// establish a matching List & Label data provider
var sqlProvider = new SqlConnectionDataProvider(connection);

// connect to this provider and start the Designer
using (var LL = new ListLabel())
{
    LL.DataSource = sqlProvider;
    LL.Design();
}

Web apps

For web applications, it's important to have the broadest possible support for different front-end technologies. It doesn't make sense to have the frontend depending on the used components. On the other hand, a component must be able to handle all common JavaScript frameworks. List & Label relies on the WebComponent technology, which ensures optimal support. To make it easier getting started, some examples are included to show how the component can be used in Visual Studio Code with React, Angular, Vue.js or Blazor, just to name a few. For the backend, the component relies on ASP.NET MVC, one of the most common backend techniques. This makes sure that the user has the largest flexibility.

There's just one controller that needs to be implemented to open the Web Report Designer. The code would read

C#
public override void OnProvideListLabel(ProvideListLabelContext provideListLabelContext)
{
    // establish a matching List & Label data provider, see above
    var sqlProvider = new SqlConnectionDataProvider(...);

    ListLabel LL = new ListLabel();
    LL.DataSource = sqlProvider;
    provideListLabelContext.NewInstance = LL;
}

Redistributing the Reporting Component

Components consist of a set of binaries that need to be redistributed to the target computer. There are many different approaches - by doing so, the component manufacturer should ensure to make redistribution as simple and foolproof as possible to avoid unnecessary frustration. Here are a few of the possibilities that List & Label supports.

XCopy deployment

This is the easiest way to share. None of the binaries require registration or installation, the files can be copied directly to the target computer. combit even includes a redistribution wizard. It allows you to select from the optional components, and then automatically creates a ZIP archive with the required binaries. Those are copied to the target computer, together with the application. It couldn't be any easier.

NuGet support

An alternative would be to use a package manager. For Visual Studio and .NET assemblies, NuGet is the format of choice. When using the NuGet package, all required binaries are created in the output directory of the compiler. The result can be copied or processed from there. This is also a very simple method for the user to handle even complex dependencies.

Image 2

Wizard for configuration of data sources

Deeper Visual Studio Integration

Visual Studio package

Visual Studio offers different extension packages. Component manufacturers can e.g. add their own menu items to Visual Studio. List & Label, for example, utilizes the automated addition of NuGet packages, or to provide helpful resources such as a tutorial, the sample center or the component's documentation. Likewise, an update check can be performed from this central location. For WinForms and WPF projects, it is also possible to add dialogs for displaying the report designer and preview to the current project. There are almost no limits for the component author, Visual Studio's modularity and extensibility are very comprehensive.

Wrapping Up

This article demonstrates the depth of Visual Studio integration for report generator List & Label. The results apply more or less to any databound component for the VS ecosystem. Make sure to check out List & Label to get an idea of how it works. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO combit
Germany Germany
Leading the development at combit as Managing Director. Microsoft .NET enthusiast driving innovation & agile project management. Used to be a physicist in my first life. I love hiking and vanlife.

Comments and Discussions