C#-如何在不覆盖原始RDLC文件的情况下将修改后的RDLC加载到报表查看器 [英] C# - How to load the modified RDLC to report viewer without overwriting the original RDLC file

查看:70
本文介绍了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();
}

推荐答案

将原始文件保存在一些临时文件夹中.根据需要修改此副本,然后将其用于显示.这样,您的原始副本将保持原样,但是您仍可以在需要时覆盖并查看修改后的版本.
Save the original in some temp folder. Modify this copy as per your need and then use it for display. This way your original copy will be left intact and yet you would be able to overwrite and view the modified version when required.




感谢您的回答.

您是否可以设置示例以在Reportviewer中动态加载或显示修改后的RDLC.


Thanks for the answer.

Can u set an example to load or display the modified RDLC in reportviewer dynamically.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆