?? frmsystemlogon.frm
字號:
VERSION 5.00
Begin VB.Form systemlogon
BorderStyle = 3 'Fixed Dialog
Caption = "系統(tǒng)登陸"
ClientHeight = 2490
ClientLeft = 45
ClientTop = 435
ClientWidth = 4200
ControlBox = 0 'False
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
Picture = "frmsystemlogon.frx":0000
ScaleHeight = 2490
ScaleWidth = 4200
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.ComboBox cmbtype
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 330
Left = 1560
TabIndex = 7
Text = "Combo1"
Top = 1320
Width = 1695
End
Begin VB.TextBox txtpwd
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
IMEMode = 3 'DISABLE
Left = 1560
PasswordChar = "*"
TabIndex = 6
Text = "Text2"
Top = 840
Width = 1695
End
Begin VB.TextBox txtname
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 315
Left = 1560
TabIndex = 5
Text = "Text1"
Top = 360
Width = 1695
End
Begin VB.CommandButton cmdcancel
Caption = "退出"
Height = 375
Left = 2280
TabIndex = 4
Top = 1920
Width = 975
End
Begin VB.CommandButton cmdok
Caption = "確定"
Default = -1 'True
Height = 375
Left = 720
TabIndex = 3
Top = 1920
Width = 1095
End
Begin VB.Label Label3
BackStyle = 0 'Transparent
Caption = "身份"
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 720
TabIndex = 2
Top = 1320
Width = 735
End
Begin VB.Label Label2
BackStyle = 0 'Transparent
Caption = "口令"
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 720
TabIndex = 1
Top = 840
Width = 615
End
Begin VB.Label Label1
BackStyle = 0 'Transparent
Caption = "用戶名"
BeginProperty Font
Name = "宋體"
Size = 10.5
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 720
TabIndex = 0
Top = 360
Width = 735
End
End
Attribute VB_Name = "systemlogon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Const maxlogtimes As Integer = 3
Dim objadmin As Recordset
Dim objstudent As Recordset
Dim objTeacher As Recordset
Private Sub cmdcancel_Click()
If MsgBox("您選擇了退出系統(tǒng)登陸,退出后將不能啟動管理系統(tǒng)!" & vbCrLf & "是否真的退出?", vbYesNo + vbQuestion, "登陸驗證") = vbYes Then
Unload Me
End If
End Sub
Private Sub cmdok_Click()
'靜態(tài)的常量intlogtimes用于保存用戶請求驗證的次數(shù)
Static intlogtimes As Integer
intlogtimes = intlogtimes + 1
If intlogtimes > maxlogtimes Then
MsgBox "你已經(jīng)超過允許的登陸驗證次數(shù)!" & vbCr & "應(yīng)用程序結(jié)束!", vbCritical, "登陸驗證"
End
End If
'檢驗是否輸入用戶名
If Trim(txtName) = "" Then
MsgBox "請輸入用戶名!", vbExclamation, "登陸驗證"
txtName.SetFocus
Exit Sub
End If
'檢驗是否輸入登陸口令
If Trim(txtpwd) = "" Then
MsgBox "請輸入登陸口令!", vbExclamation, "登陸驗證"
txtpwd = ""
txtpwd.SetFocus
Exit Sub
End If
'根據(jù)用戶身份創(chuàng)建用于檢驗用戶名和口令的合法性的recorset對象
Dim objlog As New Recordset
Select Case cmbtype
Case "學(xué)生"
Set objlog = objstudent.Clone
Case "閱卷教師"
Set objlog = objTeacher.Clone
Case "系統(tǒng)管理員"
Set objlog = objadmin.Clone
End Select
Dim strpwdfield As String
With objlog '檢驗用戶名和口令的合法性
If .RecordCount > 0 Then
.MoveFirst
Select Case cmbtype
Case "學(xué)生"
.Find "姓名='" & Trim(txtName) & "'"
strpwdfield = "考號"
studentcode = .Fields(strpwdfield)
Case "閱卷教師"
.Find "姓名='" & Trim(txtName) & "'"
strpwdfield = "口令"
Case "系統(tǒng)管理員"
.Find "用戶名='" & Trim(txtName) & "'"
strpwdfield = "口令"
End Select
If .EOF Then
MsgBox "用戶名輸入錯誤,請檢查輸入和登陸身份的正確性!", vbCritical, "登陸驗證"
txtName.SetFocus
txtName.SelStart = 0
txtName.SelLength = Len(txtName)
ElseIf .Fields(strpwdfield) <> Trim(txtpwd) Then
MsgBox "口令輸入錯誤,請檢查輸入和登陸身份的正確性!", vbCritical, "登陸驗證"
txtpwd.SetFocus
txtpwd = ""
Else
'保存用戶信息
currentusername = Trim(txtName)
currentuserpassword = Trim(txtpwd)
currentuserstatus = cmbtype
MsgBox "歡迎使用自測考試系統(tǒng)!", vbInformation, "登錄成功"
Unload Me
mdisystemmain.Show
End If
End If
End With
Set objlog = Nothing
End Sub
Private Sub Form_Load()
'清空用戶名和口令文本框
txtName = ""
txtpwd = ""
'創(chuàng)建設(shè)分列表
cmbtype.AddItem "學(xué)生"
cmbtype.AddItem "閱卷教師"
cmbtype.AddItem "系統(tǒng)管理員"
cmbtype.ListIndex = 2
'創(chuàng)建與數(shù)據(jù)庫的連接
Dim objCn As New Connection
With objCn
.Provider = "sqloledb"
.ConnectionString = "user id=sa;data source=(local);" & _
"initial catalog=自測考試"
.Open
End With
'訪問數(shù)據(jù)庫獲得管理員登陸信息
Set objadmin = New Recordset
With objadmin
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Open "select * from 管理員", objCn
Set .ActiveConnection = Nothing
End With
'訪問數(shù)據(jù)庫獲得學(xué)生登陸信息
Set objstudent = New Recordset
With objstudent
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Open "select * from 學(xué)生信息", objCn
Set .ActiveConnection = Nothing
End With
'訪問數(shù)據(jù)庫獲得教師登陸信息
Set objTeacher = New Recordset
With objTeacher
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.Open "select * from 閱卷教師", objCn
Set .ActiveConnection = Nothing
End With
objCn.Close
Set objCn = Nothing
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set objadmin = Nothing
Set objstudent = Nothing
Set objTeacher = Nothing
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -