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

📄 增加用户r.frm

📁 对学习VB很有帮助 fskdljfl kasdjfkl asdjfk lajsd f
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Frm_AddUser 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "增加用户"
   ClientHeight    =   3900
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   5220
   Icon            =   "增加用户r.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3900
   ScaleWidth      =   5220
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton Command3 
      Caption         =   "检测用户"
      Height          =   495
      Left            =   4080
      TabIndex        =   10
      Top             =   720
      Width           =   975
   End
   Begin VB.ComboBox Combo1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   330
      Left            =   2040
      TabIndex        =   9
      Text            =   "Combo1"
      Top             =   2520
      Width           =   1815
   End
   Begin VB.CommandButton Command2 
      Caption         =   "退出"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   3000
      TabIndex        =   7
      Top             =   3240
      Width           =   1215
   End
   Begin VB.CommandButton Command1 
      Caption         =   "确定"
      Default         =   -1  'True
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   495
      Left            =   840
      TabIndex        =   6
      Top             =   3240
      Width           =   1215
   End
   Begin VB.TextBox Text3 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   2040
      MaxLength       =   20
      PasswordChar    =   "*"
      TabIndex        =   5
      Text            =   "Text3"
      Top             =   1920
      Width           =   1815
   End
   Begin VB.TextBox Text2 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   2040
      MaxLength       =   20
      PasswordChar    =   "*"
      TabIndex        =   3
      Text            =   "Text2"
      Top             =   1320
      Width           =   1815
   End
   Begin VB.TextBox Text1 
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   375
      Left            =   2040
      MaxLength       =   20
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   720
      Width           =   1815
   End
   Begin VB.Label Label4 
      Caption         =   "身份:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   1320
      TabIndex        =   8
      Top             =   2520
      Width           =   735
   End
   Begin VB.Label Label3 
      Caption         =   "确定密码:"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   10.5
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   255
      Left            =   960
      TabIndex        =   4
      Top             =   1920
      Width           =   1095
   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          =   255
      Left            =   1320
      TabIndex        =   2
      Top             =   1320
      Width           =   855
   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          =   255
      Left            =   1200
      TabIndex        =   0
      Top             =   720
      Width           =   855
   End
End
Attribute VB_Name = "Frm_AddUser"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim myRs As New ADODB.Recordset
Private Sub Command1_Click()
Dim strName, strPass, strPassAgain, strShenFen As String
    strName = Trim(Text1.Text)
    strPass = Trim(Text2.Text)
    strPassAgain = Trim(Text3.Text)
    strShenFen = Trim(Combo1.Text)
    
If strName = "" Or strPass = "" Or strPassAgain = "" Or strShenFen = "" Then
    MsgBox "请填写完整所有资料!", vbOKOnly, "警告"
    Text1.SetFocus
    Exit Sub
End If

myRs.Open "select * from 管理人员 where username='" & strName & "'", conn

If Not myRs.EOF Then
    Text1.SetFocus
    MsgBox "该用户名已经存在,请使用其他用户名!", vbOKOnly, "警告"
    myRs.Close
        Exit Sub
End If

If strPass <> strPassAgain Then
    MsgBox "两次输入的密码不同!", vbOKOnly, "警告"
    Text3.SetFocus
    myRs.Close
   
    Exit Sub
End If
myRs.Close

myRs.CursorType = adOpenKeyset
myRs.LockType = adLockOptimistic
myRs.Open "管理人员", conn, 3, 2
myRs.AddNew
myRs.Fields("username") = Text1.Text
myRs.Fields("password") = Text2.Text
If Combo1.Text = "管理员" Then
myRs.Fields("admin") = True
Else
myRs.Fields("admin") = False
End If
myRs.Update
myRs.Close

    
MsgBox "注册成功!", vbOKOnly, "提示"
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.Text = ""
End Sub

Private Sub Command2_Click()
    Unload Me
End Sub

Private Sub Command3_Click()
Dim a As New ADODB.Recordset
a.Open "select * from 管理人员 where username='" & Trim(Text1.Text) & "'", conn

If Not a.EOF Then
    Text1.SetFocus
    MsgBox "该用户名已经存在,请使用其他用户名!", vbOKOnly, "警告"
    Else
    MsgBox "该用户名可以使用,欢迎您注册!", vbOKOnly, "欢迎"
    a.Close
    Exit Sub
End If
End Sub

Private Sub Form_Load()
main.StatusBar1.Panels(10) = Me.Caption
'Call menudisable
Call opendatabase

Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Combo1.Text = ""
Combo1.AddItem ("管理员")
Combo1.AddItem ("普通用户")
End Sub

Private Sub Form_Unload(Cancel As Integer)
conn.Close

End Sub

⌨️ 快捷键说明

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