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

📄 login.frm

📁 在重庆大学为毕业设计做的维修管理系统 为了赶时间做得不是很好
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmlogin 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "维修管理系统"
   ClientHeight    =   3225
   ClientLeft      =   45
   ClientTop       =   435
   ClientWidth     =   5865
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3225
   ScaleWidth      =   5865
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cancelcmd 
      Caption         =   "取消"
      Height          =   495
      Left            =   3600
      TabIndex        =   4
      Top             =   2640
      Width           =   1215
   End
   Begin VB.CommandButton okcmd 
      Caption         =   "确定"
      Height          =   495
      Left            =   960
      TabIndex        =   3
      Top             =   2640
      Width           =   1215
   End
   Begin VB.Frame Frame1 
      Caption         =   "用户登录"
      Height          =   2415
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5655
      Begin VB.TextBox pwdTxt 
         Height          =   375
         IMEMode         =   3  'DISABLE
         Left            =   2760
         PasswordChar    =   "#"
         TabIndex        =   6
         Top             =   1560
         Width           =   2655
      End
      Begin VB.TextBox userTxt 
         Height          =   375
         Left            =   2760
         TabIndex        =   5
         Top             =   600
         Width           =   2655
      End
      Begin VB.Label Label2 
         Caption         =   "密码"
         Height          =   255
         Left            =   2040
         TabIndex        =   2
         Top             =   1680
         Width           =   615
      End
      Begin VB.Label Label1 
         Caption         =   "用户名"
         Height          =   255
         Left            =   2040
         TabIndex        =   1
         Top             =   720
         Width           =   735
      End
      Begin VB.Image Image1 
         Height          =   1875
         Left            =   120
         Picture         =   "login.frx":0000
         Stretch         =   -1  'True
         Top             =   360
         Width           =   1725
      End
   End
End
Attribute VB_Name = "frmlogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Const maxlogtimes As Integer = 3
Private Sub cancelcmd_Click()
    Dim intresult As Integer
    intresult = MsgBox("你选择了退出系统登录,退出将不能启动系统!" & vbCrLf _
              & "是否真的退出?", vbQuestion + vbYesNo, "登录验证")
    If intresult = vbYes Then End
    
End Sub

Private Sub Form_Activate()
  userTxt.SetFocus
End Sub

Private Sub okcmd_Click()
    Static intlogtimes As Integer  'intlogtimes 为静态变量
    Dim intchecked As Integer, strname As String, strpassword As String
    intlogtimes = intlogtimes + 1  '计算登录次数
    If intlogtimes > maxlogtimes Then 'maxlogtimes 定义为一个常量  Const maxlogtimes As Integer = 3
        MsgBox "你已经超过允许验证次数!" & vbCr _
                       & "应用程序将结束!", vbCritical, "登录验证"
        End
    Else
        strname = Trim(userTxt.Text)
        strpassword = Trim(pwdTxt.Text)
        
        Select Case check_password(strname, strpassword)
            Case 0
                MsgBox "<" & strname & ">不是系统用户,请检查用户名输入是否正确!", vbCritical, "登录验证"
                userTxt.SetFocus
                userTxt.Text = ""
            Case 1
                MsgBox "口令错误,请重新输入!", vbCritical, "登录验证 "
                pwdTxt = ""
                pwdTxt.SetFocus
            Case 2
                
                MsgBox "登录成功,将启动系统程序!", vbInformation, "登录验证"
                frmmain.Show
                frmmain.StatusBar1.Panels(2) = "当前用户:" & strname   '用户名显示在状态条中
                Unload Me
           Case Else
                
                MsgBox "登录验证未正常完成!请重新运行登录程序," & vbCrLf _
                       & "如果仍不能登录,请报告系统管理员!", vbCritical, "登录验证"
        End Select
     End If


End Sub

Private Function check_password(ByVal username As String, ByVal password As String) As Byte
    
    On Error GoTo gperror
    Dim objcn As New Connection, objrs As New Recordset, strcn As String
    Dim strsql As String
    objcn.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;User ID=sa;Data Source=wx;Initial Catalog=wxdb"
    objcn.Open
    
    strsql = "select 密码 from 用户表 where 用户名= '" & username & "'"
    Set objrs.ActiveConnection = objcn
    objrs.Open (strsql)
    
    '判断有无查询结果
    
    If objrs.EOF Then
        check_password = 0 '没有找到用户名
    Else
        If password <> Trim(objrs.Fields("密码").Value) Then
            check_password = 1   '密码错误
        Else
            check_password = 2  '密码正确
        End If
    End If
    
    objcn.Close
    Set objrs = Nothing
    Set objcn = Nothing
    
    Exit Function

gperror:
  
    check_password = 255 '验证无法正常完成,返回错误代码
    Set objrs = Nothing
    Set objcn = Nothing

End Function

Private Sub pwdTxt_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        okcmd.SetFocus
    End If
End Sub

Private Sub userTxt_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyReturn Then
        pwdTxt.SetFocus
    End If
End Sub

⌨️ 快捷键说明

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