Create a Report in Visual Studio 在Visual Studio中创建报表
In this lesson, you will learn how to create reports in the integrated reporting system. This system is based on the DevExpress Reporting library for WinForms and ASP.NET. This lesson will guide you through creating a report that shows a list of Contact objects with their names and email addresses. Report will be available to end-users in both WinForms and ASP.NET applications.
在本课中,您将学习如何在集成报告系统中创建报表。此系统基于 WinForms 和 ASP.NET的 DevExpress 报告库。本课将指导您创建一个报表,其中显示联系人对象及其名称和电子邮件地址的列表。报告将提供给 WinForms 和ASP.NET应用程序中的最终用户。
Adding XAF Modules 添加 XAF 模块
-
Add the platform-independent Reports V2 module to your project. To do this, double-click the Module.cs (Module.vb) file in the MySolution.Module project. This will invoke the Module Designer. In the Toolbox, navigate to the DX.19.2: XAF Modules group. Drag the ReportsModuleV2 item from this group to the Designer's Required Modules section.
-
将独立于平台的报表 V2 模块添加到项目中。为此,双击 MySolution.module 项目中的Module.cs(Module.vb)文件。这将调用模块设计器。在工具箱中,导航到 DX.19.2:XAF 模块组。将报表模块V2项从该组拖动到"设计器的必需模块"部分。
-
Add a WinForms-specific Reports V2 module to your WinForms module project. Double-click the WinModule.cs (WinModule.vb) file in the MySolution.Module.Win project. This will invoke the Module Designer. In the Toolbox, navigate to the DX.19.2: XAF Modules group. Drag the ReportsWindowsFormsModuleV2 item from this group to the Designer's Required Modules section.
-
将特定于 WinForms 的报告 V2 模块添加到 WinForms 模块项目中。双击 MySolution.module.win 项目中的WinModule.cs(WinModule.vb)文件。这将调用模块设计器。在工具箱中,导航到 DX.19.2:XAF 模块组。将"报告窗口窗体模块V2"项目从该组拖动到"设计器所需的模块"部分。
-
Add the ASP.NET-specific Reports V2 module to your ASP.NET application project. Invoke the Module Designer by double-clicking the WebModule.cs (WebModule.vb) file in the MySolution.Module.Web project. In the Toolbox, navigate to the DX.19.2: XAF Modules group. Drag the ReportsAspNetModuleV2 item from this group to the Designer's Required Modules section.
-
将特定于ASP.NET报表 V2 模块添加到ASP.NET应用程序项目中。通过双击 MySolution.module.Web 项目中的WebModule.cs (WebModule.vb) 文件来调用模块设计器。在工具箱中,导航到 DX.19.2:XAF 模块组。将"报告AspNetModuleV2"项目从该组拖动到"设计器的必需模块"部分。
- Rebuild your solution.
- 重建解决方案。
If you are using eXpress Persistent Objects as your ORM, proceed to the next section (Design-Time Reporting) section. Otherwise, if you use Entity Framework Code First, execute the following steps.
如果使用 eXpress 持久对象作为 ORM,请继续下一节(设计时间报告)部分。否则,如果使用实体框架代码,请先执行以下步骤。
- Register the ReportDataV2 type in the DbContext as shown in the Set a Many-to-Many Relationship (EF) lesson.
- 在 DbContext 中注册 ReportDataV2 类型,如"设置多对多关系 (EF)"一课所示。
- Double-click the MySolution.Win\WinApplication.cs file to invoke the Application Designer. In the Modules pane, focus the ReportsModuleV2 component. In the Properties window, set the ReportsModuleV2.ReportDataType property to DevExpress.Persistent.BaseImpl.EF.ReportDataV2.
- 双击 MySolution.Win_Win应用程序.cs 文件以调用应用程序设计器。在"模块"窗格中,聚焦报表模块V2组件。在"属性"窗口中,将"报表模块V2.报表数据类型"属性设置为 DevExpress.持久.BaseImpl.EF.ReportDataV2。
- Repeat the previous step for the MySolution.Web\WebApplication.cs file.
- 对 MySolution.Web_Web 应用程序.cs 文件重复上一步。
Design-Time Reporting
设计-时间报告
-
Right-click the MySolution.Module project and select Add | New Folder. Set the name of the new folder to "Reports". Right-click the Reports folder and select Add | New Item.
-
右键单击 MySolution.模块项目并选择"添加 |新文件夹。将新文件夹的名称设置为"报告"。右键单击"报告"文件夹并选择"添加 |新项目。
Note 注意
You can place reports in any folder (including the root project folder), although it is recommended that you organize your project files.
您可以将报表放置在任何文件夹中(包括根项目文件夹),但建议您组织项目文件。
-
Select the DevExpress v19.2 Report, name it "ContactsReport" and click Add.
-
选择 DevExpress v19.2 报告,将其命名为"联系人报告",然后单击"添加"。
-
This invokes the Report Wizard. Select Blank and click Finish.
-
这将调用报表向导。选择"空白"并单击"完成"。
Note 注意
Do not use report types other than Blank. Other report types will not allow you to select an XAF-specific data source. You will be able to proceed with the Report Wizard later, after the data source is selected in the Report Designer.
不要使用空白以外的报表类型。其他报表类型将不允许您选择特定于 XAF 的数据源。在报表设计器中选择数据源后,稍后将可以继续使用报表向导。
-
After clicking Finish, the Report Designer is invoked. In the Toolbox, navigate to the DX.19.2: XAF Data Sources for Reports group. Drag the CollectionDataSource item from this group to the Report Designer window.
-
单击"完成"后,将调用报表设计器。在工具箱中,导航到 DX.19.2:报表的 XAF 数据源组。将"收集数据源"项目从该组拖动到"报表设计器"窗口。
-
In the Report Explorer window, select the collectionDataSource1 item. In the Properties window, assign the "MySolution.Module.BusinessObjects.Contact" value to the ObjectTypeName property. Note the changes in the Field List window - the fields of the Contact class are now available if you expand the collectionDataSource1 node.
-
在"报表资源管理器"窗口中,选择集合数据来源 1 项。在"属性"窗口中,将"MySolution.module.业务对象.联系人"值分配给 ObjectTypeName 属性。请注意"字段列表"窗口中的更改 - 如果展开集合数据来源 1 节点,联系人类的字段现在可用。
-
Click the Report Designer's Smart Tag and select Design in Report Wizard... in the invoked menu.
-
单击报表设计器的智能标记并选择"在报表向导中设计"...在调用的菜单中。
-
This invokes the Report Wizard. In the first step, you should select the Table Report and click Next. Since the data source is already specified, you will skip some wizard screens and the second step will allow you to choose the report data.
-
这将调用报表向导。在第一步中,应选择"表报表",然后单击"下一步"。由于已指定数据源,因此将跳过一些向导屏幕,第二步将允许您选择报表数据。
-
Select the fields that to be used within your report. Check the collectionDataSource1 data member on the left and the following data fields on the right:
-
选择要在报表中使用的字段。检查左侧的收集DataSource1数据成员和右侧的以下数据字段:
- FirstName
- LastName
- 名字名
- 姓氏
- 电子邮件
-
Click Next when finished.
-
完成后单击"下一步"。
-
Select the fields by which to group the report rows. Since grouping is not required in this example, click Next to continue.
-
选择要对报表行进行分组的字段。由于本示例中不需要分组,请单击"下一步"以继续。
-
In the next step, you can customize the report page. Stay these settings unchanged and click Next.
-
在下一步中,您可以自定义报表页。保持这些设置不变,然后单击"下一步"。
-
Choose a report color scheme, for example, Azure, and click Next.
-
选择报表配色方案(例如 Azure),然后单击"下一步"。
-
In the final step, you can set the report's title. This text will be displayed at the top of your report. Set the title to "Contacts" and click Finish.
-
在最后一步中,您可以设置报表的标题。此文本将显示在报表的顶部。将标题设置为"联系人",然后单击"完成"。
-
The report structure you created will be displayed in the Report Designer. Customize and save the report.
-
您创建的报表结构将显示在报表设计器中。自定义并保存报表。
Note 注意
At design time, the Preview tab of the Report Designer is empty. The CollectionDataSource and ViewDataSource components do not connect to a database directly and require an IObjectSpace instance (that can be created at runtime only) to load data. Thus, it cannot load data at design time.
在设计时,报表设计器的"预览"选项卡为空。收集数据源和 ViewDataSource 组件不直接连接到数据库,并且需要 IObjectSpace 实例(只能在运行时创建)来加载数据。因此,它不能在设计时加载数据。
-
Now register the report within your XAF application using the PredefinedReportsUpdater class. To do this, in the Solution Explorer, right-click the MySolution.Module | Module.cs (Module.vb) file and select View Code to edit its source code. The code snippet below demonstrates the required changes.
-
现在使用预定义报告更新器类在 XAF 应用程序中注册报表。为此,请在解决方案资源管理器中右键单击 MySolution.模块 |Module.cs (module.vb) 文件,然后选择"查看代码"以编辑其源代码。下面的代码段演示了所需的更改。
using DevExpress.ExpressApp.ReportsV2; using MySolution.Module.Reports; using MySolution.Module.BusinessObjects; //... namespace MySolution.Module { public sealed partial class MySolutionModule : ModuleBase { //... public override IEnumerable<ModuleUpdater> GetModuleUpdaters( IObjectSpace objectSpace, Version versionFromDB) { ModuleUpdater updater = new DatabaseUpdate.Updater(objectSpace, versionFromDB); PredefinedReportsUpdater predefinedReportsUpdater = new PredefinedReportsUpdater(Application, objectSpace, versionFromDB); predefinedReportsUpdater.AddPredefinedReport<ContactsReport>( "Contacts Report", typeof(Contact)); return new ModuleUpdater[] { updater, predefinedReportsUpdater }; } //... } }
-
Run the WinForms or ASP.NET application, navigate to Reports and open the Contacts Report.
-
运行 WinForms 或ASP.NET应用程序,导航到"报告"并打开联系人报告。
Note 注意
- Predefined reports are not editable at runtime, but you can edit a copy of a report (see Modify an Existing Report).
- Report data can be sorted and filtered according to a parameter defined by the end-user.
- 预定义的报表在运行时不可编辑,但您可以编辑报表的副本(请参阅修改现有报表)。
- 报表数据可以根据最终用户定义的参数进行排序和筛选。
XAF开发成品案例参考
如果您觉得阅读本文对您有帮助,请点一下“推荐”按钮,您的“推荐”将是我最大的写作动力!欢迎各位转载,但是未经作者本人同意,转载文章之后必须在文章页面明显位置给出作者和原文连接,否则保留追究法律责任的权利。
作者博客: http://www.cnblogs.com/foreachlife
欢迎加入CIIP框架\XAF技术应用交流群: 336090194 群文件中有更多相关工具及文档资料
转载请注明出处。多谢!
欢迎加我微信: admiralcn 或扫码:
![](http://files.cnblogs.com/files/foreachlife/wx.bmp)