Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
If txtEmployeeID.Text = "" Then
MessageBox.Show("กรุณาระบุรหัสพนักงาน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtEmployeeID.Focus()
Exit Sub
End If
If lsvPrintColorList.Items.Count = 0 Then
MessageBox.Show("กรุณาป้อนรายการเบิกสีหมึก !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtPrintCLID.Focus()
Exit Sub
End If
Dim sqlDisclose As String = ""
Dim comDisclose As OleDbCommand = New OleDbCommand
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
Try
If MessageBox.Show("คุณต้องการบันทึกรายการเบิกสีหมึก ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
AutoGenerateTranID()
sqlDisclose = "INSERT INTO Disclose (TransID,EmployeeID) "
sqlDisclose &= " VALUES('" & LastTransID & "',"
sqlDisclose &= "'" & txtEmployeeID.Text & "')"
With comDisclose
.CommandType = CommandType.Text
.CommandText = sqlDisclose
.Connection = Conn
.ExecuteNonQuery()
End With
Dim i As Integer = 0
Dim tmpPrintCLID As String = ""
Dim sqlPrintColor As String = ""
Dim tmpColorInShop As Integer = 0
Dim tmpColorInDisclose As Integer = 0
Dim tmpDiscloseNum As Integer = 0
Dim tmpDate_Disclose As Date
tmpDate_Disclose = Date.Now
For i = 0 To lsvPrintColorList.Items.Count - 1
sqlDisclose = "INSERT INTO DiscloseDetail(TransID,PrintCLID,Date_Disclose,DiscloseNum)"
sqlDisclose &= " VALUES('" & LastTransID & "',"
tmpPrintCLID = lsvPrintColorList.Items(i).SubItems(0).Text
tmpDiscloseNum = CInt(lsvPrintColorList.Items(i).SubItems(2).Text)
sqlDisclose &= "'" & tmpPrintCLID & "',"
sqlDisclose &= "'" & tmpDate_Disclose & "',"
sqlDisclose &= tmpDiscloseNum & ")"
With comDisclose
.CommandText = sqlDisclose
.ExecuteNonQuery()
End With
sqlDisclose = "SELECT PrintCLID,ColorInShop,ColorInDisclose FROM PrintColor"
sqlDisclose &= " WHERE (PrintCLID='" & tmpPrintCLID & "')"
da.SelectCommand.CommandText = sqlDisclose
da.Fill(ds, "PrintColor")
If IsDBNull(ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) Then
tmpColorInShop = 0
Else
tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop"))
End If
If IsDBNull(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) Then
tmpColorInDisclose = 0
Else
tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose"))
End If
ds.Tables("PrintColor").Clear()
sqlDisclose = "UPDATE PrintColor"
sqlDisclose &= " SET ColorInShop=" & tmpColorInShop - tmpDiscloseNum & ","
sqlDisclose &= " ColorInDisclose=" & tmpColorInDisclose + tmpDiscloseNum
sqlDisclose &= " WHERE (PrintCLID='" & tmpPrintCLID & "')"
With comDisclose
.CommandText = sqlDisclose
.ExecuteNonQuery()
End With
Next
MessageBox.Show("บันทึกรายการเบิกสีหมึกเรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information)
ClearAllEmployeeData()
ClearAllPrintColorData()
lsvPrintColorList.Items.Clear()
cboDepartment.SelectedIndex = 0
txtEmployeeID.Enabled = True
txtEmployeeID.Focus()
End If
Catch ErrProcess As Exception
MessageBox.Show("ไม่สามารถบันทึกรายการเบิกสีหมึกได้ เนื่องจาก " & ErrProcess.Message, "ข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Sub
End Try
End Sub