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

📄 form1.frm

📁 所在类别: 随书资源/T 工业技术/TP 自动化技术、计算机技术/TP31 计算机软件 其他题名: 作者: 夏邦贵, 刘凡馨等编著 出版者: 机械工业出版社 出版年: 2006 I
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "系统登录"
   ClientHeight    =   1830
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   4185
   LinkTopic       =   "Form2"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   1830
   ScaleWidth      =   4185
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   315
      Left            =   2310
      TabIndex        =   3
      Top             =   1215
      Width           =   945
   End
   Begin VB.CommandButton cmdOk 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   315
      Left            =   1155
      TabIndex        =   2
      Top             =   1200
      Width           =   945
   End
   Begin VB.TextBox txtPwd 
      Height          =   315
      IMEMode         =   3  'DISABLE
      Left            =   1462
      PasswordChar    =   "*"
      TabIndex        =   1
      Text            =   "Text2"
      Top             =   720
      Width           =   1935
   End
   Begin VB.TextBox txtName 
      Height          =   315
      Left            =   1462
      TabIndex        =   0
      Text            =   "Text1"
      Top             =   315
      Width           =   1935
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "口  令"
      Height          =   180
      Left            =   787
      TabIndex        =   5
      Top             =   780
      Width           =   540
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "用户名"
      Height          =   180
      Left            =   787
      TabIndex        =   4
      Top             =   375
      Width           =   540
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Const MaxLogTimes As Integer = 3    '定义允许尝试登录的最大次数
Private Sub Form_Load()
    '清空用户名和口令文本框
    txtName = ""
    txtPwd = ""
  
End Sub
Private Sub cmdCancel_Click()
    '请求用户确认是否真的退出系统登录
    If MsgBox("你选择了退出系统登录,退出将不能启动管理系统!" & vbCrLf _
              & "是否真的退出?", vbYesNo + vbQuestion, "登录验证") = vbYes Then
        Unload Me               '卸载登录窗体
    End If
End Sub
Private Sub cmdOk_Click()
    Dim objCn As Connection, objRs As Recordset, strSQL$
    '检验是否输入用户名
    If Trim(txtName) = "" Then
        MsgBox "请输入用户名!", vbExclamation, "登录验证"
        txtName = ""
        txtName.SetFocus
        Exit Sub
    End If
    '检验是否输入登录口令
    If Trim(txtPwd) = "" Then
        MsgBox "请输入登录口令!", vbExclamation, "登录验证"
        txtPwd = ""
        txtPwd.SetFocus
        Exit Sub
    End If
    '创建与数据库的联接
    Set objCn = New Connection                  '实例化联接对象
    With objCn                                  '建立数据库联接
        .Provider = "SQLOLEDB"
        .ConnectionString = "User ID=sa;PWD=123;Data Source=(local);" & _
                            "Initial Catalog=学分制选课"
        .Open
    End With
    Dim objLog As New Recordset
    strSQL = "select 学号 as 密码 from 学生信息 where 姓名='" & Trim(txtName) & "'"
    '执行查询获得用户登陆密码
    Set objRs = New Recordset
    With objRs
        Set .ActiveConnection = objCn
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .Open strSQL
        If .RecordCount < 1 Then
            MsgBox "用户名输入错误!", vbCritical, "登录验证"
            txtName.SetFocus
            txtName.SelStart = 0
            txtName.SelLength = Len(txtName)
        Else
            If .Fields("密码") <> Trim(txtPwd) Then
                MsgBox "口令错误,请重新输入!", vbCritical, "登录验证"
                txtPwd.SetFocus
                txtPwd = ""
            Else
                MsgBox "登录成功!", vbInformation, "登录成功"
            End If
        End If
     End With
    objCn.Close             '关闭数据库连接
    Set objCn = Nothing     '释放数据库连接
    Set objRs = Nothing
End Sub

⌨️ 快捷键说明

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