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
sqlPrintColor = "SELECT PrintCLID,ColorInShop,ColorInDisclose FROM PrintColor"
sqlPrintColor &= " WHERE (PrintCLID='" & tmpPrintCLID & "')"
da.SelectCommand.CommandText = sqlPrintColor
da.Fill(ds, "PrintColor")
tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop"))
tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose"))
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)
ClearAllCustomerData()
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
ใน access ไม่น่ามีให้เซ็ต fieldให้เป็น not null อะครับ
ส่วนใช้โค้ดที่แนะนำมาก็ไม่ได้อะครับ มันขึ้นว่า 'Contains' is not member of 'System.Data.DataTable'
If tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) <> DBNull.Value And tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) IsNot Nothing Then
tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop"))
End If
If tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) <> DBNull.Value And tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) IsNot Nothing Then
tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose"))
End If
มันขึ้น Operator '<>' is not defined for types 'Boolean' and 'System.DBNull'. กับ 'IsNot' requires operands that have reference type, but this operands has the value type 'Boolean' อะครับ
If String.IsNullOrEmpty(lsvPrintColorList.Items(i).SubItems(2).Text) Then
tmpDiscloseNum = 0
else
tmpDiscloseNum = CInt(lsvPrintColorList.Items(i).SubItems(2).Text)
End If
If String.IsNullOrEmpty(lsvPrintColorList.Items(i).SubItems(2).Text) Then
'กรณีที่ตรวจสอบแล้วเป็นจริง แสดงว่าเป็นค่าว่าง
tmpDiscloseNum = 0
Else
'กรณีที่ตรวจสอบแล้วไม่ใช่ค่าว่างหรือ Null
tmpDiscloseNum = CInt(lsvPrintColorList.Items(i).SubItems(2).Text)
End If
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
If String.IsNullOrEmpty(ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) Then
tmpColorInShop = 0
Else
tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop"))
End If
If String.IsNullOrEmpty(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) Then
tmpColorInDisclose = 0
Else
tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose"))
End If
If Not (DBNull.Value Is ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) And Not (Nothing Is ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) Then
tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop"))
End If
If Not (DBNull.Value Is ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) And Not (Nothing Is ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) Then
tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose"))
End If
If String.IsNullOrEmpty(ds.Tables("PrintColor").Rows(0).Item("ColorInShop")) Then
tmpColorInShop = 0
Else
tmpColorInShop = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInShop"))
End If
If String.IsNullOrEmpty(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose")) Then
tmpColorInDisclose = 0
Else
tmpColorInDisclose = CInt(ds.Tables("PrintColor").Rows(0).Item("ColorInDisclose"))
End If