上次总结的传递参数部分不够详细, 并且遗留了一个问题, 下面说明一下:
一.遗留问题
上次讲到制作安装向导时虽然打了一堆的依赖项, 附加了多个文件,但是在除.netframework2.0外啥环境都没有的情况下(干净的机器上)会报一个错, 如下图:
首先,翻译下看这个消息是啥意思, 如下:
这里说要安装相应的CRRedist*.msi,然后就算你下载并安装最新的“CRRedist for 2005.msi”也无济于事, 因为原因不在这里。
并且,有好多网友并且BO官方网站上说这个错误是由于vs2005支持64位操作系统, 而水晶报表只支持32位操作系统, 解决方法是在生成exe的时候选择x86……还说了很多种解决办法, 在这里全是不适用的 :)。
查阅了msdn及好多相关资料后,得知解决方法如下:
1. http://support.businessobjects.com/communityCS/FilesAndUpdates/crxir2sp3_net_merge_modules.zip.asp, 下载crxir2sp3_net_merge_modules.zip并将之解压缩.
2. 打开vs2005,并开启安装向导, 往项目里添加“合并模块”, 选择刚刚解压缩出的CrystalReports11_5_NET_2005.msm,编译即可。
(注意:不同版本的vs2005中自带的水晶报表版本也不用,对应的合并模块也不同, 如果是XI版本的添加上面的合并模块即可,若是X版本的则应到BO官方网站上下载添加相应的合并模块)
二.参数传递
一.CrystalReportViewer
通过 CrystalReportViewer.ParameterFieldInfo 属性……
1、CrystalReportViewer 成员
公共实例属性
ParameterFieldInfo(从 CrystalReportViewerbase 继承) ParameterFields。获取或设置参数字段集合。
二.ReportDocument
通过 ReportDocument.DataDefinition.ParameterFields 属性……
1、ReportDocument 成员
公共实例属性
DataDefinition DataDefinition。获取 DataDefinition 对象。
2、DataDefinition 成员
公共实例属性
ParameterFields ParameterFieldDefinitions。获取 ParameterFieldDefinitions 集合。
三.参数字段运行时自定义(CrystalReportViewer)
可支持用户在 Crystal 报表中通过参数进行输入。这种参数有多种用途。例如:
使参数基于数据库字段并允许用户指定该字段的值,以便对报表中的数据进行筛选。
使用参数字段将条件格式应用于报表。
使用参数字段来定义排序顺序。
下列示例说明如何在运行时通过代码设置参数字段值。此例解释了如何设置两个不同的参数:第一个是多值离散参数,第二个是区域值参数。
在运行时修改参数字段
// 声明将参数传递给查看器控件所需的变量。
ParameterFields paramFields = new ParameterFields ();
ParameterField paramField = new ParameterField ();
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue ();
ParameterRangeValue rangeVal = new ParameterRangeValue ();
// 第一个参数是具有多个值的离散参数。
// 设置参数字段的名称,它必须和报表中的参数相符。
paramField.ParameterFieldName = "客户姓名";
// 设置第一个离散值并将其传递给该参数。
discreteVal.Value = "AIC Childrens";
paramField.CurrentValues.Add (discreteVal);
// 设置第二个离散值并将其传递给该参数。discreteVal 变量被设置为新值,这样,以前的设置就不会被覆盖。
discreteVal = new ParameterDiscreteValue ();
discreteVal.Value = "Aruba Sport";
paramField.CurrentValues.Add (discreteVal);
// 将该参数添加到参数字段集合。
paramFields.Add (paramField);
// 第二个参数为区域值。paramField 变量被设置为新值,这样,以前的设置就不会被覆盖。
paramField = new ParameterField ();
// 设置参数字段的名称,它必须和报表中的参数相符。
paramField.ParameterFieldName = "客户 ID";
// 设置范围的开始值和结束值并将该范围传递给该参数。
rangeVal.StartValue = 42;
rangeVal.EndValue = 72;
paramField.CurrentValues.Add (rangeVal);
// 将第二个参数添加到参数字段集合。
paramFields.Add (paramField);
// 将参数字段集合放入查看器控件。
crystalReportViewer1.ParameterFieldInfo = paramFields;
四.实例说明:
1.需求:
4.页签-动态环比同比报表选项说明: 时间类别:1代表年月 2代表年月日 时间区域:格式为yyyymmdd,日期开窗 依据:下拉列表中增加这8项 依据范围:根据不同的依据去基础信息表中抓取放入依据范围开始和结束的下拉列表中。 对应表:在YILIBREAD数据库中 1客户 ------------COPMA 2系统 ------------CMSMR WHERE MR001='1' 3行政区 ------------CMSMR WHERE MR001='3' 4地区 ------------CMSMR WHERE MR001='4' 5服务中心------------CMSME 6业务员 ------------CMSMV 7送货工 ------------CMSMV 8品号 ------------INVMB 5.针对该页签中选项,点击查询时需要执行下面步骤: 1).调用存储过程SALE_SEARCH_TWO_TIMES,同时传入7个参数: 时间类别:1 or 2 时间区域1 开始 时间区域1 结束 时间区域2 开始 时间区域2 结束 依据 本机IP 2).调用水晶报表,同时传入3个参数至水晶报表: 依据范围 开始 依据范围 结束 本机IP 3).打开水晶报表预览画面。 |
2.核心实现代码:
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](/Images/dot.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](/Images/OutliningIndicators/None.gif)