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