本文介绍了C#-如何在不覆盖原始RDLC文件的情况下将修改后的RDLC加载到报表查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

修改后似乎无法使用StringReader加载我的RDLC文件遇到麻烦.

如果我覆盖了原始的RDCL文件,它将起作用

请更正此代码...

Hi all,

I have trouble using StringReader to load my RDLC file after modifying it seems like no effect.

If I overwrite the original RDCL file it works

Please correct this code...

public void localizeReport(LocalReport report)
        {
            //used to call the resources from database
            DbResourceManager resourceManager=new DbResourceManager("ReportTextBox");
            
            //access the report xml file
            XmlDocument xml = new XmlDocument();
            xml.Load(report.ReportPath);
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(xml.NameTable);
            nsmgr.AddNamespace("nm", "http://schemas.microsoft.com/" +
                               "sqlserver/reporting/2005/01/reportdefinition");
            nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/" +
                               "SQLServer/reporting/reportdesigner");

foreach (string nodeName in new string[]{"Value"})
            {
                foreach (XmlNode node in xml.DocumentElement.SelectNodes(String.Format("//nm:{0}[@rd:LocID]", nodeName), nsmgr))
                {
                    String nodeValue = node.InnerText.Replace(" :","");
                    if (String.IsNullOrEmpty(nodeValue) || !nodeValue.StartsWith("="))
                    {
                        try
                        {
                            string localizedValue = resourceManager.GetString(nodeValue.ToString());
                            if (!String.IsNullOrEmpty(localizedValue))
                            {
                                if (node.InnerText == "Booking Confirmation")
                                {
                                    node.InnerText = localizedValue.ToString();
                                }
                                else
                                {
                                    node.InnerText = localizedValue.ToString() + " :";
                                }
                            }
                        }

                        catch (Exception ex)
                        {
                            throw new Exception(ex.ToString());
                        }

                    }
                }

            }
//xml.save(report.ReportPath);  - it will overwrite the original report not good idea.
using (StringReader rdlcSR = new StringReader(xml.DocumentElement.OuterXml))
            {
                report.LoadReportDefinition(rdlcSR); //unable to load the report what to do??
}
}





private void btnPreview_Click(object sender, EventArgs e)
{
    reportViewer1.LocalReport.ReportPath = "C:/FM80/TR_BookUI/Report/RptBookingConfirmation.rdlc";

    localizeReport(reportViewer1.LocalReport);
    if (cboStartCustCode.Text == "")
    {
        this.dtbRptBookingConfirmationTableAdapter.Fill(this.dstRptBookingConfirmation.dtbRptBookingConfirmation, cboStartCustCode.Items[0].ToString(), cboEndCustCode.Items[cboEndCustCode.Items.Count - 1].ToString(), startDate, endDate);
        if (dstRptBookingConfirmation.Tables[0].Rows.Count != 0)
        {
            MessageBox.Show(ResReports.ErrorNoBookingConfirmation, "Message");
        }
    }
    else
    {
        this.dtbRptBookingConfirmationTableAdapter.Fill(this.dstRptBookingConfirmation.dtbRptBookingConfirmation, cboStartCustCode.Text, cboEndCustCode.Text, startDate, endDate);
        if (dstRptBookingConfirmation.Tables[0].Rows.Count <= 0)
            MessageBox.Show(ResReports.ErrorNoBookingConfirmation, "Message");
    }
    this.tPT_SPECIAL_DATA_TblTableAdapter.Fill(this.dstTransportSpecialData.TPT_SPECIAL_DATA_Tbl);
    this.dtbSpecialDataTableAdapter.Fill(this.dstSpecialData.DtbSpecialData);

    reportViewer1.RefreshReport();
}

推荐答案



这篇关于C#-如何在不覆盖原始RDLC文件的情况下将修改后的RDLC加载到报表查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 00:26