📄 frmsysusermanage.frm
字号:
VERSION 5.00
Begin VB.Form sysusermanage
BorderStyle = 1 'Fixed Single
Caption = "管理员登陆信息管理"
ClientHeight = 2730
ClientLeft = 45
ClientTop = 435
ClientWidth = 4680
FontTransparent = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
Palette = "frmsysusermanage.frx":0000
ScaleHeight = 2730
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdmove
Height = 255
Index = 3
Left = 3600
Picture = "frmsysusermanage.frx":04C8
Style = 1 'Graphical
TabIndex = 12
Top = 1920
Width = 255
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 2
Left = 3360
Picture = "frmsysusermanage.frx":094A
Style = 1 'Graphical
TabIndex = 11
Top = 1920
Width = 255
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 1
Left = 1080
Picture = "frmsysusermanage.frx":0E10
Style = 1 'Graphical
TabIndex = 10
Top = 1920
Width = 255
End
Begin VB.CommandButton cmdmove
Height = 255
Index = 0
Left = 840
Picture = "frmsysusermanage.frx":12D6
Style = 1 'Graphical
TabIndex = 9
Top = 1920
Width = 255
End
Begin VB.PictureBox Picnavigation
BackColor = &H80000009&
Height = 255
Left = 1320
ScaleHeight = 195
ScaleWidth = 1995
TabIndex = 8
Top = 1920
Width = 2055
Begin VB.TextBox txtnews
Height = 270
Left = 0
TabIndex = 13
Text = "Text1"
Top = 0
Width = 2055
End
End
Begin VB.CommandButton cmdexit
Caption = "退出"
Height = 375
Left = 3240
TabIndex = 7
Top = 1440
Width = 855
End
Begin VB.CommandButton cmdsave
Caption = "保存"
Height = 375
Left = 2400
TabIndex = 6
Top = 1440
Width = 855
End
Begin VB.CommandButton cmddelete
Caption = "删除"
Height = 375
Left = 1560
TabIndex = 5
Top = 1440
Width = 855
End
Begin VB.CommandButton cmdadd
Caption = "添加"
Height = 375
Left = 720
TabIndex = 4
Top = 1440
Width = 855
End
Begin VB.TextBox txtpwd
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 3
Text = "Text2"
Top = 840
Width = 2295
End
Begin VB.TextBox txtname
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 2
Text = "Text1"
Top = 360
Width = 2295
End
Begin VB.Label Label2
Caption = "口 令"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 1
Top = 960
Width = 735
End
Begin VB.Label Label1
Caption = "用户名"
BeginProperty Font
Name = "宋体"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 0
Top = 360
Width = 735
End
End
Attribute VB_Name = "sysusermanage"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim isadding As Boolean
Dim objadmin As Recordset
Dim objCn As Connection
Private Sub cmdadd_Click()
txtnews = "添加新记录"
txtname = ""
txtpwd = ""
isadding = True
txtname.SetFocus
End Sub
Private Sub cmddelete_Click()
'根据是否处于添加状态,执行不同的操作
If isadding Then
isadding = False
If objadmin.RecordCount <= 0 Then
txtnews = "记录:无" '显示无记录提示
Else
'显示当前录数据
txtname = objadmin.Fields("用户名")
txtpwd = objadmin.Fields("口令")
'显示当前记录编号和记录总数
txtnews = "记录" & objadmin.AbsolutePosition & "/" & objadmin.RecordCount
End If
Else
If objadmin.RecordCount > 0 Then
If MsgBox("是否删除记录?", vbYesNo + vbQuestion, "系统用户管理") = vbYes Then
'执行删除当前记录操作
objadmin.Delete
'显示下一条记录
cmdmove(2).Value = True
Else
'显示当前记录数据
txtname = objadmin.Fields("用户名")
txtpwd = objadmin.Fields("口令")
'显示当前记录和记录总数
txtnews = "记录" & objadmin.AbsolutePosition & "/" & objadmin.RecordCount
End If
End If
End If
End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub
Private Sub cmdmove_Click(Index As Integer)
With objadmin
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 .RecordCount < 1 Then
txtnews = "记录:无" '显示记录提示信息
txtname = ""
txtpwd = ""
Else
'显示当前记录数据
txtname = .Fields("用户名")
txtpwd = .Fields("口令")
'显示当前记录数和记录总数
txtnews = "记录" & .AbsolutePosition & "/" & .RecordCount
End If
End With
If isadding Then isadding = False
End Sub
Private Sub cmdsave_Click()
Dim objcopy As New Recordset
If Trim(txtname) = "" Then
MsgBox "用户名不能为空!", vbCritical, "系统用户管理"
txtname.SetFocus
txtname = ""
ElseIf Trim(txtpwd) = "" Then
MsgBox "系统登陆口令不能为空!", vbCritical, "系统用户管理"
txtpwd.SetFocus
txtpwd = ""
Else
Set objcopy = objadmin.Clone
With objcopy
If .RecordCount > 0 Then
'检验用户是否备用
.MoveFirst
.Find "用户名='" & Trim(txtname) & "'"
If (isadding And Not .EOF) Or (Not isadding And Not .EOF And .AbsolutePosition <> objadmin.AbsolutePosition) Then
MsgBox "用户名:" & Trim(txtname) & "已被使用,请使用其他用户名!", vbCritical, "系统用户管理"
txtname.SetFocus
txtname.SelStart = 0
txtname.SelLength = Len(txtname)
Exit Sub
Else
'保存记录
If isadding Then objadmin.AddNew
objadmin.Fields("用户名") = Trim(txtname)
objadmin.Fields("口令") = Trim(txtpwd)
objadmin.Update
MsgBox "数据保存成功!", vbInformation, "系统用户管理"
isadding = False
'显示记录编号和记录总数
txtnews = "记录:" & objadmin.AbsolutePosition & "/" & objadmin.RecordCount
End If
Else
'添加新记录
If isadding Then
objadmin.AddNew
objadmin.Fields("用户名") = Trim(txtname)
objadmin.Fields("口令") = Trim(txtpwd)
objadmin.Update
MsgBox "数据保存成功!", vbInformation, "系统用户管理"
txtnews = "记录:" & objadmin.AbsolutePosition & "/" & objadmin.RecordCount
End If
End If
End With
End If
End Sub
Private Sub Form_Load()
'建立数据库连接
Set objCn = New Connection '定义并实例化连接对象
With objCn '建立连接
.Provider = "SQLOLEDB"
.ConnectionString = "user id=sa;pwd=;data source=(local);" & _
"initial catalog=自测考试"
.Open
End With
'获取系统用户记录
Set objadmin = New Recordset
With objadmin
Set .ActiveConnection = objCn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open "select * from 管理员"
End With
cmdmove(0) = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
objCn.Close
Set objCn = Nothing
Set objadmin = Nothing
End Sub
'Private Sub txtname_KeyPress(KeyAscii As Integer)
'如果敲击回车键则是命令输入框获得焦点
'If KeyAscii = vbKeyReturn Then txtpwd.SetFocus
'If Not (Chr(KeyAscii) Like "[0-9]" Or Chr(KeyAscii) Like "[a-z]" Or Chr(KeyAscii) Like "[A-Z]" Or KeyAscii = vbKeyBack) Then
'KeyAscii = 0
'End If
'End Sub
Private Sub txtpwd_KeyPress(KeyAscii As Integer)
'如果敲击回车键则是命令输入框获得焦点
If KeyAscii = vbKeyReturn Then cmdsave.SetFocus
If Not (Chr(KeyAscii) Like "[0-9]" Or Chr(KeyAscii) Like "[a-z]" Or Chr(KeyAscii) Like "[A-Z]" Or KeyAscii = vbKeyBack) Then
KeyAscii = 0
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -