尽管没有错误,C#程序仍然继续运行

时间:2013-08-21 04:47:41

标签: c# crystal-reports

我正在一个项目中工作,我应该提供一个水晶报告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());
            }
        }
    }
}

编译完成后,我单击“浏览”按钮从磁盘中选择报告,但是当我单击“检索”按钮时,程序将继续运行。我没有收到任何输出或任何错误。

0 个答案:

没有答案