?? form1.frm
字號(hào):
VERSION 5.00
Begin VB.Form frmLogin
BorderStyle = 3 'Fixed Dialog
Caption = "請(qǐng)登錄"
ClientHeight = 3990
ClientLeft = 45
ClientTop = 435
ClientWidth = 6555
Icon = "Form1.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
Picture = "Form1.frx":29C12
ScaleHeight = 3990
ScaleWidth = 6555
ShowInTaskbar = 0 'False
StartUpPosition = 2 '屏幕中心
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 495
Left = 3840
TabIndex = 5
Top = 3000
Width = 1575
End
Begin VB.CommandButton cmdOK
Caption = "確定"
Height = 495
Left = 1320
TabIndex = 4
Top = 3000
Width = 1575
End
Begin VB.TextBox txtPWD
Height = 300
IMEMode = 3 'DISABLE
Left = 3480
PasswordChar = "*"
TabIndex = 3
Top = 2040
Width = 2055
End
Begin VB.ComboBox cmbUserName
Height = 300
Left = 3480
TabIndex = 2
Text = "cmbUserName"
Top = 1200
Width = 2055
End
Begin VB.Image Image1
Height = 1080
Left = 600
Picture = "Form1.frx":387AD
Top = 1200
Width = 1080
End
Begin VB.Label labPWD
BackStyle = 0 'Transparent
Caption = "密 碼:"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1920
TabIndex = 1
Top = 2040
Width = 1455
End
Begin VB.Label labUsername
BackStyle = 0 'Transparent
Caption = "用戶名:"
BeginProperty Font
Name = "宋體"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 1920
TabIndex = 0
Top = 1200
Width = 1455
End
End
Attribute VB_Name = "frmLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim connstring As String
Dim num As Integer ' 用于保存密碼輸入錯(cuò)誤次數(shù)
Private Sub CmdCancel_Click()
Unload frmLogin '卸載登錄窗口
End Sub
Private Sub cmdOK_Click()
If Trim(cmbUserName.Text) = "" Then '首先要求用戶名不能為空
MsgBox "用戶名不能為空!", vbOKOnly + vbExclamation, "警告!"
cmbUserName.SetFocus '將焦點(diǎn)轉(zhuǎn)移到用戶名組合框中
Exit Sub
End If
connstring = "Provider=SQLOLEDB.1;Password=ecc;Persist Security Info=True;User ID=sa;" _
& "Initial Catalog=PetrolStation System;Server=(local)"
If conn.State <> 1 Then '如果數(shù)據(jù)庫沒有打開則打開數(shù)據(jù)庫
conn.Open (connstring)
End If
Set rs = conn.Execute("select * from PS_Users where 用戶='" & Trim(cmbUserName.Text) & "'")
' 在users數(shù)據(jù)表中檢索用戶字段值為用戶輸入的用戶名的記錄,將結(jié)果存放在rs記錄集中
If rs.EOF Then ' 如果記錄為空則說明不存在此條記錄,也說明用戶名錯(cuò)誤
MsgBox " 沒有該用戶!" & vbCrLf & " 請(qǐng)重新輸入!", vbOKOnly + vbExclamation, "提示"
cmbUserName.SetFocus
Exit Sub
Else '存在此用戶名,檢查密碼
rs.MoveFirst
If rs.Fields("密碼").Value = Trim(txtPWD.Text) Then '密碼正確
Unload frmLogin '卸載登錄窗口
Load frmMain '加載主窗口
frmMain.Show '顯示主窗口
Else '密碼錯(cuò)誤
If num < 2 Then '輸入錯(cuò)誤次數(shù)不足三次
num = num + 1 '錯(cuò)誤次數(shù)加1
MsgBox "口令不對(duì),請(qǐng)重輸!" & vbCrLf & " 您還有" & Str(3 - num) & "次機(jī)會(huì)!", _
vbOKOnly + vbExclamation, "提示" '提示錯(cuò)誤
txtPWD.SetFocus
Exit Sub
Else '輸入錯(cuò)誤打到3次,提示后退出系統(tǒng)
MsgBox "對(duì)不起,您無權(quán)使用本系統(tǒng)!", vbOKOnly + vbExclamation, "提示"
Unload frmLogin
Exit Sub
End If
End If
End If
conn.Close '關(guān)閉數(shù)據(jù)庫連接
End Sub
Private Sub Form_Load()
connstring = "Provider=SQLOLEDB.1;Password=ecc;Persist Security Info=True;User ID=sa;" _
& "Initial Catalog=PetrolStation System;Server=(local)"
If conn.State <> 1 Then '如果數(shù)據(jù)庫未打開,則打開數(shù)據(jù)庫
conn.Open (connstring)
End If
Set rs = conn.Execute("select * from PS_Users") '執(zhí)行查詢操作,結(jié)果保存在rs記錄集中
With rs
.MoveFirst
Do While Not .EOF ' 逐條讀取用戶名稱,添加到cmbUserName組合框中
DoEvents
cmbUserName.AddItem (!用戶)
.MoveNext
Loop
End With
cmbUserName.ListIndex = 0 '將cmbUserName組合框的默認(rèn)選項(xiàng)設(shè)置為第一條
conn.Close
End Sub
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -