⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmuser.frm

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmUser 
   BackColor       =   &H0080C0FF&
   Caption         =   "用户管理"
   ClientHeight    =   3900
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5160
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3900
   ScaleWidth      =   5160
   StartUpPosition =   2  '屏幕中心
   Begin VB.Frame Frame1 
      BackColor       =   &H0080C0FF&
      Caption         =   "用户列表"
      Height          =   2535
      Left            =   120
      TabIndex        =   7
      Top             =   1080
      Width           =   2295
      Begin VB.ListBox lstname 
         BackColor       =   &H00FFFFFF&
         ForeColor       =   &H00FF0000&
         Height          =   1860
         Left            =   120
         TabIndex        =   8
         Top             =   360
         Width           =   2055
      End
   End
   Begin VB.Frame Frame2 
      BackColor       =   &H0080C0FF&
      Caption         =   "添加新用户"
      Height          =   2535
      Left            =   2520
      TabIndex        =   0
      Top             =   1080
      Width           =   2535
      Begin VB.CommandButton CmdOK 
         Caption         =   "确定"
         Default         =   -1  'True
         Height          =   375
         Left            =   120
         Picture         =   "frmUser.frx":0000
         Style           =   1  'Graphical
         TabIndex        =   4
         Top             =   2040
         Width           =   735
      End
      Begin VB.CommandButton CmdNO 
         Caption         =   "取消"
         Height          =   375
         Left            =   1680
         Picture         =   "frmUser.frx":030A
         Style           =   1  'Graphical
         TabIndex        =   3
         Top             =   2040
         Width           =   735
      End
      Begin VB.TextBox txtUser 
         Appearance      =   0  'Flat
         ForeColor       =   &H00FF0000&
         Height          =   375
         Left            =   1080
         TabIndex        =   2
         Top             =   480
         Width           =   1215
      End
      Begin VB.TextBox txtPassword 
         Appearance      =   0  'Flat
         ForeColor       =   &H00FF0000&
         Height          =   375
         IMEMode         =   3  'DISABLE
         Left            =   1080
         PasswordChar    =   "*"
         TabIndex        =   1
         Top             =   1200
         Width           =   1215
      End
      Begin VB.Label lb1 
         BackStyle       =   0  'Transparent
         Caption         =   "用户名:"
         ForeColor       =   &H00FF0000&
         Height          =   255
         Left            =   120
         TabIndex        =   6
         Top             =   480
         Width           =   975
      End
      Begin VB.Label lb2 
         BackStyle       =   0  'Transparent
         Caption         =   "密码:"
         ForeColor       =   &H00FF0000&
         Height          =   372
         Left            =   120
         TabIndex        =   5
         Top             =   1200
         Width           =   852
      End
   End
   Begin MSComctlLib.ImageList ImList 
      Left            =   4080
      Top             =   600
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   14
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0614
            Key             =   "Print"
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0728
            Key             =   "Priview"
         EndProperty
         BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0C6C
            Key             =   "Add"
         EndProperty
         BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0D80
            Key             =   "Del"
         EndProperty
         BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0E94
            Key             =   "Edit"
         EndProperty
         BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":0FA8
            Key             =   "Save"
         EndProperty
         BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":10BC
            Key             =   "Undo"
         EndProperty
         BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":11D0
            Key             =   "Exit"
         EndProperty
         BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":12E4
            Key             =   "First"
         EndProperty
         BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":1838
            Key             =   "Previous"
         EndProperty
         BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":194C
            Key             =   "Next"
         EndProperty
         BeginProperty ListImage12 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":1A60
            Key             =   "Last"
         EndProperty
         BeginProperty ListImage13 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":1FB4
            Key             =   "Inline"
         EndProperty
         BeginProperty ListImage14 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmUser.frx":2308
            Key             =   "Delline"
         EndProperty
      EndProperty
   End
   Begin MSComctlLib.Toolbar Tlbar 
      Align           =   1  'Align Top
      Height          =   552
      Left            =   0
      TabIndex        =   9
      Top             =   0
      Width           =   5160
      _ExtentX        =   9102
      _ExtentY        =   979
      ButtonWidth     =   609
      ButtonHeight    =   926
      Appearance      =   1
      Style           =   1
      ImageList       =   "ImList"
      _Version        =   393216
   End
   Begin VB.Label x 
      BackStyle       =   0  'Transparent
      Caption         =   "已启用"
      ForeColor       =   &H000000FF&
      Height          =   255
      Left            =   120
      TabIndex        =   10
      Top             =   3720
      Visible         =   0   'False
      Width           =   1575
   End
End
Attribute VB_Name = "frmUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit


Public rec As Recordset
Sub save()
  Dim strSQL As String
  If txtUser.Text = "" Then Exit Sub
  
  strSQL = " INSERT INTO UserInfo([Name], [Password])"
  strSQL = strSQL & " VALUES("
  strSQL = strSQL & "'" & RealString(txtUser.Text) & "',"
  strSQL = strSQL & "'" & RealString(txtPassword.Text) & "')"
  g_Conn.Execute strSQL
  
  lstname.AddItem txtUser.Text
  txtUser.Text = ""
  txtPassword.Text = ""
  txtUser.SetFocus
End Sub
Private Sub CmdNO_Click()
  Unload Me
End Sub
Private Sub CmdOK_Click()
  save
End Sub
Private Sub Form_Load()
  cmdOK.Enabled = False
  txtUser.Enabled = False
  txtPassword.Enabled = False
  Tlbar.Buttons.add 1, "Add", "添加", , "Add"     '添加按钮
  Tlbar.Buttons.add 2, "Del", "删除", , "Del"
  Tlbar.Buttons.add 3, , , tbrSeparator
  Tlbar.Buttons.add 4, "Save", "保存", , "Save"
  Tlbar.Buttons.add 5, "Undo", "撤销", , "Undo"
  Tlbar.Buttons.add 6, , , tbrSeparator
  Tlbar.Buttons.add 7, "Exit", "退出", , "Exit"
  
  Set rec = g_Conn.Execute("SELECT * FROM UserInfo")   '打开数据库
  If rec.RecordCount = 0 Then Exit Sub
  
  Do While Not rec.EOF                      '添加新的记录
    lstname.AddItem rec.Fields(0)
    rec.MoveNext
  Loop
  
  Tlbar.Buttons(2).Enabled = False
  Tlbar.Buttons(3).Enabled = False
  Tlbar.Buttons(4).Enabled = False
End Sub
Private Sub Tlbar_ButtonClick(ByVal Button As MSComctlLib.Button)
  Dim rst As VbMsgBoxResult
  
  Select Case Button.Key
    Case "Add"                 '添加新的用户
      Tlbar.Buttons(5).Enabled = False
      txtUser.Enabled = True
      txtPassword.Enabled = True
      txtUser.Text = ""
      txtPassword.Text = ""
      txtUser.SetFocus
      cmdOK.Enabled = False
    Case "Undo"                 '撤销输入内容
      txtUser.Text = ""
      txtPassword.Text = ""
      Tlbar.Buttons(2).Enabled = False
      Tlbar.Buttons(3).Enabled = False
      Tlbar.Buttons(5).Enabled = False
    Case "Save"                 '保存用户信息
      Tlbar.Buttons(2).Enabled = False
      save
    Case "Del"                   '从记录中删除旧的用户
      If lstname.SelCount <> 1 Then
        Exit Sub
      End If
      If lstname.Text = "超级用户" Then
        MsgBox "默认管理员不能删除!", vbExclamation, "股票分析系统"
        Exit Sub
      End If
      If lstname.Text = g_UserName Then
        MsgBox "自己无法删除自己!", vbCritical, "股票分析系统"
        Exit Sub
      End If
      rst = MsgBox("确定删除吗?(Y/N)", 1 + 64, "股票分析系统")
      If rst = vbYes Or rst = vbOK Then
        g_Conn.Execute "DELETE FROM " _
        & "[UserInfo] WHERE name ='" & RealString(lstname.Text) & "'"
        txtUser.Text = ""
        lstname.RemoveItem lstname.ListIndex
        txtPassword.Text = ""
      End If
    Case "Exit"
       Unload Me
  End Select
End Sub
Private Sub txtPassword_Change()
  cmdOK.Enabled = True
  Tlbar.Buttons(4).Enabled = True
End Sub
Private Sub lstname_Click()
  If lstname.Text = "SuperUser" Then
    Tlbar.Buttons(2).Enabled = False
  Else
    Tlbar.Buttons(2).Enabled = True
  End If
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -