📄 frmsysusermanage.frm
字号:
VERSION 5.00
Begin VB.Form SysUserManage
Caption = "系统用户管理"
ClientHeight = 1965
ClientLeft = 60
ClientTop = 345
ClientWidth = 4635
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 1965
ScaleWidth = 4635
Begin VB.CommandButton cmdRefresh
Caption = "刷新"
Height = 300
Left = 3360
TabIndex = 16
Top = 825
Width = 735
End
Begin VB.PictureBox picNavigation
AutoSize = -1 'True
BorderStyle = 0 'None
Height = 350
Left = 720
ScaleHeight = 345
ScaleWidth = 2415
TabIndex = 14
Top = 1440
Width = 2410
Begin VB.TextBox txtNews
Height = 270
Left = 570
Locked = -1 'True
TabIndex = 15
TabStop = 0 'False
Top = -15
Width = 1185
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 2
Left = 1755
Picture = "frmSysUserManage.frx":0000
Style = 1 'Graphical
TabIndex = 5
Top = 0
Width = 300
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 3
Left = 2040
Picture = "frmSysUserManage.frx":0044
Style = 1 'Graphical
TabIndex = 6
Top = 0
Width = 300
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 0
Left = -15
Picture = "frmSysUserManage.frx":0090
Style = 1 'Graphical
TabIndex = 3
Top = 0
Width = 300
End
Begin VB.CommandButton cmdMove
Height = 270
Index = 1
Left = 270
Picture = "frmSysUserManage.frx":00DD
Style = 1 'Graphical
TabIndex = 4
Top = 0
Width = 300
End
End
Begin VB.TextBox txtPWD
DataField = "口令"
DataMember = "SysUsers"
DataSource = "Drug_Store"
Height = 270
Left = 1095
MaxLength = 6
TabIndex = 1
Top = 600
Width = 2175
End
Begin VB.CommandButton cmdAdd
Caption = "添加"
Height = 300
Left = 3360
TabIndex = 7
Top = 195
Width = 735
End
Begin VB.CommandButton cmdDelete
Caption = "删除"
Height = 300
Left = 3360
TabIndex = 8
Top = 495
Width = 735
End
Begin VB.CommandButton cmdExit
Cancel = -1 'True
Caption = "关闭"
Height = 300
Left = 3360
TabIndex = 10
Top = 1465
Width = 735
End
Begin VB.CommandButton cmdSave
Caption = "保存"
Height = 300
Left = 3360
TabIndex = 9
Top = 1155
Width = 735
End
Begin VB.ComboBox cmbStatus
DataField = "权限"
DataMember = "SysUsers"
DataSource = "Drug_Store"
Height = 300
ItemData = "frmSysUserManage.frx":0121
Left = 1095
List = "frmSysUserManage.frx":0123
TabIndex = 2
Text = "cmbStatus"
Top = 1005
Width = 2175
End
Begin VB.TextBox txtUser
DataField = "编号"
DataMember = "SysUsers"
DataSource = "Drug_Store"
Height = 270
Left = 1080
MaxLength = 5
TabIndex = 0
Top = 195
Width = 2175
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "口令"
Height = 180
Left = 600
TabIndex = 13
Top = 645
Width = 360
End
Begin VB.Label Label4
AutoSize = -1 'True
Caption = "权限"
Height = 180
Left = 600
TabIndex = 12
Top = 1065
Width = 360
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "编号"
Height = 180
Left = 600
TabIndex = 11
Top = 240
Width = 360
End
End
Attribute VB_Name = "SysUserManage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim isAdding As Boolean
Private Sub cmdExit_Click()
Unload Me '关闭系统用户管理窗体
End Sub
Private Sub cmdRefresh_Click()
With Drug_Store.rsSysUsers
If .RecordCount > 0 Then
.CancelUpdate '取消前一步执行的操作
.Requery '刷新记录集
'重新执行数据绑定
Set txtUser.DataSource = Drug_Store
txtUser.DataMember = "SysUsers"
txtUser.DataField = "编号"
Set txtPWD.DataSource = Drug_Store
txtPWD.DataMember = "SysUsers"
txtPWD.DataField = "口令"
Set cmbStatus.DataSource = Drug_Store
cmbStatus.DataMember = "SysUsers"
cmbStatus.DataField = "权限"
End If
End With
cmdAdd.Enabled = True
cmdDelete.Enabled = True
isAdding = False
picNavigation.Enabled = True
cmdMove(0).Value = True
End Sub
Private Sub Form_Load()
cmdMove(0).Value = True '触发按钮单击事件
End Sub
'验证用户名输入
Private Sub txtUser_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 _
Or KeyAscii >= Asc("a") And KeyAscii <= Asc("z") _
Or KeyAscii >= Asc("A") And KeyAscii <= Asc("Z") _
Or KeyAscii = vbKeyBack) Then
KeyAscii = 0 '输入不是数字、英文字母或退格键,取消输入
End If
picNavigation.Enabled = False
End Sub
'验证口令输入
Private Sub txtPWD_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 _
Or KeyAscii >= Asc("a") And KeyAscii <= Asc("z") _
Or KeyAscii >= Asc("A") And KeyAscii <= Asc("Z") _
Or KeyAscii = vbKeyBack) Then
KeyAscii = 0 '输入不是数字、英文字母或退格键,取消输入
End If
picNavigation.Enabled = False
End Sub
'验证权限代码输入
Private Sub cmbStatus_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = vbKey0 Or KeyAscii = vbKey1 Or KeyAscii = vbKey2 _
Or KeyAscii = vbKey3 Or KeyAscii = vbKey4 Or KeyAscii = vbKeyBack) Then
KeyAscii = 0
End If
picNavigation.Enabled = False
End Sub
Private Sub cmdAdd_Click()
Drug_Store.rsSysUsers.AddNew '添加新记录
cmbStatus.ListIndex = 1 '设置默认权限
txtNews = "记录:" & Drug_Store.rsSysUsers.AbsolutePosition _
& "/" & Drug_Store.rsSysUsers.RecordCount
isAdding = True
cmdAdd.Enabled = False '在保存新记录之前禁用控件
cmdDelete.Enabled = False
picNavigation.Enabled = False
End Sub
Private Sub cmdDelete_Click()
With Drug_Store.rsSysUsers
If Not .EOF Then
If MsgBox("将删除编号为" & Trim(txtUser) & "的用户数据,是否继续?", _
vbCritical + vbYesNo, "系统用户管理") = vbYes Then
.Delete
.MoveNext
If .EOF And .RecordCount > 0 Then .MoveLast
End If
End If
End With
End Sub
Private Sub cmdSave_Click()
Dim objCopy As New Recordset
If Len(Trim(txtUser)) <> 5 Then
MsgBox "用户编号必须为5位字符串!", vbCritical, "系统用户管理"
txtUser.SetFocus
txtUser.SelStart = 0
txtUser.SelLength = Len(txtUser)
ElseIf Len(Trim(txtPWD)) <> 6 Then
MsgBox "用户口令必须为6位字符串!", vbCritical, "系统用户管理"
txtPWD.SetFocus
txtPWD.SelStart = 0
txtPWD.SelLength = Len(txtPWD)
ElseIf Not cmbStatus Like "[0,1,2,3,4]" Then
MsgBox "用户权限代码必须为0、1、2、3或4!", vbCritical, "系统用户管理"
cmbStatus = "": cmbStatus.SetFocus
Else
Set objCopy = Drug_Store.rsSysUsers.Clone
With objCopy
If .RecordCount > 0 Then
.MoveFirst
.Find "编号='" & Trim(txtUser) & "'"
If Not .EOF And .AbsolutePosition <> Drug_Store.rsSysUsers.AbsolutePosition Then
MsgBox "编号:" & Trim(txtUser) & "已被使用,请使用其他用户名!", _
vbCritical, "系统用户管理"
txtUser.SetFocus
txtUser.SelStart = 0: txtUser.SelLength = Len(txtUser)
Exit Sub
End If
End If
End With
Drug_Store.rsSysUsers.Update
MsgBox "数据保存成功!", vbInformation, "系统用户管理"
cmdAdd.Enabled = True
cmdDelete.Enabled = True
isAdding = False
picNavigation.Enabled = True
End If
End Sub
Private Sub cmdMove_Click(Index As Integer)
With Drug_Store.rsSysUsers
Select Case Index
Case 0 '使第一个记录成为当前记录
If .RecordCount > 0 And Not .BOF Then .MoveFirst
Case 1 '使上一个记录成为当前记录
If .RecordCount > 0 And Not .BOF Then
.MovePrevious
If .BOF Then .MoveFirst
End If
Case 2 '使下一个记录成为当前记录
If .RecordCount > 0 And Not .EOF Then
.MoveNext
If .EOF Then .MoveLast
End If
Case 3 '使最后一个记录成为当前记录
If .RecordCount > 0 And Not .EOF Then .MoveLast
End Select
If .BOF And .EOF Then
txtNews = "记录:无"
Else
txtNews = "记录:" & .AbsolutePosition & "/" & .RecordCount
End If
End With
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -