frmImprimir.vb 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. Imports CrystalDecisions.CrystalReports.Engine
  2. Imports CrystalDecisions.Shared
  3. Public Class frmImprimir
  4. Public NombreRPT As String = String.Empty
  5. Public IdDocumento As String = String.Empty
  6. Public VistaPrevia As Boolean = True
  7. Sub New()
  8. ' Esta llamada es exigida por el diseñador.
  9. InitializeComponent()
  10. ' Agregue cualquier inicialización después de la llamada a InitializeComponent().
  11. End Sub
  12. Sub New(ByRef NombreRPT As String, ByRef IdDocumento As String, ByRef VistaPrevia As Boolean)
  13. Me.New
  14. Me.NombreRPT = NombreRPT
  15. Me.IdDocumento = IdDocumento
  16. CargarRPT()
  17. End Sub
  18. Private Sub frmImpresion_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  19. End Sub
  20. Public Sub CargarRPT()
  21. Dim crSubDB As Database
  22. Dim crTables As Tables
  23. Dim cInfo = New ConnectionInfo()
  24. Dim oRPT As New ReportDocument
  25. 'MsgBox("Cultura: " & Threading.Thread.CurrentThread.CurrentUICulture.LCID.ToString)
  26. crViewer.SetProductLocale(Threading.Thread.CurrentThread.CurrentUICulture.LCID)
  27. cInfo.ServerName = My.Settings.ServidorSQL
  28. cInfo.UserID = My.Settings.UsuarioSQL
  29. cInfo.Password = My.Settings.ClaveSQL
  30. cInfo.DatabaseName = My.Settings.BaseDeDatos
  31. oRPT.Load(My.Settings("RutaReportes") & NombreRPT)
  32. oRPT.SetDatabaseLogon(cInfo.UserID, cInfo.Password)
  33. oRPT.SetParameterValue(0, IdDocumento)
  34. crSubDB = oRPT.Database
  35. crTables = crSubDB.Tables
  36. Dim crTableLogOnInfo As TableLogOnInfo
  37. For Each crTable In crTables
  38. crTableLogOnInfo = crTable.LogOnInfo
  39. crTableLogOnInfo.ConnectionInfo = cInfo
  40. crTable.ApplyLogOnInfo(crTableLogOnInfo)
  41. Next
  42. If VistaPrevia = False Then
  43. oRPT.PrintToPrinter(IdDocumento, False, 0, 0)
  44. End If
  45. crViewer.ReportSource = oRPT
  46. End Sub
  47. Private Sub crViewer_Load(sender As Object, e As EventArgs) Handles crViewer.Load
  48. End Sub
  49. End Class