使用带有ASP.NET的Crystal Report 2008服务器绕过参数提示

时间:2011-02-03 12:28:13

标签: asp.net crystal-reports

我有一个非常具体的问题,解决方案也无济于事。我需要使用我的Crystal报表服务器为一长串报表生成PDF。

我使用了来自http://msdn.microsoft.com/en-us/library/ms227542(VS.90).aspx的示例代码来创建测试报告,这非常有效。

然后我创建了一个报告,将参数输出到页面上以开始测试参数输入。这也有效。

现在我需要以编程方式设置参数,然后禁止报表查看器控件生成的参数输入屏幕。

我可以设置参数,但查看器控件仍然会提示参数输入。如果我将控件设置为隐藏参数提示,则会出现以下错误:

无法获取SI_MACHINECHOICE属性值

这是我的源代码,省略了服务器名称和凭据。

我尝试过的事情:

  • 将报告名称设置为报告并设置为空字符串。
  • 将ReportSource“setter”的顺序更改为参数“setter”之前和之后。
  • 使用和不使用ShowFirstPage()方法

我正在使用Crystal报告12个dll,服务器也在运行12版本。这是在VS2008上运行。

        string reportName = "TestReport2";



        //http://msdn.microsoft.com/en-us/library/ms227542(VS.90).aspx
        string serverName = "server";
        SessionMgr sessionMgr = new SessionMgr();
        EnterpriseSession enterpriseSession = sessionMgr.Logon("Administrator", "", serverName, "secEnterprise");
        EnterpriseService enterpriseService = enterpriseSession.GetService("InfoStore");
        InfoStore infoStore = new InfoStore(enterpriseService);
        enterpriseService = enterpriseSession.GetService("PSReportFactory");
        Object psrfObject = enterpriseService.Interface;
        PSReportFactory psReportFactory = (PSReportFactory)psrfObject;
        string queryString = "Select SI_ID, SI_NAME, SI_PARENTID From CI_INFOOBJECTS "
        + "Where SI_PROGID='CrystalEnterprise.Report' "
        + "And SI_NAME Like '" + reportName + "'";
        InfoObjects infoObjects = infoStore.Query(queryString);
        InfoObject infoObject = infoObjects[1];           

        ReportSource reportSource = psReportFactory.OpenReportSource(infoObject.ID);


        CrystalReportViewer1.ReportSource = reportSource;
        CrystalReportViewer1.ParameterFieldInfo.Clear();

        ParameterFields paramFields;
        paramFields = new ParameterFields();

        ParameterDiscreteValue paramDiscreteValue;
        paramDiscreteValue = new ParameterDiscreteValue();
        paramDiscreteValue.Value = "John Doe";

        ParameterField paramField;
        paramField = new ParameterField();
        paramField.Name = "UserName";
        paramField.CurrentValues.Add(paramDiscreteValue);
        paramField.HasCurrentValue = true;
        paramField.ReportName = "";
        paramFields.Add(paramField);

        CrystalReportViewer1.ParameterFieldInfo = paramFields;
        CrystalReportViewer1.ShowFirstPage();

1 个答案:

答案 0 :(得分:2)

以下是我解决此问题的方法。

这一行((ParameterFields)Session [reportGuid];)是我将sql数据集驱动的参数列表传递给代码的方法。

在这部分代码之后,我还有一些从服务器上获取PDF并显示的代码。如果您使用普通的Crystal报表查看器,它将在每个页面更改事件上重新运行报表。

如果您遇到此类问题,可以给我发消息,我可以提供更多代码 - 这些东西很痛苦!

            string reportName = Request["RptName"].ToString();
            string reportGuid = Request["RptGuid"].ToString();
            string outputType = Request["outputType"].ToString();

            SessionMgr sessionMgr = new SessionMgr();
            EnterpriseSession enterpriseSession;
            EnterpriseService enterpriseService;
            InfoStore infoStore;
            InfoObjects infoObjects;
            InfoObject infoObject;
            ReportAppFactory reportAppFactory;
            ISCDReportClientDocument reportClientDocument;

            // Log on to the Enterprise service.
            // 
            enterpriseSession = sessionMgr.Logon(ConfigurationManager.AppSettings["BusinessObjectsUser"].ToString(), ConfigurationManager.AppSettings["BusinessObjectsPassword"].ToString(), ConfigurationManager.AppSettings["BusinessObjectsServer"].ToString(), ConfigurationManager.AppSettings["BusinessObjectsAuthentication"].ToString());

            // Create an instance of the InfoStore Enterprise Service.
            enterpriseService = enterpriseSession.GetService("InfoStore");
            infoStore = new InfoStore(enterpriseService);

            // Query for the ID of the report in the Enterprise CMS.
            infoObjects = infoStore.Query("Select SI_ID From CI_INFOOBJECTS Where SI_NAME='" + reportName + "' And SI_INSTANCE=0");
            infoObject = infoObjects[1];

            // Create an instance of ReportAppFactory from the enterpriseSession.
            EnterpriseService tempService = enterpriseSession.GetService("", "RASReportFactory");
            reportAppFactory = (ReportAppFactory)tempService.Interface;

            ParameterFields paramFieldsDatabase = (ParameterFields)Session[reportGuid];

            // Use the OpenDocument() method of ReportClientDocument with the sample report ID passed in as a parameter.
            reportClientDocument = reportAppFactory.OpenDocument(infoObject.ID, 0);



            foreach (ParameterField paramFieldCrystal in paramFieldsDatabase)
            {
                try
                {

                    LabelInformation.Text = String.Format("{0} \n {1}", LabelInformation.Text, paramFieldCrystal.Name);

                    ParameterDiscreteValue val = (ParameterDiscreteValue)paramFieldCrystal.CurrentValues[0];
                    reportClientDocument.DataDefController.ParameterFieldController.SetCurrentValue("", paramFieldCrystal.Name, val.Value);


                }
                catch (Exception ex)
                {
                    errorList = String.Format("{0} \n {1}", errorList, ex.Message);
                }


            }