Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my problem, i have application that updates form data and prints after updating, problem is most of the time it works fine, i use webBrowser Control for printing because it print as html document, one function updates data second function filter according to last entered number and fill those data to richtextbox and after that it saves that data to html file and my webcontrol Print that file.

problem is my client facing in some rare occasion it prints old data that has been updated before current updated time, this happens once in while, is it my code or the printer?
VB
If saveDataToDB() = True Then
    'if second or net value is greater than zero ticket will be printed'
    If Val(txtSWeight.Text) > 0 Or Val(txtNetWeight.Text) > 0 Then
    'this function loads last updated ticket that according to autonumber'
        PrintFunc(" WHERE dbo.tbl_Tickets.QS_Code=" & CInt(lblQS_Code.Text))

        rtb_TicketFormat.Rtf = rtb_TicketFormat.Rtf.Replace("Duplicate.png", "Original.png")
        Dim myFileName As String = IO.Path.Combine(IO.Path.GetTempPath, "_.html")
        rtb_TicketFormat.SaveFile(myFileName, RichTextBoxStreamType.PlainText)

        PrintTktz()
End If  

Private Sub PrintTktz()
    Dim webBrowserForPrinting As New WebBrowser()

    'Add an event handler that prints the document after it loads.'
    AddHandler webBrowserForPrinting.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PrintDocumentz)

    'Set the Url property to load the document.'
    webBrowserForPrinting.Url = New Uri(IO.Path.GetTempPath & "_.html")
End Sub

Private Sub PrintDocumentz(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
    Dim webBrowserForPrinting As WebBrowser = CType(sender, WebBrowser)
    webBrowserForPrinting.ScriptErrorsSuppressed = True
    'Print the document now that it is fully loaded.'
    webBrowserForPrinting.Print()

    'MessageBox.Show("print")'
    webBrowserForPrinting.Dispose()
    ' Dispose the WebBrowser now that the task is complete.'
End Sub
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900