我有一个表单,允许用户选择他们想要生成的报告。他们还可以选择条件,选择打印、预览、导出等。在用户做出选择并单击“生成”按钮后,我有一个类可以创建报表对象、加载报表、数据集,然后打印或导出那个报告。我创建了一个单独的表单来预览报告。当我将报表对象传递给预览表单时,我收到“无效的报表源”。报告打印和导出都很好,我只是无法预览报告。我不想在预览表单中复制代码,我希望我可以只传递报告对象。我的代码片段如下。有什么建议么?
public static class CrystalReportUtilities
{
private static ReportDocument goReport {get; set;}
private static string gsReportName { get; set; }
private static string gsSqlString { get; set; }
private static object[,] goParameters { get; set; }
public static void generateReport(parameters...)
{
goReport = loadReport();
...
goReport.SetDataSource(DataTable);
...
previewReport();
private static void previewReport()
{
CrystalReportPrintPreviewForm loReportPreview = new CrystalReportPrintPreviewForm(goReport);
loReportPreview.ShowDialog();
}
public partial class CrystalReportPrintPreviewForm : Form
{
private ReportDocument goReport;
public CrystalReportPrintPreviewForm(ReportDocument poReport)
{
InitializeComponent();
goReport = poReport;
}
private void crystalReportViewer1_Load(object sender, EventArgs e)
{
try
{
if (goReport != null)
{
crystalReportViewer1.ReportSource = goReport; // Receive "Invalid Report Source"
}
}