Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtName_E.Text = "" Then
MessageBox.Show("กรุณาระบุชื่อเจ้าหน้าที่ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtName_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,Data_W,ID_E) "
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)
'MessageBox.Show("คุณไม่ติดตั้ง Printer แล้วจะพิมพ์เอกสารได้ไงเล่า 555", "ผลการตรวจสอบ", 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
Private Sub CalculateBring()
Dim i As Integer = 0
Dim tmpNumber_W As Integer = 0
Dim tmpNumber_approval As Integer = 0
For i = 0 To lsvProductsList.Items.Count - 1
tmpNumber_W = CInt(lsvProductsList.Items(i).SubItems(2).Text)
tmpNumber_approval = CInt(lsvProductsList.Items(i).SubItems(3).Text)
Next
End Sub