📄 adduser.frm
字号:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.Form usermanager
Caption = "用户管理"
ClientHeight = 3780
ClientLeft = 60
ClientTop = 345
ClientWidth = 8205
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3780
ScaleWidth = 8205
StartUpPosition = 3 '窗口缺省
Begin VB.PictureBox Picture1
Height = 3735
Left = 0
ScaleHeight = 3675
ScaleWidth = 8115
TabIndex = 0
Top = 0
Width = 8175
Begin VB.Frame Frame1
Height = 3015
Left = 6600
TabIndex = 2
Top = 240
Width = 1335
Begin VB.CommandButton Command4
Caption = "返回"
Height = 375
Left = 240
TabIndex = 6
Top = 2280
Width = 855
End
Begin VB.CommandButton Command3
Caption = "修改"
Height = 375
Left = 240
TabIndex = 5
Top = 1680
Width = 855
End
Begin VB.CommandButton Command2
Caption = "删除"
Height = 375
Left = 240
TabIndex = 4
Top = 1080
Width = 855
End
Begin VB.CommandButton Command1
Caption = "增加"
Height = 375
Left = 240
TabIndex = 3
Top = 360
Width = 855
End
End
Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1
Height = 3015
Left = 240
TabIndex = 1
Top = 240
Width = 6135
_ExtentX = 10821
_ExtentY = 5318
_Version = 393216
Cols = 4
BackColorBkg = 16777215
End
End
End
Attribute VB_Name = "usermanager"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim m_row As Integer
Private Sub Command1_Click()
Unload Me
useradd.Show vbModal
End Sub
Private Sub Command2_Click()
Call DelUser
End Sub
Private Sub Command3_Click()
If ChgUser = True Then
Unload Me
userchg.Show vbModal
End If
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Form_Load()
'窗口居中
Me.Left = (Screen.Width - Me.Width) / 2
Me.Top = (Screen.Height - Me.Height) / 2 - 550
'初始化表格窗体
MSFlexGrid1.ColWidth(0) = 500
MSFlexGrid1.ColWidth(1) = 1000
MSFlexGrid1.ColWidth(2) = 1000
MSFlexGrid1.ColWidth(3) = 1000
'初始化表格名称
MSFlexGrid1.TextMatrix(0, 1) = "用户名"
MSFlexGrid1.TextMatrix(0, 2) = "用户身份"
MSFlexGrid1.TextMatrix(0, 3) = "密码"
m_row = 0
Call LoadUser
End Sub
'加载用户信息
Private Sub LoadUser()
Dim n As Integer
For n = MSFlexGrid1.Rows - 1 To 2 Step -1
MSFlexGrid1.RemoveItem (n)
Next
Dim str As String
str = "select * from userinfo,quan where userinfo.quanxian=quan.quanxian"
Dim myrs As ADODB.Recordset
Set myrs = New ADODB.Recordset
myrs.CursorLocation = adUseClient
myrs.LockType = adLockOptimistic
myrs.CursorType = adOpenDynamic
myrs.Open str, myCon
myrs.MoveFirst
Dim m_sum As Integer '读取共多少条记录
m_sum = myrs.RecordCount
MSFlexGrid1.Rows = MSFlexGrid1.Rows + m_sum - 1
Dim m As Integer
For m = 1 To m_sum
MSFlexGrid1.TextMatrix(m, 1) = myrs("uid")
MSFlexGrid1.TextMatrix(m, 2) = myrs("value")
MSFlexGrid1.TextMatrix(m, 3) = myrs("pass")
myrs.MoveNext
Next
End Sub
Private Sub DelUser()
With MSFlexGrid1
If m_row = 0 Then
MsgBox "请选择要删除的用户!", vbExclamation
Exit Sub
ElseIf .TextMatrix(m_row, 2) = "管理员" Then
MsgBox "不可删除管理员!", vbExclamation
Exit Sub
Else
Dim str As String
Dim m_id As String
m_id = .TextMatrix(.MouseRow, 1)
str = "delete from userinfo where uid='" & m_id & "'"
If MsgBox("确认删除Y/N?", vbYesNo) = vbYes Then
myCon.Execute (str)
MsgBox "删除用户成功!", vbExclamation
Call LoadUser
End If
End If
End With
End Sub
Private Sub MSFlexGrid1_Click()
m_row = MSFlexGrid1.MouseRow
End Sub
Private Function ChgUser() As Boolean
With MSFlexGrid1
If m_row = 0 Then
MsgBox "请选择要修改的用户!", vbExclamation
ChgUser = False
Exit Function
ElseIf .TextMatrix(m_row, 2) = "管理员" And .TextMatrix(m_row, 1) = "admin" Then
MsgBox "不可修改Admin!", vbExclamation
ChgUser = False
Exit Function
Else
userchg.txt_name = .TextMatrix(m_row, 1)
userchg.comb_shen.Text = .TextMatrix(m_row, 2)
userchg.txt_pwd1.Text = .TextMatrix(m_row, 3)
userchg.txt_pwd2.Text = .TextMatrix(m_row, 3)
ChgUser = True
End If
End With
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -