0

我正在开发一个asp.net 网站。

在那个网站上,我需要在水晶报告的帮助下显示一份报告。

html

<asp:UpdatePanel ID="uPnlMain" runat="server" UpdateMode="Conditional">
    <ContentTemplate> 
        <table>
            <tr>
                <td>
                    <asp:Button ID="btnSave" runat="server" 
                            CssClass="btn" OnClick="btnSave_Click" Text="Show"/>
                </td>
            </tr>
            <tr>
                <td>
                    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />                
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

报告源代码

protected void btnSave_Click(object sender, EventArgs e)
{
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("Reports/crptBalance.rpt"));
        DSBalance dsCustomers = GetData(@"
DECLARE @DateFrom DATETIME;
DECLARE @p_Dt DATETIME;
SELECT @p_Dt = '2013-11-14 00:00:00';
SELECT TOP 1 @DateFrom = vdate FROM tblLedger WHERE fdocid = 1 AND vdate <= @p_Dt ORDER BY vdate DESC;
IF @DateFrom IS NULL BEGIN
    SELECT TOP 1 @DateFrom = OpBalDate FROM tblTrnsOpBalMaster WHERE OpBalDate <= @p_Dt ORDER BY OpBalDate DESC;
END
SELECT Y.Customer,
    CONVERT(VARCHAR,Y.Date,103) AS [Date],
    UPPER(Y.Description) AS Description,
    Y.[Due Days],
    Y.Debit,
    Y.Credit,
    CASE WHEN Y.[Balance] >= 0 THEN Y.[Balance] ELSE -1 * Y.[Balance] END AS [Balance],
    CASE WHEN Y.[Balance] >= 0 THEN 'DR' ELSE 'CR' END AS [TP] FROM 
(
    SELECT X.Customer,
        X.Date,
        X.Description,
        X.[Due Days],
        X.Debit,
        X.Credit,
        X.Debit - X.Credit AS [Balance] FROM 
    (
        SELECT CUS.nm + ',  ' + cus.[add] AS [Customer],
            vdate [Date],
            narration AS [Description],
            DATEDIFF(DAY, vdate, GETDATE()) AS [Due Days],
            CASE WHEN amttype = 'DR' THEN amt ELSE 0.0000 END AS Debit,
            CASE WHEN amttype = 'CR' THEN amt ELSE 0.0000 END AS Credit
        FROM tblledger LED
            LEFT OUTER JOIN tblCustomer CUS ON (LED.acid = CUS.id)
        WHERE acid IN (42,7) AND vdate >= @DateFrom AND vdate < @p_Dt 
    )X
)Y
ORDER BY Y.Customer,Y.Date");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
}

我的问题是,当我在更新面板中使用水晶报表查看器时,它不会在报表中显示任何数据。

我的意思是说它显示空白报告。

如果没有更新面板,它可以正常工作。

谁能告诉我是什么问题

4

2 回答 2

0

我认为您在更新面板中缺少报告源,这就是它可能无法正常工作的原因。另一方面,Crystal 报表在更新面板中似乎不能很好地工作。我个人从未尝试过(我建立了一个报告门户,但使用了单独的页面),但已经阅读了很多关于它的内容。即使人们让它显示在更新面板中,工具栏上的打印和导出按钮也经常不起作用。这篇文章内容丰富,并提出了几种不同的解决方案,您可以采用这些解决方案来获得可接受的解决方案。

于 2013-11-14T13:59:41.237 回答
0

我曾经试图做同样的事情,但我做不到。我进行了很多研究,但一无所获,因此我使用了另一种解决方案。

我创建了一个名为“Reposrts”的母版页,并在 jquery 内部使用另一个页面填充 iframe,它是水晶报表。

像这样:

“报告.aspx”

<div id="frameReport" style="display: none;"></div>
<script type="text/javascript">
    $(document).ready(function () {

        $("a.lnkReportMenu").click(function (e) {
            var idReport = $(this).attr("rel");

            if (idReport != "0") {
                $('#frameReport').html('<iframe id="ifrReport" width="99%" height="980px" src="Report.aspx?idReport=' + idReport + '">');
                $('#frameReport').show();

                e.preventDefault();
            }
        });
    });
</script>

“报告.aspx”

<%@ Page Language="C#" AutoEventWireup="true" Theme="theme" CodeFile="Report.aspx.cs"
    Inherits="Report" Title="Crystal Report" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
    Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<head></head>
<body>
    <form id="ReportCrystal" runat="server">
    <div>
        <CR:CrystalReportViewer ID="crvReport" runat="server" AutoDataBind="true" />
    </div>
    </form>
</body>

“报告.aspx.cs”

private void ReportParameter()
{
    string reportName = "Test.rpt";
    string reportPath = Server.MapPath(String.Concat("~/reports/", reportName));
    string serverName = System.Configuration.ConfigurationManager.AppSettings["db"].ToString();
    string databaseName = String.Empty;
    string userId = Session["USERNAME"].ToString();
    string password = Session["PASSWORD"].ToString();

    if (File.Exists(reportPath))
    {
        ReportDocument reportDoc = new ReportDocument();
        reportDoc.Load(reportPath);

        foreach (ParameterField paramField in reportDoc.ParameterFields)
        {
            paramField.CurrentValues.Clear();
        }

        reportDoc.SetDatabaseLogon(userId, password, serverName, databaseName);

        ConnectionInfo crConnectionInfo = new ConnectionInfo();
        crConnectionInfo.Type = ConnectionInfoType.SQL;
        crConnectionInfo.AllowCustomConnection = true;
        crConnectionInfo.IntegratedSecurity = false;
        crConnectionInfo.ServerName = serverName;
        crConnectionInfo.DatabaseName = databaseName;
        crConnectionInfo.UserID = userId;
        crConnectionInfo.Password = password;

        this.ApplyConnection(reportDoc, crConnectionInfo);

        this.crvRelatorio.EnableParameterPrompt = true;
        this.crvRelatorio.ReportSource = reportDoc;
        this.crvRelatorio.RefreshReport();
    }
    else
    {
        this.divHeader.Visible = true;
        this.ltrTitulo.Text = String.Concat("Relatório não foi encontrado ");
    }
}

private void ApplyConnection(ReportDocument report, ConnectionInfo connectionInfo)
{
    this.ApplyLogOnInfo(report, connectionInfo);
    this.ApplyLogOnInfoForSubreports(report, connectionInfo);
}

private void ApplyLogOnInfo(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
    foreach (CrystalDecisions.CrystalReports.Engine.Table tableTemp in reportDocument.Database.Tables)
    {
        if (tableTemp.Name.ToUpper().StartsWith("COMMAND"))
        {

        }

        TableLogOnInfo tableLogonInfo = tableTemp.LogOnInfo;
        tableLogonInfo.ConnectionInfo = connectionInfo;
        tableTemp.ApplyLogOnInfo(tableLogonInfo);

        bool b = tableTemp.TestConnectivity();
    }
}

private void ApplyLogOnInfoForSubreports(ReportDocument reportDocument, ConnectionInfo connectionInfo)
{
    foreach (Section sectionTemp in reportDocument.ReportDefinition.Sections)
    {
        foreach (ReportObject reportObjectTemp in sectionTemp.ReportObjects)
        {
            if (reportObjectTemp.Kind == ReportObjectKind.SubreportObject)
            {
                SubreportObject subreportObject = (SubreportObject)reportObjectTemp;

                ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);

                this.ApplyLogOnInfo(subReportDocument, connectionInfo);
            }
        }
    }
}

private ParameterFields ApplyParameters(string paramName, object paramValue)
{
    ParameterFields paramFields = new ParameterFields();
    ParameterField paramField = new ParameterField();
    paramField.ParameterFieldName = paramName; // Crystal Report Parameter name.

    ParameterDiscreteValue pdvValue = new ParameterDiscreteValue();
    pdvValue.Value = paramValue;

    paramField.CurrentValues.Add(pdvValue);

    paramFields.Add(paramField);

    return paramFields;
}

“网络配置”

<system.web>
    <compilation>
        <assemblies>
            <add assembly="CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportAppServer.ClientDoc, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.ReportSource, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Shared, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
            <add assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692FBEA5521E1304"/>
        </assemblies>
    </compilation>
</system.web>
于 2013-11-14T12:42:34.290 回答