in my database: [tbl, nod, qty, DorT, tme, price]
I wanted to call 3fields in the database, The nod[name of dish], tbl[table], DorT[dinein/takeout]
nod[in listview, subitems(1)], tbl[cbtable in the form], and DorT[combobox1 in the form]
In listview[LVORDER]-(qty, nod, price, total)
In my case, adding order is already OK. But i've got a situation that when a customer wants to add an ADDITIONAL DISH, so i need to update his/her, and add a new dish that is not in the list of her/his order before

PROBLEM: scenario: DINE IN and TAKEOUT, i have the same dish, so it is expected to update/add the quantity of the dish as well as the total, but when the dish is in list of her/his order before but diffrent OF DineIn/Takeout, the quantity of that dish is updating In TAKEOUT / DINEIN
EXAMPLE:
qty - name of dish - DineIn/TakeOut
1 - Pasta - dineIn
1 - Chicken - dineIn
2 - Rice - TakeOut

i want to add aditional dish now in DineIn, the same Pasta and a Rice
but this is my output

qty - name of dish - DineIn/TakeOut
2 - Pasta - dineIn
1 - Chicken - dineIn
3 - Rice - TakeOut

[the rice should be added in the dinein list, not to update the takeout list]

 Sub additional_dish()
        Dim tme As String = TimeOfDay
        Dim sql = "select Count(*) from TBLORDER where nod= '" & lvorder.Items(0).SubItems(1).Text & "' AND tbl = '" & cbtable.Text & "' AND DorT='" & ComboBox1.Text & "'"
        Dim cmd = New OleDbCommand(sql, con)

       Try
            Dim result As Integer = Convert.ToInt32(cmd.ExecuteScalar())
            cmd.Parameters.Clear()
            cmd.Dispose()

            If result > 0 Then
                For Each x As ListViewItem In lvorder.Items
                    'sql = "Update TBLORDER set [qty] = [qty] + ? , [price] = [price] + ? where nod = ?"
                    sql = "Update TBLORDER set [qty] = [qty] + ? , [price] = [price] + ? where nod ='" & x.SubItems(1).Text & "' AND tbl = '" & cbtable.Text & "' AND DorT='" & ComboBox1.Text & "'"
                    cmd = New OleDbCommand(sql, con)
                    cmd.Parameters.AddWithValue("@qty", Val(x.SubItems(0).Text))
                    cmd.Parameters.AddWithValue("@price", Val(x.SubItems(3).Text))

                    cmd.ExecuteNonQuery()
                    MsgBox("The Dish Has Been Updated")
                Next
            Else
                For Each x As ListViewItem In lvorder.Items
                    sql = "Insert into TBLORDER (tbl, nod, [qty], DorT, tme, [price]) values (?, ?, ?, ?, ?, ?)"
                    cmd = New OleDbCommand(sql, con)
                    cmd.Parameters.AddWithValue("@tbl", cbtable.Text)
                    cmd.Parameters.AddWithValue("@nod", x.SubItems(1).Text)
                    cmd.Parameters.AddWithValue("@qty", Val(x.SubItems(0).Text))
                    cmd.Parameters.AddWithValue("@DorT", ComboBox1.Text)
                    cmd.Parameters.AddWithValue("@tme", tme)
                    cmd.Parameters.AddWithValue("@price", Val(x.SubItems(3).Text))
                    cmd.ExecuteNonQuery()
                    MsgBox("The Dish Has Been Save")
                Next
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Recommended Answers

All 4 Replies

There should be an option to edit item(s).

@Shark_1, instead of saving all records in listview, i think i need to check first wether the dish[with the same table, and dinein/takeout] is in the database already.
when the dish[the same table, dinein/takeout] need to update
if not the dish need to add. Can you please help me, how to check the records in listview if it i alreay exist in the database?

The easiest way is select Item from listview and edit its status dinen/takeout, then add a new dish as takeout.
Another way , at the time of item insertion to the listview, it automatically choose the last one will be as takeout.
Your list was
qty - name of dish - DineIn/TakeOut
2 - Pasta - dineIn
1 - Chicken - dineIn
3 - Rice - TakeOut

You want to add a new dish like Raita, it automatically adds Raita as takeout and converts Rice as Dinein.
qty - name of dish - DineIn/TakeOut
2 - Pasta - dineIn
1 - Chicken - dineIn
3 - Rice - dineIn
1 - Raita - TakeOut

Hope it can help you.

that would be nice, but i dont want to convert/edit dish from dinein/takeout

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.