form4.frm
字号:
VERSION 5.00
Object = "{9D587096-1A23-49BD-906D-AD6A319C22E6}#1.0#0"; "FlexCell.ocx"
Object = "{CFA7AFF4-3242-4269-9172-7389D695AE01}#1.0#0"; "StoneXP.ocx"
Begin VB.Form Form4
BorderStyle = 0 'None
Caption = "管理员数据"
ClientHeight = 5025
ClientLeft = 0
ClientTop = 0
ClientWidth = 5760
LinkTopic = "Form4"
ScaleHeight = 5025
ScaleWidth = 5760
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin StoneXP.XPButton XPButton1
Height = 375
Left = 480
TabIndex = 1
Top = 4560
Width = 975
_ExtentX = 1720
_ExtentY = 661
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "增 加"
MouseIcon = "Form4.frx":0000
MousePointer = 99
End
Begin FlexCell.Grid Grid1
Height = 4455
Left = 0
TabIndex = 0
Top = 0
Width = 5775
_ExtentX = 10186
_ExtentY = 7858
Appearance = 0
Rows = 16
End
Begin StoneXP.XPButton XPButton2
Height = 375
Left = 1440
TabIndex = 2
Top = 4560
Width = 975
_ExtentX = 1720
_ExtentY = 661
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "保 存"
MouseIcon = "Form4.frx":031A
MousePointer = 99
End
Begin StoneXP.XPButton XPButton3
Height = 375
Left = 2400
TabIndex = 3
Top = 4560
Width = 975
_ExtentX = 1720
_ExtentY = 661
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "修 改"
MouseIcon = "Form4.frx":0634
MousePointer = 99
End
Begin StoneXP.XPButton XPButton4
Height = 375
Left = 3360
TabIndex = 4
Top = 4560
Width = 975
_ExtentX = 1720
_ExtentY = 661
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "删 除"
MouseIcon = "Form4.frx":094E
MousePointer = 99
End
Begin StoneXP.XPButton XPButton5
Height = 375
Left = 4320
TabIndex = 5
Top = 4560
Width = 975
_ExtentX = 1720
_ExtentY = 661
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Name = "宋体"
Size = 9
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Caption = "退 出"
MouseIcon = "Form4.frx":0C68
MousePointer = 99
End
End
Attribute VB_Name = "Form4"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetKeyState Lib "user32" _
(ByVal nVirtKey As Long) As Integer
Private Sub Form_Load()
Grid1.AllowUserResizing = True
Grid1.DisplayFocusRect = False
Grid1.ExtendLastCol = True
Grid1.Appearance = Flat
Grid1.FixedRowColStyle = Flat
Grid1.ScrollBarStyle = Flat
Grid1.DefaultFont.Name = "Tahoma"
Grid1.DefaultFont.SIZE = 8
Grid1.BackColorFixed = RGB(90, 158, 214)
Grid1.BackColorFixedSel = RGB(110, 180, 230)
Grid1.BackColorBkg = RGB(90, 158, 214)
Grid1.BackColorScrollBar = RGB(231, 235, 247)
Grid1.BackColor1 = RGB(231, 235, 247)
Grid1.BackColor2 = RGB(239, 243, 255)
Grid1.GridColor = RGB(148, 190, 231)
Grid1.Column(0).Width = 0
Grid1.Column(1).Width = 100
Grid1.Column(2).Width = 100
Grid1.Column(3).Width = 100
Grid1.Column(3).CellType = cellComboBox
Grid1.ComboBox(3).Clear
Grid1.ComboBox(3).AddItem "超级管理员"
Grid1.ComboBox(3).AddItem "一般管理员"
Call callmain
End Sub
Private Sub callmain()
gridsave = False
gridedit = True
griddelete = True
If qy1.State = adStateOpen Then '表状态
qy1.Close
End If
qy1.Open "select * from 登录", cnn, adOpenKeyset, adLockReadOnly, adCmdText
Grid1.Rows = 1 '清除所有记录
Grid1.Rows = qy1.RecordCount + 1
i = 3
Grid1.Cols = i + 1 '必须+2,因为实际上为11行,但第一行是隐藏的
For i = 0 To 2 '显示数据的字段名
Grid1.Cell(0, i + 1).Text = qy1.Fields(i).Name '读取表中的各字段名
Next
For i = 1 To Grid1.Rows - 1 '设定读取行
For j = 1 To Grid1.Cols - 1 '设定读取列
If qy1.Fields(j - 1) = Null Then '空值的处理
Grid1.Cell(i, j).Text = ""
Else
Grid1.Cell(i, j).Text = qy1.Fields(j - 1)
End If
Next
qy1.MoveNext '读取下一记录
Next
Grid1.Column(1).Locked = True
End Sub
Private Sub Grid1_CellChange(ByVal Row As Long, ByVal Col As Long)
If griddel = True Then
If qy1.State = adStateOpen Then
qy1.Close
End If
qy1.Open "select * from 登录 where 用户名='" & Grid1.Cell(hang, 1).Text & "'", cnn, adOpenKeyset, adLockOptimistic, adCmdText
If qy1.EOF = True Then
MsgBox "当前记录己经不存在!", vbInformation, "记录不存在"
Else
qy1.Delete
qy1.Update
End If
MsgBox "目标己删除,请刷新数据!", vbInformation, "删除成功"
Call callmain
griddel = False
End If
End Sub
Private Sub Grid1_Validate(Cancel As Boolean) '设定TAB键切换
Dim nActiveRow As Long, nActiveCol As Long
Const VK_TAB = 9
If GetKeyState(VK_TAB) < 0 Then
nActiveRow = Grid1.ActiveCell.Row
nActiveCol = Grid1.ActiveCell.Col
If nActiveCol < Grid1.Cols - 1 Then
Grid1.Range(nActiveRow, nActiveCol + 1, _
nActiveRow, nActiveCol + 1).Selected
End If
Cancel = True
End If
End Sub
Private Sub XPButton1_Click()
gridsave = True
gridedit = False
griddelete = False
If qy1.State = adStateOpen Then '表状态
qy1.Close
End If
qy1.Open "select * from 登录", cnn, adOpenKeyset, adLockReadOnly, adCmdText
Grid1.Rows = 1 '清除所有记录
Grid1.Rows = 2 '默认为2行
i = 3
Grid1.Cols = i + 1 '必须+2,因为实际上为11行,但第一行是隐藏的
For i = 0 To 2 '显示数据的字段名
Grid1.Cell(0, i + 1).Text = qy1.Fields(i).Name '读取表中的各字段名
Next
Grid1.Column(1).Locked = False
Grid1.Cell(1, 1).SetFocus
End Sub
Private Sub XPButton2_Click()
If gridsave = False Then
MsgBox "不支持保存操作!", vbInformation, "当前不支持"
Exit Sub
End If
If Grid1.Cell(1, 1).Text <> "" Then
If qy1.State = adStateOpen Then '表状态
qy1.Close
End If
qy1.Open "select * from 登录 where 用户名='" & Grid1.Cell(1, 1).Text & "'", cnn, adOpenKeyset, adLockOptimistic, adCmdText
If qy1.EOF = True Then
qy1.AddNew
qy1.Fields(0) = Grid1.Cell(1, 1).Text
qy1.Fields(1) = Grid1.Cell(1, 2).Text
qy1.Fields(2) = Grid1.Cell(1, 3).Text
qy1.Update
MsgBox "保存成功!", vbInformation, ""
Call callmain
Else
MsgBox "该管理员己存在!", vbInformation, "不可重名"
Exit Sub
End If
Else
MsgBox "用户名不可以是空格", vbInformation, "错误提示"
End If
End Sub
Private Sub XPButton3_Click()
If gridedit = False Then
MsgBox "当前修改操作不被允许!", vbInformation, "非使用对象"
Exit Sub
End If
For i = 1 To Grid1.Rows - 1
If qy1.State = adStateOpen Then '表状态
qy1.Close
End If
qy1.Open "select * from 登录 where 用户名='" & Grid1.Cell(i, 1).Text & "'", cnn, adOpenKeyset, adLockOptimistic, adCmdText
If qy1.EOF = False Then
For j = 1 To Grid1.Cols - 1
qy1.Fields(j - 1) = Grid1.Cell(i, j).Text
Next
qy1.Update
Else
MsgBox "学号为" + Grid1.Cell(i, 1).Text + "己经被删除,无法作出修改!", vbInformation, "数据将跳过"
End If
Next
MsgBox "修改的数据己经完成", vbInformation, "完成操作"
Call callmain
End Sub
Private Sub XPButton4_Click()
If griddelete = False Then
MsgBox "当前删除操作不被允许!", vbInformation, "非使用对象"
Exit Sub
End If
If hang = "" Or hang = "0" Then
Exit Sub
End If
griddel = True
Call Grid1_CellChange(hang, 1)
End Sub
Private Sub XPButton5_Click()
Unload Me
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -