📄 frmlogon.frm
字号:
VERSION 5.00
Begin VB.Form frmLogon
BorderStyle = 1 'Fixed Single
Caption = "登录"
ClientHeight = 3195
ClientLeft = 45
ClientTop = 330
ClientWidth = 4680
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H8000000C&
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 3 '窗口缺省
Begin VB.Data Data1
Caption = "Data1"
Connect = "Access"
DatabaseName = "F:\作业\作业\database2.mdb"
DefaultCursorType= 0 '缺省游标
DefaultType = 2 '使用 ODBC
Exclusive = 0 'False
Height = 345
Left = 600
Options = 0
ReadOnly = 0 'False
RecordsetType = 1 'Dynaset
RecordSource = "User"
Top = 2040
Visible = 0 'False
Width = 3375
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "取 消"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 1
Left = 2760
MaskColor = &H8000000F&
Style = 1 'Graphical
TabIndex = 6
Top = 2520
Width = 1215
End
Begin VB.CommandButton cmdOK
Caption = "确 定"
BeginProperty Font
Name = "仿宋_GB2312"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 0
Left = 600
MaskColor = &H80000012&
Style = 1 'Graphical
TabIndex = 5
Top = 2520
Width = 1215
End
Begin VB.TextBox Text2
Height = 375
IMEMode = 3 'DISABLE
Index = 0
Left = 1920
PasswordChar = "*"
TabIndex = 4
Top = 1560
Width = 1935
End
Begin VB.TextBox Text1
Height = 375
IMEMode = 3 'DISABLE
Index = 1
Left = 1920
TabIndex = 3
Top = 840
Width = 1935
End
Begin VB.Label lblPassword
Caption = "密码"
BeginProperty Font
Name = "隶书"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 255
Index = 1
Left = 720
TabIndex = 2
Top = 1560
Width = 735
End
Begin VB.Label lblUserName
Caption = "用户名"
BeginProperty Font
Name = "隶书"
Size = 10.5
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ForeColor = &H00000000&
Height = 255
Index = 0
Left = 720
TabIndex = 1
Top = 840
Width = 735
End
Begin VB.Label lblInstruction
Caption = "请输入您的用户名和口令"
BeginProperty Font
Name = "隶书"
Size = 12
Charset = 134
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 720
TabIndex = 0
Top = 240
Width = 2895
End
End
Attribute VB_Name = "frmLogon"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim db As Database
Dim rs As Recordset
Dim connect As ADODB.Connection
Dim login_rs As ADODB.Recordset '定义一个Recordset对象的变量
Dim user_power As Integer
Dim connect_string As String
Private Sub cmdCancel_Click(Index As Integer)
End
End Sub
Private Sub Label1_Click()
If txtUserName.Text <> "" And txtPassword.Text <> "" Then
cmdOK.Enabled = ture
Else
cmdOK.Enable = False
End If
End Sub
Private Sub cmdOK_Click(Index As Integer)
Dim local_sql As String '定义SQL语句的变量
Dim user_name As String '定义用户名变量
Dim password As String '定义确认的密码变量
'Set db = OpenDatabase(App.Path + "/database2.mdb")
'Set rs = db.OpenRecordset("user")
'连接Access数据库
'Set login_rs = New ADODB.Recordset
'login_rs.ActiveConnection = connect
'查找用户名
user_name = Text1(1).Text
password = Text2(0).Text
data1.RecordSource = "select * from user where UID='" & user_name & "'"
data1.Refresh
If data1.Recordset.RecordCount = 0 Then
MsgBox ("用户名错误!")
Text1(1).Text = ""
Text2(0).Text = ""
Else
'Text1(1).Text <> "" And Text2(0).Text <> "" And
If password = data1.Recordset.Fields("PWD") Then
user_power = data1.Recordset.Fields("Power")
Load Form4 '装载MDIForm1窗体
Form4.Show '显示MIForm4窗体
Unload Me
Else
MsgBox ("用户密码错误!")
Text1(1).Text = ""
Text2(0).Text = ""
End If
End If
' rs.Open local_sql, connect, adOpenForwardOnly, adLockReadOnly
'If rs.EOF Then '系统中无此用户
'MsgBox "用户名或密码错误!", vbCritical, "用户登录"
'用户名、密码置空
'Text1(1).Text = ""
'Text2(0).Text = ""
'Text1(1).SetFocus
' Else
'系统中有此用户
'rs.MoveFirst
'If rs.Fields("UID").Value = user_name And rs.Fields("PWD").Value = password Then
' user_power = rs.Fields("Power").Value '取出用户权限
'Load Form1 '装载MDIForm1窗体
'Form1.Show '显示MDIForm1窗体
'End If
'End If
'If Not rs.EOF Then '系统中有此用户
'rs.Close '关闭打开的数据库
' Set rs = Nothing
' connect.Close
' Set connect = Nothing
'Unload frmLogon
'Else
' rs.Close
' Set rs = Nothing
' End If
End Sub
Private Sub Form_Load()
frmLogon.Show
'连接Access数据库
'Set connect = New ADODB.Connection
'connect.ConnectionString = "dsn=chen;"
'connect.Open
'Set db = OpenDatabase(App.Path + "/database2.mdb")
'Set rs = db.OpenRecordset("user")
Text1(1).Text = ""
Text2(0).Text = ""
data1.DatabaseName = App.Path & "/database2.mdb"
Text1(1).SetFocus
End Sub
Private Sub lblInstruction_Click()
If txtUserName.Text <> "" And txtPassword.Text <> "" Then
cmdOK.Enabled = True
Else
cmdOK.Enable = False
End If
End Sub
Private Sub Text1_Change(KeyCode As Integer)
If KeyCode = vbKeyReturn Then Text2(0).SetFocus
End Sub
Private Sub Text2_Change(KeyCode As Integer)
If KeyCode = vbKeyReturn Then cmdOK(0).SetFocus
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -