Scenario
This example demonstrates one possible way of integrating Snap reports in an XAF WinForms application. It contains the Snap module (the SnapModule class library) implementing this functionality and the SnapExampleXpo and SnapExampleEF projects demonstrating how to use this module with XPO and EF.
The example integration shows how to store reports layout in business objects and show a list of these objects, as this is done in the built-in Reports module. The main tool for working with these reports is a custom Snap designer form. Underlying business objects can be configured using custom buttons from this form. It is also possible to show a read-only preview form using corresponding actions.
Note that the Snap module from this example is not a part of the standard XAF delivery and is not tested as intensively as our built-in modules. Feel free to modify and test it further according to your business requirements.
If your clients require other scenarios of integrating the Snap reports, please describe them here or in the Create a Snap Report Module for XAF ticket. Thank you in advance!
Steps to implement
The Snap module contains a custom SnapDesigner form and classes used to integrate this form in an XAF application - business classes for storing reports and controllers used to show the designer and preview forms. To learn more about integrating custom forms and controls, refer to the Using a Custom Control that is not Integrated by Default topic.
To see how the module works, download the example and launch the SnapExample.Win or SnapExampleEF.Win project. To create a new Snap document, navigate to the Reports navigation item and click New. A Snap designer will be opened (see the screenshot above). It contains several custom commands implemented especially for XAF:
New - creates a new Snap document;
Save - saves changes to the database. If the report is new, shows a DetailView allowing to define document's properties;
Add XAF Data Source - shows a DetailView allowing to define a new data source. Adds this data source to the current Snap document;
Edit Object - opens a DetailView of the current IDocumentData object that stores report's settings in the database. Use this button to remove or change the existing XAF data sources or other report's properties.
To see information about built-in Snap designer's commands and learn more about Snap reports, refer to Snap documentation.
To use the Snap module from this example in your application, perform the following steps:
1. Download the example and build it with your version of our components.
2. Copy the DocumentData and DocumentDataSource classes from the example to your application's business classes module (YourSolutionName.Module). If you are using EF, copy classes from the SnapExampleEF\BusinessObjects folder. If you are using XPO, copy classes from the SnapExample.Module\BusinessObjects folder.
3. Add a reference to the SnapModule assembly to your project (YourSolutionName.Win).
4. Add SnapModule to your application's Modules list. To do this, either open the WinApplication.cs file of the YourSolutionName.Win project and add a SnapModule instance to the Modules collection in a constructor, or add the SnapModule project to your VS solution and drag & drop the Snap module from a toolbox in the Application Designer.
5. Set SnapModule's DocumentDataType property to the DocumentData type you have created in step 2.