📄 frmuser.frm
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Begin VB.Form frmUser
ClientHeight = 3384
ClientLeft = 48
ClientTop = 48
ClientWidth = 3804
ControlBox = 0 'False
BeginProperty Font
Name = "宋体"
Size = 10.8
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
LockControls = -1 'True
ScaleHeight = 3384
ScaleWidth = 3804
StartUpPosition = 3 '窗口缺省
Begin VB.Frame Frame1
Caption = "用户管理"
BeginProperty Font
Name = "宋体"
Size = 9
Charset = 134
Weight = 700
Underline = 0 'False
Italic = -1 'True
Strikethrough = 0 'False
EndProperty
Height = 3192
Left = 132
TabIndex = 0
Top = 72
Width = 3600
Begin VB.CommandButton Command5
Caption = "保存"
Height = 408
Left = 2376
TabIndex = 6
Top = 2076
Width = 900
End
Begin VB.CommandButton Command4
Caption = "关闭"
Height = 408
Left = 2376
TabIndex = 5
Top = 2604
Width = 900
End
Begin VB.CommandButton Command3
Caption = "删除"
Height = 408
Left = 2376
TabIndex = 4
Top = 1560
Width = 900
End
Begin VB.CommandButton Command2
Caption = "修改"
Height = 408
Left = 2376
TabIndex = 3
Top = 1032
Width = 900
End
Begin VB.CommandButton Command1
Caption = "添加"
Height = 408
Left = 2376
TabIndex = 2
Top = 504
Width = 900
End
Begin MSComctlLib.ListView List1
Height = 2796
Left = 216
TabIndex = 1
Top = 264
Width = 2100
_ExtentX = 3704
_ExtentY = 4932
View = 3
LabelEdit = 1
LabelWrap = -1 'True
HideSelection = 0 'False
FullRowSelect = -1 'True
GridLines = -1 'True
_Version = 393217
ForeColor = -2147483640
BackColor = -2147483643
BorderStyle = 1
Appearance = 1
NumItems = 0
End
End
End
Attribute VB_Name = "frmUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Sub Command1_Click()
Dim user As String, pwd As String
frmAddUser.user = ""
frmAddUser.pwd = ""
frmAddUser.Show vbModal
user = frmAddUser.user
pwd = frmAddUser.pwd
Dim tmp_item As ListItem
For Each tmp_item In List1.ListItems
If tmp_item.Text = user Then
MsgMsg "相同的用户名已经存在!"
Exit Sub
End If
Next
Set tmp_item = List1.ListItems.Add(, , user)
tmp_item.SubItems(1) = pwd
End Sub
Private Sub Command2_Click()
If List1.ListItems.Count <= 0 Then Exit Sub
frmAddUser.user = List1.SelectedItem.Text
frmAddUser.pwd = ""
frmAddUser.Show vbModal
List1.SelectedItem.Text = frmAddUser.user
List1.SelectedItem.SubItems(1) = frmAddUser.pwd
End Sub
Private Sub Command3_Click()
If List1.ListItems.Count <= 0 Then Exit Sub
If Not MsgboxYesOrNo("是否真的要出除?") Then Exit Sub
List1.ListItems.Remove List1.SelectedItem.Index
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Command5_Click()
Dim sSQL As String
Dim Rs As New ADODB.Recordset
Dim tmp_item As ListItem
sSQL = "delete from users"
dbcon.Execute sSQL
sSQL = "select * from users"
Rs.open sSQL, dbcon, adOpenKeyset, adLockOptimistic, adCmdText
For Each tmp_item In List1.ListItems
Rs.AddNew
Rs("name") = tmp_item.Text
Rs("pwd") = tmp_item.SubItems(1)
Rs.Update
Next
Rs.Close
MsgMsg "保存完毕!"
End Sub
Private Sub Form_Load()
List1.ColumnHeaders.Add , , "用户名", List1.Width
List1.ColumnHeaders.Add , , "", 0
Dim sSQL As String
Dim Rs As New ADODB.Recordset
Dim tmp_item As ListItem
sSQL = "select * from users"
Rs.open sSQL, dbcon, adOpenKeyset, adLockOptimistic, adCmdText
Do While Not Rs.EOF
Set tmp_item = List1.ListItems.Add(, , Rs("name"))
tmp_item.SubItems(1) = Rs("pwd")
Rs.MoveNext
Loop
Rs.Close
End Sub
Private Sub Form_Resize()
SetWindowPos Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -