у тебя класс неправильно оформлен. Попробуй так , но не факт, будут похоже и другие траблы:
using System;
using System.Data;
using System.IO;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
public class PrintReport : Form
{
private Report report;
private DataBaseManager dataBase;
private ReportViewer reportViewer1;
private Button button1;
public PrintReport()
{
report = new Report();
dataBase = new DataBaseManager();
reportViewer1 = new ReportViewer();
button1 = new Button();
button1.Text = "Print Report";
button1.Click += new EventHandler(button1_Click);
Controls.Add(reportViewer1);
Controls.Add(button1);
InitializeComponent();
}
private void InitializeComponent()
{
this.Load += new EventHandler(PrintReport_Load);
this.reportViewer1.Load += new EventHandler(reportViewer1_Load);
}
private void PrintReport_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
private void reportViewer1_Load(object sender, EventArgs e)
{
// Можно добавить дополнительную логику, если требуется
}
private void button1_Click(object sender, EventArgs e)
{
DataTable dt = dataBase.ExecuteQuery("Select * from Issuance");
report.LoadReport(dt, "Report1", reportViewer1);
}
}
public class Report
{
public void LoadReport(DataTable dataTable, string nameReport, ReportViewer reportViewer)
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\{nameReport}.rdlc");
reportViewer.LocalReport.DataSources.Clear();
ReportDataSource source = new ReportDataSource("DataSet1", dataTable);
reportViewer.LocalReport.ReportPath = path;
reportViewer.LocalReport.DataSources.Add(source);
reportViewer.RefreshReport();
}
}
public class DataBaseManager
{
public DataTable ExecuteQuery(string query)
{
// Реализация метода ExecuteQuery для выполнения SQL-запроса и возврата DataTable
// Пример:
DataTable dataTable = new DataTable();
// Заполнение dataTable данными из базы данных
return dataTable;
}
}
{
public void LoadReport(DataTable dataTable, string nameReport, ReportViewer reportViewer)
{
string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $@"..\..\{nameReport}.rdlc");
reportViewer.LocalReport.DataSources.Clear();
ReportDataSource source = new ReportDataSource("DataSet1", dataTable);
reportViewer.LocalReport.ReportPath = path;
reportViewer.LocalReport.DataSources.Add(source);
reportViewer.RefreshReport();
}
}
}