📄 frm_wh.frm
字号:
VERSION 5.00
Begin VB.Form frm_wh
AutoRedraw = -1 'True
BorderStyle = 3 'Fixed Dialog
Caption = "维护"
ClientHeight = 3990
ClientLeft = 45
ClientTop = 330
ClientWidth = 5130
Icon = "frm_wh.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3990
ScaleWidth = 5130
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "db.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 285
Left = 2040
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "员工表"
Top = 2400
Visible = 0 'False
Width = 1140
End
Begin VB.CommandButton Command3
Caption = "返回"
Height = 495
Left = 3758
TabIndex = 12
Top = 3360
Width = 1215
End
Begin VB.TextBox Text1
Height = 375
Left = 960
TabIndex = 0
Top = 240
Width = 1335
End
Begin VB.TextBox Text2
Height = 375
Left = 960
TabIndex = 1
Top = 840
Width = 1335
End
Begin VB.TextBox Text4
Height = 375
Left = 960
TabIndex = 4
Top = 2040
Width = 1335
End
Begin VB.TextBox Text5
Height = 375
Left = 3600
TabIndex = 8
Top = 2040
Width = 1335
End
Begin VB.TextBox Text6
Height = 375
Left = 960
TabIndex = 9
Top = 2760
Width = 3975
End
Begin VB.TextBox Text7
Height = 375
Left = 3600
TabIndex = 5
Top = 240
Width = 1335
End
Begin VB.TextBox Text8
Height = 375
Left = 3600
TabIndex = 6
Top = 720
Width = 1335
End
Begin VB.TextBox Text9
Height = 375
Left = 3600
TabIndex = 7
Top = 1440
Width = 1335
End
Begin VB.Frame Frame1
Height = 615
Left = 960
TabIndex = 13
Top = 1320
Width = 1335
Begin VB.OptionButton Option1
Caption = "男"
Height = 180
Left = 120
TabIndex = 2
Top = 240
Value = -1 'True
Width = 495
End
Begin VB.OptionButton Option2
Caption = "女"
Height = 180
Left = 720
TabIndex = 3
Top = 240
Width = 495
End
End
Begin VB.CommandButton Command1
Caption = "修改"
Height = 495
Left = 158
TabIndex = 10
Top = 3360
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "删除"
Height = 495
Left = 1958
TabIndex = 11
Top = 3360
Width = 1215
End
Begin VB.Label Label1
Caption = "工号"
Height = 375
Left = 120
TabIndex = 22
Top = 240
Width = 615
End
Begin VB.Label Label2
Caption = "姓名"
Height = 375
Left = 120
TabIndex = 21
Top = 840
Width = 615
End
Begin VB.Label Label3
Caption = "性别"
Height = 375
Left = 120
TabIndex = 20
Top = 1440
Width = 615
End
Begin VB.Label Label4
Caption = "年龄"
Height = 375
Left = 120
TabIndex = 19
Top = 2040
Width = 615
End
Begin VB.Label Label5
Caption = "电话"
Height = 375
Left = 2760
TabIndex = 18
Top = 2040
Width = 615
End
Begin VB.Label Label6
Caption = "住址"
Height = 375
Left = 120
TabIndex = 17
Top = 2760
Width = 615
End
Begin VB.Label Label7
Caption = "部门"
Height = 375
Left = 2760
TabIndex = 16
Top = 240
Width = 615
End
Begin VB.Label Label8
Caption = "职务"
Height = 375
Left = 2760
TabIndex = 15
Top = 720
Width = 615
End
Begin VB.Label Label9
Caption = "政治面貌"
Height = 375
Left = 2760
TabIndex = 14
Top = 1440
Width = 735
End
End
Attribute VB_Name = "frm_wh"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
If Text1.Text <> "" And MsgBox("你确认要修改这条记录吗?", vbInformation Or vbOKCancel) = vbOK Then
For i = 1 To Len(Text1.Text)
If Asc(Mid(Text1.Text, i, 1)) < 48 Or Asc(Mid(Text1.Text, i, 1)) > 57 Then
MsgBox "工号输入数据不合法!请输入数字!", vbCritical
Exit Sub
End If
Next
Data1.Recordset.Edit
Data1.Recordset.Fields("工号") = Text1.Text
Data1.Recordset.Fields("姓名") = Text2.Text
Data1.Recordset.Fields("性别") = IIf(Option1.Value = True, "男", "女")
Data1.Recordset.Fields("年龄") = Text4.Text
Data1.Recordset.Fields("部门") = Text7.Text
Data1.Recordset.Fields("职务") = Text8.Text
Data1.Recordset.Fields("政治面貌") = Text9.Text
Data1.Recordset.Fields("电话") = Text5.Text
Data1.Recordset.Fields("住址") = Text6.Text
Data1.Recordset.Update
MsgBox "记录修改成功!", vbInformation
Text1.Text = ""
Text2.Text = ""
Option1.Value = True
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command2_Click()
If Text1.Text <> "" And MsgBox("你确认要删除这条记录吗?", vbInformation Or vbOKCancel) = vbOK Then
Data1.Recordset.Delete
MsgBox "记录删除成功!", vbInformation
Text1.Text = ""
Text2.Text = ""
Option1.Value = True
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Text1.SetFocus
End If
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
For i = 1 To Len(Text1.Text)
If Asc(Mid(Text1.Text, i, 1)) < 48 Or Asc(Mid(Text1.Text, i, 1)) > 57 Then
MsgBox "工号输入数据不合法!请输入数字!", vbCritical
Exit Sub
End If
Next
Data1.RecordSource = "select * from 员工表 where 工号=" + Text1.Text + ""
Data1.Refresh
If Data1.Recordset.RecordCount > 0 Then
Text1.Text = Data1.Recordset.Fields("工号")
Text2.Text = Data1.Recordset.Fields("姓名")
If Data1.Recordset.Fields("性别") = "男" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text4.Text = Data1.Recordset.Fields("年龄")
Text7.Text = Data1.Recordset.Fields("部门")
Text8.Text = Data1.Recordset.Fields("职务")
Text9.Text = Data1.Recordset.Fields("政治面貌")
Text5.Text = Data1.Recordset.Fields("电话")
Text6.Text = Data1.Recordset.Fields("住址")
Else
MsgBox "没有这条记录!", vbCritical
Text1.Text = ""
End If
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Data1.RecordSource = "select * from 员工表 where 姓名='" + Text2.Text + "'"
Data1.Refresh
If Data1.Recordset.RecordCount > 0 Then
Text1.Text = Data1.Recordset.Fields("工号")
Text2.Text = Data1.Recordset.Fields("姓名")
If Data1.Recordset.Fields("性别") = "男" Then
Option1.Value = True
Else
Option2.Value = True
End If
Text4.Text = Data1.Recordset.Fields("年龄")
Text7.Text = Data1.Recordset.Fields("部门")
Text8.Text = Data1.Recordset.Fields("职务")
Text9.Text = Data1.Recordset.Fields("政治面貌")
Text5.Text = Data1.Recordset.Fields("电话")
Text6.Text = Data1.Recordset.Fields("住址")
Else
MsgBox "没有这条记录!", vbCritical
Text2.Text = ""
End If
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -