Click here to Skip to main content
11,478,174 members (70,824 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hello !

i have a datagridview like this:

ID |Items Name | Qyt.|Price| Sum|
--------------------------------------
1 |Coca cola | 2 | 3.5 | 7.00|
2 |chesseburger | 2 | 6.0 |12.00|
.
.
.
.

I want to brint this in a receipt?

i have a code but what is doing is this:


1 |Coca cola | 2 | 3.5 | 7.00|
2 |chesseburger | 2 | 6.0 |12.00|
 Dim line As String
        Dim c As Integer = 70
        For Each row As DataGridViewRow In DataGridView.Rows
            line = String.Empty
            For Each cell As DataGridViewCell In row.Cells
                line += cell.Value.ToString() & vbTab
            Next
            c = c + 20
            g.DrawString(line, myfont, Brushes.Black, 10, c)
        Next
i want to make a receipt like this:

that the item string mus have maximum 15 characters, price 4 caracters,qty. 4 caracters sum 4 caracters !

but i dont know how!
plz Help me!



sorry for my english!
Posted 29-May-11 15:09pm
Atmir862
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here you go...(I recommend this)

How to Print Receipt by POS Printer using VB.Net.[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Dear Have you got answer for that? I am using datagridview1. Please reply me how do I print receipt by using datagridview1. I am not understanding the link. it says there
If CType(dgTransactionList.Item(k, 0), System.String) = "True"

No Idea of "dgTransactionList" what it mean.

Please reply me with the datagridview1 to receipt print.

my email id <REMOVED>@gmail.com

waiting for your quick reply
  Permalink  
v2
Comments
VitorHugoGarcia at 5-Feb-13 5:05am
   
you shouldn't post your email here, unless you love spam.
This is a public website and the solutions should be available to the community, not exchanged via email as you proposed.

You also posted a question as a solution, which isn't the right thing to do.

Take care,VG
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Try

Dim displayString As String
Dim ESC As String = Chr(&H1B) + "a" + Chr(0)
Dim ESC2 As String = Chr(&H1B) + "@"
Dim ESC1 As String = Chr(&H1B) + "a" + Chr(1) 'Allign Middle
Dim ESC4 As String = Chr(&H1B) + "a" + Chr(2) 'Allign right
Dim ESC5 As String = Chr(&H1B) + "!" + Chr(17) ' Double hight font mode
Dim ESC6 As String = Chr(&H1B) + "!" + Chr(1) ' Cancel Double hight font mode

strSQl = "Select * from vewSalesInvoice where DocNo ='" & strDocNo & "'"
Dim da As New SqlDataAdapter(strSQl, cnn)
Dim dt As New DataTable
da.Fill(dt)
Dim strCustomer As String
Dim strMemo As String
strMemo = dt.Rows(0)("TokenNo")
strCustomer = dt.Rows(0)("Name")
displayString = vbNewLine
displayString += ESC1 + ESC5 + CNm + ESC6 + vbNewLine
displayString += ESC1 + "Ratnapura Rd, Bandaragama." + vbNewLine
displayString += ESC1 + "Cash Receipt" + vbNewLine
displayString += "---------------------------------------"
displayString += vbNewLine
displayString += ESC + "Transaction #:" + strDocNo
displayString += ESC + vbNewLine
displayString += "Date: " + Date.Today() + vbTab.ToString() + "Time: "
displayString += DateAndTime.Now().ToLongTimeString() + ESC
displayString += ESC + vbNewLine

displayString += "Cashier: " + CStr(GlobalUserName) + vbTab.ToString()
displayString += vbNewLine
displayString += "Customer: " + strCustomer
displayString += vbNewLine
displayString += "Memo: " + strMemo
displayString += vbNewLine
displayString += "---------------------------------------"
displayString += vbNewLine
displayString += ESC + "# " + "Item" + vbTab.ToString() + "Rate" + vbTab.ToString() + "Qty" + vbTab.ToString() + "Total" + vbTab.ToString() + "Desc."
displayString += vbNewLine
displayString += "---------------------------------------"
displayString += vbNewLine

Dim dblGrossTot As Double
Dim dblDiscount As Double
Dim dblNetTotal As Double
Dim dblPaid As Double
Dim dblBalRetuned As Double

'Iterate loop for each row of the Data Set.

dblDiscount = dt.Rows(0)("LineDiscount")
dblNetTotal = dt.Rows(0)("TranValue")
dblPaid = dt.Rows(0)("Paid")
dblBalRetuned = dt.Rows(0)("BalanceReturned")
If dt.Rows.Count > 0 Then
Dim k As Integer
Dim n As Integer
k = dt.Rows.Count - 1
n = 1
Do While Not k < 0

Dim strItemCode As String
Dim strItemName As String
Dim dblRate As Double
Dim dblQty As Double
Dim dblLineTotal As Double

strItemCode = dt.Rows(k)("ItemNumber")
strItemName = dt.Rows(k)("Description")
dblRate = FormatNumber(dt.Rows(k)("RegPrice"), 2)
dblQty = -dt.Rows(k)("Qty")
dblLineTotal = dblQty * dblRate
dblGrossTot = dblGrossTot + dblLineTotal

displayString += ESC4 + n.ToString + " "
displayString += strItemCode + " "
displayString += FormatNumber(dblRate.ToString, 2) + " " + dblQty.ToString + vbTab.ToString() + vbTab.ToString() + FormatNumber(dblLineTotal.ToString, 2)
displayString += ESC + vbNewLine
displayString += ESC + strItemName + vbTab.ToString()
displayString += ESC + vbNewLine
k = k - 1
n = n + 1
Loop
displayString += "---------------------------------------"
displayString += vbNewLine
displayString += ESC4 + "GROSS TOTAL :" + vbTab.ToString() + vbTab.ToString() + FormatNumber(dblGrossTot.ToString, 2)
displayString += vbNewLine
displayString += ESC4 + "DISCOUNT :" + vbTab.ToString() + vbTab.ToString() + FormatNumber(-dblDiscount.ToString, 2)
displayString += vbNewLine
displayString += ESC4 + "NET TOTAL :" + vbTab.ToString() + vbTab.ToString() + FormatNumber(dblNetTotal.ToString, 2)
displayString += vbNewLine
displayString += "---------------------------------------"
displayString += vbNewLine
displayString += ESC4 + "PAID :" + vbTab.ToString() + vbTab.ToString() + FormatNumber(dblPaid.ToString, 2)
displayString += vbNewLine
displayString += ESC4 + "BAL. RETUNED :" + vbTab.ToString() + vbTab.ToString() + FormatNumber(dblBalRetuned.ToString, 2)
displayString += vbNewLine
displayString += vbNewLine
displayString += ESC1 + "Thank You for shopping"
displayString += vbNewLine
displayString += vbNewLine
displayString += vbNewLine
displayString += vbNewLine
displayString += vbNewLine
displayString += vbNewLine
displayString += vbNewLine
displayString += vbNewLine

ADRport.Open()
ADRport.Write(displayString)
ADRport.Close()
End If

Catch ex As Exception

MsgBox(ex.ToString())

End Try
  Permalink  
Comments
Member 11341317 at 29-Dec-14 9:57am
   
Good day, I just wanted to follow-up on the already existing solution here as I have the same problem. The following are giving me errors in the above code

displayString += ESC1 + ESC5 + CNm + ESC6 + vbNewLine

CNm - do I need to declared this or maybe there is some referencing I missed.

the next one is in the line for

displayString += "Cashier: " + CStr(GlobalUserName) + vbTab.ToString()

CStr(GlobalUserName) - that is also prompting the same error, how do I declare it.

The last one is in the line

Dim da As New SqlDataAdapter(strSQl, cnn)

cnn - I want to belive this is the connection string to the database, however when I replace it with what my string is (Con1), the error shifts to "da" ... is there something am missing

Thanks in advance, I really am stuck

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Frankie-C 160
1 Sergey Alexandrovich Kryukov 149
2 Sascha Lefèvre 145
3 F-ES Sitecore 130
4 siddartha kopparapu 103
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,321
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,325


Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 27 Aug 2014
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100