FastReport.net 常用方法

之前说起过FastReport.NET这款报表工具的使用,但当时主要是从程序的角度,示例了在B/S架构下的相关使用,但报表终归还是要划到设计的范畴里来,毕竟能够将报表的内容展示在客户的眼前,这才是报表的根本目的,而诸如打印、转换格式个人觉得应该算是锦上添花的功能吧。

  而随着报表设计的复杂,问题自然也就增多了,没办法,硬着头皮上官网下点文档吧。

  这里将遇到的一些小问题汇总如下,自己做个记录,需要的朋友也可以省点“阅读理解”的时间哈。。。

   

  一、页面设置

  情景:FastReport设计器页面默认设置为A4纸,但如果需要显示的字段过多,这时就出现了页面的大小无法满足完整显示所需内容的问题。

  解决:出现这个问题后,我们可以在来到"文件"—"页面设置"选项中进行设置,在这里可以直接调整页面的纸张类型和尺寸,但是我使用的时候更多的会调整Portrait为Landscape,所谓Portrait按词霸的翻译就是“纸短的一边在顶端和底端的打印方式”,而Landscape则恰恰相反,意思是“纸长的一边在顶端和底端的打印方式”,可以简单的理解Portrait为纵向,Landscape为横向,通过这样的调整既可以保证用标准的A4纸打印,又满足了设计时能够扩充纸张大小,保证显示内容的目的。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  

  二、过滤或排序显示数据

  情景:为了将数据按顺序显示,便于查看。

  解决:此时可以双击数据区,这时就会看到排序和过滤的选项,可以通过点击后面fx图标,使用设计器的方式实现,当然也可以手动添加代码:

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

 

  三、添加和设置子报表

  情景:显示复杂关系的数据。

  解决:进入"报表"--"设置报表栏",可以对报表进行各种设置,其中数据首只会打印一次,数据尾则会在所有数据之后被打印。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  

  四、日期显示

  情景:有些数据表里的日期字段是空的,这时FastReport会自动将其转化为0001/1/1的形式。

  解决:此时如果想要让日期为空时不显示此默认的形式,可以再次进入"报表"--"选项"中,在"一般"选项卡中取消勾选"转换空值"即可。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  五、数据表的嵌套

  情景:复杂的数据库表之间有很多复杂的主从对应关系,这时需要在数据源中建立关系。

  解决:选择动作--新建关系,然后就可以象在数据库里一样建立主外键关联了。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  六、手动确定数据源

  情景:有些时候SQL语句建立表的关系过于复杂,以至于很难建立良好的主从关系,比如我遇到的这样的SQL查询

  SELECT i.SheetKeyId,i.SheetId,i.OperatorName,
      i.InCheckDateTime,i.OutCheckDateTime,i.OutCheckPeople,
      s1.BranchName AS InBranchName,s2.BranchName AS OutBranchName
    FROM   dbo.T_StorageBranch s1 , dbo.T_StorageBranch s2 ,
      dbo.T_LeechdomIOSheet i , dbo.T_LeechdomIOSheet i2
    WHERE  i.InBranchKeyId = s1.BranchKeyId
    AND    i2.OutBranchKeyId = s2.BranchKeyId
    AND    i.SheetId = i2.SheetId

  既有自表关联,又有和其他表的关联,那建立主从关系岂不要郁闷死。。。

  解决:此时我的解决方法有两种,一个是基于FastReport是支持表和视图作为数据源的,此时可以事先在数据库中建立视图,从而使用视图作为数据源解决此表的关联问题,当然如没有项目的需求,大可采用第二种方法,即点击"添加SQL查询",这是输入我们的SQL语句,便会自动生成一个查询结果,我们只需要在报表设计时用其作为数据源就ok了。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  七、使用系统变量

  情景:我们经常会在报表打印时要求显示当前的页数,当前的数据量统计以及当前的打印时间等。

  解决:FastReport其实已经我们内置了所有这些功能,可以在系统变量中找到,只需要简单的拖入Date就可以显示出当前日期,拖入PageN就可以显示页码等。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  八、使报表显示时呈现常见的奇偶行变色效果。

  情景:数据量大时可以方便查看数据。

  解决:这里同样有两种方法,一是在"报表"--"样式"中添加一个样式,叫做EvenRows,什么样式都不用设置,确定即可,然后单击数据区,在外观的EvenStyle属性里面选择此样式,最后改变Fill属性的填充颜色即可。第二种方法是通过程序的方式来实现,代码如下:

  private void Data1_BeforePrint(object sender, EventArgs e)

  {

      if (((Int32)Report.GetVariableValue("Row#")) % 2 == 0)

         Data1.FillColor = Color.Gainsboro;

  }

  这里的Row#为系统内置变量,代表行号,我们选出偶数行后,设置FillColor为自己想要的颜色即可,但不可为window颜色,这样就看不出效果了。

  九、使用程序操作报表

  情景:在窗体程序中可以使用编程的方式对报表的相关字段进行操作。

  解决:

    //获取数据源中列的值

    string productName = (string)Report.GetColumnValue("Products.Name");

     

    //获取数据源

    DataSourceBase ds = Report.GetDataSource("Products");

 

    //获取系统变量值

    DateTime date = (DateTime)Report.GetVariableValue("Date");

 

    //获取总计数

    float sales = Report.GetTotalValue("TotalSales");

 

    //获取参数

    int myParam = (int)Report.GetParameterValue("MyParameter");

 

    //设置参数

    report1.SetParameterValue("EmployeeID", 2);

  十、备注

  1、在FastReport中的变量都使用的是[DataSourceName.FieldName]的形式,凡是以这种形式表示的都需要从数据库中读取,而普通文本则需要[文本内容]这样的形式就可以搞定。

  2、在FastReport中可以设定数据表的别名,这样可以在多表关联的时候使用别名与相关字段对应。

  3、如果你还没有心动的话,我贴几张现成的基于Northwind数据库的demo示例看看吧。。。

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  

  FastReport.net 常用方法 - hcyu2012 - hcyu2012的博客

  

  估计就说这么多了,好用的东西大家一起分享哇。。。^_^

作者:Rocky翔
出处:http://www.cnblogs.com/RockyMyx/
本文版权归作者和博客园共有,欢迎转载,但请在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

转载于:https://www.cnblogs.com/zyj-keyen/p/8537355.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
This programming guide contains information about FastReport library's extension. This extension allows to build reports on client-server technology with using of standard FastReport 3 components and additional components (that are intended for organization of interaction between client and server). FastReport 3 is a highly productive report generator with unique capabilities. Read detailed description of FastReport at "FastReport 3 - developer's guide" [7], "FastReport 3 - programmer's guide" [8] , "FastReport 3 - user's guide" [9]. This guide describes the structure of client components and server components, their properties and methods, as well as architecture of a report server and the principles of its functioning. Furthermore, it gives recommendations concerning optimization and usage of new capabilities in already existing applications and those developed anew. The experienced FastReport users will be interested in recommendations about increasing server components' speed, optimization of reports for their correct export to various tabular formats, application of rules of information safety for application protection from non-authorized access. We have been constantly improving the FastReport 3 Enterprise components. That is why there is a probability that some capabilities are not mentioned in this manual. Descriptions of all changes will be necessarily included to the next version of this manual. -------------------------------------------------------------------------------- next page >
FastReport 6.6.17 Enterprise Source Code for Delphi7 and Delphi27 (10.4 Sydney) FastReport Package Simplification Management Toolkit by xander.xiao@gmail.com, version 2.0, 2020-5-27 What is Package simplification management ? As Fastreport include a stack of design package files, it is boring to install these packages manually, we need a easy way to work out it, here is my solution which may apply to any package management besides Fastreport: My solution, in a brief, copy all files of all packages in one folder which is named by a Environment varible %ProjectHome% which has following structure: %ProjectHome%\Bin for all BPL files of all packages, runtime and design time files %ProjectHome%\LibD7 for Delphi 7 Compiled unit files and resource files (dcu,dcp,dfm,res etc.) %ProjectHome%\LibD26 for Delphi XE 10 Rio Compiled unit files and resource files (dcu,dcp,dfm,res etc.) Each Delphi version related folder may have platform (Win32,Win64 etc.) and configuration (release or debug) specified subfolders. after that, double click REG files to import Delphi known design time packages. This toolkit include two sets: 1. Resource translation, this function is provided by res\FR4Trans.exe, res\frccEx.exe and res\Chinese\@Deploy.bat, besides Chinese it can work with any language 2. Package simplification management, it is functioned by @DelUnUsedFiles.bat,@Deploy.bat,@BuildAllPackages.bat and REG files in quickInstall folder All source code included, you can modified freely. Usage: step0: Make a backup of your fastreport source code, then copy all files in this folder to FastReport home folder. Step1: Execute recompile.exe to generate specified version related folder and files (Recompile all package first, then Change Language to Chinese or othor one). step2: Execute @DelUnUsedFiles.bat to delete unused files in the folder which step1 generated. step3: Execute @Deploy.bat to deploy all files to the project home folder. step4: Double Click reg files in quickInstall folder to install design time BPLs in Delphi IDE, here assume that your ProjectHome is D:\Projects, you may change it. step5: optional, Instead of "recompile.exe-Recompile all package", Execute customized @BuildAllPackages.bat to recompile all package files if you modified any file in the folder which step1 generated. Step6: optional, Instead of "recompile.exe-Change Language to", Execute res\chinese\@deploy.bat if you need very formated Chinese resource code files, before this, you can Execute res\FR4Trans.exe to do translating in your prefered way, you may copy res\chinese\@deploy.bat to othor language folder.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值