Private Sub process(ByVal st As String)
If dtpPrint.Text = "" Or dgvshow.Rows.Count = 0 Then
MessageBox.Show("ข้อมูลไม่ครบ")
Exit Sub
End If
If st = "add" Then '--เลือก insert ลงตารางก่อนบันทึก
If MessageBox.Show("ต้องการบันทึกข้อมูลหรือไม่", "ยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
Dim sql As String = ""
sql = "INSERT INTO [Sale] (Sale_id, Sale_date, Sale_total)" & _
"VALUES('" & Me.txtSaleid.Text & "','" & Me.dtpPrint.Text & "','" & Me.txttotal.Text & "')"
Dim cm As New OleDbCommand(sql, Cnn)
cm.ExecuteNonQuery()
'--loop
For i As Integer = 0 To dgvshow.Rows.Count - 1
Dim sql2 As String
sql2 = "INSERT INTO sale_detail (Sale_id, Pro_id, Sale_Quality)" & _
"VALUES('" & Me.txtSaleid.Text & "','" & dgvshow.Rows(i).Cells(1).Value & "','" & CInt(dgvshow.Rows(i).Cells(3).Value) & "')"
'--ตัดสต๊อก
Dim up As String
up = "UPDATE product SET Pro_amount = Pro_amount -'" & txtamount.Value & "' WHERE Pro_id= '" & dgvshow.Rows(i).Cells(1).Value & "'"
Try
Dim com As New OleDbCommand(sql2, Cnn)
com.ExecuteNonQuery()
'--ตัดสต๊อก
Dim cmd As New OleDbCommand(up, Cnn)
cmd.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show("ไม่สามารถบันทึกข้อมูลได้", "ผลการดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
Next
MessageBox.Show("บันทึกข้อมูลเรียบร้อย", "ผลการดำเนินการ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub