There is a problem when printing a receipt. The rows are not printing correctly on the paper.
Let me show you the code:
Code:
Private Sub SalesReceipt()
Dim barcode As String
Dim item As String
Dim qty As String
Dim unitprice As String
Dim totalprice As String
Dim sb As New System.Text.StringBuilder
For Each r As DataGridViewRow In ItemGridView.Rows
barcode = sb.Append(r.Cells("Barcode").Value.ToString).ToString
item = sb.Append(r.Cells("ItemName").Value.ToString).ToString
qty = sb.Append(r.Cells("Qty").Value.ToString).ToString
unitprice = sb.Append(r.Cells("ItemPrice").Value.ToString).ToString
totalprice = sb.Append(r.Cells("TotalPrice").Value.ToString & vbCrLf).ToString
Next
PrintLineItem(ReceiptPrinter, barcode, item, qty, unitprice, totalprice) <<<<< I think it may be here??
End Sub
Code:
Private Sub PrintLineItem(printer As PosPrinter, barcode As String, item As String, qty As String, unitprice As String, totalprice As String)
PrintText(printer, TruncateAt(barcode.PadRight(9), 9))
PrintText(printer, TruncateAt(item.ToString.PadLeft(9), 9))
PrintText(printer, TruncateAt(qty.ToString.PadLeft(9), 9))
PrintText(printer, TruncateAt(unitprice.ToString.PadLeft(10), 10))
PrintTextLine(printer, TruncateAt((totalprice).ToString.PadLeft(10), 10))
End Sub
Code:
Private Sub PrintText(ReceiptPrinter As PosPrinter, text As String)
If text.Length <= ReceiptPrinter.RecLineChars Then
ReceiptPrinter.PrintNormal(PrinterStation.Receipt, text)
ElseIf text.Length > ReceiptPrinter.RecLineChars Then
ReceiptPrinter.PrintNormal(PrinterStation.Receipt, TruncateAt(text, ReceiptPrinter.RecLineChars))
End If
End Sub
Everything should print like this:
|BARCODE| |ITEM| |QTY| |UNIT PRICE| |TOTAL PRICE|
-----------------------------------------------------------------
12345 Item1 1 1.00 1.00
123 Item 2 1 1.00 1.00
...
...
...
Let me show you the code:
Code:
Private Sub SalesReceipt()
Dim barcode As String
Dim item As String
Dim qty As String
Dim unitprice As String
Dim totalprice As String
Dim sb As New System.Text.StringBuilder
For Each r As DataGridViewRow In ItemGridView.Rows
barcode = sb.Append(r.Cells("Barcode").Value.ToString).ToString
item = sb.Append(r.Cells("ItemName").Value.ToString).ToString
qty = sb.Append(r.Cells("Qty").Value.ToString).ToString
unitprice = sb.Append(r.Cells("ItemPrice").Value.ToString).ToString
totalprice = sb.Append(r.Cells("TotalPrice").Value.ToString & vbCrLf).ToString
Next
PrintLineItem(ReceiptPrinter, barcode, item, qty, unitprice, totalprice) <<<<< I think it may be here??
End Sub
Code:
Private Sub PrintLineItem(printer As PosPrinter, barcode As String, item As String, qty As String, unitprice As String, totalprice As String)
PrintText(printer, TruncateAt(barcode.PadRight(9), 9))
PrintText(printer, TruncateAt(item.ToString.PadLeft(9), 9))
PrintText(printer, TruncateAt(qty.ToString.PadLeft(9), 9))
PrintText(printer, TruncateAt(unitprice.ToString.PadLeft(10), 10))
PrintTextLine(printer, TruncateAt((totalprice).ToString.PadLeft(10), 10))
End Sub
Code:
Private Sub PrintText(ReceiptPrinter As PosPrinter, text As String)
If text.Length <= ReceiptPrinter.RecLineChars Then
ReceiptPrinter.PrintNormal(PrinterStation.Receipt, text)
ElseIf text.Length > ReceiptPrinter.RecLineChars Then
ReceiptPrinter.PrintNormal(PrinterStation.Receipt, TruncateAt(text, ReceiptPrinter.RecLineChars))
End If
End Sub
Everything should print like this:
|BARCODE| |ITEM| |QTY| |UNIT PRICE| |TOTAL PRICE|
-----------------------------------------------------------------
12345 Item1 1 1.00 1.00
123 Item 2 1 1.00 1.00
...
...
...