WPF报表
来源:互联网 发布:怎样消费到淘宝v2 编辑:程序博客网 时间:2024/06/02 02:08
在机房合作中,在给操作员结账后,为了更方便的看,我们用到了报表,那么wpf的报表如何实现呢,下面就由小编带着一步步走下去
1、添加一个名称为Report的rdlc报表
界面是:
现在我们在工具箱拖放一个“表”
点下一步
继续下一步
点击确定,点下一步,下一步
点击完成,完成就得到下面界面
绑定完全之后的界面
在U层添加引用Microsoft.ReportViewer.WinForms和WindowsFormsIntegration
下面新建一个wpf窗体:MaskLayer.xaml
<span style="font-family:KaiTi_GB2312;font-size:24px;"><UserControl x:Class="JfCooperate.管理员.Report.MaskLayer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:JfCooperate" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Opacity="0.85" Background="#fbfcfc"> <Grid> <TextBlock Text="正在生成报表..." VerticalAlignment="Center" HorizontalAlignment="Center"/> </Grid></UserControl></span>
其对应的cs代码:
<span style="font-family:KaiTi_GB2312;font-size:24px;">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace JfCooperate.管理员.Report{ /// <summary> /// MaskLayer.xaml 的交互逻辑 /// </summary> public partial class MaskLayer : UserControl { public MaskLayer() { InitializeComponent(); } }}</span>
新建wpf窗体:ReportCtrl
ReportCtrl.xaml
<span style="font-family:KaiTi_GB2312;font-size:24px;"><UserControl x:Class="JfCooperate.管理员.Report.ReportCtrl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms" xmlns:local="clr-namespace:JfCooperate.管理员.Report" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <Grid> <WindowsFormsHost> <rv:ReportViewer x:Name="ReportViewer"/> </WindowsFormsHost> <local:MaskLayer x:Name="maskLayer" Visibility="Collapsed"/> </Grid></UserControl></span>其对应的cs代码
<span style="font-family:KaiTi_GB2312;font-size:24px;">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using Microsoft.Reporting.WinForms;using System.Data;using System.IO;using System.Windows.Navigation;using Package.Facade;using Package.BLL;using Package.Entity;namespace JfCooperate.管理员.Report{ /// <summary> /// ReportCtrl.xaml 的交互逻辑 /// </summary> public partial class ReportCtrl : UserControl { public ReportCtrl() { InitializeComponent(); this.Loaded += ReportCtrl_Loaded; this.ReportViewer.RenderingComplete += ReportViewer_RenderingComplete; } private void ReportCtrl_Loaded(object sender, RoutedEventArgs e) { maskLayer.Visibility = Visibility.Visible; CheckOutEntity ECheck = new CheckOutEntity(); DataTable dt = new DataTable(); ReportFacade fa = new ReportFacade(); dt = fa.QueryReport(ECheck); if (dt.Rows.Count != 0) { ReportDataSource reportDataSource = new ReportDataSource(); //定义数据集名称 reportDataSource.Name = "ReportDataSet"; reportDataSource.Value = dt; //说明reportViews承载的表名 ReportViewer.LocalReport.ReportPath = Directory.GetCurrentDirectory() + "\\Report.rdlc"; //添加报表数据源 ReportViewer.LocalReport.DataSources.Add(reportDataSource); ReportViewer.RefreshReport(); } } private void ReportViewer_RenderingComplete(object sender, Microsoft.Reporting.WinForms.RenderingCompleteEventArgs e) { maskLayer.Visibility = Visibility.Collapsed; } }}</span>
新建ReportWindow.xaml来承载报表
reportwindow.xaml 代码:
<span style="font-family:KaiTi_GB2312;font-size:24px;"><Window x:Class="JfCooperate.管理员.Report.ReportWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:JfCooperate.管理员.Report" mc:Ignorable="d" WindowStartupLocation="CenterScreen" Title="报表" Height="279" Width="653.541"> <Grid> <local:ReportCtrl/> </Grid></Window></span>
其对应的cs代码:
<span style="font-family:KaiTi_GB2312;font-size:24px;">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;namespace JfCooperate.管理员.Report{ /// <summary> /// ReportWindow.xaml 的交互逻辑 Interaction logic for ReportWindow.xaml /// </summary> /// public partial class ReportWindow : Window { public ReportWindow() { InitializeComponent(); } }}</span>
在这里,我想通过查询数据库里面的时间来生成报表,所以我就新建了一个frmReport窗体
xaml代码:
<span style="font-family:KaiTi_GB2312;font-size:24px;"><Controls:MetroWindow x:Class="JfCooperate.管理员.Report.frmReport" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" Title="账单" Height="300" Width="351.77" Background="#FFFFFF" WindowStartupLocation="CenterScreen"> <Grid> <DatePicker x:Name="DpStart" HorizontalAlignment="Left" Margin="137,38,0,0" VerticalAlignment="Top" FontSize="24" FontFamily="Microsoft YaHei Light"/> <DatePicker x:Name="DpEnd" HorizontalAlignment="Left" Margin="137,110,0,0" VerticalAlignment="Top" FontSize="24" FontFamily="Microsoft YaHei Light" /> <Label Content="起始日期" HorizontalAlignment="Left" Margin="26,38,0,0" VerticalAlignment="Top" FontSize="24" FontFamily="Microsoft YaHei Light"/> <Label Content="终止日期" HorizontalAlignment="Left" Margin="26,108,0,0" VerticalAlignment="Top" FontSize="24" FontFamily="Microsoft YaHei Light"/> <Button x:Name="ShowReport" Content="查询账单" HorizontalAlignment="Left" Margin="97,185,0,0" VerticalAlignment="Top" Width="125" FontSize="24" FontFamily="Microsoft YaHei Light" Click="Button_Click_1"/> <Label x:Name="lblShow" Content="" HorizontalAlignment="Left" Height="123" Margin="297,38,0,0" VerticalAlignment="Top" Width="45" Foreground="Red"/> </Grid></Controls:MetroWindow></span>
其cs代码
<span style="font-family:KaiTi_GB2312;font-size:24px;">using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Shapes;using MahApps.Metro.Controls;using MahApps.Metro.Controls.Dialogs;using Package.Entity;using Package.Facade;namespace JfCooperate.管理员.Report{ /// <summary> /// frmReport.xaml 的交互逻辑 /// </summary> public partial class frmReport : MetroWindow { public frmReport() { InitializeComponent(); } private void Button_Click_1(object sender, RoutedEventArgs e) { if (DpStart.SelectedDate > DpEnd.SelectedDate) { lblShow.Content = "终止时间必须大于初始时间"; } else { CheckOutEntity ECheck = new CheckOutEntity(); //先声明后实例化 ECheck.DateStart = (DateTime.Parse(DpStart.Text)).ToString("yyyy-MM-dd"); ECheck.DateEnd = (DateTime.Parse(DpEnd.Text)).ToString("yyyy-MM-dd"); } ReportWindow rpt = new ReportWindow(); rpt.ShowDialog(); } }}</span>
结果显示:账单可打印,可导出。
0 0
- WPF报表
- C# WPF打印报表
- 【机房合作】WPF报表
- WPF技术与初识报表
- wpf报表rdlc报错
- WPF中使用ReportViewer报表
- WPF中使用ReportViewer报表
- WPF开发的报表工具控件Stimulsoft Reports.Wpf
- WPF报表控件(折线图、柱状图、饼状图)
- WPF水晶报表控件(.RDLC报表、RDLC报表设计器)
- 在WPF中使用水晶报表for vs2010的方法
- 水晶报表在vs2010 WPF环境下的尝试
- 4款主流的WPF报表控件对比与分析
- 比较不错的几款开源的WPF Charts报表控件
- 比较不错的几款开源的WPF Charts报表控件
- 比较不错的几款开源的WPF Charts报表控件
- WPF DocumentViewer控件报表去掉不必要的工具按钮
- WPF 柱状图报表饼图报表区域折线图报表横向柱状图报表折线图报表
- Python 之 pickle/json序列化
- 代码审计的艺术系列—第三篇
- php 自动加载类方法小结
- PHP开发APP接口
- 全局获取Context
- WPF报表
- Leetcode 107. Binary Tree Level Order Traversal II (Easy) (cpp)
- TCP三次握手,四次挥手,NAT和代理服务器的原理
- Java异常处理-----运行时异常(RuntimeException)
- 【C++ 与 STL】集合:set
- hdu 5726 2016 Multi-University Training Contest 1(二分+dp)
- karma +jasmine+karma-coverage
- IO流以日志文件记录异常
- 并发编程之锁--由浅到深!