Dim a, t, b, c As Integer
For a = 0 To ListView1.SelectedItems.Count - 1
Dim lvi1 As ListViewItem
lvi1 = ListView1.SelectedItems(a)
t = ListView1.SelectedItems(a).SubItems(4).Text
Next
Dim i As Integer = 0
For i = 0 To ListView1.SelectedItems.Count - 1
Dim lvi As ListViewItem
lvi = ListView1.SelectedItems(i)
ListView1.Items.Remove(lvi)
Next
textbox12.Text = textbox12.Text - ((t * 7) / 100)
TextBox9.Text = TextBox9.Text - (t + textbox12.Text)
For b = 0 To ListView1.SelectedItems.Count - 1
c = c + ListView1.Items(b).SubItems(4).Text
Next
MsgBox(c)
ใช้ Function แล้วประกาศเรียกใช้เวลาเรากดปุ๋ม Clear ของเรามันก็จะหักลบ ราคา จำนวนอะไรให้เสร็จเลย อย่างที่ผมใช้ก็
Code (VB.NET)
Private Function UpdProductMinus(ByVal ProductId As String, ByVal Unitprice As Integer) As Boolean
Dim sqlAdd As String
sqlAdd = "UPDATE tblProduct "
sqlAdd &= " SET UnitInstock = UnitInstock - " & Unitprice & ""
sqlAdd &= " WHERE Product_ID = '" & ProductId & "'"
Try
With conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
comBookType = New OleDbCommand
With comBookType
.CommandType = CommandType.Text
.CommandText = sqlAdd
.Connection = conn
.ExecuteNonQuery()
End With
Catch
MessageBox.Show("คุณป้อนรายการสั่งซื้อซั้า !!! ", "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Return False
End Try
Return True
End Function
Dim i As Integer = 0
For i = 0 To ListView1.SelectedItems.Count - 1
Dim lvi As ListViewItem
lvi = ListView1.SelectedItems(i)
ListView1.Items.Remove(lvi)
Next