加载水晶报表时如何显示进度条 [英] how to show the progress bar while loading the crystal report

查看:309
本文介绍了加载水晶报表时如何显示进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows窗体应用程序上工作...我有一个水晶报表...用于在按钮单击事件中显示水晶报表,我给出了如下代码:

i am working on windows form application...i have a crystal report...for showing crystal report in button click event i given code like this:

SqlCommand cmdrslt = new SqlCommand("rptdeptwisevisitor", con.connect);
cmdrslt.CommandType = CommandType.StoredProcedure;
cmdrslt.Parameters.Add("@startDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = frmdateval;
cmdrslt.Parameters.Add("@endDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = Todateval;
SqlParameter tvp1 = cmdrslt.Parameters.AddWithValue("@Dept", DepTable);
tvp1.SqlDbType = SqlDbType.Structured;
tvp1.TypeName = "dbo.Dept";
da.SelectCommand = cmdrslt;
da.Fill(ds);
DeptWiseRpt rpt = new DeptWiseRpt();
if ((ds.Tables(0).Rows.Count > 0)) {
    rpt.SetDataSource(ds.Tables(0));
    rpt.SetParameterValue("frmd", setparmstartd);
    rpt.SetParameterValue("tod", setparmendd);
    CrystalReportViewer1.ReportSource = rpt;

}

这需要时间来加载数据。所以我想要在此表单上放置进度条。.我怎么放呢?

任何帮助都非常可观...

this is taking time to load the data..so i want to put a progress bar on this form..how could I put it?
any help is very appreciable...

推荐答案

加载报告是一项操作(最多两个:查询和显示查看器),因此您不能拆分它来准确显示进度。您可以显示 progressless 栏或使用像这样的动画图像:

Loading report is a single operation (two at most: query and displaying the viewer), so that you can't split it do display progress accurately. You could display progressless bar or use animated image like this one:

该操作必须与UI线程并行运行(使用Thread,Task或BackgroundWorker),否则您的进度(进度条或图像)甚至不会更新一次。在加载时,您不应显示报表查看器本身(使其不可见或尺寸为1x1)。加载完成后:隐藏进度并显示查看器。

That operation has to run in parallel to UI thread (use Thread, Task or BackgroundWorker), otherwise your progress (progressbar or image) will not get updated even once. For the time of loading you should not display report viewer itself (make it invisible or size 1x1). Once loading is completed: hide progress and display viewer.

某些代码:

// hide viewer, show progress
CrystalReportViewer1.Visible = false;
pictureBoxProgress.Visible = true;
// start thread
(new Thread(() => {

    // your code
    SqlCommand cmdrslt = new SqlCommand("rptdeptwisevisitor", con.connect);
    cmdrslt.CommandType = CommandType.StoredProcedure;
    cmdrslt.Parameters.Add("@startDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = frmdateval;
    cmdrslt.Parameters.Add("@endDate", SqlDbType.NVarChar, 50, ParameterDirection.Input).Value = Todateval;
    SqlParameter tvp1 = cmdrslt.Parameters.AddWithValue("@Dept", DepTable);
    tvp1.SqlDbType = SqlDbType.Structured;
    tvp1.TypeName = "dbo.Dept";
    da.SelectCommand = cmdrslt;
    da.Fill(ds);
    DeptWiseRpt rpt = new DeptWiseRpt();
    if ((ds.Tables(0).Rows.Count > 0)) {
        rpt.SetDataSource(ds.Tables(0));
        rpt.SetParameterValue("frmd", setparmstartd);
        rpt.SetParameterValue("tod", setparmendd);
        // controls operations require invoke
        BeginInvoke(() => {
            CrystalReportViewer1.ReportSource = rpt;
            pictureBoxProgress.Visible = false;
            CrystalReportViewer1.Visible = true;
        });
    }
})).Start();

这篇关于加载水晶报表时如何显示进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆