这就是我设法使它工作的方法可能不是最好的解决方案....它使用 EF 和 WPF
private void PrepareReport(ViewTravelOrderEmployees travelOrder)
{
entities = new PNEntities();
this.mform_components = new System.ComponentModel.Container();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource();
Microsoft.Reporting.WinForms.ReportDataSource reportDataSource2 = new Microsoft.Reporting.WinForms.ReportDataSource();
this.ProductBindingSource = new System.Windows.Forms.BindingSource(this.mform_components);
this.ProductBindingSource2 = new System.Windows.Forms.BindingSource(this.mform_components);
reportDataSource1.Name = "ViewTravelOrderEmployees";
reportDataSource1.Value = this.ProductBindingSource;
//DAL_Destination is Subreport -> Properties -> General -> Name in rdlc
reportDataSource2.Name = "DAL_Destinations";
reportDataSource2.Value = this.ProductBindingSource2;
this.reprt.LocalReport.DataSources.Add(reportDataSource1);
this.reprt.LocalReport.DataSources.Add(reportDataSource2);
this.reprt.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(SubreportProcessingEventHandler);
this.reprt.LocalReport.ReportEmbeddedResource = "PNWPF.TravelOrder.rdlc";
string exeFolder = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.StartupPath);
string reportPath = System.IO.Path.Combine(exeFolder, @"Reports\TravelOrder.rdlc");
this.reprt.LocalReport.ReportPath = reportPath;
this.ProductBindingSource.DataSource = travelOrder;
this.reprt.RefreshReport();
}
void SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
{
entities = new PNEntities();
string dataSourceName = e.DataSourceNames[0];
//query needs to be completed this is just example
List<Destinations> destinations = entities.Destinations.ToList();
e.DataSources.Add(new ReportDataSource(dataSourceName, destinations));
}
PNEntities entities;
private System.ComponentModel.IContainer mform_components = null;
private System.Windows.Forms.BindingSource ProductBindingSource;
private System.Windows.Forms.BindingSource ProductBindingSource2;
XAML
<Window x:Class="PNWPF.frmReportWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:viewer="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Title="frmReportWindow" Height="300" Width="300">
<Grid>
<wfi:WindowsFormsHost Name="winfrmHost">
<viewer:ReportViewer x:Name="reprt">
</viewer:ReportViewer>
</wfi:WindowsFormsHost>
</Grid>