Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared


Public Class frmImprimir
    Public NombreRPT As String = String.Empty
    Public IdDocumento As String = String.Empty
    Public VistaPrevia As Boolean = True

    Sub New()

        ' Esta llamada es exigida por el diseñador.
        InitializeComponent()

        ' Agregue cualquier inicialización después de la llamada a InitializeComponent().

    End Sub




    Private Sub frmImpresion_Load(sender As Object, e As EventArgs) Handles MyBase.Load


    End Sub

    Public Sub CargarRPT()
        Dim crSubDB As Database
        Dim crTables As Tables
        Dim cInfo = New ConnectionInfo()
        Dim oRPT As New ReportDocument



        crViewer.SetProductLocale(Threading.Thread.CurrentThread.CurrentUICulture.LCID)

        cInfo.ServerName = My.Settings.ServidorSQL
        cInfo.UserID = My.Settings.UsuarioSQL
        cInfo.Password = My.Settings.ClaveSQL
        cInfo.DatabaseName = My.Settings.BaseDeDatos


        oRPT.Load(My.Settings("RutaReportes") & NombreRPT)
        oRPT.SetDatabaseLogon(cInfo.UserID, cInfo.Password)
        oRPT.SetParameterValue(0, IdDocumento)

        crSubDB = oRPT.Database
        crTables = crSubDB.Tables

        Dim crTableLogOnInfo As TableLogOnInfo

        For Each crTable In crTables

            crTableLogOnInfo = crTable.LogOnInfo
            crTableLogOnInfo.ConnectionInfo = cInfo
            crTable.ApplyLogOnInfo(crTableLogOnInfo)

        Next

        If VistaPrevia = False Then
            oRPT.PrintToPrinter(IdDocumento, False, 0, 0)
        End If

        crViewer.ReportSource = oRPT
    End Sub

    Private Sub crViewer_Load(sender As Object, e As EventArgs) Handles crViewer.Load






    End Sub
End Class