Crystal Report for Web应用程序

时间:2011-10-06 17:36:03

标签: crystal-reports crystal-reports-2008 crystal-reports-server

我需要制作一个Crystal Report V.S 2008,在c#中用于 Web应用程序,报告使用带有参数的存储过程:@id_Document,我找到了一个Windows应用程序示例。但不是网络,有人请告诉我如何在网上制作或在哪里可以看到一个很好的例子?

因为在网络上它有一些不同。

由于

1 个答案:

答案 0 :(得分:0)

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {


            if (!IsPostBack)
            {

            }
            else
            {
                if (Session["ReportMaster"] != null)
                {
                    ReportDocument cryRpt = (ReportDocument)Session["ReportMaster"];
                    CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
                    CrystalReportViewer1.ReportSource = cryRpt;
                    CrystalReportViewer1.RefreshReport();
                }
            }

        }
        catch (Exception)
        {

        }
    }


protected void btnUser_Click(object sender, EventArgs e)
    {


        ParameterField paramField1 = new ParameterField();
        ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();


        paramField1.Name = "@id_Document";
        string Document = TextBox1.Text;
        paramDiscreteValue1.Value = Document;
        paramField1.CurrentValues.Add(paramDiscreteValue1);
        paramFields.Add(paramField1);


        ReportDocument cryRpt = new ReportDocument();
        TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
        TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        Tables CrTables;
        string filePath = System.Configuration.ConfigurationSettings.AppSettings["CrysReportDir"];

        cryRpt.Load(Server.MapPath("yourReport.rpt"));
        crConnectionInfo.ServerName = System.Configuration.ConfigurationSettings.AppSettings["CrysServer"];
        crConnectionInfo.DatabaseName = System.Configuration.ConfigurationSettings.AppSettings["CrysDatabase"];
        crConnectionInfo.UserID = System.Configuration.ConfigurationSettings.AppSettings["CrysUser"];
        crConnectionInfo.Password = System.Configuration.ConfigurationSettings.AppSettings["CrysPass"];
        CrTables = cryRpt.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
        {
            crtableLogoninfo = CrTable.LogOnInfo;
            crtableLogoninfo.ConnectionInfo = crConnectionInfo;
            CrTable.ApplyLogOnInfo(crtableLogoninfo);
        }

        CrystalReportViewer1.ReportSource = cryRpt;
        CrystalReportViewer1.ParameterFieldInfo = paramFields;
        CrystalReportProperty();

        Session.Add("ReportMaster", cryRpt);


    }

       private void CrystalReportProperty()
    {

        try
        {
            CrystalReportViewer1.ReuseParameterValuesOnRefresh = true;
            CrystalReportViewer1.RefreshReport();
            CrystalReportViewer1.HasRefreshButton = true;
            CrystalReportViewer1.HasGotoPageButton = true;
            CrystalReportViewer1.HasViewList = false;
            CrystalReportViewer1.HasCrystalLogo = false;
            CrystalReportViewer1.HasPageNavigationButtons = true;
            CrystalReportViewer1.HasDrillUpButton = true;
            CrystalReportViewer1.EnableDatabaseLogonPrompt = false;
            CrystalReportViewer1.EnableParameterPrompt = false;

        }
        catch (Exception)
        {}

    }

在web.config文件中添加

<appSettings>
<add key="ProviderType" value="" />
<add key="CrystalImageCleaner-AutoStart" value="true" />
<add key="CrystalImageCleaner-Sleep" value="60000" />
<add key="CrystalImageCleaner-Age" value="120000" />
<add key="CrysServer" value="servername" />
<add key="CrysDatabase" value="dbname" />
<add key="CrysUser" value="username" />
<add key="CrysPass" value="password" />
<add key="CrysReportDir" value="/" />


希望这能解决您的问题。