65.9K
CodeProject 正在变化。 阅读更多。
Home

。NET 报表工具教程 - 1

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.89/5 (9投票s)

2013年4月20日

CPOL

4分钟阅读

viewsIcon

112980

downloadIcon

4668

ReportMax 工具的基础教程

引言

ReportMax is a free reporting tool for .NET Framework developers on Visual Studio.NET 2010 and 2012. It is easy to use and rich in features. In this tip, I would like to step through a basic tutorial to get you started in this tool. More tutorials to come.

背景

As a main developer for this tool, I would like to provide help on how to use this tool. It is free and great to use. The current version is 2.2 and we have fixed many bugs and issues. Feel free to use the tool. You can view your reports in PDF format.

Using the Code

In this tutorial, I will show how we can use ReportMax without a single line of code. You can instantly preview your report from the designer by right clicking on a blank area and select Preview Report. Here are the steps to use the tool. You need to install ReportMax 2.2 from here.

设计报表

  1. 运行 Visual Studio.NET
  2. 转到 文件 -> 新建项目
  3. 选择 Visual C# - Windows。然后选择 Windows Forms 应用程序。输入 TestReportMaxWinForms 作为项目名称。单击“确定”。
  4. 在“项目”菜单中,选择“添加新项”。从左侧选择 ReportMax 文件。从右侧选择“空白报表(英寸)”。将文件命名为 MainReport。单击“确定”。
  5. 在页面页眉部分的中间添加一个标签(lblHeader)。将字体设置为 Arial Bold 24。将对齐属性设置为居中。输入标签文本为“世界城市”。
  6. 右键单击报表中的空白区域,然后选择“添加节 - 分组页眉/页脚”
  7. 单击报表中的空白区域以查看页面属性。或右键单击空白区域并选择“属性”。
  8. 单击 ConnectionString 属性中的“...”按钮。选择 Microsoft Jet 4.0 OLE DB 提供程序。单击“下一步”。浏览到 Cities.mdb Access 数据库示例文件。单击“测试连接”以确保连接正常。单击“确定”关闭对话框。请注意,为了运行示例报表文件,您需要执行此步骤来选择示例数据库,否则数据库路径将无效。
  9. 在 SQL 属性中。单击“...”按钮。输入以下 SQL 语句并单击“确定”。
    SELECT Country.Code, Country.CountryName, City.CityName, City.Population
    FROM Country INNER JOIN City ON Country.Code = City.Country
    ORDER BY Country.CountryName;
  10. 单击分组页眉的蓝色条以查看其属性。在 DataField 属性中输入“Code”(不带引号)
  11. 在分组页眉区域(分组页眉和详细信息节之间)添加一个 Textbox。将此 textbox 留空。命名为:txtCountryName。将 DataField 属性设置为“CountryName”。
  12. 选择 Detail 节条。将 AutoExpand 设置为 True,将 AutoShrink 属性设置为 True
  13. Detail 节中添加两个 textbox。将第一个命名为 txtCityName,将第二个命名为 txtPopulation。在 txtCityName DataField 属性中,输入“CityName”。在 txtPopulation DataField 属性中,输入“Population”。
  14. 在分组页脚节中。添加一个名为 txtPopulationTotal textbox(Field)。将 DataField 属性设置为“Population”。将 FunctionType 属性设置为 Sum。将 FormatType 设置为 1-Number ,将 Format 设置为 3 - 123,356,789
  15. txtPopulationTotal 附近添加一个文本为“Population Total”的标签。
  16. 在页面页脚节中。添加一个名为“txtPageNo”的 Field 控件。将 FunctionType 属性设置为“页码”。您可以添加另一个 Field 控件并将 FunctionType 设置为“页总数”。这样,每页底部都会显示“第 n 页,共 m 页”。
  17. 请务必保存您的工作。

查看报表

  1. 转到 Form1 设计窗口。查看 Toolbox。右键单击“General”类别,然后选择“Choose Items...”。“Choose Items”对话框将出现。在“.NET Framework Components”选项卡中,单击“Namespace”列。转到顶部,找到 ReportMaxViewer 组件并将其添加到对话框中。
  2. 您将在 Toolbox 中找到 ReportMaxViewer 组件。单击并将其拖到窗体上,然后将其拉伸到整个窗体。
  3. 单击放置在窗体上的控件,然后找到 OutputType 属性。您有三种选择。您可以将其显示在控件窗口中、发送到打印机或保存为 PDF 文件。确保其设置为 rmOutputTypeWindow
  4. ReportFile 属性中,浏览到您创建的 MainReport.rpm 的位置。
  5. 运行项目。您应该能够看到您的报表。

关注点

ReportMax 的源代码尚不可用,但我提供了示例项目。请确保将 Page ConnectionString 属性指向提供的数据库 Cities.mdb 的正确位置。我想提一下,您可以使用图像和图表,并且可以通过代码自定义输出。您还可以连接到几乎任何类型的数据库。

另外,请参考

历史

  • 添加了 VB.NET 示例。请遵循本技巧中的相同步骤。
© . All rights reserved.