📄 frmuser.frm
字号:
VERSION 5.00
Begin VB.Form frmUser
BorderStyle = 3 'Fixed Dialog
Caption = "用户管理"
ClientHeight = 2910
ClientLeft = 3450
ClientTop = 1815
ClientWidth = 5865
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2910
ScaleWidth = 5865
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdDelete
Caption = "删除并退出[&D]"
Height = 564
Left = 3972
TabIndex = 9
Top = 1056
Width = 1692
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "放弃并退出[&C]"
Height = 576
Left = 3972
TabIndex = 8
Top = 2076
Width = 1692
End
Begin VB.CommandButton cmdSave
Caption = "保存并退出[&S]"
Height = 564
Left = 3972
TabIndex = 7
Top = 144
Width = 1680
End
Begin VB.Frame Frame4
Height = 2664
Left = 132
TabIndex = 0
Top = 48
Width = 3660
Begin VB.TextBox txtUserName
Height = 312
Left = 1188
TabIndex = 3
Top = 480
Width = 1788
End
Begin VB.TextBox txtPassword
Height = 300
IMEMode = 3 'DISABLE
Left = 1188
PasswordChar = "*"
TabIndex = 2
Top = 1092
Width = 1764
End
Begin VB.ComboBox cboLevel
Height = 276
ItemData = "frmUser.frx":0000
Left = 1188
List = "frmUser.frx":0002
Style = 2 'Dropdown List
TabIndex = 1
Top = 1752
Width = 1800
End
Begin VB.Label Label12
Caption = "用户名:"
Height = 408
Left = 252
TabIndex = 6
Top = 492
Width = 792
End
Begin VB.Label Label13
Caption = "密码:"
Height = 408
Left = 252
TabIndex = 5
Top = 1140
Width = 792
End
Begin VB.Label Label14
Caption = "用户级别:"
Height = 408
Left = 252
TabIndex = 4
Top = 1800
Width = 948
End
End
End
Attribute VB_Name = "frmUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private theUser As New ClassUser
Public isUpdate As Boolean
Private Sub cmdCancel_Click()
With theUser
If .isDirty Then
If MsgBox("你已经更改数据,是否做保存数据后再退出?", vbYesNo) = vbYes Then
If saveData() = False Then
Exit Sub
End If
End If
End If
End With
Me.Hide
End Sub
Private Sub cmdDelete_Click()
theUser.deleteData (theUser.uid)
isUpdate = True
Me.Hide
End Sub
Private Function saveData() As Boolean
Dim UserName As String
Dim Password As String
Dim Level As Integer
saveData = False
UserName = Trim(txtUserName.Text)
Password = txtPassword.Text
If Len(UserName) = 0 Then
MsgBox "请输入用户名!"
txtUserName.SetFocus
Exit Function
End If
If Len(Password) = 0 Then
MsgBox "请输入密码!"
txtPassword.SetFocus
Exit Function
End If
With theUser
.UserName = UserName
.Password = Password
Select Case cboLevel.ListIndex
Case 1
.Level = 1
Case 2
.Level = -1
Case Else
.Level = 0
End Select
If .uid = 0 Then
saveData = .addData
Else
saveData = .saveData
End If
If saveData = False Then MsgBox "保存不成功,请检查用户名是否唯一!"
End With
End Function
Private Sub cmdSave_Click()
If saveData() = True Then
isUpdate = True
Me.Hide
End If
End Sub
Private Sub Form_Load()
With cboLevel
.AddItem "普通用户"
.AddItem "数据操作员"
.AddItem "系统管理员"
.ListIndex = 0
End With
isUpdate = False
End Sub
Public Sub loadUser(uid As String)
'显示用户数据
With theUser
.loadDataByID uid
txtUserName.Text = .UserName
txtPassword.Text = .Password
Select Case .Level
Case 1 '数据操作员
cboLevel.ListIndex = 1
Case -1 '系统管理员
cboLevel.ListIndex = 2
Case Else '普通用户
cboLevel.ListIndex = 0
End Select
End With
End Sub
Public Sub setStatus()
If theUser.uid = 0 Then
cmdDelete.Enabled = False
Else
'控制输入
txtUserName.Locked = True '不允许修改用户名;
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -