Private Sub btnSave1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave1.Click
If cboName.Text = "" Then
MessageBox.Show("กรุณาเลือกตัวแทนจำหน่าย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
cboName.Focus()
Exit Sub
End If
If lsvOrder.Items.Count = 0 Then
MessageBox.Show("กรุณาป้อนรายการยาที่จะสั่งซื้อ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtMed_ID.Focus()
txtMed_ID.SelectAll()
Exit Sub
End If
If MessageBox.Show("คุณต้องการบันทึกรายการสั่งซื้อ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
AutoGenerateOrderID()
Dim sqlOrder As String = ""
sqlOrder = "INSERT INTO tblOrder(OrderID,Ph_ID,OrderDate,PaidDate,Vat,NetPaid,IsPaid,IsReceived,IsNormal)"
sqlOrder &= " VALUES ('" & tmpOrderID & "',"
sqlOrder &= "'" & CStr(cboName.SelectedValue) & "',"
sqlOrder &= "'" & Today & "',"
sqlOrder &= "'" & dtpPaidDate.Value & "',"
sqlOrder &= CStr(txtVAT.Text) & ","
sqlOrder &= CStr(txtNetPaid.Text) & ","
sqlOrder &= "'0','0','1')"
Dim comOrder As OleDbCommand = New OleDbCommand
Try
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strconnection
.Open()
End With
With comOrder
.CommandType = CommandType.Text
.CommandText = sqlOrder
.Connection = Conn
.ExecuteNonQuery()
End With
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถเพิ่มข้อมูลได้เนื่องจาก" & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
Dim i As Integer = 0
For i = 0 To lsvOrder.Items.Count - 1
sqlOrder = "INSERT INTO tblOrderDetail(OrderID,Med_ID,MedNumber,MedUnit,Discount,Total,ReceiveDate,MedExp)"
sqlOrder &= " VALUES('" & tmpOrderID & "',"
sqlOrder &= "'" & CStr(lsvOrder.Items(i).SubItems(0).Text) & "',"
sqlOrder &= CInt(lsvOrder.Items(i).SubItems(3).Text) & ","
sqlOrder &= CStr(lsvOrder.Items(i).SubItems(4).Text) & ","
sqlOrder &= CSng(lsvOrder.Items(i).SubItems(5).Text) & ","
sqlOrder &= CSng(lsvOrder.Items(i).SubItems(6).Text) & ","
sqlOrder &= "'" & dtpPaidDate.Value & "',"
sqlOrder &= "'0')"
With comOrder
.CommandText = sqlOrder
.ExecuteNonQuery() <======มัน erroe ว่า No value given for one or more required parameters
End With
Next
MessageBox.Show("บันทึกการทำงารเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = DialogResult.OK Then
prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
txtDiscountRate.Text = "10"
txtVATRate.Text = "7"
txtDiscount.Text = "0.00"
txtVAT.Text = "0.00"
cboName.Focus()
lsvOrder.Items.Clear()
txtNetPaid.Text = "0.00"
End If