📄 frmlogin.frm
字号:
VERSION 5.00
Begin VB.Form frmLogin
Caption = "用户登陆"
ClientHeight = 3345
ClientLeft = 60
ClientTop = 465
ClientWidth = 5115
LinkTopic = "Form1"
ScaleHeight = 3345
ScaleWidth = 5115
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton Command3
Caption = "新用户"
Height = 495
Left = 3600
TabIndex = 7
Top = 1680
Width = 1215
End
Begin VB.CommandButton Command2
Caption = "取消"
Height = 495
Left = 3600
TabIndex = 6
Top = 1080
Width = 1215
End
Begin VB.CommandButton Command1
Caption = "确定"
Height = 495
Left = 3600
TabIndex = 5
Top = 480
Width = 1215
End
Begin VB.Frame Frame1
Caption = "登陆"
Height = 1815
Left = 120
TabIndex = 0
Top = 360
Width = 3135
Begin VB.TextBox Text2
Height = 375
IMEMode = 3 'DISABLE
Left = 1200
PasswordChar = "*"
TabIndex = 4
Top = 840
Width = 1575
End
Begin VB.TextBox Text1
Height = 375
Left = 1200
TabIndex = 3
Top = 360
Width = 1575
End
Begin VB.Label Label2
Caption = "密码"
Height = 495
Left = 240
TabIndex = 2
Top = 960
Width = 855
End
Begin VB.Label Label1
Caption = "用户名"
Height = 375
Left = 240
TabIndex = 1
Top = 480
Width = 855
End
End
End
Attribute VB_Name = "frmlogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim rs_user As New ADODB.Recordset
Private Sub Command1_Click()
'首先检查用户是否输入了用户名和密码
If Text1.Text = "" Then
MsgBox "请输入用户名!", vbOKOnly + vbInformation, "注意"
Text1.SetFocus
Exit Sub
ElseIf Text2.Text = "" Then
MsgBox "请输入密码!", vbOKOnly + vbInformation, "注意"
Text2.SetFocus
Exit Sub
End If
Dim sqluser As String
'构造查询该用户名和密码的sql语句
sqluser = "select * from sjk where 用户名 = '" & Text1.Text _
& "' and 密码 = '" & Text2.Text & "'"
rs_user.CursorLocation = adUseClient
'打开数据游标
rs_user.open sqluser, conn, adLockPessimistic
If rs_user.EOF = True Then
MsgBox "用户名和密码不正确!", vbOKOnly + vbInformation, "注意"
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
rs_user.Close
Exit Sub
Else
'提示用户登录成功并关闭游标和登录窗口
MsgBox "登录成功!", vbOKOnly + vbInformation, "注意"
rs_user.Close
Unload Me
frmMain.Show
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub Command3_Click()
Unload Me
frmAddUser.Show
End Sub
Private Sub Form_Load()
Dim strCnn As String '定义一个连接串变量
Dim X0 As Long
Dim Y0 As Long
'让窗体居中
X0 = Screen.Width
Y0 = Screen.Height
X0 = (X0 - Me.Width) / 2
Y0 = (Y0 - Me.Height) / 2
Me.Move X0, Y0
' 在窗体中打开对数据库的连接
strCnn = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Sjk"
conn.open strCnn
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -