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