Imprimir report rdlc vs 2010 vb.net , Consulta

Iniciado por Yaldabaot, 12 Octubre 2015, 23:10 PM

0 Miembros y 1 Visitante están viendo este tema.

Yaldabaot

Buenas, estoy tratando de realizar un POS y pues ya puedo meter los datos en la base de datos y ya tengo mi archivo rdlc con la personalización que necesito, pues como ustedes saben las impresoras POS tienen ciertas medidas, pues tengo el reporte con el formato definido y sus respectivos parámetros.

Necesito agarrar ese reporte e imprimirlo directamente en la impresora sin vista previa, ya he visto varios enlaces como por ejemplo este

https://msdn.microsoft.com/en-us/library/ms252091.aspx

Y pues me parece un poco engorroso ese código y sobretodo no me sirve, sólo errores. También veo en ese código que ellos definen los datos del tamaño y el formato, pues yo ya tengo el reporte hecho el diseñador del VS lo cuál creo que no necesito definirselo ahí.


Necesito pasarle los parámetros al reporte para hacer correctamente la consulta, donde ya tengo mis datasets definidos, entonces sinceramente no se como hacer para llenar ese reporte y poder imprimirlo. Ya que antes simplemente ponía un control de report viewer y el me lanzaba el dialogo para imprimirlo, pero como es para facturas necesito que no se vea.


Código (vbnet) [Seleccionar]


Private Sub imprimir_reporte()

        Dim FACT As New ReportParameter("FACT", lbl_Consecutivo.Text)
        Dim deviceInfo As String = "<DeviceInfo><OutputFormat>EMF</OutputFormat><PageWidth>8.5in</PageWidth><PageHeight>11in</PageHeight><MarginTop>0.25in</MarginTop><MarginLeft>0.25in</MarginLeft><MarginRight>0.25in</MarginRight><MarginBottom>0.25in</MarginBottom></DeviceInfo>"
     
        Dim report As New LocalReport()

        Try

            Me.Tbl_DETAILTableAdapter1.Fill(Me.FacturacionDataSet1.tbl_DETAIL)
            Me.Tbl_HEADERTableAdapter1.Fill(Me.FacturacionDataSet11.tbl_HEADER)

            'report.ReportPath = "..\..\Report2.rdlc"

            report.DataSources.Add(New ReportDataSource("HEADER", Me.Tbl_HEADERTableAdapter1.Fill(Me.FacturacionDataSet11.tbl_HEADER)))
            report.DataSources.Add(New ReportDataSource("DETAIL", Me.Tbl_HEADERTableAdapter1.Fill(Me.FacturacionDataSet11.tbl_HEADER)))

            report.SetParameters((New ReportParameter() {FACT}))

            report.ReportEmbeddedResource = "Report2.rdlc"


         
        Catch ex As Exception
            MessageBox.Show(ex.ToString)
        End Try
    End Sub





Ese es el código que tengo, realmente yo tenía el código para imprimir y que a ese reporte le lleguen los datos del dataset les agradezco pero como les digo se hace realmente engorroso y da errores.

Con respecto a los datos del dataset pues he visto que uno le define el datasource, y le mando por medio de parámetros el adapter, dataset pero en ninguna parte de mi rdlc necesito hacer eso y pues me tiene confundido.

Si uds serían tan amables de darme una guía se los agradezco mucho


GRACIAS POR LEER.
Nunca me contestan -_-

Yaldabaot

Me rindo, sinceramente no se como pasarle el documento YA CREADO

El control tiene todos los datos necesarios desde su atributos, como carajos los obtengo para pasarselo al P....  reporte!?

Código (vbnet) [Seleccionar]


Me.ReportViewer1.Clear()

            Dim FACT As New ReportParameter("FACT", Convert.ToInt32(lbl_Consecutivo.Text))
            Dim Subtotal_Descuento As String = String.Empty


            Subtotal_Descuento = Convert.ToDouble(lbl_Subtotal.Text - lblDescuento.Text)

            Dim Subtotal_con_Descuento As New ReportParameter("Subtotal_Con_Descuento", Subtotal_Descuento)

           'Acá lleno los table adapter para el CONTROL del report viewer, donde si se ve!!

            Me.tbl_HEADERTableAdapter.Fill(Me.FACTURACIONDataSet1.tbl_HEADER)
            Me.tbl_DETAILTableAdapter.Fill(Me.FACTURACIONDataSet.tbl_DETAIL)


            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {FACT})
            Me.ReportViewer1.LocalReport.SetParameters(New ReportParameter() {Subtotal_con_Descuento})

            Me.ReportViewer1.RefreshReport()

            imprimir_reporte(Me.ReportViewer1.LocalReport(), 3.92884, 8.9933)




Acá es donde trato de imprimir

Código (vbnet) [Seleccionar]


' Export the given report as an EMF (Enhanced Metafile) file.
    Private Sub Exportar(ByVal report As LocalReport)

        Dim w As Integer = 0
        Dim h As Integer = 0


        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>" & _
            "<MarginTop>0.0in</MarginTop>" & _
            "<MarginLeft>0.0in</MarginLeft>" & _
            "<MarginRight>0.0in</MarginRight>" & _
            "<MarginBottom>0.0in</MarginBottom>" & _
            "</DeviceInfo>"


        m_streams = New List(Of Stream)()
        report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)

        For Each stream As Stream In m_streams
            stream.Position = 0
        Next

    End Sub



Código (vbnet) [Seleccionar]

'Imprimir
    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 ImprimirPagina
        m_currentPageIndex = 0
        printdoc.Print()
    End Sub




Código (vbnet) [Seleccionar]


'Imprime el reporte
    Public Sub imprimir_reporte(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 'Obtiene el nombre de la impresora.

        If Not printdoc.PrinterSettings.IsValid Then 'Detecta si tiene configuración válida
            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
            Exportar(Me.ReportViewer1.LocalReport)
            Print()

        End If
    End Sub



Código (vbnet) [Seleccionar]


Private Sub ImprimirPagina(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 System.Drawing.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
    'Crea un stream
    Private Function CreateStream(ByVal name As String, ByVal fileNameExtension As String, ByVal encoding As System.Text.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




Nunca me contestan -_-