RSS 2.0 Feed
Reporting Service Tips 101
Reporting Service Tips 101
摘要:       一般来说,我们把报表分为两类,一类是ad-hoc的报表,用于实时查询,客户可以输入特定的参数,得到他们感兴趣的报表,还有一类是scheduling的报表,用于自动生成,一般包括daliy,monthly,quarterly和yearly的报表,这种定制类的报表,可以在指定的时间,生成到指定的目录,他们生成的内容也会提前定制,参数不可更改。一般在报表的需求定义中,客户都会要求报表能够做到自动生成,这也就是我们所说的第二类报表,有时候,客户还会要求能够在自动生成的同时,实现自动打印。下面我们来谈谈如何实现报表的自动生成以及自动打印。        首先来谈谈解决方案,由于RS提供web service式的调用,因此我们可以写一个remoting service或者windows service或者仅仅是一段程序,然后由job之类的调用,来实现报表的自动。在程序中,我们调用RS,来实现报表的生成。需要生成的报表列表,报表的参数(时间参数),导出文件的格式,我们定义在数据库里,解决方案简单的用图表来表现如下: 下面我们来谈具体的步骤 第一步:创建项目,添加web引用(C#项目),URL为http://localhost/ReportServer/ReportService.asmx 第二步,取参数以及定义其他的参数。 参数表的内容为: ReportName PeriodType PromptName1 Prompttype1 Format SupplierD D date datetime PDF SupplierM M date datetime PDF SupplierQ Q date datetime PDF SupplierY Y date datetime PDF ReportName为报表的名称,PeriodType为报表的类别,分别是日报,月报,季度报和年报,PromptName1和Prompttype1为参数的名字和类别,如果有需要,可以加更多的参数。Format为报表导出的格式。(为方便描述,下述代码中的参数都写死,实际操作中,会从数据库或者从注册表中读取。) 定义参数的代码为: ParameterValue[] parameters = null; parameters[1] = new ParameterValue(); parameters[1].Name = “date”; parameters[1].Value =”01/01/2008”;   定义其他参数: string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"; string encoding; string mimeType; Warning[] warnings = null; string[] streamIDs = null; DataSourceCredentials[] credentials = null; ParameterValue[] used = null;   第三步,生成报表并得到报表的二进制流 ReportingService rep = new ReportingService(); rep.Credentials = rep.Credentials = System.Net.CredentialCache.DefaultCredentials; byte[] ss = null; 得到报表: ss = rep.Render(“SupplierD” , “PDF”, null, devInfo, parameters, credentials, null, out encoding, out mimeType, out used, out warnings, out streamIDs); 使用的方法是RS提供的 Render ( Report As string ,  Format As string ,  HistoryID As string ,  DeviceInfo As string......[阅读全文]

posted @ | Feedback (2) | Filed Under [ Reporting Service Tips 101 ]

摘要:接上一篇(Reporting Service Tips 101 - 关于使用Sum函数会遇到的问题(1)),谈谈使用sum可能会遇到的另外一个问题。 Dateset的数据如下: Supplier      Revenue    status A               5.00        0 A               6.00        1 A               7.00        0 需求是只用sum算出Supplier A在status为0时候的Revenue总和。单看这个需求,我们其实很容易用在报表中添加分组,或者直接在数据的上一层group来解决,但是在做很多复杂报表的时候,如果能够在计算公式里面去解决一些问题,整个报表的开发过程会简单得多。 报表如下: 计算公式为:=FormatNumber(Sum(Fields!Revenue.Value and Fields!status.Value=0),2) 结果如下: 可以看到,正是我们想要的结果。但是这种方法,在遇到很复杂的报表的时候,有时候会有问题,所以我们还可以用另外一种方法。 报表: 计算公式为:=FormatNumber(Sum(iif(Fields!status.Value=0,Fields!Revenue.Value,0)),2) 结果: 和上一种方法的结果一样,但是这种方法的好处是,基本上无论多复杂的报表,都不会有问题。 留言请访问如下链接: Reporting Service Tips 101(#3) - 关于使用Sum函数会遇到的问题(2)...[阅读全文]

posted @ | Feedback (1) | Filed Under [ Reporting Service Tips 101 ]