?? login.frm
字號:
VERSION 5.00
Begin VB.Form frmLogin
BorderStyle = 3 'Fixed Dialog
Caption = "請登錄"
ClientHeight = 1815
ClientLeft = 2835
ClientTop = 3480
ClientWidth = 4335
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1072.362
ScaleMode = 0 'User
ScaleWidth = 4070.329
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdOK
Caption = "確定"
Default = -1 'True
Height = 390
Left = 3240
TabIndex = 8
Top = 240
Width = 900
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取消"
Height = 390
Left = 3240
TabIndex = 7
Top = 960
Width = 900
End
Begin VB.Frame frmLogin
Caption = "登錄"
Height = 1695
Left = 120
TabIndex = 2
Top = 0
Width = 2895
Begin VB.ComboBox cboUserType
Height = 315
ItemData = "Login.frx":0000
Left = 1080
List = "Login.frx":000A
Style = 2 'Dropdown List
TabIndex = 3
Top = 1200
Width = 1485
End
Begin VB.TextBox txtPwd
Height = 345
IMEMode = 3 'DISABLE
Left = 1080
PasswordChar = "*"
TabIndex = 1
Top = 765
Width = 1485
End
Begin VB.TextBox txtUser
Height = 345
Left = 1080
TabIndex = 0
Top = 360
Width = 1485
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "選擇身份:"
Height = 180
Index = 2
Left = 180
TabIndex = 6
Top = 1200
Width = 900
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "用戶名:"
Height = 195
Index = 0
Left = 360
TabIndex = 5
Top = 390
Width = 720
End
Begin VB.Label lblLabels
AutoSize = -1 'True
Caption = "口令:"
Height = 195
Index = 1
Left = 540
TabIndex = 4
Top = 795
Width = 540
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
'表示當(dāng)前用戶登錄所選擇的身份,即用戶類型, 0-表示管理員;1-表示學(xué)生
Dim mnUserType As Integer
Private Sub cboUserType_Change()
mnUserType = cboUserType.ListIndex
End Sub
Private Sub cboUserType_Click()
mnUserType = cboUserType.ListIndex
End Sub
Private Sub cmdCancel_Click()
Unload Me
End Sub
Private Sub cmdOK_Click()
''取得用戶輸入的用戶名和密碼
Dim user As String, pwd As String
user = txtUser
pwd = txtPwd
''根據(jù)不同的身份,選擇不同的表用以查詢
Dim r As New ADODB.Recordset
Set r = DataEnv.rssqlSeek
Dim strSQL As String
Select Case mnUserType
Case 0: '若身份為管理員
strSQL = "select * from admin where name='" & user & "' and pwd='" & pwd & "'"
Case 1: '若身份為學(xué)生
strSQL = "select * from student where name='" & user & "' and serial='" & pwd & "'"
End Select
On Error Resume Next
''查詢DataEnv.rssqlSeek的狀態(tài),如果已經(jīng)打開,則先關(guān)閉
If r.State = adStateOpen Then r.Close
r.Open strSQL ''根據(jù)strSQL的內(nèi)容刷新DataEnv.rssqlSeek
''用戶密碼錯誤的次數(shù),如果錯誤次數(shù)超過3次,則退出系統(tǒng)
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 "您無權(quán)操作本系統(tǒng)!再見!", vbCritical, "無權(quán)限"
Unload Me
End If
Else ''登陸成功
''顯示MDI窗體, 并將用戶類型和用戶名傳到MDI窗體中的mnUserType, msUserName中
Load MDIMain
With MDIMain
.mnUserType = cboUserType.ListIndex
.msUserName = pwd
.Show
End With
Unload Me
End If
End Sub
Private Sub Form_Load()
cboUserType.ListIndex = 0
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -