Visual Basic.NET - Imprimir sin vista previa

 
Vista:

Imprimir sin vista previa

Publicado por Robinson Gutierrez (2 intervenciones) el 23/08/2019 18:38:39
Tengo desarrollado un Soft para punto de venta en Visual basic.net con Visual Studio 2013, conectado a SQL. pero necesito que los ticket se impriman directamente sin vista previa. ¿Como puedo hacerlo?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 83
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Imprimir sin vista previa

Publicado por Raúl Mejía (31 intervenciones) el 23/08/2019 21:26:47
Estimado Robinson, te envío el código que yo utilizo para imprimir un ticket de venta, sin vista previa, solo tienes que adecuarlo a tus necesidades.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Private Sub PrintDocument1_PrintPage(sender As Object, e As PrintPageEventArgs) Handles PrintDocument1.PrintPage
    Dim fuente As System.Drawing.Font = New Font("Consolas", 8) 'New Font("consolas", 15)
    Dim topMargin As Double = e.MarginBounds.Top
    Dim yPos As Double = 0
    Dim count As Integer = 0
    Dim texto As String = "" : Dim strEmpresa As String = ""
    Dim unidad As Byte = 0
    Dim detalle As String : Dim intSpace As Integer
    Dim valor As Decimal = 0
    Dim tabulacion As String = ""
    Dim compensador As Integer = 0
    Dim total As Decimal = 0
    Dim Lvalor As Integer = 0
    Dim lineaTotal As New String("", 60)
 
    Try
        Using cnx As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dSn)
            cnx.Open()
            sSql = "SELECT * FROM VENTAS WHERE FOLIO = (SELECT MAX(FOLIO) FROM VENTAS)"
            Dim cmd As New OleDbCommand(sSql, cnx)
            cmd.CommandType = CommandType.Text
            'cmd.Parameters.AddWithValue("FOLIO", txtRow.Text)
            Dim rstVENTAS As OleDbDataReader = cmd.ExecuteReader()
            If rstVENTAS.Read = True Then
                intFolio = CStr(rstVENTAS(0)) + 1
            Else
                intFolio = 1
            End If
            cnx.Close()
            rstVENTAS.Close()
        End Using
    Catch ex As Exception
        MessageBox.Show("Error : " + ex.Message + "", "¡Ocurrio el siguiente Error!", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
 
    ' Imprime la cabecera
    yPos = 40
    Dim printFont As System.Drawing.Font = New Font("Consolas", 6)
    strEmpresa = "DEPOSITO IVANNA"
    e.Graphics.DrawString(strEmpresa, fuente, Brushes.Black, 100, 40)
    e.Graphics.DrawString("Antonio Madrazo # 620", printFont, Brushes.Black, 10, 60)
    e.Graphics.DrawString("Col. sta, Rosa de Lima", printFont, Brushes.Black, 10, 70)
    e.Graphics.DrawString("Tiket N. " & intFolio, printFont, Brushes.Black, 10, 80)
    e.Graphics.DrawString("Fecha:  " & Date.Now, printFont, Brushes.Black, 10, 90)
    e.Graphics.DrawString("Articulos: " & dgvVentas.Rows.Count - 1, printFont, Brushes.Black, 10, 100)
    'e.Graphics.DrawString("Mesa N. " & NumeroMesa.Text, printFont, Brushes.Black, 10, 160)
    e.Graphics.DrawString("------------------------------------------------------", printFont, Brushes.Black, 10, 110)
 
    intRow = 0
    intRow = dgvVentas.Rows.Count - 1
    If intRow > 0 Then
        For Each row As DataGridViewRow In dgvVentas.Rows
            If Val(row.Cells(0).Value) = 0 Then Exit For
            intSpace = 46 - Len(row.Cells(2).Value)
            unidad = row.Cells(4).Value : detalle = row.Cells(2).Value : valor = row.Cells(5).FormattedValue
            Lvalor = Len(row.Cells(5).FormattedValue.ToString)
            compensador = Len(row.Cells(1).Value)
            tabulacion = StrDup(22 - compensador, " ")
            'texto = unidad & "    " & detalle & tabulacion & StrDup(8 - Lvalor, " ") & valor 'Configura la linea
            texto = Space(4 - Len(Format(unidad, "###"))) & Format(unidad, "###") & "    " &
                detalle & Space(intSpace - Len(Format(valor, "#,###.00"))) & Format(valor, "#,###.00")
            yPos = 40 + topMargin + (count * printFont.GetHeight(e.Graphics)) ' Calcula la posición en la que se escribe la línea
            ' Imprime la línea con el objeto Graphics
            If Not row.IsNewRow Then
                e.Graphics.DrawString(texto, printFont, System.Drawing.Brushes.Black, 10, yPos)
                total += valor
            End If
            count += 1
        Next
    End If
    yPos += 10
    e.Graphics.DrawString("                                              _________", printFont, System.Drawing.Brushes.Black, 10, yPos)
    Dim XXX As Integer = 0
    XXX = Len(total.ToString)
    lineaTotal = StrDup(40 - XXX, ".")
    yPos += 20
    e.Graphics.DrawString("Total : " & lineaTotal & Space(10 - Len(Format(total, "##,###.00"))) &
                          Format(total, "##,###.00"), printFont, System.Drawing.Brushes.Black, 10, yPos)
    yPos += 30
    If rbCard.Checked = True Then
        e.Graphics.DrawString("Tarjeta  : " & Space(10 - Len(Format(Val(txtEfectivo.Text), "##,###.00"))) &
                               Format(Val(txtEfectivo.Text), "##,###.00"), printFont, System.Drawing.Brushes.Black, 10, yPos)
    Else
        e.Graphics.DrawString("Efectivo : " & Space(10 - Len(Format(Val(txtEfectivo.Text), "##,###.00"))) &
                               Format(Val(txtEfectivo.Text), "##,###.00"), printFont, System.Drawing.Brushes.Black, 10, yPos)
    End If
    e.Graphics.DrawString("Cambio   : " & Space(10 - Len(Format(Val(txtCambio.Text), "##,###.00"))) &
                          Format(Val(txtCambio.Text), "##,###.00"), printFont, Brushes.Black, 10, yPos + 20)
End Sub


Espero te sirva y por favor infórmame si te fue de utilidad, saludos desde México.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Imprimir sin vista previa

Publicado por Robinson Gutièrrez (2 intervenciones) el 25/08/2019 00:59:07
Buenas tardes,

Raul muchas gracias por tomarte el tiempo en responder. Estoy analizando el código que me enviaste. Te doy mas detalles, el reporte ya lo tengo listo, ya está configurado y muestra toda la información por venta. Lo único que me falta, es que al presionar el botón imprimir, no salga la vista previa sino que vaya directo a la impresora. En tu código colocas campos como Tarjeta, efectivo etc, pero esos campos ya los muestro en el reporte, así que no veo la parte, donde se haga la impresión directa, y por ende tampoco se, donde iría todo tu código, adaptándolo a mi proyecto. Mira como tengo los códigos:

Esto va en el botón imprimir:
1
2
3
4
5
6
7
8
9
10
11
Private Sub BtnImprimirGasto_Click(sender As Object, e As EventArgs) Handles BtnImprimirGasto.Click
    Try
        'Para Llamar al reporte de Gastos
        FrmReporteGastos.TxtIdGastos.Text = TxtIdGasto.Text
        FrmReporteGastos.ShowDialog()
 
        Me.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

Y esto en el formulario que tiene el ReportViewer1:
1
2
3
4
5
6
7
8
9
10
11
12
13
Private Sub FrmReporteGastos_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 
    Try
        Me.Reporte_GastosTableAdapter.Fill(Me.SisventasDataSet18.Reporte_Gastos, Idgastos:=TxtIdGastos.Text)
 
        Me.ReportViewer1.RefreshReport()
    Catch ex As Exception
 
        Me.ReportViewer1.RefreshReport()
    End Try
 
    Me.ReportViewer1.RefreshReport()
End Sub

Saludos dede Colombia y muchas gracias.
Quedo atento a tu ayuda
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 83
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Imprimir sin vista previa

Publicado por Raúl Mejía (31 intervenciones) el 26/08/2019 21:20:55
Estimado Robinson, no sabía que usabas el reportviwer, no se como funciona, yo cuando quiero hacer un reporte lo hago en word o en pdf y la función del reporte que te envié esa es directa a la impresora, entonces en lo personal no encuentro otra manera de ayudarte, analízalo y si crees que te sirve lo que te mandé, solamente adecúalo, espero poder ayudarte en lo que pueda.

Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Imprimir sin vista previa

Publicado por Phil Rob (1546 intervenciones) el 23/08/2019 21:27:01
Hola,

Si tienes una vista previa, este es que tu codigo contiene PreviewDialog1.ShowDialog o otra cosa similare.
Es sufisante que eliminas esta frase.

Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Phil Rob
Val: 3.353
Oro
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Imprimir sin vista previa

Publicado por Phil Rob (1546 intervenciones) el 25/08/2019 11:13:56
Hola,

Disculpa me pero tu mensaje precedente no decía que utilizas un ReportViewer (o no he lo vista), en este caso mi repuesta no estaba bien.

He puesto extractos de códigos para la impresión en la conversación Como guardar el contenido de un ticket en una base de datos del 04/08/2019 21:03.
Adjunto el archivo ImpresionES.zip para el caso dónde es útil.

Estos códigos no serán la solución que preguntas, pero quizá darán ideas.

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar