Click here to Skip to main content
15,887,027 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Data Access Layer, How to get the count, and use the data returned by the first function posted above Pin
jkirkerx8-Jul-15 7:40
professionaljkirkerx8-Jul-15 7:40 
GeneralRe: Data Access Layer, How to get the count, and use the data returned by the first function posted above Pin
Dave Kreskowiak8-Jul-15 9:58
mveDave Kreskowiak8-Jul-15 9:58 
GeneralRe: Data Access Layer, How to get the count, and use the data returned by the first function posted above Pin
jkirkerx8-Jul-15 10:37
professionaljkirkerx8-Jul-15 10:37 
GeneralRe: Data Access Layer, How to get the count, and use the data returned by the first function posted above Pin
Dave Kreskowiak8-Jul-15 11:15
mveDave Kreskowiak8-Jul-15 11:15 
GeneralRe: How to load a single record, and with a join Pin
jkirkerx9-Jul-15 9:08
professionaljkirkerx9-Jul-15 9:08 
GeneralRe: How to load a single record, and with a join Pin
Dave Kreskowiak9-Jul-15 12:08
mveDave Kreskowiak9-Jul-15 12:08 
GeneralRe: How to load a single record, and with a join Pin
jkirkerx9-Jul-15 12:31
professionaljkirkerx9-Jul-15 12:31 
QuestionPrint RDLC without preview using VB.NET Pin
emmapaq6-Jul-15 10:00
emmapaq6-Jul-15 10:00 
I need to print from rdlc without preview. I runs well when report is previewed with ReportViewer.

However, I have searched and copied from all available sources of "printing RDLC without preview but when i run my code I receive the error, "An error occurred during local report processing"


this occurs at the
report.Render("IMAGE", deviceInfo, AddressOf CreateStream, warnings)

below is my entire code

XML
Imports System
Imports System.IO
Imports System.Data
Imports System.Text
Imports System.Drawing
Imports System.Drawing.Printing
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports Microsoft.Reporting.WinForms
Imports System.Drawing.Imaging

Module modul_print_reports
    Private m_currentPageIndex As Integer
    Private m_streams As IList(Of Stream)
    Private printDoc As PrintDocument

    ''' <summary>
    ''' Print rdlc report with custom page width and height
    ''' </summary>
    ''' <param name="report"></param>
    ''' <param name="page_width">the width of the papger, in hunderdths of an inch</param>
    ''' <param name="page_height">the height of the papger, in hunderdths of an inch</param>
    ''' <param name="islandscap"></param>
    ''' <param name="printer_name">Ignore this parameter to use default printer</param>
    ''' <remarks></remarks>
    Public Sub print_microsoft_report(ByRef report As LocalReport, ByVal page_width As Integer, ByVal page_height As Integer, _
                                      Optional ByVal islandscap As Boolean = False, _
                                      Optional ByVal printer_name As String = Nothing)
        printDoc = New PrintDocument()
        If printer_name <> Nothing Then printDoc.PrinterSettings.PrinterName = printer_name
        If Not printDoc.PrinterSettings.IsValid Then ' detecate is the printer is exist
            Throw New Exception("Cannot find the specified printer")
        Else
            Dim ps As New PaperSize("Custom", page_width, page_height)
            printDoc.DefaultPageSettings.PaperSize = ps
            printDoc.DefaultPageSettings.Landscape = islandscap
            Export(report)
            Print()
        End If
    End Sub
    ''' <summary>
    ''' Print rdlc report with specific paper kind
    ''' </summary>
    ''' <param name="report"></param>
    ''' <param name="paperkind">String paper Kind, ex:"letter"</param>
    ''' <param name="islandscap"></param>
    ''' <param name="printer_name">Ignore this parameter to use default printer</param>
    ''' <remarks></remarks>
    Public Sub print_microsoft_report(ByVal report As LocalReport, Optional ByVal paperkind As String = "A4", _
                                      Optional ByVal islandscap As Boolean = False, _
                                      Optional ByVal printer_name As String = Nothing)

        printDoc = New PrintDocument()
        If printer_name <> Nothing Then printDoc.PrinterSettings.PrinterName = printer_name
        If Not printDoc.PrinterSettings.IsValid Then ' detecate is the printer is exist
            Throw New Exception("Cannot find the specified printer")
        Else
            Dim ps As PaperSize
            Dim pagekind_found As Boolean = False
            For i = 0 To printDoc.PrinterSettings.PaperSizes.Count - 1
                If printDoc.PrinterSettings.PaperSizes.Item(i).Kind.ToString = paperkind Then
                    ps = printDoc.PrinterSettings.PaperSizes.Item(i)
                    printDoc.DefaultPageSettings.PaperSize = ps
                    pagekind_found = True
                End If
            Next
            If Not pagekind_found Then Throw New Exception("paper size is invalid")
            printDoc.DefaultPageSettings.Landscape = islandscap
            Export(report)
            Print()
        End If

    End Sub

    ' Routine to provide to the report renderer, in order to
    ' save an image for each page of the report.
    Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, _
                   ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream

        Dim stream As Stream = New MemoryStream()
        m_streams.Add(stream)
        Return stream
    End Function
    ' Export the given report as an EMF (Enhanced Metafile) file.
    Private Sub Export(ByVal report As LocalReport)
        Dim w As Integer
        Dim h As Integer
        If printDoc.DefaultPageSettings.Landscape = True Then
            w = printDoc.DefaultPageSettings.PaperSize.Height
            h = printDoc.DefaultPageSettings.PaperSize.Width
        Else
            w = printDoc.DefaultPageSettings.PaperSize.Width
            h = printDoc.DefaultPageSettings.PaperSize.Height
        End If
        Dim deviceInfo As String = "<DeviceInfo>" & _
            "<OutputFormat>EMF</OutputFormat>" & _
            "<PageWidth>" & w / 100 & "in</PageWidth>" & _
            "<PageHeight>" & h / 100 & "in</PageHeight>" & _
            "<StartPage>0</StartPage><EndPage>0</EndPage><MarginTop>0.0in</MarginTop>" & _
            "<MarginLeft>0.0in</MarginLeft>" & _
            "<MarginRight>0.0in</MarginRight>" & _
            "<MarginBottom>0.0in</MarginBottom>" & _
            "</DeviceInfo>"
        Dim warnings As Warning()
        m_streams = New List(Of Stream)()

        'Dim byt As Byte() = report.Render("IMAGE")

        report.Render("IMAGE", deviceInfo, AddressOf CreateStream, warnings)
        For Each stream As Stream In m_streams
            stream.Position = 0
        Next
    End Sub

    ' Handler for PrintPageEvents
    Private Sub PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        Dim pageImage As New Metafile(m_streams(m_currentPageIndex))

        ' Adjust rectangular area with printer margins.
        Dim adjustedRect As New Rectangle(ev.PageBounds.Left - CInt(ev.PageSettings.HardMarginX),
                                          ev.PageBounds.Top - CInt(ev.PageSettings.HardMarginY), _
                                          ev.PageBounds.Width, _
                                          ev.PageBounds.Height)

        ' Draw a white background for the report
        ev.Graphics.FillRectangle(Brushes.White, adjustedRect)

        ' Draw the report content
        ev.Graphics.DrawImage(pageImage, adjustedRect)

        ' Prepare for the next page. Make sure we haven't hit the end.
        m_currentPageIndex += 1
        ev.HasMorePages = (m_currentPageIndex < m_streams.Count)
    End Sub
    Private Sub Print()
        If m_streams Is Nothing OrElse m_streams.Count = 0 Then
            Throw New Exception("Error: no stream to print.")
        End If
        AddHandler printDoc.PrintPage, AddressOf PrintPage
        m_currentPageIndex = 0
        printDoc.Print()
    End Sub
End Module


  cn.Open()
  Dim cmd = New SqlCommand("SELECT [BatchNo]," +
                           "[ProdID],[ProdName],[MfgDate],[ExpDate],[ImgName],[ImgPath],[UserID],[FullName]" +
                           "FROM dbo.vwBatchRecs WHERE [BatchNo]=@bn ORDER BY [ImgName]", cn)
          cmd.Parameters.Clear()
          cmd.Parameters.AddWithValue("@bn", pf_Id)
          Dim dr = cmd.ExecuteReader()
          Dim dt As New DataTable
          dt.Load(dr)

          Dim rpt As New LocalReport
          rpt.DataSources.Clear()
          rpt.EnableExternalImages = True
          rpt.ReportEmbeddedResource = "PharmaDoc.BatchPrep.rdlc"
          rpt.ReportPath = "BatchPrep.rdlc"
          rpt.DataSources.Add(New ReportDataSource("vwBatchRecs", dt)) '

         rpt.Refresh()

         dr.Close()
         cmd.Dispose()
         cn.Close()
                    'rpt.SetDisplayMode(DisplayMode.PrintLayout)
                    'rpt.ZoomMode = ZoomMode.FullPage

                    'Dim cp As New Reportprint
                    print_microsoft_report(rpt)

I have also tried the following source but still same problem <a href="https://msdn.microsoft.com/en-us/library/ms252091%28v=vs.100%29.aspx">https://msdn.microsoft.com/en-us/library/ms252091%28v=vs.100%29.aspx</a>[<a href="https://msdn.microsoft.com/en-us/library/ms252091%28v=vs.100%29.aspx" target="_blank" title="New Window">^</a>]

QuestionExcel VBA Function runtime error 1004: Application-defined or object-defined error Pin
Member 118122063-Jul-15 11:57
Member 118122063-Jul-15 11:57 
SuggestionRe: Excel VBA Function runtime error 1004: Application-defined or object-defined error Pin
Richard MacCutchan3-Jul-15 21:28
mveRichard MacCutchan3-Jul-15 21:28 
QuestionPublic Delegate Sub Action(Of T) (obj As T) Pin
Member 1171394230-Jun-15 20:23
Member 1171394230-Jun-15 20:23 
AnswerRe: Public Delegate Sub Action(Of T) (obj As T) Pin
Richard MacCutchan30-Jun-15 21:21
mveRichard MacCutchan30-Jun-15 21:21 
QuestionFirstData G4 V14 HMAC Header Pin
jkirkerx29-Jun-15 13:47
professionaljkirkerx29-Jun-15 13:47 
AnswerRe: FirstData G4 V14 HMAC Header Pin
Jörgen Andersson29-Jun-15 20:17
professionalJörgen Andersson29-Jun-15 20:17 
GeneralRe: FirstData G4 V14 HMAC Header Pin
jkirkerx30-Jun-15 6:49
professionaljkirkerx30-Jun-15 6:49 
GeneralConclusion - XMLWriter, UTF16 and XML empty element short form. Pin
jkirkerx5-Jul-15 8:54
professionaljkirkerx5-Jul-15 8:54 
AnswerRe: FirstData G4 V14 HMAC Header - Issue 1: Pin
jkirkerx30-Jun-15 11:10
professionaljkirkerx30-Jun-15 11:10 
GeneralUpdate - got the calc to work now with the request message Pin
jkirkerx1-Jul-15 7:38
professionaljkirkerx1-Jul-15 7:38 
AnswerCan't get the hashed content right Pin
jkirkerx1-Jul-15 12:39
professionaljkirkerx1-Jul-15 12:39 
QuestionExecute multiple sql queries with one database hit Pin
satc27-Jun-15 19:53
satc27-Jun-15 19:53 
AnswerRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre27-Jun-15 22:04
professionalSascha Lefèvre27-Jun-15 22:04 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc27-Jun-15 22:49
satc27-Jun-15 22:49 
GeneralRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre27-Jun-15 23:15
professionalSascha Lefèvre27-Jun-15 23:15 
GeneralRe: Execute multiple sql queries with one database hit Pin
satc27-Jun-15 23:28
satc27-Jun-15 23:28 
GeneralRe: Execute multiple sql queries with one database hit Pin
Sascha Lefèvre28-Jun-15 1:11
professionalSascha Lefèvre28-Jun-15 1:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.