📄 main_jbxx_gys.frm
字号:
TabIndex = 8
Top = 195
Width = 800
End
Begin VB.CommandButton CmdMD
BackColor = &H00FFC0C0&
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Index = 1
Left = 900
Picture = "main_jbxx_gys.frx":16A7
Style = 1 'Graphical
TabIndex = 7
Top = 195
Width = 800
End
Begin VB.CommandButton CmdMD
BackColor = &H00FFC0C0&
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Index = 2
Left = 1695
Picture = "main_jbxx_gys.frx":2BD9
Style = 1 'Graphical
TabIndex = 6
Top = 195
Width = 800
End
Begin VB.CommandButton CmdMD
BackColor = &H00FFC0C0&
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 360
Index = 3
Left = 2505
Picture = "main_jbxx_gys.frx":40DD
Style = 1 'Graphical
TabIndex = 5
Top = 195
Width = 800
End
Begin VB.CommandButton ComExit
BackColor = &H00C0C0C0&
Caption = "[X]退出"
Height = 360
Left = 8205
Style = 1 'Graphical
TabIndex = 4
Top = 195
Width = 800
End
Begin VB.CommandButton ComEsc
BackColor = &H00C0C0C0&
Caption = "[E]取消"
Height = 360
Left = 7410
Style = 1 'Graphical
TabIndex = 3
Top = 195
Width = 800
End
Begin VB.CommandButton ComDelete
BackColor = &H00C0C0C0&
Caption = "[D]删除"
Height = 360
Left = 5820
Style = 1 'Graphical
TabIndex = 2
Top = 195
Width = 800
End
Begin VB.CommandButton ComAdd
BackColor = &H00C0C0C0&
Caption = "[A]添加"
Height = 360
Left = 4215
Style = 1 'Graphical
TabIndex = 1
Top = 195
Width = 800
End
Begin VB.CommandButton ComSave
BackColor = &H00C0C0C0&
Caption = "[S]保存"
Enabled = 0 'False
Height = 360
Left = 6615
Style = 1 'Graphical
TabIndex = 14
Top = 195
Width = 800
End
End
End
Attribute VB_Name = "main_jbxx_gys"
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 '定义数据集对象
Public Sub view_data() '定义显示数据的函数
For i = 0 To 13
If Adodc1.Recordset.Fields(i) <> "" Then gys(i).Text = Adodc1.Recordset.Fields(i)
Next i
End Sub
Private Sub Form_Activate()
' 向combo1中添加查询项目列表
Combo1.AddItem ("供应商编号")
Combo1.AddItem ("供应商全称")
Combo1.ListIndex = 1
'打开"gys"表
rs1.Open "select * from gys order by 供应商编号", cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then
For i = 0 To 13
If rs1.Fields(i) <> "" Then gys(i).Text = rs1.Fields(i)
Next i
End If
rs1.Close '关闭数据集对象
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 gys_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyReturn And Index < 13 Then gys(Index + 1).SetFocus '回车获得焦点
If KeyCode = vbKeyReturn And Index = 13 Then ComSave.SetFocus
If KeyCode = vbKeyUp And Index > 1 Then gys(Index - 1).SetFocus
End Sub
Private Sub SSTab1_Click(PreviousTab As Integer)
If Adodc1.Recordset.RecordCount <> 0 Then
If SSTab1.Tab = 1 And ComAdd.Enabled = False Then
MsgBox ("您正在处理数据,请取消数据处理,在执行本操作!")
SSTab1.Tab = 0
End If
End If
End Sub
Private Sub Comfind_Click() '查询供应商信息
Adodc1.RecordSource = "select * from gys where (gys." & Combo1.Text & " like + '" + Text1.Text + "'+'%')"
Adodc1.Refresh
Call view_data '调用函数
SSTab1.Tab = 1
End Sub
Private Sub CmdMD_Click(Index As Integer)
Select Case Index
Case Is = 0 '移到第一条记录
If Not Adodc1.Recordset.BOF Then Adodc1.Recordset.MoveFirst
Case Is = 1 '移到上一条记录
If Adodc1.Recordset.RecordCount <> 0 Then
If Adodc1.Recordset.BOF = False Then Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF = True Then Adodc1.Recordset.MoveFirst
End If
Case Is = 2 '移到下一条记录
If Adodc1.Recordset.RecordCount <> 0 Then
If Adodc1.Recordset.EOF = False Then Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then Adodc1.Recordset.MoveLast
End If
Case Is = 3 '移到最后一条记录
If Adodc1.Recordset.EOF = False Then Adodc1.Recordset.MoveLast
End Select
Call view_data '调用函数
End Sub
Private Sub ComAdd_Click() '添加
'自动创建供应商编号
Dim bh As Integer
rs1.Open "select * from gys order by 供应商编号", cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then
If Not rs1.EOF Then rs1.MoveLast
If rs1.Fields("供应商编号") <> "" Then
bh = Right(Trim(rs1.Fields("供应商编号")), 4) + 1
gys(0).Text = "gys" & Format(bh, "0000")
End If
Else
gys(0).Text = "gys0001"
End If
rs1.Close
For i = 1 To 13
gys(i).Enabled = True
gys(i).Text = ""
Next i
'设置控件状态
ComSave.Enabled = True: ComEsc.Enabled = True: ComAdd.Enabled = False
ComModify.Enabled = False: ComDelete.Enabled = False
For i = 0 To 3
CmdMD(i).Enabled = False
Next i
SSTab1.Tab = 0
gys(1).SetFocus
End Sub
Private Sub ComModify_Click() '允许用户修改
If Adodc1.Recordset.RecordCount <> 0 Then
For i = 0 To 13
gys(i).Enabled = True
Next i
ComSave.Enabled = True: ComEsc.Enabled = True: ComAdd.Enabled = False
ComModify.Enabled = False: ComDelete.Enabled = False
For i = 0 To 3
CmdMD(i).Enabled = False
Next i
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
If Adodc1.Recordset.RecordCount <> 0 Then
Call view_data '调用函数
End If
ComSave.Enabled = False: ComEsc.Enabled = False: ComAdd.Enabled = True
ComModify.Enabled = True: ComDelete.Enabled = True
For i = 0 To 3
CmdMD(i).Enabled = True
Next i
End If
Else
MsgBox ("没有要删除的数据!")
End If
End Sub
Private Sub ComSave_Click() '保存供应商信息
Set rs1 = New ADODB.Recordset
rs1.Open "select * from gys where 供应商编号='" & Trim(gys(0).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 13
If gys(1).Text <> "" Then rs1.Fields(i) = Trim(gys(i).Text)
gys(i).Enabled = False
Next i
rs1.Update
Adodc1.Refresh
End If
Else
If gys(1).Text <> "" And gys(2).Text <> "" Then
'添加供应商信息
rs1.AddNew
For i = 0 To 13
rs1.Fields(i) = Trim(gys(i).Text)
gys(i).Enabled = False
Next i
rs1.Update '更新数据库
Adodc1.Refresh
Else
MsgBox "请填写完整的信息"
End If
End If
rs1.Close '关闭数据集对象
'设置控件有效或无效
ComSave.Enabled = False: ComEsc.Enabled = False: ComAdd.Enabled = True
ComModify.Enabled = True: ComDelete.Enabled = True
For i = 0 To 3
CmdMD(i).Enabled = True
Next i
End Sub
Private Sub ComEsc_Click() '取消操作
rs1.Open "select * from gys order by 供应商编号", cnn, adOpenKeyset, adLockOptimistic
If rs1.RecordCount > 0 Then
For i = 0 To 13
If rs1.Fields(i) <> "" Then gys(i).Text = rs1.Fields(i) '赋值给gys(i)
gys(i).Enabled = False
Next i
End If
rs1.Close
'设置控件有效或无效
ComSave.Enabled = False: ComEsc.Enabled = False: ComAdd.Enabled = True
ComModify.Enabled = True: ComDelete.Enabled = True
For i = 0 To 3
CmdMD(i).Enabled = True
Next i
End Sub
Private Sub ComExit_Click()
frm_main.Enabled = True
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -