Foros del Web » Programación para mayores de 30 ;) » .NET »

Error al capturar impresion de un documento .net 2005 sql server.

Estas en el tema de Error al capturar impresion de un documento .net 2005 sql server. en el foro de .NET en Foros del Web. hola nuevamente amigos... bueno yo creo q este el codigo que mas problemas me ha dado... y unos de los mas importante que tengo que ...
  #1 (permalink)  
Antiguo 05/11/2009, 11:55
 
Fecha de Ingreso: octubre-2009
Mensajes: 5
Antigüedad: 14 años, 6 meses
Puntos: 0
Error al capturar impresion de un documento .net 2005 sql server.

hola nuevamente amigos... bueno yo creo q este el codigo que mas problemas me ha dado... y unos de los mas importante que tengo que sacar :( este codigo captura los datos de los documentos que se van a imprimir. pero me tira un error cuando imprimo un documento es el siguiente

no se puede cargar el archivo DLL kernel32.lib no se puede encontrar el modulo especificado

bueno ojala me den ideas de que puede ser. he buscado por el error pero nada referente a lo que estoy haciendo... :(

para el form. se necesita 3 textbox 3 botones y 1 timer1

[code]Imports System.Diagnostics.Debug
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices

Public Class Form3
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Command1 As System.Windows.Forms.Button
Friend WithEvents Command2 As System.Windows.Forms.Button
Friend WithEvents Command3 As System.Windows.Forms.Button
Friend WithEvents Timer1 As System.Windows.Forms.Timer
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Command1 = New System.Windows.Forms.Button
Me.Command2 = New System.Windows.Forms.Button
Me.Command3 = New System.Windows.Forms.Button
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.SuspendLayout()
'
'Command1
'
Me.Command1.Location = New System.Drawing.Point(352, 24)
Me.Command1.Name = "Command1"
Me.Command1.Size = New System.Drawing.Size(136, 23)
Me.Command1.TabIndex = 0
Me.Command1.Text = "Activar"
'
'Command2
'
Me.Command2.Location = New System.Drawing.Point(360, 112)
Me.Command2.Name = "Command2"
Me.Command2.Size = New System.Drawing.Size(128, 23)
Me.Command2.TabIndex = 1
Me.Command2.Text = "Parar"
'
'Command3
'
Me.Command3.Location = New System.Drawing.Point(360, 224)
Me.Command3.Name = "Command3"
Me.Command3.Size = New System.Drawing.Size(128, 23)
Me.Command3.TabIndex = 2
Me.Command3.Text = "actualizar"
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(8, 24)
Me.TextBox1.Multiline = True
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(320, 80)
Me.TextBox1.TabIndex = 3
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(8, 120)
Me.TextBox2.Multiline = True
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.Size = New System.Drawing.Size(320, 80)
Me.TextBox2.TabIndex = 4
'
'Timer1
'
Me.Timer1.Enabled = True
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(8, 216)
Me.TextBox3.Multiline = True
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.ScrollBars = System.Windows.Forms.ScrollBars.Vertical
Me.TextBox3.Size = New System.Drawing.Size(320, 80)
Me.TextBox3.TabIndex = 5
'
'Form3
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(504, 317)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Controls.Add(Me.Command3)
Me.Controls.Add(Me.Command2)
Me.Controls.Add(Me.Command1)
Me.Name = "Form3"
Me.Text = "Form1"
Me.ResumeLayout(False)
Me.PerformLayout()

End Sub
#End Region

Public Shared Sub main()
Dim PrntInfo As New Form1
PrntInfo.ShowDialog()
End Sub

Private Sub Command1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Command1.Click
'Enable the timer to start printer status checks.
Timer1.Enabled = True
Timer1.Start()

'Enable and disable the start and stop buttons.
Command1.Enabled = False
Command2.Enabled = True
Command3.Enabled = True
End Sub

Private Sub Command2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Command2.Click
'Disable the timer to stop additional printer checks.
Timer1.Enabled = False

'Enable and disable the start and stop buttons.
Command1.Enabled = True
Command2.Enabled = False
Command3.Enabled = True
API = Nothing
End Sub
  #2 (permalink)  
Antiguo 05/11/2009, 11:59
 
Fecha de Ingreso: octubre-2009
Mensajes: 5
Antigüedad: 14 años, 6 meses
Puntos: 0
Respuesta: Error al capturar impresion de un documento .net 2005 sql server.

ESTA ES LA SEGUNDA PARTE PQ NO PUDE COLOCAR TODO YA QUE SE PASA DEL RANGO DE LINEAS.


Private Sub Command3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Command3.Click
'Clear the text boxes to display the printer status.
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
'Initialize captions for the buttons.
Command1.Text = "Empezar"
Command2.Text = "Para"
Command3.Text = "Actualizar"

'Clear the text boxes to display the printer status.
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""

Command1.Enabled = True
'Disable the stop and clear buttons.
Command2.Enabled = False
Command3.Enabled = False

'Set the timer interval to 500 milliseconds to examine the printer status.
Timer1.Enabled = False
Timer1.Interval = 500
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Timer1.Tick
Dim PrinterStatus As String
Dim JobStatus As String
Dim ErrorInfo As String

'Clear the text boxes to display the status.
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""

'Call the CheckPrinter function.
TextBox1.Text = CheckPrinter(PrinterStatus, JobStatus)
TextBox2.Text = PrinterStatus
TextBox3.Text = JobStatus
End Sub

Public Function CheckPrinter(ByRef PrinterStr As String, _
ByRef JobStr As String) As String
Dim hPrinter As IntPtr
Dim ByteBuf As Long
Dim BytesNeeded As Int32
Dim PI2 As New PRINTER_INFO_2
Dim intCount As Long
Dim JI2(intCount) As JOB_INFO_2
Dim PrinterInfo() As Byte
Dim JobInfo() As Byte
Dim result As Long
Dim LastError As Long
Dim PrinterName As String
Dim tempStr As String
Dim NumJI2 As Int32
Dim pDefaults As PRINTER_DEFAULTS

'Set a default return value if no errors occur.
CheckPrinter = "Printer info retrieved!"

Dim PD As New PrintDocument
PrinterName = PD.PrinterSettings.PrinterName

'Set the access security setting that you want.
pDefaults.DesiredAccess = PRINTER_ACCESS_USE

'Call the API to obtain a handle to the printer.
'If an error occurs, display the error.
result = WINAPI.OpenPrinter(PrinterName, hPrinter, pDefaults)
If result = 0 Then

CheckPrinter = "Cannot open printer " & PrinterName & _
", Error: " & Marshal.GetLastWin32Error()
Exit Function
End If

'Initialize the BytesNeeded variable.
BytesNeeded = 0

'Clear the error object.
Err.Clear()

'Determine the buffer size that is required to obtain the printer information.
result = WINAPI.GetPrinter(hPrinter, 2, 0&, 0, BytesNeeded)
'Display the error message that you receive when you call the GetPrinter function,
'and then close the printer handle.
If Marshal.GetLastWin32Error() <> ERROR_INSUFFICIENT_BUFFER Then
CheckPrinter = " > GetPrinter Failed on initial call! <"
WINAPI.ClosePrinter(hPrinter)
Exit Function
End If
ReDim PrinterInfo(BytesNeeded)
ByteBuf = BytesNeeded

'Call the GetPrinter function to obtain the status.
result = WINAPI.GetPrinter(hPrinter, 2, PrinterInfo(0), ByteBuf, _
BytesNeeded)

'Check for any errors.
If result = 0 Then
'Get the error.
LastError = Marshal.GetLastWin32Error()

'Display the error message, and then close the printer handle.
CheckPrinter = "Could not get Printer Status! Error = " _
& LastError
WINAPI.ClosePrinter(hPrinter)
Exit Function
End If

'Copy the contents of the printer status byte array into a
'PRINTER_INFO_2 structure.
PI2 = CType(DatatoDeserial(PrinterInfo, GetType(PRINTER_INFO_2), 1), PRINTER_INFO_2)
PrinterStr = CheckPrinterStatus(PI2.Status)

'Add the printer name, the driver, and the port to the text box.
PrinterStr = PrinterStr & "Printer Name = " & _
GetString(PI2.pPrinterName) & vbCrLf
PrinterStr = PrinterStr & "Printer Driver Name = " & _
GetString(PI2.pDriverName) & vbCrLf
PrinterStr = PrinterStr & "Printer Port Name = " & _
GetString(PI2.pPortName) & vbCrLf

'Call the API to obtain the buffer size that is required.
result = WINAPI.EnumJobs(hPrinter, 0, &HFFFFFFFF, 2, JobInfo, 0, BytesNeeded, NumJI2)
If result = 0 Then
'Display the error, and then close the printer handle.
LastError = Marshal.GetLastWin32Error()
CheckPrinter = " > EnumJobs Failed on initial call! < Error = " _
& LastError
WINAPI.ClosePrinter(hPrinter)
Exit Function
End If

'If no current jobs exist, display the message.
If BytesNeeded = 0 Then
JobStr = "No Print Jobs!"
Else
'Resize the byte array to hold information about the print jobs.
ReDim JobInfo(BytesNeeded - 1)

'Call the API to obtain the print job information.
result = WINAPI.EnumJobs(hPrinter, 0, &HFFFFFFFF, 2, JobInfo, _
BytesNeeded, BytesNeeded, NumJI2)

'Check for errors.
If result = 0 Then
'Display the error, and then close the printer handle.
LastError = Marshal.GetLastWin32Error()
CheckPrinter = " > EnumJobs Failed on second call! < Error = " _
& LastError
WINAPI.ClosePrinter(hPrinter)
Exit Function
End If
ReDim JI2(NumJI2)

'Copy the contents of print job info byte array into a
'JOB_INFO_2 structure.
Try
For intCount = 0 To NumJI2 - 1 ' Loop through jobs and obtain the job information.
Dim test As Object
JI2(intCount) = CType(DatatoDeserial(JobInfo, _
GetType(JOB_INFO_2), intCount + 1), JOB_INFO_2)

JobStr = JobStr & "Job ID = " & JI2(intCount).PrinterJobId & _
vbCrLf & "Total Pages = " & JI2(intCount).TotalPages & vbCrLf

tempStr = ""
'Check for a ready state.
If JI2(intCount).pStatus = 0& Then ' If pStatus is Null, check Status.
If JI2(intCount).pStatus = 0 Then
tempStr = tempStr & "Ready! " & vbCrLf
Else 'Check for the various print job states.
If (JI2(intCount).pStatus And JOB_STATUS_SPOOLING) Then
tempStr = tempStr & "Spooling "
End If

If (JI2(intCount).pStatus And JOB_STATUS_OFFLINE) Then
tempStr = tempStr & "Off line "
End If

If (JI2(intCount).pStatus And JOB_STATUS_PAUSED) Then
tempStr = tempStr & "Paused "
End If

If (JI2(intCount).pStatus And JOB_STATUS_ERROR) Then
tempStr = tempStr & "Error "
End If

If (JI2(intCount).pStatus And JOB_STATUS_PAPEROUT) Then
tempStr = tempStr & "Paper Out "
End If

If (JI2(intCount).pStatus And JOB_STATUS_PRINTING) Then
tempStr = tempStr & "Printing "
End If

If (JI2(intCount).pStatus And JOB_STATUS_USER_INTERVENTION) Then
tempStr = tempStr & "User Intervention Needed "
End If

If Len(tempStr) = 0 Then
tempStr = "Unknown Status of " & JI2(intCount).PrinterStatus
End If
End If
Else

tempStr = Pointer_to_String(JI2(intCount).pStatus)
End If

'Report the job status.
JobStr = JobStr & tempStr & vbCrLf
Next intCount
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
'Close the printer handle.
WINAPI.ClosePrinter(hPrinter)
End Function


End Class[/code]
  #3 (permalink)  
Antiguo 06/11/2009, 12:07
Avatar de eperedo  
Fecha de Ingreso: septiembre-2009
Ubicación: Perú
Mensajes: 654
Antigüedad: 14 años, 7 meses
Puntos: 16
Respuesta: Error al capturar impresion de un documento .net 2005 sql server.

La verdad dudo que alguien pueda leerse todo este código.
Por la descripción del error, creo que estás usando una api para imprimir???

Porque no pruebas con los controles de impresión del .net?
Te dejo informacion sobre esto.

__________________
Eduardo Peredo
Wigoin
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:19.