本文介绍了C#app在使用子报表的rpts中设置参数时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio 2005和CRXI Release 2.我正在使用C#创建一个应用程序,它将运行我们在公司应用程序中使用的.rpt文件。我的应用程序接受正在调用的.rpt文件的路径和文件名。其他参数包括登录信息。最后,我们传递.rpt所需的参数。

I'm working with Visual Studio 2005 and CRXI Release 2.  I am creating an application, using C#, which will run the .rpt files that we use in our company application.  My application accepts a path and file name for the .rpt file which is being called.  Other arguments include the logon information.  Lastly, we pass the parameters that the .rpt takes.

这是OC2.rpt的命令行:
"预览报告[C:\\EMS_DEV \\ \\\reports\\CR XI转换报告\ OC2.rpt]服务器[blah] DB [blah]用户[blah] Parm1 [3191636]"

Here is the command line for the OC2.rpt:
"Preview  Report[C:\\EMS_DEV\\reports\\CR XI converted reports\OC2.rpt] Server[blah] DB[blah] User[blah] Parm1[3191636]"


我的问题是设置.rpt参数。在此示例中,.rpt包含4个子报表。主报表和所有子报表使用存储过程作为其数据源。每个存储过程都使用相同的参数order_id。换句话说,报告应该需要一个参数,所有参数都被所有5个报告使用。


My problem is in setting the .rpt parameters.  In this example, the .rpt includes 4 subreports.  The main report and all the subreports use stored procedures as their datasources.  Each stored procedure takes the same parameter, order_id.  In other words, the report should require one parameter, which gets used by all 5 reports. 

如果我传递报告一个参数,子报告会询问相同的参数,所以我得到4个order_id提示。如果我尝试传递报告5参数,则返回badindex错误。

If I pass the report one parameter, the subreports ask for the same parameter, so I get 4 prompts for the order_id.  If I try to pass the report 5 parameters, it returns an badindex error. 

此代码将返回OC2.rpt文件的一个计数,这是正确的:

crParameterFieldDefinitions = this.reportDocument1.DataDefinition.ParameterFields;
int ct = crParameterFieldDefinitions.Count;

This code will return a count of one for the OC2.rpt file, which is correct:
  
crParameterFieldDefinitions = this.reportDocument1.DataDefinition.ParameterFields;
int ct = crParameterFieldDefinitions.Count;

但.rpt无法识别参数或认为它需要5个参数。

But the .rpt doesn't recognize the parameter or thinks that it needs 5 parameters. 


以下是设置参数的代码:
public void SetParameters(ArrayList arrParams)
{
CRPrintLog log = new CRPrintLog(" Entering SetParameters" ;);
String strCurrentParamName;


Here is the code for setting the parameters:
public void SetParameters(ArrayList arrParams)
    {
      CRPrintLog log = new CRPrintLog("Entering SetParameters");
      String strCurrentParamName;

//从报告中检索Parameters集合。值得注意的是,//子报表参数包含在主报表的ParameterFieldDefinitions
//集合中。

      // Retrieve the Parameters collection from the report. It is important to note that
      // subreport parameters are contained within the Main Report's ParameterFieldDefinitions
      // collection.

//注意:将子报表参数值直接传递给子报表将导致//在未应用的值中以及在运行时提示用户提供新的
/ / values。

crParameterFieldDefinitions = this.reportDocument1.DataDefinition.ParameterFields;
int ct = crParameterFieldDefinitions.Count;

      // NOTE: Passing subreport parameter values directly to the subreport will result
      // in the values not being applied and the user being prompted at runtime to provide new
      // values.
    
      crParameterFieldDefinitions = this.reportDocument1.DataDefinition.ParameterFields;
      int ct = crParameterFieldDefinitions.Count;

//完整性检查
Debug.Assert (arrParams.Count == ct);

int num = 0;
foreach(arrParams中的Object strParam)
{
//访问单个子报表参数字段
crParameterFieldDefinition = crParameterFieldDefinitions [num];

      // Sanity check
      Debug.Assert(arrParams.Count == ct);
     
      int num = 0;
      foreach (Object strParam in arrParams)
      {
        //Access the individual subreport parameter field
        crParameterFieldDefinition = crParameterFieldDefinitions[num];

//仅用于调试目的
strCurrentParamName = crParameterFieldDefinition.ParameterFieldName;

//转换变量以保存要传递给的值在exe之前报告cution
crParameterValues = crParameterFieldDefinition.CurrentValues;

        // for debug purposes only
        strCurrentParamName = crParameterFieldDefinition.ParameterFieldName;
     
        //Cast the variable to hold the values to pass to the Report before execution
        crParameterValues = crParameterFieldDefinition.CurrentValues;

//实例化对象
crParameterDiscreteValue = new ParameterDiscreteValue();

        // instantiate an object
        crParameterDiscreteValue = new ParameterDiscreteValue();

// set object对当前参数的值
crParameterDiscreteValue.Value = strParam;

        // set object's value to current param
        crParameterDiscreteValue.Value = strParam;

//将值添加到集合
crParameterValues.Add(crParameterDiscreteValue);

num ++ ;
}
//将参数值传递回报告
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

}

        // add the value to the collection
        crParameterValues.Add(crParameterDiscreteValue);
     
        num++;
      }
      //Pass the parameter values back to the report
      crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
      
    }
   

已有谁经历过这个?我做错了什么?

Has anyone been through this?  What am I doing wrong?

提前致谢。

推荐答案


这篇关于C#app在使用子报表的rpts中设置参数时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 18:20