如何使用VB.NET中的进度条显示实际的处理时间 [英] How to show actual process time using progress bar in VB.NET

查看:477
本文介绍了如何使用VB.NET中的进度条显示实际的处理时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在开发一个程序。在它里面,有一个按钮可以将水晶报告导出为PDF格式。



点击该按钮需要一段时间才能将水晶报告导出为PDF格式。 />


我想在表格中使用进度条显示实际处理时间。



请帮助某人及以下我提到了我用来导出水晶报告的代码为PDF



谢谢



我尝试过的事情:



Hi all,

I am developing a program. inside it, there is a button that exporting the crystal report to a PDF.

when we click that button it takes some time to export crystal report as PDF.

I want to show that actual processing time using progress bar in my form.

Please help someone and below I mentioned the codes that I've used to export crystal report as PDF

Thanks

What I have tried:

Private Sub SavePDF()
        Dim Local = File.ReadAllLines(Application.StartupPath + "\Settings\Connection\db.TWC") ' Use a note pad file to save the connectopn string
        Dim dt As New DataSet
        Dim cnn As SqlConnection
        Dim sqlAdp As SqlDataAdapter

        cnn = New SqlConnection(Local(0))
        cnn.Open()
        sqlAdp = New SqlDataAdapter("Select * from QuotationDB where Reference = '" & lblRef.Text.Trim.ToString & "'", cnn)
        cnn.Close() 'connection close here , that is disconnected from data source
        DataSet11.Clear()
        sqlAdp.Fill(DataSet11, "DataTable1")

        Dim objRpt As New ReportDocument
        objRpt.Load(Application.StartupPath + "\Settings\Reports\CrystalReport2.rpt")
        frmQuotationPrint.CrystalReportViewer2.ReportSource = objRpt
        frmQuotationPrint.CrystalReportViewer2.Refresh()
        Try
            Dim CrExportOptions As ExportOptions
            Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions()
            Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions()
            objRpt.SetDataSource(DataSet11.Tables(0))
            If lblMachine.Text = "25ton Mobile Crane" Then
                CrDiskFileDestinationOptions.DiskFileName = ("E:\Quoatitons\2018\25t MC\XPS\" & lblRef.Text & " (" & lblCustomerName.Text & ").pdf")
            End If
            If lblMachine.Text = "45ton Rough Terrain" Then
                CrDiskFileDestinationOptions.DiskFileName = ("E:\Quoatitons\2018\45t RT\XPS\" & lblRef.Text & " (" & lblCustomerName.Text & ").pdf")
            End If
            If lblMachine.Text = "50ton Mobile Crane" Then
                CrDiskFileDestinationOptions.DiskFileName = ("E:\Quoatitons\2018\50t MC\XPS\" & lblRef.Text & " (" & lblCustomerName.Text & ").pdf")
            End If
            If lblMachine.Text = "55ton Crawler Crane" Then
                CrDiskFileDestinationOptions.DiskFileName = ("E:\Quoatitons\2018\55t CC\XPS\" & lblRef.Text & " (" & lblCustomerName.Text & ").pdf")
            End If
            CrExportOptions = objRpt.ExportOptions
            With CrExportOptions
                .ExportDestinationType = ExportDestinationType.DiskFile
                .ExportFormatType = ExportFormatType.PortableDocFormat
                .DestinationOptions = CrDiskFileDestinationOptions
                .FormatOptions = CrFormatTypeOptions
            End With
            objRpt.Export()

        Catch ex As Exception

        End Try
    End Sub

推荐答案

您的问题是及时的,因为我继承了一个旧的应用程序,它运行CR报告并且无法在用户运行时通知用户。但是,在我的情况下,从数据库获取数据所需的时间比在CR报告中写出数据要长。



我没有找到任何数据CR中ExportOptions类的合理文档。我的猜测是你不能挂钩到Export()方法来从中获取进度状态。我能提供的最好的是使用标准的.Net ProgressBar控件并使用Marquee样式,该样式明确用于指示场景发生了什么,但我不知道需要多长时间。启动(或显示)进度条,调用Export()方法,并在从Export()返回后立即停止(或使其不可见)进度条。
Your question is timely as I have inherited an old application and it runs CR reports and there is no way of keeping the user informed when it is running. However, in my case, it takes longer to get the data from the database than it does to write it out in a CR report.

I have failed to find any reasonable documentation for the ExportOptions class in CR. My guess is that you cannot hook into the Export() method to get progress statuses from it. The best that I can offer is to use a standard .Net ProgressBar control and use the Marquee style, which is explicitly intended to indicate to indicate the scenario "something is happening, but I do not know how long it will take". Start (or make visible) the progress bar, call the Export() method, and immediately after returning from the Export() stop (or make invisible) the progress bar.


这篇关于如何使用VB.NET中的进度条显示实际的处理时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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