Private Sub btn_add_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_add.Click
If confirm("คุณต้องการที่จะเพิ่มรายการใช่หรือไม่") = vbNo Then Return
If txt_tag.Text = "" Or txt_name.Text = "" Or txt_description.Text = "" Or cb_loacation.SelectedIndex = 0 Then
msg_error("กรุณากรอบข้อมูลให้ครบ")
Return
End If
If pic_equipment.Image Is Nothing Then
sql = "insert into tbl_equipment(wd_tag,equipment_name,discription,location ,category,date_pm,date_due,username,status,path_invioce,date_add,date_update,update_by)values(@swd_tag,@sequipment_name,@sdiscription,@slocation,@scategory,@sdate_pm,@sdate_due,@susername ,@sstatus,@spath_invioce,@sdate_add,@sdate_update,@supdate_by)"
Else
sql = "insert into tbl_equipment(wd_tag,equipment_name,discription,location,category, date_pm,date_due,username,status,path_invioce,img, date_add,date_update,update_by)values(@swd_tag,@sequipment_name,@sdiscription,@slocation,@scategory,@sdate_pm,@sdate_due,@susername, @sstatus,@spath_invioce,@simg,@sdate_add,@sdate_update,@supdate_by)"
End If
cmd = New OleDbCommand(sql, cn)
cmd.Parameters.Clear()
cmd.Parameters.AddWithValue("swd_tag", txt_tag.Text.ToUpper)
cmd.Parameters.AddWithValue("sequipment_name", txt_name.Text)
cmd.Parameters.AddWithValue("sdiscription", txt_description.Text)
cmd.Parameters.AddWithValue("slocation", cb_loacation.Text)
cmd.Parameters.AddWithValue("scategory", cb_category.Text)
cmd.Parameters.AddWithValue("sdate_pm", dpPM.Text)
cmd.Parameters.AddWithValue("sdate_due", dpDue.Text)
cmd.Parameters.AddWithValue("susername", cb_Username.Text)
cmd.Parameters.AddWithValue("sstatus", cb_Status.Text)
cmd.Parameters.AddWithValue("spath_invioce", txt_invionce.Text)
cmd.Parameters.AddWithValue("sdate_addtatus", DateTime.Now.ToString("dd/MM/yyyy"))
cmd.Parameters.AddWithValue("sdate_update", DateTime.Now.ToString("dd/MM/yyyy"))
cmd.Parameters.AddWithValue("supdate_by", frm_main.lblUsername.Text)
If Not pic_equipment.Image Is Nothing Then
Dim mem As New IO.MemoryStream
pic_equipment.Image.Save(mem, Imaging.ImageFormat.Bmp)
Dim pic_for_add() As Byte
pic_for_add = mem.ToArray()
cmd.Parameters.AddWithValue("simg", pic_for_add)
End If
If cmd.ExecuteNonQuery = 0 Then
msg_error("การเพิ่มไม่สำเร็จ")
Else
msg_OK("การเพิ่มสำเร็จ")
refreash_data()
End If
End Sub