none
usando backgroudworker in crystal RRS feed

  • Pergunta

  • Ola ao amigo e colaboradores e visitantes

     

    ulitizo visual basic 2005 pro. + sql enterprise

    tenho alguns relatorios que demora muito para abrir , e gostaria de colocar um progressbar mostrando o tempo de execucao dos relatorios .

     

    como  eu ja utilizo o backgroundworker dentro do sistema , queria fazer o crystal report  funcionar dentro da sub DOWORK  ,  mas nao consegui ,  depois de muita pesquisa , descobri este link  http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=288189&SiteID=1 

     

    veja o exemplo : 

    Public Class MainForm

    Private viewer As New MyViewer  AKI TEM O SEGUINTE ERRO : 'MyViewer' is not defined.

    ' This variable will be used in the print button

    ' Click event and in the background worker RunWorkerCompleted

    ' event.  It will let the background worker know if the

    ' print button was clicked while it was loading Crystal.

    Private printRequested As Boolean = False

     

    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Me.BackgroundWorker1.WorkerSupportsCancellation = True

    ' Start worker. 

    Me.BackgroundWorker1.RunWorkerAsync(printRequested)

    End Sub

     

    Private Sub PrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreview.Click

    If Not BackgroundWorker1.IsBusy Then

    viewer.ShowDialog()

    Else

    printRequested = True

    End If

    End Sub

     

    Private Sub MainForm_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing

    ' Cancel worker before closing

    If BackgroundWorker1.IsBusy Then BackgroundWorker1.CancelAsync()

    End Sub

     

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    Dim worker As BackgroundWorker = CType(sender, BackgroundWorker)

    e.Result = LoadCrystalReports(CBool(e.Argument), worker, e)

    End Sub

    Private Function LoadCrystalReports(ByVal showViewer As Boolean, ByVal worker As BackgroundWorker, ByVal e As DoWorkEventArgs) As Boolean

    If worker.CancellationPending Then

    e.Cancel = True

    Else

    Dim report As New MyReport

    viewer.CrystalReportViewer1.ReportSource = report

    report.SetDataSource(Me.BindingSource1)

    viewer.CrystalReportViewer1.Zoom(1) 'Page width

    End If

    Return showViewer

    End Function

     

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted

    If Not (e.Error Is Nothing) Then

    MessageBox.Show(e.Error.Message)

    ElseIf e.Cancelled Then

    ' Next, handle the case where the user canceled the

    ' operation.

    ' Note that due to a race condition in

    ' the DoWork event handler, the Cancelled

    ' flag may not have been set, even though

    ' CancelAsync was called.

    ElseIf e.Result = True OrElse printRequested = True Then

    ' Finally, handle the case where the operation succeeded.

    ' If the print button was clicked then display viewer.

    viewer.ShowDialog()

    End If

    End Sub

    End Class

     

    mas nao consegui fazer funcionar devido ao erro 'MyViewer' is not defined.

    conto comj a colaboracao dos amigos .

     

    Renato

     

    quarta-feira, 30 de abril de 2008 18:48

Respostas

Todas as Respostas