using System; using System.Collections.Generic; using System.Linq; using System.Text; 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.Runtime.InteropServices; namespace WpfApp { /// /// Interaction logic for Window1.xaml /// public partial class Window1 : Window { public Window1() { InitializeComponent(); FillReportWithoutParameter(); } private void button1_Click(object sender, RoutedEventArgs e) { string crew = textBox1.Text; //Call fill method and pass textbox1 value as parameter FillReport(); } private void checkBox1_Checked(object sender, RoutedEventArgs e) { if (checkBox1.IsChecked == true) { //fill report with all data //FillReport(textBox1.Text); } else { //pass filter value and fill report //FillReport(textBox1.Text); } } private void FillReport() { DataSet1 dataset = new DataSet1(); dataset.BeginInit(); DataSet1TableAdapters.EmployeeTableAdapter ad = new DataSet1TableAdapters.EmployeeTableAdapter(); this.Report1.LocalReport.ReportPath = "../../Report1.rdlc"; //Report parameters ReportParameter param = new ReportParameter("ReportParameter1", textBox1.Text); Report1.LocalReport.SetParameters(new ReportParameter[] { param }); ad.ClearBeforeFill = true; dataset.EnforceConstraints = false; ad.FillBy(dataset.Employee,textBox1.Text); ReportDataSource reportDataSource1 = new ReportDataSource("DataSet1", dataset.Tables[0]); Report1.LocalReport.DataSources.Clear(); Report1.LocalReport.DataSources.Add(reportDataSource1); Report1.LocalReport.Refresh(); Report1.SetDisplayMode(DisplayMode.PrintLayout); Report1.ZoomMode = ZoomMode.PageWidth; Report1.RefreshReport(); } private void FillReportWithoutParameter() { DataSet1 dataset = new DataSet1(); dataset.BeginInit(); DataSet1TableAdapters.EmployeeTableAdapter ad = new DataSet1TableAdapters.EmployeeTableAdapter(); ad.ClearBeforeFill = true; dataset.EnforceConstraints = false; ad.Fill(dataset.Employee); Report1.LocalReport.ReportPath = "../../Report1.rdlc"; //Report parameters //ReportParameter param = new ReportParameter("ReportParameter1",new string[] { null }, true); //Report1.LocalReport.SetParameters(new ReportParameter[] { param }); ReportDataSource reportDataSource1 = new ReportDataSource("DataSet1", dataset.Tables[0]); Report1.LocalReport.DataSources.Clear(); Report1.LocalReport.DataSources.Add(reportDataSource1); ReportParameter param = new ReportParameter("ReportParameter1", textBox1.Text); Report1.LocalReport.SetParameters(new ReportParameter[] { param }); Report1.RefreshReport(); } } }