Private Sub Toolbar1_ButtonClick(ByVal Button As MSComctlLib.Button)
Select Case Button.Key
Case "add"
blnAdd = True
tlbState Toolbar1, True
For i = 1 To Text1.UBound
Text1(i) = ""
Text1(i).Locked = False
Next i
DataCombo1.Text = "": DataCombo2.Text = ""
DataCombo1.Locked = False: DataCombo2.Locked = False
DataCombo1.SetFocus
Case "modify"
If Adodc1.Recordset.RecordCount > 0 Then
blnAdd = False
tlbState Toolbar1, True
For i = 1 To Text1.UBound
Text1(i).Locked = False
Next i
DataCombo1.Locked = False
DataCombo2.Locked = False
view_data
Else
MsgBox "系統沒有要修改的數據!", , "提示窗口"
End If
Case "delete"
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Else
MsgBox "系統沒有要刪除的數據!", , "提示窗口"
End If
Case "save"
If Text1(1).Text = "" Then
MsgBox "系統不允許商品名稱為空!", , "提示窗口"
Exit Sub
End If
If IsNumeric(Text1(4)) = False Then
MsgBox "請在成本價文本框中輸入數字!", , "提示窗口"
Exit Sub
End If
If IsNumeric(Text1(5)) = False Then
MsgBox "請在銷售價文本框中輸入數字!", , "提示窗口"
Exit Sub
End If
If IsNumeric(Text1(6)) = False Then
MsgBox "請在庫存文本框中輸入數字!", , "提示窗口"
Exit Sub
End If
On Error GoTo SaveErr
If blnAdd = True Then
rs1.Open "select * from 商品信息表 where 商品名稱='" + Text1(1) + "'and 規格='" + Text1(2) + "'", Cnn, adOpenKeyset
If rs1.RecordCount > 0 Then
MsgBox "此商品已存在!", , "提示窗口"
Else
Cnn.Execute ("insert into 商品信息表(商品類別,商品名稱,規格,單位,成本價,銷售價,庫存數量,備註,存放庫位)values('" + DataCombo1 + _
"','" + Text1(1) + "','" + Text1(2) + "','" + Text1(3) + "'," + Text1(4) + "," + Text1(5) + "," + Text1(6) + ",'" + Text1(7) + "','" + DataCombo2 + "')")
Adodc1.Refresh
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
DataCombo1.Locked = True: DataCombo2.Locked = True
End If
rs1.Close
Else
rs1.Open "select * from 商品信息表 where 商品名稱='" + Text1(1) + "'and 規格='" + Text1(2) + "'", Cnn, adOpenKeyset
If rs1.RecordCount > 0 And Text1(1) <> DataGrid1.Columns(1) And Text1(2) <> DataGrid1.Columns(2) Then
MsgBox "此記錄已存在!", , "提示窗口"
Else
Cnn.Execute ("update 商品信息表 set 商品類別 ='" + DataCombo1 + "',商品名稱 ='" + Text1(1) + "',規格 ='" + Text1(2) + _
"',單位 ='" + Text1(3) + "',成本價=" + Text1(4) + ",銷售價=" + Text1(5) + ",庫存數量=" + Text1(6) + ",備註='" + Text1(7) + "',存放庫位 ='" + DataCombo2 + "'where 商品名稱 ='" + DataGrid1.Columns(1) + _
"'and 規格 ='" + DataGrid1.Columns(2) + "'")
Adodc1.Refresh
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
DataCombo1.Locked = True: DataCombo2.Locked = True
End If
rs1.Close
End If
Exit Sub
SaveErr:
MsgBox Err.Description
Case "cancel"
tlbState Toolbar1, False
For i = 1 To Text1.UBound
Text1(i).Locked = True
Next i
DataCombo1.Locked = True: DataCombo2.Locked = True
view_data
Case "close"
Unload Me
End Select
End Sub