If ListViewOrder.Items.Count <> 0 Then
If MessageBox.Show("คุณต้องการบันทึกรายการขายเข้าสู่ระบบ ใช่หรือไม่ ? ", "ยืนยันการบันทึก",
MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
Dim i As Integer
Dim SqlSave As String
Dim ComSave As New OleDb.OleDbCommand
For i = 0 To ListViewOrder.Items.Count - 1
SqlSave = "INSERT INTO TableOrderdetail (Order_ID,Product_ID,SalePrice,Quantity,TotalSale)"
SqlSave = SqlSave & " VALUES(" & CStr(ListViewOrder.Items(i).SubItems(0).Text) & ","
SqlSave = SqlSave & CInt(ListViewOrder.Items(i).SubItems(1).Text) & ","
SqlSave = SqlSave & CStr(ListViewOrder.Items(i).SubItems(4).Text) & ","
SqlSave = SqlSave & CInt(ListViewOrder.Items(i).SubItems(5).Text) & ","
SqlSave = SqlSave & CInt(ListViewOrder.Items(i).SubItems(6).Text) & ")"
MessageBox.Show(SqlSave)
With cn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconnection
.Open()
End With
With ComSave
.CommandType = CommandType.Text
.CommandText = SqlSave
.Connection = cn
.ExecuteNonQuery()
End With
Next
MessageBox.Show("บันทึกรายการขายเรียบร้อยแล้ว!!!", "แจ้งผลการทํางาน",
MessageBoxButtons.OK, MessageBoxIcon.Information)
ListViewOrder.Clear()
ClearProductData()
TextBoxReceiptid.Text = ""
LabelTotalSale.Text = ""
ListViewOrder.Columns.Add("รหัสสินค้า", 100, HorizontalAlignment.Center)
ListViewOrder.Columns.Add("รายการสินค้า", 160, HorizontalAlignment.Center)
ListViewOrder.Columns.Add("ราคาขาย", 70, HorizontalAlignment.Center)
ListViewOrder.Columns.Add("จํานวน", 70, HorizontalAlignment.Center)
ListViewOrder.Columns.Add("คิดเป็นเงิน", 100, HorizontalAlignment.Center)
TextBoxReceiptid.Focus()
End If
End If