开发者

Bypass parameter prompt with Crystal Report 2008 server with ASP.NET

开发者 https://www.devze.com 2023-02-08 12:55 出处:网络
I have a very specific problem, and a work around solution will not help. I need to use my Crystal reporting server to generate the PDFs for a long list of reports.

I have a very specific problem, and a work around solution will not help. I need to use my Crystal reporting server to generate the PDFs for a long list of reports.

I have used sample code from http://msdn.microsoft.com/en-us/library/ms227542(VS.90).aspx to create a test report and this works perfectly.

I then created a report that outputs the parameter onto the page to start testing for parameter input. This works too.

Now I need to programmatically set the parameters, and then suppress the parameter input screen generated by the report viewer control.

I am able to set the parameter but the viewer control still prompts for parameter input. If I set the control to hide the parameter prompt I get the following error:

Unable to get SI_MACHINECHOICE property value

Here is my source code with the server name and credentials omitted.

Things I have tried:

  • Setting the report name to the report and to an empty string.
  • Changing the order of the ReportSource "setter" to before and after the parameters "setter".
  • Using and not using the ShowFirstPage() method

I am using Crystal reports 12 dlls and the server is running off version 12 also. This is running on 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.Qu开发者_如何学Pythonery(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();


Here is how I resolved this issue.

This line ((ParameterFields)Session[reportGuid];) is my method of passing a sql dataset driven list of parameters to the code.

After this section of code I have some more that get a PDF off the server and displays that. If you use the normal Crystal report viewer it will re-run the report on every page changed event.

If you have problems with this kind of stuff, you can send me a message, and I can provide more code - this stuff is painful!

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


            }
0

精彩评论

暂无评论...
验证码 换一张
取 消