我在一个项目中工作,我应该提供一个水晶报告 RPT 文件作为输入并获取该报告的属性。
我在加载报告本身时遇到问题,所以我使用isLoaded()
函数来检查报告是否已加载。
我使用了以下代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Web;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace sampleretreival
{
public partial class Form1 : Form
{
public string flName;
public Form1()
{
InitializeComponent();
Retrieve.Enabled = false;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (lstFiles.SelectedItems.Count > 0)
{
Retrieve.Enabled = true;
}
else
{
Retrieve.Enabled = false;
}
}
private void Browse_Click(object sender, EventArgs e)
{
openFileDialog1 = new OpenFileDialog();
openFileDialog1.Multiselect = false;
openFileDialog1.Filter = "Crystal Report Files | *.rpt";
openFileDialog1.ShowDialog();
flName = openFileDialog1.FileName;
if (flName.Length != 0)
{
lstFiles.Items.Insert(0, flName);
Retrieve.Enabled = true;
}
else
{
MessageBox.Show("Please select the crystal report files for analysis.", "SAMPLE", MessageBoxButtons.OK, MessageBoxIcon.Information);
Browse.Focus();
}
}
private void Retrieve_Click(object sender, EventArgs e)
{
int a=1;
ReportDocument rpt = new ReportDocument();
rpt.Load(flName);
int count = 5;
if (rpt.IsLoaded)
{
MessageBox.Show(count.ToString());
}
else
{
MessageBox.Show(a.ToString());
}
}
}
}
编译后,我单击“浏览”按钮从磁盘中选择报告,但是当我单击“检索”按钮时,程序继续运行。我没有得到任何输出或任何错误。