图5-4 用户管理界面
5.4.2用户管理界面代码设计
用户管理界面实现的代码设计如下(这里以添加用户为例):
Dim MyAddUser As OpenRs ’调用类函数
Dim Choose As Boolean
Dim Level As Integer
Private Sub Cmdcancel_Click() ’设置取消键
Unload Me
End Sub
Private Sub cmdComp_Click()
If Choose = False Then
MsgBox "请选择一个操作级别!", vbOKOnly + vbInformation, "添加新用户"
Exit Sub
End If
MyAddUser.rs1.AddNew ’增加一条连接到表的记录集
MyAddUser.rs1!user_id = Trim(txtUserid.Text) ’把输入框数据存入记录集
MyAddUser.rs1!user_name = Trim(txtUsername .Text)
MyAddUser.rs1!user_des = Trim(txtUserdes.Text)
MyAddUser.rs1!user_pwd = Trim(txtPwd1.Text)
MyAddUser.rs1!user_level = Level
MyAddUser.rs1.Update ’更新存入表
If MsgBox("添加用户成功!" & vbCrLf & vbCrLf & "是否继续添加用户?", vbYesNo + vbQuestion, "添加用户") = vbYes Then
Frame3.Visible = False
cmdComp.Visible = False
Frame1.Visible = True
cmdNext.Visible = True
txtUserid.SetFocus
Call ClearText
Else
Unload Me
End If
End Sub
Private Sub cmdNext_Click() ’设置下一步按钮
Choose = False
Dim txtUseridSQL As String
If Trim(txtUserid.Text) = "" Then ’用户id为空重新输入
MsgBox "用户编号不能为空!", vbOKOnly + vbInformation, "提示"
txtUserid.SetFocus
Exit Sub
Else
txtUseridSQL = "select * from User_Info" ’从数据库读出用户id验证
MyAddUser.rsDK1 txtUseridSQL
While (MyAddUser.rs1.EOF = False)
If Trim(MyAddUser.rs1!user_id) = Trim(txtUserid.Text) Then
MsgBox "用户编号已存在,请重新输入用户编号!", vbOKOnly + vbExclamation, "警告"
txtUserid.Text = ""
txtUsername.Text = ""
txtUserdes.Text = ""
txtUserid.SetFocus
Exit Sub
Else
MyAddUser.rs1.MoveNext
End If
Wend
End If
If txtUsername.Text = "" Then ’用户名为空提示
MsgBox "用户名不能为空!", vbOKOnly + vbInformation, "提示"
txtUsername.SetFocus
Exit Sub
End If
Frame1.Visible = False
Frame2.Visible = True
txtPwd1.SetFocus
cmdNext.Visible = False
cmdNext1.Visible = True
End Sub
Private Sub cmdNext1_Click() ’密码为空提示
Dim i As Integer
If txtPwd1.Text = "" Then
MsgBox "请输入密码!", vbOKOnly + vbInformation, "提示"
txtPwd1.SetFocus
Exit Sub
End If
If txtPwd2.Text = "" Then
MsgBox "请输入确认密码!", vbOKOnly + vbInformation, "提示"
txtPwd2.SetFocus
Exit Sub
End If
If txtPwd1.Text <> txtPwd2.Text Then ’密码不一致提示
MsgBox "两次输入的密码不一致!!!" & vbCrLf & vbCrLf & "请重新输入!", vbOKOnly + vbInformation, "提示"
txtPwd1.Text = ""
txtPwd2.Text = ""
txtPwd1.SetFocus
Exit Sub
End If
Frame2.Visible = False
Frame3.Visible = True
cmdNext1.Visible = False
cmdComp.Visible = True
For i = 0 To 2 '取消选项按钮选择
Option1(i).Value = False
Next i
List1.ListIndex = -1
End Sub
Private Sub Choose_level() ’各用户等级权限设置
Dim i As Integer
If Option1(0).Value = True Then
Level = 1
For i = 0 To 9 '全选
List1.Selected(i) = True
Next i
List1.ListIndex = -1
ElseIf Option1(1).Value = True Then
Level = 2
For i = 0 To 6
List1.Selected(i) = True
Next i
List1.Selected(7) = False
List1.Selected(8) = False
List1.Selected(9) = False
List1.ListIndex = -1
ElseIf Option1(2).Value = True Then
Level = 3
List1.Selected(0) = True
List1.Selected(1) = True
For i = 2 To 9
List1.Selected(i) = False
Next i
List1.ListIndex = -1
End If
End Sub
Private Sub Form_Load()
Set MyAddUser = New OpenRs
End Sub
Private Sub Option1_Click(Index As Integer)
Choose = True
Call Choose_level
End Sub
Private Sub ClearText()
Dim i As Integer
txtUserid.Text = ""
txtUsername.Text = ""
txtUserdes.Text = ""
txtPwd1.Text = ""
txtPwd2.Text = ""
For i = 0 To 2 '取消选项按钮选择
Option1(i).Value = False
Next i
Choose = False
For i = 0 To 9
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>