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

📄 login.frm

📁 进销存管理系统是基于用户的数据库管理系统
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmLogin 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "请登录"
   ClientHeight    =   3495
   ClientLeft      =   2835
   ClientTop       =   3480
   ClientWidth     =   4050
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2064.962
   ScaleMode       =   0  'User
   ScaleWidth      =   3802.729
   ShowInTaskbar   =   0   'False
   StartUpPosition =   2  '屏幕中心
   Begin VB.CommandButton cmdOK 
      Caption         =   "确定"
      Default         =   -1  'True
      Height          =   390
      Left            =   2520
      TabIndex        =   3
      Top             =   2520
      Width           =   780
   End
   Begin VB.CommandButton cmdCancel 
      Cancel          =   -1  'True
      Caption         =   "取消"
      Height          =   375
      Left            =   1560
      TabIndex        =   4
      Top             =   2520
      Width           =   780
   End
   Begin VB.Frame fraLogin 
      Caption         =   "登录"
      Height          =   3015
      Left            =   240
      TabIndex        =   5
      Top             =   120
      Width           =   3495
      Begin VB.TextBox txtPwd 
         Height          =   345
         IMEMode         =   3  'DISABLE
         Left            =   1080
         PasswordChar    =   "*"
         TabIndex        =   1
         Top             =   1020
         Width           =   2085
      End
      Begin VB.ComboBox cboUserType 
         Height          =   300
         ItemData        =   "Login.frx":0000
         Left            =   1080
         List            =   "Login.frx":000A
         Style           =   2  'Dropdown List
         TabIndex        =   2
         Top             =   1800
         Width           =   2085
      End
      Begin VB.TextBox txtUser 
         Height          =   345
         Left            =   1080
         TabIndex        =   0
         Top             =   360
         Width           =   2085
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         Caption         =   "密码:"
         Height          =   180
         Index           =   1
         Left            =   540
         TabIndex        =   8
         Top             =   1095
         Width           =   540
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         Caption         =   "选择身份:"
         Height          =   180
         Index           =   2
         Left            =   180
         TabIndex        =   7
         Top             =   1860
         Width           =   900
      End
      Begin VB.Label lblLabels 
         AutoSize        =   -1  'True
         Caption         =   "用户名:"
         Height          =   195
         Index           =   0
         Left            =   360
         TabIndex        =   6
         Top             =   435
         Width           =   720
      End
   End
End
Attribute VB_Name = "frmLogin"
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()
    On Error GoTo errHandler
    
    '建立全局性的数据连接
    Set gConn = New ADODB.Connection
    Dim strConn As String
    strConn = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Sale;Data Source=DAVID-PC"
    gConn.Open strConn

    
    '取得用户输入的用户名和密码
    Dim user As String, pwd As String
    user = txtUser
    pwd = txtPwd
        
    '取得用户的用户类型和用户名,并分别保存在两个全局变量gnUserType和gsUserName中
    gnUserType = cboUserType.ListIndex
    gsUserName = user
        
    '根据所取得的用户名、密码和用户类型在数据库中进行搜索
    Dim strSQL As String
    strSQL = "select * from userlist where 用户名= '" & user & "' and 用户密码 ='" & pwd & "' and 用户类型=" & gnUserType
    Dim r As New ADODB.Recordset
    r.Open strSQL, gConn, adOpenStatic
       
    '用户密码错误的次数,如果错误次数超过3次,则退出系统
    Static nTryCount As Integer
    
    If r.EOF Then   '登录失败
      MsgBox "对不起,无此用户或者密码不正确!请重新输入!!", vbCritical, "错误"
      txtUser.SetFocus
      txtUser.SelStart = 0
      txtUser.SelLength = Len(txtUser)
      nTryCount = nTryCount + 1
      If nTryCount >= 3 Then
         MsgBox "您无权操作本系统!再见!", vbCritical, "无权限"
         Unload Me
         '关闭数据连接
         gConn.Close
      End If
    Else            '登陆成功
      Unload Me
      frmMain.Show  '显示MDI主窗口
    End If
    r.Close
    
    Exit Sub
    
errHandler:
    MsgBox Err.Description, vbCritical, "错误"
End Sub

Private Sub Form_Load()
    cboUserType.Clear
    '在cboUser中加载用以表示用户类型的字符串
    cboUserType.AddItem "管理人员", 0
    cboUserType.AddItem "仓管人员", 1
    cboUserType.AddItem "销售人员", 2
    cboUserType.AddItem "进货人员", 3

    cboUserType.ListIndex = 0
End Sub

⌨️ 快捷键说明

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