Private Sub BtnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnSave.Click
If (TbxUserID.Text = "" Or TbxUserName.Text = "" Or TbxSuppliesID.Text = "" Or TbxSuppliesName.Text = "" Or TbxQuan.Text = "" Or TbxDate1.Text = "" Or TbxDate2.Text = "" Or TbxObject.Text = "" Or TbxEmail.Text = "") Then
MsgBox("กรุณาใส่ข้อมูลให้ครบ")
Return
End If
If Not (IsNumeric(TbxUserID.Text) Or (TbxSuppliesID.Text) Or (TbxQuan.Text)) Then
MsgBox("ต้องใส่ข้อมูลเป็นตัวเลข")
Return
End If
Dim sql As String = ""
Dim adapter As New OleDbDataAdapter
If (TbxOrder.Text = "") Then
sql = "Insert Into runner("
sql &= "Runner_ID,Runner_NAME,Runner_LASTNAME,Supp_ID,Supp_NAME,Supp_QUAN,Supp_DATE,Supp_DATE2,Supp_Object,Email) "
sql &= "Values(@rid,@nm,@lst,@suppid,@suppnm,@suppquan,@suppdate,@suppdate2,@suppob,@email)"
Else
sql = "Update runner Set "
sql &= "Runner_ID = @rid , Runner_NAME = @nm , Runner_LASTNAME = @lst,Supp_ID = @suppid , Supp_NAME = @suppnm , Supp_QUAN = @suppquan , Supp_DATE = @suppdate , Supp_DATE2 = @suppdate2 , Supp_Object = @suppob , Email = @email"
sql &= "Where Runner_ID = " & TbxOrder.Text
End If
_cmd = New OleDbCommand(sql, _conn)
_cmd.Parameters.AddWithValue("rid", TbxUserID.Text)
_cmd.Parameters.AddWithValue("nm", TbxUserName.Text)
_cmd.Parameters.AddWithValue("lst", TbxLastName.Text)
_cmd.Parameters.AddWithValue("suppid", TbxSuppliesID.Text)
_cmd.Parameters.AddWithValue("suppnm", TbxSuppliesName.Text)
_cmd.Parameters.AddWithValue("suppquan", TbxQuan.Text)
_cmd.Parameters.AddWithValue("suppdate", TbxDate1.Text)
_cmd.Parameters.AddWithValue("suppdate2", TbxDate2.Text)
_cmd.Parameters.AddWithValue("suppob", TbxObject.Text)
_cmd.Parameters.AddWithValue("email", TbxEmail.Text)
Dim affectedRow As Integer = _cmd.ExecuteNonQuery()
If (affectedRow < 1) Then
ToolStripStatusLabel1.Text = "เกิดข้อผิดพลาดในการบันทึกข้อมูล!"
Else
ToolStripStatusLabel1.Text = "ข้อมูลถูกจัดเก็บแล้ว"
Dim name As String = TbxUserName.Text
ReadData()
FillListBox()
ClearBindings()
If (TabControl1.SelectedIndex = 0) Then
Bindings()
End If
Dim idx As Integer = ListBox1.FindStringExact(name)
If (idx > -1) Then
ListBox1.SetSelected(idx, True)
End If
End If
UpdateStatus()
End Sub