Private Sub btnSaveList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtID_E.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสเจ้าหน้าที่ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtID_E.Focus()
Exit Sub
End If
If lsvProductsList.Items.Count = 0 Then
MessageBox.Show("กรุณาป้อนรายการยืมอุปกรณ์ !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtID_P.Focus()
Exit Sub
End If
Dim sqlBring As String = ""
Dim comBring As SqlCommand = New SqlCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConnection
.Open()
End With
Try
If MessageBox.Show("คุณต้องการบันทึกรายการการยืมอุปกรณ์ ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
AutoGenerateNo_W()
**** คิดว่าผิดตรงนี้ แต่แก้ไม่ถูกว่าต้องแก้ยังไง *****
sqlBring = "INSERT INTO I_Withdraw (ID_W,Date_W,ID_E,DataCheck_W) "
sqlBring &= " VALUES('" & LastID_W & "',"
sqlBring &= "'" & dtpDateWithdraw.Value & "',"
sqlBring &= "'" & txtID_E.Text & "')"
With comBring
.CommandType = CommandType.Text
.CommandText = sqlBring
.Connection = Conn
.ExecuteNonQuery()
End With
Dim i As Integer = 0
Dim tmpID_P As String = ""
Dim sqlProducts As String = ""
Dim tmpRemain_P As Integer = 0
Dim tmpNumber_W As Integer = 0
Dim tmpNumber_approval As Integer = 0
Dim tmpDateWithdraw As Date
tmpDateWithdraw = Date.Now
For i = 0 To lsvProductsList.Items.Count - 1
sqlBring = "INSERT INTO I_WithdrawDetails(ID_W,ID_P,Number_W,"
sqlBring &= " Number_approval)"
sqlBring &= " VALUES('" & LastID_W & "',"
tmpID_P = lsvProductsList.Items(i).SubItems(0).Text
tmpNumber_W = CInt(lsvProductsList.Items(i).SubItems(2).Text)
tmpNumber_approval = CInt(lsvProductsList.Items(i).SubItems(3).Text)
sqlBring &= "'" & tmpID_P & "',"
sqlBring &= tmpNumber_approval & ","
sqlBring &= tmpNumber_W & ")"
With comBring
.CommandText = sqlBring
.ExecuteNonQuery()
End With
sqlProducts = "SELECT ID_P,Remain_P FROM I_Equipment"
sqlProducts &= " WHERE (ID_P='" & tmpID_P & "')"
da.SelectCommand.CommandText = sqlProducts
da.Fill(ds, "I_Equipment")
tmpRemain_P = CInt(ds.Tables("I_Equipment").Rows(0).Item("Remain_P"))
ds.Tables("I_Equipment").Clear()
sqlBring = "UPDATE I_Equipment"
sqlBring &= " SET Remain_P =" & tmpRemain_P - tmpNumber_W
sqlBring &= " WHERE (ID_P='" & tmpID_P & "')"
With comBring
.CommandText = sqlBring
.ExecuteNonQuery()
End With
Next
'frmMain.tslStatus.Text = "กำลังบันทึกข้อมูล..."
MessageBox.Show("บันทึกรายการการยืมอุปกรณ์เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
'frmMain.tslStatus.Text = ""
If IsInstallPrinter() = True Then
If prDlg.ShowDialog = DialogResult.OK Then
prDoc.Print()
End If
Else
MessageBox.Show("กรุณาติดตั้งเครื่อง Printer ก่อนสั่งพิมพ์เอกสาร", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
ClearAllEmployeesData()
ClearAllProductsData()
lsvProductsList.Items.Clear()
txtID_E.Enabled = True
txtID_E.Focus()
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการการยืมได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End Sub