VB登录界面设计代码
2006-05-26 12:34
441 查看
Option Explicit
'窗口始终在最前
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const HWND_TOPMOST& = -1
' 将窗口置于列表顶部,并位于任何最顶部窗口的前面
Public Const SWP_NOSIZE& = &H1
' 保持窗口大小
Public Const SWP_NOMOVE& = &H2
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim LoginSuccess(0 To 5)
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
If Me.DataCombo1.Text = "" Or Text1.Text = "" Then '当用户名或密码未填时,提示错误
MsgBox "Login Error!", vbInformation, Me.Caption
Text1.SetFocus
Exit Sub
End If
rs.Close
'查询出与用户名相同的记录
strSQL = "SELECT * FROM User_Table WHERE UserID='" & Me.DataCombo1.Text & "'"
rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly
If Text1.Text = rs.Fields("UserPWD").Value Then '如果密码与记录相同
Me.Hide
Form2.Show
LoginSuccess(0) = Me.DataCombo1.Text '用户名
LoginSuccess(1) = rs.Fields("UserLevel").Value '用户级别
LoginSuccess(2) = Format(Now, "YYYY-MM-DD HH:MM:SS") '登录时间
Else
MsgBox "Login Error!", vbInformation, Me.Caption
Text1.Text = ""
Text1.SetFocus
End If
Case 1
rs.Close
cnn.Close
Set cnn = Nothing
Set FormLogin = Nothing
End
End Select
End Sub
Private Sub DataCombo1_Change()
Text1.SetFocus
End Sub
Private Sub Form_Load()
'窗口位于最前,API
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
'引用 Microsoft ActiveX Data Objects 2.8 Library
'连接Access数据库
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
Dim cnnFile As String
cnnFile = "Data Source=" & App.Path & "/data.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123456789"
cnn.Open cnnFile
'查询用户表,并将用户名显示在DataCombo控件中
Set rs = New ADODB.Recordset
strSQL = "SELECT UserID FROM User_Table"
rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly 'Open table "User"
Set Me.DataCombo1.DataSource = rs
Set Me.DataCombo1.RowSource = rs
Me.DataCombo1.ListField = rs.Fields("UserID").Name
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
rs.Close
cnn.Close
Set cnn = Nothing
Set FormLogin = Nothing
End
End Sub
'窗口始终在最前
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const HWND_TOPMOST& = -1
' 将窗口置于列表顶部,并位于任何最顶部窗口的前面
Public Const SWP_NOSIZE& = &H1
' 保持窗口大小
Public Const SWP_NOMOVE& = &H2
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
Dim LoginSuccess(0 To 5)
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
If Me.DataCombo1.Text = "" Or Text1.Text = "" Then '当用户名或密码未填时,提示错误
MsgBox "Login Error!", vbInformation, Me.Caption
Text1.SetFocus
Exit Sub
End If
rs.Close
'查询出与用户名相同的记录
strSQL = "SELECT * FROM User_Table WHERE UserID='" & Me.DataCombo1.Text & "'"
rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly
If Text1.Text = rs.Fields("UserPWD").Value Then '如果密码与记录相同
Me.Hide
Form2.Show
LoginSuccess(0) = Me.DataCombo1.Text '用户名
LoginSuccess(1) = rs.Fields("UserLevel").Value '用户级别
LoginSuccess(2) = Format(Now, "YYYY-MM-DD HH:MM:SS") '登录时间
Else
MsgBox "Login Error!", vbInformation, Me.Caption
Text1.Text = ""
Text1.SetFocus
End If
Case 1
rs.Close
cnn.Close
Set cnn = Nothing
Set FormLogin = Nothing
End
End Select
End Sub
Private Sub DataCombo1_Change()
Text1.SetFocus
End Sub
Private Sub Form_Load()
'窗口位于最前,API
SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
'引用 Microsoft ActiveX Data Objects 2.8 Library
'连接Access数据库
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
Dim cnnFile As String
cnnFile = "Data Source=" & App.Path & "/data.mdb;Persist Security Info=False;Jet OLEDB:Database Password=123456789"
cnn.Open cnnFile
'查询用户表,并将用户名显示在DataCombo控件中
Set rs = New ADODB.Recordset
strSQL = "SELECT UserID FROM User_Table"
rs.Open strSQL, cnn, adOpenStatic, adLockReadOnly 'Open table "User"
Set Me.DataCombo1.DataSource = rs
Set Me.DataCombo1.RowSource = rs
Me.DataCombo1.ListField = rs.Fields("UserID").Name
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
rs.Close
cnn.Close
Set cnn = Nothing
Set FormLogin = Nothing
End
End Sub
相关文章推荐
- 在登录页面设计中输入密码错误后弹框提示并返回到登录界面的代码实现
- 在登录页面设计中输入密码错误后弹框提示并返回到登录界面的代码实现
- VB中设置登录界面的代码
- C#设计登录界面及代码
- C#登录成功提示和登录成功后进入新的窗口界面代码:
- QQ登录界面设计
- swing界面设计之登录注册界面
- 设计一个普通的登录界面,都需要了解哪些信息?
- DirectUI Skin++界面解决方案 界面设计 界面开发 软件UI界面开发 软件UI界面美术设计 界面编程 界面教程 Skin VC VB C# .net pb delphi c builder GUI
- Android界面设计的4种方式之二——在Java代码中控制UI界面
- 学生信息管理系统之第三篇登录界面java代码
- 巧妙设计一个mobile or pc 的登录界面
- 【Android】Android 登录界面设计和网络连接及验证登录
- E-TASK(4) 设计登录界面
- 登录界面设计
- WPF换肤之四:界面设计和代码设计分离
- 登录界面设计分享
- 设计简单登录界面(Java web)
- 不错的设计创意:给WEB程序员的登录界面!
- 毕业论文设计客户订单界面及代码(WinForm之间传递参数,公式的Sql计算方式)