?? main_htgl_spinf.frm
字號:
ForeColor = &H000000FF&
Height = 315
Index = 1
Left = 150
TabIndex = 22
Top = 2085
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "商品編號:"
ForeColor = &H000000FF&
Height = 315
Index = 0
Left = 150
TabIndex = 21
Top = 1215
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "本級編號:"
ForeColor = &H000000FF&
Height = 315
Index = 11
Left = 150
TabIndex = 20
Top = 795
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "單 價:"
ForeColor = &H00000000&
Height = 315
Index = 7
Left = 150
TabIndex = 19
Top = 3360
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "供 應 商:"
Height = 315
Index = 9
Left = 150
TabIndex = 18
Top = 4275
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "商品級別:"
ForeColor = &H000000FF&
Height = 315
Index = 10
Left = 150
TabIndex = 17
Top = 345
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "聯系地址:"
ForeColor = &H00000000&
Height = 315
Index = 5
Left = 150
TabIndex = 16
Top = 4710
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "聯系電話:"
ForeColor = &H00000000&
Height = 315
Index = 8
Left = 150
TabIndex = 15
Top = 5190
Width = 1065
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "聯 系 人:"
ForeColor = &H00000000&
Height = 315
Index = 12
Left = 150
TabIndex = 14
Top = 5580
Width = 1065
End
End
End
Attribute VB_Name = "main_htgl_spinf"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i As Integer '定義整型變量
Dim rs1 As New ADODB.Recordset '定義數據集對象
Private nod As Node
Public Sub tree_change() '定義添加樹狀列表的函數
Dim key, text, bh As String
Dim nod As Node
Adodc1.RecordSource = "select * from 商品基礎信息表 order by 商品編號"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Adodc1.Recordset.EOF = False
If Len(Trim(Adodc1.Recordset.Fields("商品編號"))) = 2 Then
key = Trim(Adodc1.Recordset.Fields("本級名稱"))
text = "(" & Trim(Adodc1.Recordset.Fields("商品編號")) & ")" & Trim(Adodc1.Recordset.Fields("本級名稱"))
Set Node1 = TreeView1.Nodes.Add(, , key, text, 1)
End If
If Len(Trim(Adodc1.Recordset.Fields("商品編號"))) = 4 Then
key = Trim(Adodc1.Recordset.Fields("本級名稱"))
text = "(" & Trim(Adodc1.Recordset.Fields("商品編號")) & ")" & Trim(Adodc1.Recordset.Fields("本級名稱"))
Set Node2 = TreeView1.Nodes.Add(Node1.Index, tvwChild, key, text, 2)
End If
If Len(Trim(Adodc1.Recordset.Fields("商品編號"))) = 7 Then
key = Trim(Adodc1.Recordset.Fields("本級名稱"))
text = "(" & Trim(Adodc1.Recordset.Fields("商品編號")) & ")" & Trim(Adodc1.Recordset.Fields("本級名稱"))
Set Node3 = TreeView1.Nodes.Add(Node2.Index, tvwChild, key, text, 3)
End If
Adodc1.Recordset.MoveNext
Loop
End If
End Sub
Private Sub Form_Activate()
'添加商品級別列表
Combo1.AddItem ("1級"): Combo1.AddItem ("2級"): Combo1.AddItem ("3級")
Combo1.ListIndex = 0
'打開連接
rs1.Open "select * from 商品基礎信息表 order by 商品級別,商品編號", cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then
For i = 1 To 12
If rs1.Fields(i) <> "" Then Text1(i).text = rs1.Fields(i)
Text1(i).Enabled = False
Next i
End If
rs1.Close '關閉數據集對象
Call tree_change '調用函數
ComSave.Enabled = False
Me.Caption = Me.Caption & " " & frm_main.St1.Panels(3).text
End Sub
Private Sub Form_Unload(Cancel As Integer)
frm_main.Enabled = True
End Sub
Private Sub Text1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And Index < 11 Then Text1(Index + 1).SetFocus '回車獲得焦點
If KeyCode = vbKeyReturn And Index = 11 Then ComSave.SetFocus
If KeyCode = vbKeyUp And Index > 1 Then Text1(Index - 1).SetFocus
End Sub
Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
Text1(3).text = TreeView1.SelectedItem.key '賦值給text1(3).text
Adodc1.RecordSource = "select * from 商品基礎信息表 where 本級名稱='" + Trim(Text1(3).text) + "'order by 商品級別,商品編號"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
For i = 1 To 12
Text1(i).text = ""
If Adodc1.Recordset.Fields(i) <> "" Then Text1(i).text = Trim(Adodc1.Recordset.Fields(i))
Next i
Combo1.text = Trim(Adodc1.Recordset.Fields("商品級別")) '賦值給combo1.text
End Sub
Private Sub ComAdd_Click()
Dim bh As Integer '定義一個整型變量
If Combo1.text = "1級" Then
Adodc1.RecordSource = "select * from 商品基礎信息表 where 商品級別='" + Combo1.text + "'order by 商品級別,商品編號"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
If Adodc1.Recordset.Fields("本級編號") <> "" Then
bh = Trim(Adodc1.Recordset.Fields("本級編號")) + 1
Text1(1).text = Format(bh, "00")
End If
Else
Text1(1).text = "01"
End If
Text1(2).text = Text1(1).text
End If
If Combo1.text = "2級" Then
Adodc1.RecordSource = "select * from 商品基礎信息表 where 商品級別='" + Combo1.text + "'and 商品編號 Like '" + Trim(Text1(2).text) + "'+'_____'order by 商品編號"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
If Adodc1.Recordset.Fields("本級編號") <> "" Then
bh = Trim(Adodc1.Recordset.Fields("本級編號")) + 1
Text1(1).text = Format(bh, "00")
Text1(2).text = Left(Trim(Adodc1.Recordset.Fields("商品編號")), 2) & Text1(1).text
End If
Else
Text1(1).text = "01"
Text1(2).text = Trim(Text1(2).text) & "01"
End If
End If
If Combo1.text = "3級" Then
Adodc1.RecordSource = "select * from 商品基礎信息表 where 商品級別='" + Combo1.text + "'and 商品編號 Like '" + Trim(Text1(2).text) + "'+'_____'order by 商品編號"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.MoveLast
If Adodc1.Recordset.Fields("本級編號") <> "" Then
bh = Trim(Adodc1.Recordset.Fields("本級編號")) + 1
Text1(1).text = Format(bh, "000")
Text1(2).text = Left(Trim(Adodc1.Recordset.Fields("商品編號")), 4) & Text1(1).text
End If
Else
Text1(1).text = "001"
End If
End If
'清空輸入框中的內容
For i = 3 To 12
Text1(i).Enabled = True
Text1(i).text = ""
Next i
'設置控件狀態
ComSave.Enabled = True: ComEsc.Enabled = True: ComAdd.Enabled = False
ComModify.Enabled = False: ComDelete.Enabled = False
Text1(3).SetFocus
End Sub
Private Sub ComModify_Click() '修改商品信息
If Adodc1.Recordset.RecordCount <> 0 Then
For i = 3 To 12
Text1(i).Enabled = True
Next i
ComSave.Enabled = True: ComEsc.Enabled = True: ComAdd.Enabled = False
ComModify.Enabled = False: ComDelete.Enabled = False
Else
MsgBox ("沒有要修改的數據!")
End If
End Sub
Private Sub ComDelete_Click() '刪除商品信息
If Adodc1.Recordset.RecordCount > 0 Then
A = MsgBox("您確實要刪除這條數據嗎?", vbYesNo)
If A = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Refresh
TreeView1.Nodes.Clear
Call tree_change '調用函數
Adodc1.RecordSource = "select * from 商品基礎信息表"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount <> 0 Then
For i = 1 To 12
If Adodc1.Recordset.Fields(i) <> "" Then Text1(i).text = Adodc1.Recordset.Fields(i)
Next i
Combo1.text = Adodc1.Recordset.Fields("商品級別")
End If
ComSave.Enabled = False: ComEsc.Enabled = False: ComAdd.Enabled = True
ComModify.Enabled = True: ComDelete.Enabled = True
End If
Else
MsgBox ("沒有要刪除的數據!")
End If
End Sub
Private Sub ComSave_Click() '保存商品信息
Set rs1 = New ADODB.Recordset
rs1.Open "select * from 商品基礎信息表 where 商品編號='" & Trim(Text1(2).text) & "'order by 商品編號", cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then
Dim A As String '定義一個字符串變量
A = MsgBox("您確實要修改這條數據嗎?", vbYesNo)
If A = vbYes Then
For i = 1 To 6
If Text1(1).text <> "" Then rs1.Fields(i) = Trim(Text1(i).text) '賦值給rs1.fields(i)
Text1(i).Enabled = False
Next i
rs1.Fields(7) = Val(Trim(Text1(7).text))
For i = 8 To 12
If Text1(1).text <> "" Then rs1.Fields(i) = Trim(Text1(i).text)
Text1(i).Enabled = False
Next i
rs1.Fields("商品級別") = Combo1.text
rs1.Update
Adodc1.Refresh
End If
Else
If Text1(1).text <> "" And Text1(2).text <> "" Then
'添加商品信息
rs1.AddNew
For i = 1 To 6
If Text1(1).text <> "" Then rs1.Fields(i) = Trim(Text1(i).text)
Text1(i).Enabled = False
Next i
rs1.Fields(7) = Val(Trim(Text1(7).text))
For i = 8 To 12
If Text1(1).text <> "" Then rs1.Fields(i) = Trim(Text1(i).text)
Text1(i).Enabled = False
Next i
rs1.Fields("商品級別") = Combo1.text
rs1.Update '更新數據庫
Adodc1.Refresh
Else
MsgBox "請填寫完整的信息"
End If
End If
rs1.Close '關閉數據集對象
TreeView1.Nodes.Clear
Call tree_change '調用函數
'設置控件狀態
ComSave.Enabled = False: ComEsc.Enabled = False: ComAdd.Enabled = True
ComModify.Enabled = True: ComDelete.Enabled = True
End Sub
Private Sub ComEsc_Click() '取消操作
If Not Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
For i = 1 To 12
If Adodc1.Recordset.Fields(i) <> "" Then Text1(i).text = Adodc1.Recordset.Fields(i)
Next i
Combo1.text = Adodc1.Recordset.Fields("商品級別")
End If
ComSave.Enabled = False: ComEsc.Enabled = False: ComAdd.Enabled = True
ComModify.Enabled = True: ComDelete.Enabled = True
End Sub
Private Sub ComExit_Click()
frm_main.Enabled = True
Unload Me
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -