📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form Frmlogin
BorderStyle = 1 'Fixed Single
Caption = "身份验证"
ClientHeight = 3120
ClientLeft = 45
ClientTop = 405
ClientWidth = 4680
ControlBox = 0 'False
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3120
ScaleWidth = 4680
StartUpPosition = 2 '屏幕中心
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = ""
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 375
Left = 1320
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = ""
Top = 0
Visible = 0 'False
Width = 2295
End
Begin VB.Frame Frame1
Height = 2055
Left = 480
TabIndex = 2
Top = 240
Width = 3855
Begin VB.ComboBox txtUser
DataSource = "Data1"
Height = 300
Left = 1440
TabIndex = 6
Top = 360
Width = 1815
End
Begin VB.TextBox txtPwd
Height = 495
IMEMode = 3 'DISABLE
Left = 1440
PasswordChar = "*"
TabIndex = 5
Top = 1200
Width = 1815
End
Begin VB.Label Label2
Caption = "密码:"
Height = 495
Left = 240
TabIndex = 4
Top = 1200
Width = 855
End
Begin VB.Label Label1
Caption = "用户名:"
Height = 495
Left = 360
TabIndex = 3
Top = 360
Width = 975
End
End
Begin VB.CommandButton Cmd_Cancel
Caption = "取消"
Height = 495
Left = 2520
TabIndex = 1
Top = 2400
Width = 1215
End
Begin VB.CommandButton Cmd_OK
Caption = "确定"
Height = 495
Left = 840
TabIndex = 0
Top = 2400
Width = 1215
End
End
Attribute VB_Name = "Frmlogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Public Try_times As Integer
Private Sub cmd_cancel_Click()
Unload Me
End Sub
Private Sub cmd_OK_Click()
Dim mystr As String
Dim response As String
Dim response1 As String
If txtUser.Text = "" Or txtPwd.Text = "" Then
response1 = MsgBox("请将用户名和密码填写完整!", vbExclamation, "警告")
'Call txtUser_Click
Exit Sub
End If
Data1.Recordset.MoveFirst
Data1.Refresh
Do While Not Data1.Recordset.EOF
If Trim(Data1.Recordset.Fields("UserName")) = Trim(txtUser.Text) Then
If Trim(Data1.Recordset.Fields("UserPwd")) = Trim(txtPwd.Text) Then
Unload Me
' MsgBox "连接成功", 0 + 48, "提示"
FrmMain.Show
Load FrmMain
Exit Sub
'Mainfrm.Show
' Load safrm
'safrm.Show
Else
response = MsgBox("密码错误!", vbExclamation, "警告")
txtPwd.Text = ""
txtPwd.SetFocus
Exit Sub
End If
Else
Data1.Recordset.MoveNext
End If
'MsgBox "无此用户", 0 + 48, "警告"
Loop
response1 = MsgBox("无此用户!", vbExclamation, "警告")
txtUser.Text = ""
txtPwd.Text = ""
txtUser.SetFocus
End Sub
Private Sub Form_Load()
Dim dbname As String
Dim sql As String
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "student_MG.mdb"
Data1.DatabaseName = dbname
sql = "select * from " & "Users"
Data1.RecordSource = sql
connStr = "provider=microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\student_MG.mdb;"
inituser
'txtUser.Text = ""
'Data1.Refresh
'Data1.Recordset.MoveFirst
'Data1.Recordset.Edit
End Sub
'Private Sub txtUser_Click()
'Set txtUser.Container = Frame1
'txtUser.SetFocus
'End Sub
Private Sub txtPwd_click()
'Set txtPwd.Container = Frame1
txtPwd.SetFocus
End Sub
Private Sub txtPwd_KeyPress(KeyAscii As Integer)
If KeyAscii = Asc(vbCr) Then
KeyAscii = 0
Call cmd_OK_Click
End If
End Sub
Sub inituser()
Dim rstuser As ADODB.Recordset
sqlStr = "select UserName from Users"
Set rstuser = executesql(sqlStr, msgText)
txtUser.Clear
If Not rstuser.EOF Then
Do While Not rstuser.EOF
txtUser.AddItem Trim(rstuser.Fields(0))
rstuser.MoveNext
Loop
txtUser.ListIndex = 0
Else
MsgBox "不存在用户", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
rstuser.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -