Sub Save_Click()
txtsearchID.Text = ""
Dim UseID As String = txtUseID.Text
Dim RepairID As String = txtRepairID.Text
Dim EmployeeID As String = cmbEmp.SelectedValue.ToString
Dim d As String = DateUse.Value.Date.Day
Dim m As String = DateUse.Value.Date.Month
Dim y As String = DateUse.Value.Date.Year
Dim DateUses As String = m + "/" + d + "/" + y
Dim Spare_ID As String = txtSpareID.Text
Dim Spare_name As String = txtSpareN.Text
Dim Spare_Cost As String = txtSpareP.Text
Dim UseOty As String = txtQty.Text
Dim connect As SqlConnection = getDriver()
Dim SqlInsertString1 As String = "INSERT INTO UsesSpare (UseID, RepairID ,EmployeeID,DateUses) values ( '" + UseID + "', '" + RepairID + "','" + EmployeeID + "','" + DateUses + "')"
Dim SqlCmd1 As SqlCommand = New SqlCommand(SqlInsertString1, connect)
connect.Open()
Dim successInsert1 As Integer = SqlCmd1.ExecuteNonQuery()
Dim successInsert2 As Integer
Dim SqlCmd2 As SqlCommand
For i = 0 To dgvUseDetail.Rows.Count - 1
SqlCmd2 = New SqlCommand("INSERT INTO UsesDetail (UseID,Spare_ID,Spare_name,Spare_Cost,UseOty) VALUES ('" + UseID + "','" + dtuse.Rows(i)("spareID") + "','" + dtuse.Rows(i)("sparename") + "','" + dtuse.Rows(i)("spareCost") + "','" + dtuse.Rows(i)("use") + "')", connect)
successInsert2 = SqlCmd2.ExecuteNonQuery()
Next
If (successInsert2 > 0) Then
MessageBox.Show("บันทึกข้อมูลเรียบร้อยแล้ว", "รายงานผล", MessageBoxButtons.OK)
dgvUse.Hide()
dgvUseDetail.Update()
dgvUseDetail.Show()
ClearData()
LoadData_2()
Else
MessageBox.Show("การบันทึกข้อมูลไม่สำเร็จ", "รายงานผล", MessageBoxButtons.OK)
End If
connect.Close()
End Sub