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

📄 frm_login.frm

📁 <Visual Basic 数据库开发实例精粹(第二版)>一书首先介绍了Visual Basic(简称VB)开发的技巧和重点技术
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmLoginOld 
   BackColor       =   &H00D9722D&
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "用户登录"
   ClientHeight    =   2490
   ClientLeft      =   4395
   ClientTop       =   3540
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2490
   ScaleWidth      =   4680
   ShowInTaskbar   =   0   'False
   Begin VB.TextBox TextUser 
      Height          =   375
      Left            =   1920
      TabIndex        =   0
      Top             =   1080
      Width           =   2415
   End
   Begin VB.TextBox TextPwd 
      Height          =   375
      IMEMode         =   3  'DISABLE
      Left            =   1920
      PasswordChar    =   "*"
      TabIndex        =   1
      Top             =   1560
      Width           =   2415
   End
   Begin VB.CommandButton CmdOK 
      Caption         =   "登录"
      Default         =   -1  'True
      Height          =   375
      Left            =   1080
      TabIndex        =   2
      Top             =   2040
      Width           =   1095
   End
   Begin VB.CommandButton CmdCancel 
      Caption         =   "取消"
      Height          =   375
      Left            =   2520
      TabIndex        =   3
      Top             =   2040
      Width           =   1095
   End
   Begin VB.Label Label3 
      BackStyle       =   0  'Transparent
      Caption         =   "用户ID:"
      BeginProperty Font 
         Name            =   "楷体_GB2312"
         Size            =   14.25
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   255
      Left            =   600
      TabIndex        =   7
      Top             =   1080
      Width           =   1335
   End
   Begin VB.Label Label4 
      Alignment       =   1  'Right Justify
      BackStyle       =   0  'Transparent
      Caption         =   "密码:"
      BeginProperty Font 
         Name            =   "楷体_GB2312"
         Size            =   14.25
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   375
      Left            =   840
      TabIndex        =   6
      Top             =   1560
      Width           =   975
   End
   Begin VB.Label Label2 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "特瑞飞软件公司开发"
      BeginProperty Font 
         Name            =   "楷体_GB2312"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H0054D86F&
      Height          =   255
      Left            =   2400
      TabIndex        =   5
      Top             =   720
      Width           =   2295
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      BackStyle       =   0  'Transparent
      Caption         =   "访客登记查询系统"
      BeginProperty Font 
         Name            =   "楷体_GB2312"
         Size            =   26.25
         Charset         =   134
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H000000FF&
      Height          =   495
      Left            =   0
      TabIndex        =   4
      Top             =   120
      Width           =   4695
   End
End
Attribute VB_Name = "frmLoginOld"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Sub CmdCancel_Click()   '取消
  Unload Me
End Sub

Private Sub CmdOK_Click()        '登录
  Dim check As New ADODB.Recordset '定义Recordset对象
  Dim DBstr As String
  Dim UsrID As String
  Dim UsrPwd As String
    
  '检验用户名和密码
  '1.读出数据库中的记录
  '2.找到输入的用户名
  '3.比较输入的密码是否与数据库中的记录相符
    
  If Len(Trim(Me.TextUser.Text)) <= 0 Then      '没有输入用户名
    MsgBox "请输入用户名!", , "登陆信息"
    Exit Sub
  End If
  If Len(Trim(Me.TextUser.Text)) > 16 Then      '用户名过长
    MsgBox "您输入用户名过长!", , "登陆信息"
    Exit Sub
  End If
  UsrID = Replace(Trim(Me.TextUser.Text), "'", "''")
    
  If Len(Trim(Me.TextPwd.Text)) <= 0 Then      '没有输入密码
    MsgBox "请输入密码!", , "登陆信息"
    Exit Sub
  End If
  If Len(Trim(Me.TextPwd.Text)) > 16 Then       '密码过长
    MsgBox "您输入密码过长!", , "登陆信息"
    Exit Sub
  End If
  UsrPwd = Trim(Me.TextPwd.Text)
   
  DBstr = "select * from UserInfo where UserID='" & UsrID & "'"
  '打开数据集
  check.Open DBstr, DBCnn, adOpenStatic, adLockReadOnly, -1
    
  If check.RecordCount <= 0 Then  '找不到该用户名
    MsgBox "用户名不存在!" & vbCrLf & "请重新输入!", , "登陆信息"
    check.Close
    Exit Sub
  Else
    '数据集指针指向第一个记录,这里查找到的记录唯一
    check.MoveFirst
    '检验密码
    If TextPwd = check.Fields("UserPwd").Value Then
      UserNow.ID = Trim(Me.TextUser.Text)
      UserNow.Type = check.Fields("UserType").Value
    Else
      MsgBox "密码错误!", , "登陆信息"
      check.Close
      Exit Sub
    End If
    '关闭数据集
    check.Close
  End If
      
  '用户名,密码都正确,进入主窗口
  Unload Me
  Frm_Main.Show
End Sub

Private Sub Form_Load()
  Dim SqlStr As String
    
  '确定该程序没有被启动过
  If App.PrevInstance Then
    MsgBox "您已经启动过了本程序!"
    End
  End If
    
  '连接数据库
  SqlStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
     App.Path & "\mdb\Guest.mdb;Persist Security Info=False"
  DBCnn.Open SqlStr
              
End Sub






⌨️ 快捷键说明

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