2011-02-03 58 views
2

我有一个非常特殊的问题,解决方法无效。我需要使用我的Crystal报表服务器为一长串报表生成PDF。使用ASP.NET的Crystal Report 2008服务器绕过参数提示

我已经使用http://msdn.microsoft.com/en-us/library/ms227542(VS.90).aspx的示例代码来创建测试报告,并且完美地工作。

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

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

我可以设置参数,但查看器控件仍然提示输入参数。如果我设置为隐藏参数提示我收到以下错误控制:

无法获取SI_MACHINECHOICE属性值

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

事情我已经尝试:

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

我使用Crystal Reports 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(); 
+0

我刚做了一个小小的突破。我会看看是否可以使用多参数 – superkew 2011-02-03 13:34:25

回答

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); 
       } 


      }