📄 frmaddnewuser.frm
字号:
VERSION 5.00
Begin VB.Form frmAddNewUser
BorderStyle = 1 'Fixed Single
Caption = "添加用户"
ClientHeight = 4035
ClientLeft = 45
ClientTop = 330
ClientWidth = 4665
LinkTopic = "Form2"
MaxButton = 0 'False
MDIChild = -1 'True
MinButton = 0 'False
ScaleHeight = 4035
ScaleWidth = 4665
Begin VB.TextBox txtNewUser
Appearance = 0 'Flat
BackColor = &H80000018&
ForeColor = &H00000000&
Height = 270
Index = 0
Left = 1800
TabIndex = 13
TabStop = 0 'False
Top = 240
Width = 2055
End
Begin VB.TextBox txtNewUser
Appearance = 0 'Flat
BackColor = &H80000018&
ForeColor = &H00000000&
Height = 270
IMEMode = 3 'DISABLE
Index = 1
Left = 1800
PasswordChar = "*"
TabIndex = 12
TabStop = 0 'False
Top = 600
Width = 2055
End
Begin VB.Frame Frame2
Caption = "权限"
ForeColor = &H00000000&
Height = 1935
Left = 1920
TabIndex = 7
Top = 1440
Width = 2535
Begin VB.CheckBox chkWeight
Caption = "系统管理"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 255
Index = 0
Left = 240
TabIndex = 11
Top = 360
Width = 2055
End
Begin VB.CheckBox chkWeight
Caption = "班级与学生档案管理"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 255
Index = 1
Left = 240
TabIndex = 10
Top = 720
Width = 2055
End
Begin VB.CheckBox chkWeight
Caption = "学生交费管理"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 255
Index = 2
Left = 240
TabIndex = 9
Top = 1080
Width = 2055
End
Begin VB.CheckBox chkWeight
Caption = "课程与成绩管理"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 255
Index = 3
Left = 240
TabIndex = 8
Top = 1440
Width = 2055
End
End
Begin VB.CommandButton cmdOK
Caption = "确定"
Height = 375
Left = 1200
TabIndex = 6
Top = 3480
Width = 1095
End
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 375
Left = 2520
TabIndex = 5
Top = 3480
Width = 1095
End
Begin VB.Frame Frame3
Caption = "用户类别"
ForeColor = &H00000000&
Height = 1935
Left = 240
TabIndex = 1
Top = 1440
Width = 1575
Begin VB.OptionButton optUserClass
Caption = "高级用户"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 495
Index = 0
Left = 240
TabIndex = 4
Top = 360
Width = 1095
End
Begin VB.OptionButton optUserClass
Caption = "只读用户"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 495
Index = 1
Left = 240
TabIndex = 3
Top = 840
Width = 1095
End
Begin VB.OptionButton optUserClass
Caption = "普通用户"
BeginProperty Font
Name = "新宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 495
Index = 2
Left = 240
TabIndex = 2
Top = 1320
Width = 1095
End
End
Begin VB.TextBox txtNewUser
Appearance = 0 'Flat
BackColor = &H80000018&
ForeColor = &H00000000&
Height = 270
IMEMode = 3 'DISABLE
Index = 2
Left = 1800
PasswordChar = "*"
TabIndex = 0
TabStop = 0 'False
Top = 960
Width = 2055
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "用户名:"
ForeColor = &H00000000&
Height = 180
Left = 900
TabIndex = 16
Top = 285
Width = 720
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "密码:"
ForeColor = &H00000000&
Height = 180
Left = 1080
TabIndex = 15
Top = 645
Width = 540
End
Begin VB.Label Label3
AutoSize = -1 'True
Caption = "确认密码:"
ForeColor = &H00000000&
Height = 180
Left = 720
TabIndex = 14
Top = 1005
Width = 900
End
End
Attribute VB_Name = "frmAddNewUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'----------------------------------frmAddNewUser.frm----------------------------------
Option Explicit
Private Sub cmdOK_Click()
Dim blnWeight As Boolean
Dim i As Integer
Dim j As Integer
'声明ADODB.Recordset对象变量
Dim objRecordset As ADODB.Recordset
'用户添加输入设置合法性判断
If Trim(txtNewUser(0).Text) = "" Then
MsgBox "用户名不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(0).SetFocus
Exit Sub
End If
If Trim(txtNewUser(1).Text) = "" Then
MsgBox "密码不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(1).SetFocus
Exit Sub
End If
If Trim(txtNewUser(2).Text) = "" Then
MsgBox "确认密码不能为空!", vbExclamation + vbOKOnly, "警告"
txtNewUser(2).SetFocus
Exit Sub
End If
If Trim(txtNewUser(1).Text) <> Trim(txtNewUser(2).Text) Then
MsgBox "确认密码不正确!", vbExclamation + vbOKOnly, "警告"
txtNewUser(2).SetFocus
Exit Sub
End If
'判断,普通用户必须至少设置一个权限
blnWeight = False
If optUserClass(2).Value = True Then
For i = 0 To 3
If chkWeight(i).Value = 1 Then
blnWeight = True
Exit For
End If
Next
If blnWeight = False Then
MsgBox " 普通用户至少要有一项权限!", vbExclamation + vbOKOnly, "警告"
Exit Sub
End If
End If
'查询用户是否存在
strSQL = "select * from Users where UserName='" & Trim(txtNewUser(0).Text) & "'"
Set objRecordset = ExecuteSQL(strSQL)
'如果用户存在
If objRecordset.EOF = False Then
MsgBox " 已存在该用户!", vbExclamation + vbOKOnly, "警告"
txtNewUser(0).SetFocus
txtNewUser(0).SelStart = 0
txtNewUser(0).SelLength = Len(txtNewUser(0).Text)
Exit Sub
End If
'如果用户不存在,添加新用户
strSQL = "select * from Users"
Set objRecordset = ExecuteSQL(strSQL)
objRecordset.AddNew
objRecordset.Fields(0) = Trim(txtNewUser(0).Text)
objRecordset.Fields(1) = Trim(txtNewUser(1).Text)
'设置新用户权限
For i = 0 To 2
If optUserClass(i).Value = True Then
Select Case i
'高级拥护
Case 0
objRecordset.Fields("Administration") = "Y"
'只读用户
Case 1
objRecordset.Fields("ReadOnly") = "Y"
'普通用户
Case 2
'普通用户权限
For j = 0 To 3
If chkWeight(j).Value = 1 Then
Select Case j
Case 0
objRecordset.Fields("Weight1") = "Y"
Case 1
objRecordset.Fields("Weight2") = "Y"
Case 2
objRecordset.Fields("Weight3") = "Y"
Case 3
objRecordset.Fields("Weight4") = "Y"
End Select
End If
Next j
End Select
End If
Next
'更新用户数据库
objRecordset.Update
'添加
MsgBox " 用户添加成功!", vbExclamation + vbOKOnly, "提示"
txtNewUser(0).Text = ""
txtNewUser(1).Text = ""
txtNewUser(2).Text = ""
End Sub
'取消
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub Form_Load()
'默认添加只读用户
optUserClass(2).Value = True
End Sub
'用户类型选择
Private Sub optUserClass_Click(Index As Integer)
Dim i As Integer
'权限设置
If Index <> 2 Then
For i = 0 To 3
chkWeight(i).Enabled = False
Next i
Else
For i = 0 To 3
chkWeight(i).Enabled = True
Next
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -