📄 setper.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form SetPer
BorderStyle = 3 'Fixed Dialog
Caption = "管理员设置"
ClientHeight = 2775
ClientLeft = 45
ClientTop = 330
ClientWidth = 5370
Icon = "SetPer.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2775
ScaleWidth = 5370
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdExit
Caption = "关 闭"
Height = 375
Left = 3720
TabIndex = 10
Top = 2160
Width = 1215
End
Begin VB.CommandButton cmdSave
Caption = "保存/添加"
Enabled = 0 'False
Height = 375
Left = 2400
TabIndex = 9
Top = 2160
Width = 1215
End
Begin VB.Frame Frame3
Height = 135
Left = 2040
TabIndex = 8
Top = 1800
Width = 3135
End
Begin VB.TextBox txtOkPass
Height = 270
IMEMode = 3 'DISABLE
Left = 2760
PasswordChar = "*"
TabIndex = 7
Top = 1440
Width = 2175
End
Begin VB.TextBox txtPass
Height = 270
IMEMode = 3 'DISABLE
Left = 2760
PasswordChar = "*"
TabIndex = 6
Top = 960
Width = 2175
End
Begin VB.TextBox txtName
Height = 270
Left = 2760
TabIndex = 0
Top = 480
Width = 2175
End
Begin VB.Frame Frame1
Caption = "管理员列表"
Height = 2535
Left = 120
TabIndex = 1
Top = 120
Width = 1815
Begin MSComctlLib.ListView Lv
Height = 2175
Left = 120
TabIndex = 2
Top = 240
Width = 1575
_ExtentX = 2778
_ExtentY = 3836
View = 3
LabelWrap = -1 'True
HideSelection = -1 'True
FullRowSelect = -1 'True
GridLines = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 1
BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628}
Text = "管理员"
Object.Width = 2540
EndProperty
End
End
Begin VB.Label Label1
Caption = "双击左侧列表修改,右键弹出菜单!"
ForeColor = &H000000FF&
Height = 255
Left = 2160
TabIndex = 11
Top = 240
Width = 2895
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "重复"
Height = 180
Index = 2
Left = 2160
TabIndex = 5
Top = 1440
Width = 360
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "口令"
Height = 180
Index = 1
Left = 2160
TabIndex = 4
Top = 960
Width = 360
End
Begin VB.Label Label2
AutoSize = -1 'True
Caption = "姓名"
Height = 180
Index = 0
Left = 2160
TabIndex = 3
Top = 480
Width = 360
End
Begin VB.Menu MainMnu
Caption = "MainMnu"
Visible = 0 'False
Begin VB.Menu EditMnu
Caption = "修改(&E)"
End
Begin VB.Menu DeleteMnu
Caption = "删除(&D)"
End
Begin VB.Menu s2
Caption = "-"
End
Begin VB.Menu ExitMnu
Caption = "退出"
End
End
End
Attribute VB_Name = "SetPer"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' **********************************************************************
' 描 述:银龙图书管理系统
' 中国VB网收集整理 http://www.ChinaVB.net
' QQ交流群:13047826 14356878
' 发表源码或文章请发邮件到:info@chinavb.net
' **********************************************************************Dim i As Integer
Dim db As Database '定义数据库类型
Dim rst As Recordset '定义为记录型
Dim Rec As Integer '定义记录总数变量为数值型
Dim StrFlag As String '定义变化的字符为字符型
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub cmdSave_Click()
If StrFlag = "修改" Then
'对选择项目和数据库比较,以进行相应操作
rst.Seek "=", Lv.SelectedItem.Text
'判断姓名、密码、重复输入框有一个为空时给出提示
If txtName.Text = "" Or txtPass.Text = "" Or txtOkPass = "" Then
MsgBox "请将所有信息填写完整!", 0 + 16, "提示"
Exit Sub
End If
'判断密码和重复密码不同时给出提示,并设置光标位于重复密码输入框
If txtPass.Text <> txtOkPass.Text Then
MsgBox "密码不相同!", 0 + 16, "密码"
txtOkPass.SetFocus
Exit Sub
End If
'编辑更新数据库
rst.Edit
rst.Fields("名称") = txtName.Text
rst.Fields("密码") = Trim(txtPass.Text)
rst.Update
'调用Disp过程,显示更新内容,给出提示
Disp
StrFlag = ""
MsgBox "修改成功!", 0 + 48, "提示"
Else
'以下是增加管理员过程
'判断姓名、密码、重复输入框有一个为空时给出提示
If txtName.Text = "" Or txtPass.Text = "" Or txtOkPass = "" Then
MsgBox "请将所有信息填写完整!", 0 + 16, "提示"
Exit Sub
End If
'判断密码和重复密码不同时给出提示,并设置光标位于重复密码输入框
If txtPass.Text <> txtOkPass.Text Then
MsgBox "密码不相同!", 0 + 16, "密码"
txtOkPass.SetFocus
Exit Sub
End If
'增加新记录并保存到数据库
rst.AddNew
rst.Fields("名称") = txtName.Text
rst.Fields("密码") = Trim(txtPass.Text)
rst.Update
'调用Disp过程,显示更新内容,给出提示
Disp
StrFlag = ""
MsgBox "添加成功!", 0 + 48, "提示"
End If
'添加成功后,将姓名、密码、重复输入框置空
txtName.Text = ""
txtPass.Text = ""
txtOkPass.Text = ""
End Sub
Private Sub DeleteMnu_Click()
'菜单--删除
'定义Str字符变量,作为提示信息用
Dim Str As String
'判断是否选择了超级用户,给出不可删除提示
If Lv.SelectedItem.Text = "超级用户" Then
MsgBox "超级用户不能删除!", 0 + 16, "错误"
Exit Sub
End If
'对所选项目和数据库比较,给出确认删除提示
rst.Seek "=", Lv.SelectedItem.Text
Str = "确实要删除 " & Lv.SelectedItem.Text & "吗?"
'如果点击确定按钮,删除所选用户,并显示更新后记录
If MsgBox(Str, 4 + 32, "删除") = vbYes Then
rst.Delete
Disp
End If
End Sub
Private Sub EditMnu_Click()
'菜单--编辑
'调用Lv_DblClick过程,进行修改操作
Lv_DblClick
End Sub
Private Sub Form_Load()
'设置数据库路径
DBpath = App.Path + "\DataBase\Data.mdb"
'连接数据库,打开表用户
Set db = Workspaces(0).OpenDatabase(DBpath, False)
Set rst = db.OpenRecordset("用户", dbOpenTable)
'对名称索引
rst.Index = "名称"
'调用Disp,显示用户列表
Disp
End Sub
'自定义过程,过程名为:Disp
Private Sub Disp()
'清除用户名列表
Lv.ListItems.Clear
rst.MoveLast
'将记录总数给变量:Rec
Rec = rst.RecordCount
rst.MoveFirst
'显示数据库所有名称字段内容
For i = 1 To Rec
Lv.ListItems.Add i, , rst.Fields("名称")
rst.MoveNext
'如果到记录末尾,退出本过程
If rst.EOF Then Exit Sub
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
'关闭窗体时,关闭数据库
rst.Close
db.Close
End Sub
Private Sub Lv_DblClick()
'在ListView用户列表的双击事件
'判断如果选择了超级用户,给出提示
If Lv.SelectedItem.Text = "超级用户" Then
MsgBox "超级用户不能修改!", 0 + 16, "错误"
Exit Sub
End If
'非超级用户,进行相应更改
StrFlag = "修改"
txtName.Text = Lv.SelectedItem.Text
End Sub
Private Sub Lv_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
'在ListView点击鼠标右键,弹出菜单MainMnu
If Button = 2 Then
PopupMenu MainMnu
End If
End Sub
Private Sub txtName_Change()
'如果用户名不为空时,设置保存按钮可用,否则,保存按钮不可用
If txtName.Text <> "" Then
cmdSave.Enabled = True
Else
cmdSave.Enabled = False
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -