2

WPF.

我有两个相关的表。

表 A-客户:

CustomerID(PK)
Names
Phone Number
Customer Num

表 B-项目:

Products
Price
CustomerID

我希望能够生成这样的报告:

CustomerA
Items     Price
Item A    10
Item B    10
Item C    10
---------------
Total     30

所以这就是我所做的:

<Window x:Class="ReportViewerWPF.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:rv="clr-namespace:Microsoft.Reporting.WinForms;
    assembly=Microsoft.ReportViewer.WinForms" 
    Title="Customer Report" Height="300" Width="400">

 <Grid>
    <WindowsFormsHost Name="windowsFormsHost1">
        <rv:ReportViewer x:Name="reportViewer1"/>
    </WindowsFormsHost>
 </Grid>

然后我创建了一个数据集并加载了两个表,然后是一个报告向导(将所有可用字段拖放到“值”窗格中)。

WPF 窗口后面的代码是这样的:

public partial class CustomerReport : Window  
{
    public CustomerReport()  
    {
        InitializeComponent();  
        _reportViewer.Load += ReportViewer_Load;  

    } 

    private bool _isReportViewerLoaded;  

    private void ReportViewer_Load(object sender, EventArgs e)
    {
        if (!_isReportViewerLoaded)
        {
            Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
            HM2DataSet dataset = new HM2DataSet();
            dataset.BeginInit();
            reportDataSource1.Name = "DataSet";//This is the dataset name
            reportDataSource1.Value = dataset.CustomerTable;
            this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
            this.reportViewer1.LocalReport.ReportPath = "../../Report3.rdlc";
            dataset.EndInit();
            HM2DataSetTableAdapters.CustomerTableAdapter funcTableAdapter = new HM2DataSetTableAdapters.CustomerTableAdapter();
            funcTableAdapter.ClearBeforeFill = true;
            funcTableAdapter.Fill(dataset.CustomerTable);
            _reportViewer.RefreshReport();
            _isReportViewerLoaded = true;
         }
     }

正如您可能已经猜到的那样,这会加载包含商品和价格的客户列表:

Customer    Items     Price
Customer A  Items A    10
Customer A  Items B    10
Customer B  Items D    10
Customer B  Items C    10

我如何微调此报告以使其看起来像上面的报告,用户可以在其中过滤他希望在报告上显示的客户?在此先感谢您的帮助。我宁愿LINQ在过滤数据时使用

4

0 回答 0