rdlc水晶报表在wpf里的使用

摘要:
1引用程序集Microsoft.ReportViewer.WinForms2xaml namespace xmlns:rv=“clr namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewr.WinForms”3xaml使用windowsFormsHost安装报表控件˂WindowsFormsHostMargin=“135,75

1引用程序集 

Microsoft.ReportViewer.WinForms

2 xaml 命名空间

      xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"

3 xaml 里用windowsFormsHost 来装报表控件

            <WindowsFormsHost Margin="135,75,0,0" Panel.ZIndex="-1" Height="auto">
                <rv:ReportViewer x:Name="reportViewer"  />
            </WindowsFormsHost>

3.初始化控件参数

this.reportViewer.Messages = new Health.Client.Base.ReportViewerMessagesZhcn();
    public class ReportViewerMessagesZhcn : IReportViewerMessages
    {
        public string BackButtonToolTip { get { return "后退"; } }

        public string BackMenuItemText { get { return "后退"; } }

        public string ChangeCredentialsText { get { return "更改"; } }

        public string CurrentPageTextBoxToolTip { get { return "当前页"; } }

        public string DocumentMapButtonToolTip { get { return "文档视图"; } }

        public string DocumentMapMenuItemText { get { return "文档视图"; } }

        public string ExportButtonToolTip { get { return "导出"; } }

        public string ExportMenuItemText { get { return "选择格式"; } }

        public string FalseValueText { get { return "不正确的值"; } }

        public string FindButtonText { get { return "查找"; } }

        public string FindButtonToolTip { get { return "查找"; } }

        public string FindNextButtonText { get { return "下一个"; } }

        public string FindNextButtonToolTip { get { return "下一个"; } }

        public string FirstPageButtonToolTip { get { return "首页"; } }

        public string LastPageButtonToolTip { get { return "最后一页"; } }

        public string NextPageButtonToolTip { get { return "下一页"; } }

        public string NoMoreMatches { get { return "无匹配项"; } }

        public string NullCheckBoxText { get { return "空值"; } }

        public string NullCheckBoxToolTip { get { return "空值"; } }

        public string NullValueText { get { return "空值"; } }

        public string PageOf { get { return ""; } }

        public string PageSetupButtonToolTip { get { return "页面设置"; } }

        public string PageSetupMenuItemText { get { return "页面设置"; } }

        public string ParameterAreaButtonToolTip { get { return "参数设置区"; } }

        public string PasswordPrompt { get { return "请输入密码:"; } }

        public string PreviousPageButtonToolTip { get { return "前一页"; } }

        public string PrintButtonToolTip { get { return "打印"; } }

        public string PrintLayoutButtonToolTip { get { return "打印"; } }

        public string PrintLayoutMenuItemText { get { return "打印"; } }

        public string PrintMenuItemText { get { return "打印"; } }

        public string ProgressText { get { return "正在生成报表......"; } }

        public string RefreshButtonToolTip { get { return "刷新"; } }

        public string RefreshMenuItemText { get { return "刷新"; } }

        public string SearchTextBoxToolTip { get { return "查找"; } }

        public string SelectAll { get { return "全选"; } }

        public string SelectAValue { get { return "SelectAValue"; } }

        public string StopButtonToolTip { get { return "停止"; } }

        public string StopMenuItemText { get { return "停止"; } }

        public string TextNotFound { get { return "未找到"; } }

        public string TotalPagesToolTip { get { return "总页数"; } }

        public string TrueValueText { get { return "正确值"; } }

        public string UserNamePrompt { get { return "用户名"; } }

        public string ViewReportButtonText { get { return "显示报表"; } }

        public string ViewReportButtonToolTip { get { return "显示报表"; } }

        public string ZoomControlToolTip { get { return "缩放"; } }

        public string ZoomMenuItemText { get { return "缩放"; } }

        public string ZoomToPageWidth { get { return "页宽"; } }

        public string ZoomToWholePage { get { return "整页"; } }
    }

4 .加载视图,设置视图RDLC的方法

        private void ShowReportViewer(int index, Microsoft.Reporting.WinForms.ReportDataSource dataSourse, List<Microsoft.Reporting.WinForms.ReportParameter> reportParameters, System.Collections.IEnumerable detailDataSource)
        {
            ReportViewer reportViewer = SelectReportViewer(index);
            //索引超出范围
            if (reportViewer == null) return;
            if (dataSourse != null)
            {
                reportViewer.LocalReport.ReportPath = GetReportFilePath(dataSourse.Name);
                reportViewer.LocalReport.DataSources.Clear();
                reportViewer.LocalReport.DataSources.Add(dataSourse);
            }
            else
            {
                reportViewer.LocalReport.ReportPath = GetReportFilePath("ChargeFeezyAmountMain");
                reportViewer.LocalReport.DataSources.Clear();
            }

            if (reportParameters != null)
            {
                reportViewer.LocalReport.SetParameters(reportParameters);
            }

            if (detailDataSource != null)
            {
                _subDataSource = detailDataSource as List<ReportDataSource>;
                reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
            }
            //if (dataSourse.Name == "CancelArrears")
            //{
            //    var pageSettings = reportViewer.GetPageSettings();

            //    pageSettings.Landscape = false;
            //    reportViewer.SetPageSettings(pageSettings);
            //}
            //else if (dataSourse.Name == "CarrearagePat" || dataSourse.Name == "RecoveryArrears")
            //{
            //    var pageSettings = reportViewer.GetPageSettings();

            //    pageSettings.Landscape = true;
            //    reportViewer.SetPageSettings(pageSettings);
            //}
            reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer.ZoomPercent = 100;
            reportViewer.RefreshReport();
        }
        private void ShowReportViewer1(int index, List<Microsoft.Reporting.WinForms.ReportDataSource> dataSourse, List<Microsoft.Reporting.WinForms.ReportParameter> reportParameters, System.Collections.IEnumerable detailDataSource)
        {
            ReportViewer reportViewer = SelectReportViewer(index);
            //索引超出范围
            if (reportViewer == null) return;
            if (dataSourse != null)
            {
                reportViewer.LocalReport.ReportPath = Health.Reports.ReportHelper.GetReportFilePath(dataSourse[0].Name);
                reportViewer.LocalReport.DataSources.Clear();
                foreach (var data in dataSourse)
                {
                    reportViewer.LocalReport.DataSources.Add(data);
                }
            }
            else
            {
                reportViewer.LocalReport.ReportPath = Health.Reports.ReportHelper.GetReportFilePath("ChargeFeezyAmountMain");
                reportViewer.LocalReport.DataSources.Clear();
            }

            if (reportParameters != null)
            {
                reportViewer.LocalReport.SetParameters(reportParameters);
            }
            if (detailDataSource != null)
            {
                _subDataSource = detailDataSource as List<ReportDataSource>;
                reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(LocalReport_SubreportProcessing);
            }
            reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            reportViewer.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
            reportViewer.ZoomPercent = 100;
            reportViewer.RefreshReport();
        }
        private ReportViewer SelectReportViewer(int index, bool isReset = true)
        {
            if (isReset) reportViewer.Reset();
            return reportViewer;
        }
        private void LocalReport_SubreportProcessing(object sender, SubreportProcessingEventArgs e)
        {
            foreach (var item in _subDataSource)
            {
                e.DataSources.Add(item);
            }
        }
        public static string GetReportFilePath(string reportFileName)
        {
            
            string filePath= @"Reports" + reportFileName + ".rdlc";
            filePath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);
             if(!System.IO.File.Exists(filePath))
             {
                return "";
             }
             
            return filePath;
        }

调用

免责声明:文章转载自《rdlc水晶报表在wpf里的使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇前端缓存最佳实践Python-判断正负小数下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

WPF简介

  要赢得世界,必须在恰当的时间做出恰当的事。这一点,微软做到了。历经微软 DOS,Win 31, Windows 95, Windows 98, Windows 2000, Windows XP, 一路走来,一次比一次热闹,一个比一个精彩、炫丽。Windows Vista的宣传更是轰轰烈烈,喧嚣日上。初见Windows Vista,都会被它的酷炫界面所...

WPF多语言化的实现

  Metro插件系统系列就暂时停一下,这次我们讨论一下WPF的资源本地化实现,主要用到的:CultureInfo,ResourceManger,MarkupExtension,RESX文件,这些都是.NET框架提供的。 项目结构: 运行结果: 可在程序运行时,实时切换语言 CultureInfo   CultureInfo类表示有关特定区域性的信息...

【转】编写高质量代码改善C#程序的157个建议——建议87:区分WPF和WinForm的线程模型

建议87:区分WPF和WinForm的线程模型WPF和WinForm窗体应用程序都有一个要求,那就是UI元素(如Button、TextBox等)必须由创建它的那个线程进行更新。WinForm在这方面的限制并不是很严格,所以像下面这样的代码,在WinForm中大部分情况下还能运行(本建议后面会详细解释为什么会出现这种现象): private void but...

WPF ClickOnce应用程序IIS部署发布攻略

WPF程序非常适合公司内网使用,唯一缺点就是客户端要安装.net框架4.0。优势也很明显,在客户端运行的是一个WinForm程序,自动下载,可以充分利用客户机的性能,而且是以当前的Windows用户权限运行,避免了权限带来的问题。而我觉得最大的益处还是可以自动更新!这样就具备了CS程序功能强大速度快的优点,又有BS程序部署升级容易的优点。 本文要讨论的就是...

wpf研究之道——datagrid控件数据绑定

前台: <DataGrid x:Name="TestCaseDataGrid" ItemsSource="{Binding}" > {binding} 是个简写的方式,绑定的是datagrid 对象的DataContext 后台: this.TestCaseDataGrid.DataContext = Data.PagerSource;...

【WPF学习】第五十二章 动画性能

  通常,为用户界面应用动画只不过是创建并配置正确的动画和故事板对象。但在其他情况下,特别是同时发生多个动画时,可能需要更加关注性能。特定的效果更可能导致这些问题——例如,那些涉及视频、大位图以及多层透明等的效果通常需要占用更多CPU开销。如果不谨慎实现这类效果,运行它们使可能造成明显抖动,或者会从其他同时运行的应用程序抢占CPU时间。   幸运的是,WP...