TABLE OF CONTENTS
- Steps to create a new DevExpress report
Steps to create a new DevExpress report
- Get an instance that has the DevExpress setup and license installed and available or else contact the IT support team to help provide a similar instance. For reference check if the below desktop app is available.
- Once the DevExpress setup is ready, clone the SDK project onto that instance.
- Open the SDK project in the visual studio and on the top menu section there is a menu for DevExpress as shown below which will confirm that the DevExpress setup is now available and ready to use.
- Open the SSMS and select the database which needs to be used.
- Below is the set of database tables that are responsible for the DevExpress report creation/updation.
The ZnodeReportCategories table contains a list of report categories that are shown in the left side panel of the Advanced reports.
Only those categories appear whose IsActive property is set to 1.
The ZnodeReportDetails table contains all the reports that fall under the above categories.
For the Sales menu whose ZnodeCategoryId is 1, the admin will only display two reports Orders and Coupons since IsActive is 1 for them.
In order to add a new report lets say Vouchers under the sales category,
The first entry that we will make is in the ZnodeReportDetails table where ZnodeCategoryId will be the Id of the menu under which the report should be shown.
ReportCode should be a unique name given to the report. Eg Vouchers, this is not used for displaying purpose but just for internal use.
ReportName is the name that needs to be displayed in the admin section under that particular menu.
Description is the information needed to be provided about the report. This again is displayed on admin.
IsActive determines if that should be shown on admin or not.
So with the above new entry we should be able to see the new sales report as
Next in the ZnodeReportSetting table we will have to add a new entry for Vouchers which will contain the SettingXML that displays the report grid.
SettingXML - Copy any existing report’s SettingXML and make changes in the xml as per the columns needed in the grid.
The header text is the column name of the report.
Datatype determines the column’s datatype.
The must-show column if set to y determines that the Store Name column will appear on the report grid. Else the column is hidden on the grid.
The isallowsearch column if set to y confirms that this column will also appear in the preview parameter section as well for searching as shown below.
DisplayMode is set to 1.
ZnodeReportStyleSheets is the Id from ZnodeReportStyleSheets tables. It should be the one whose IsDefault flag is 1.
DefaultLayoutXML is the default layout that appears if no layout is set for the report.
ZnodeReportStyleSheets table contains XML containing the styling of the report. Only one style sheet can be set to Default which will appear for all the reports.
API and Code level Customization
- The Znode base has a few DevExpress Reports already created. As a result, the flow for creating and viewing the reports is already available in the full source code.
- In order to create a new report we will have to override a few methods and write some custom code.
- In the full source code’s DevExpressReportAgent.cs file we have a method GetReportDataFromAPI which contains a switch case and on the basis of the report code that is passed from the controller, it calls the API flow for that particular report.
- We will have to override this method by creating a Custom DevExpressReportAgent.cs file. We will introduce a new case in the switch case for our new report
And from here we will create a custom API flow from the znode API client till the service gets the data for this new report.
- The service call will have the logic that will get the data for this report either by writing a stored procedure or an entity called as per need.
- For this, we will have to create the Model and ListModel for the API flow like we usually do as per the properties needed in it which is to be created in the Znode.API.Custom.Model.
- Along with this, there are two very important models that are needed to be binded with the report structure. For this in the Libraries -> Znode.Libraries.DevExpress.Report-> ReportSchemaModels folder we will have to create a folder with the report name of our new report wherein we will be creating two models one of which is the YourReportNameInfo model ie. VoucherInfo model and the other one YourReportNameModel model ie. VoucherModel.
- Now the VoucherInfo model will inherit from the BaseInfo model and will exactly contain all the properties as we created for the API model.
- The real hero of the report model is the VoucherModel which contains two very important attributes HighlightedClass and HighlightedMember. The VoucherModel will inherit the List<VoucherInfo> and the HighlightedClass attribute will be provided above the class and HighlightedMember will be provided above the method. One important namespace that this class needs is DevExpress.DataAccess.ObjectBinding.
- So for any new report we will have to create these two models in the Libraries -> Znode.Libraries.DevExpress.Report-> ReportSchemaModels folder. These models will be used to bind the report in the future steps when we add a new report in the SDK structure. (point no of below step ieAdding a DevExpress Item)
- Rest all are the base methods that are being called.
Adding a new report in the solution explorer/ Adding a DevExpress item
- Open the solution explorer and navigate to Libraries->Znode.Libraries.DevExpress.Report-> Reports.
- Right click on the Reports and click Add DevExpress Item and open XtraReport Wizard Web.
- This opens up a popup that allows to provide a name to the report. Here the name Vouchers.cs is given.
- On clicking OK it redirects to another pop up that is Report Wizard that allows to select the report type that needs to be created. Select Data-bound Report and click Next.
- Now it is redirected to select the data source type. Select Object Binding and press Next.
- Now it is redirected to another Report Wizard wherein the selection of the data model needs to be made that was created.
This will be the highlighted model that we created in the Libraries -> Znode.Libraries.DevExpress.Report-> ReportSchemaModels folder for the Vouchers with the two highlighted attributes for class and method.
- Select the Voucher model and click Next.
It is redirected to selecting the data binding mode where the first option is selected which is Retrieve the data source schema and move to Next.
- This will redirect you to another wizard where one or more data members need to be selected to assign to the report and its detailed reports. Click on Object Data Source on both sides and click next.
- Click next for two more wizards till you reach the report title wizard. Specify the report title and click Finish. The report is ready.
- Style the report by either copying the existing report’s style or creating your own. From the properties tab as shown below.
- Also, it can save the styles of existing reports which will be saved with the extension .repss and use it for future reports if needed.
- Run the application and check its appearance in the admin Advanced Reports.