📄 login.vb
字号:
Imports System
Imports System.Data
Imports System.Drawing
Imports System.Data.OleDb
Public Class Login
Inherits System.Windows.Forms.Form
Private UserID As String
Private Password As String
'定义窗体级全局变量账号和密码。
Private LoginSQLstr As String
''定义结构化查询语句。
Private Caption As String
'定义消息对话框中显示的消息标题。
Private Message As String
'定义消息对话框中显示的消息内容。
Private DR As DataRow
'定义一个数据行
Private MainForm As Form
'定义一个窗体
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Login))
Me.Label1 = New System.Windows.Forms.Label()
Me.Label2 = New System.Windows.Forms.Label()
Me.Label3 = New System.Windows.Forms.Label()
Me.TextBox1 = New System.Windows.Forms.TextBox()
Me.TextBox2 = New System.Windows.Forms.TextBox()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("华文行楷", 24.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.ForeColor = System.Drawing.Color.Blue
Me.Label1.Location = New System.Drawing.Point(8, 24)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(368, 56)
Me.Label1.TabIndex = 0
Me.Label1.Text = "全国高速公路收费系统"
Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label2
'
Me.Label2.Font = New System.Drawing.Font("隶书", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label2.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.Label2.Location = New System.Drawing.Point(72, 128)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 16)
Me.Label2.TabIndex = 1
Me.Label2.Text = "账号:"
Me.Label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'Label3
'
Me.Label3.Font = New System.Drawing.Font("隶书", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label3.ForeColor = System.Drawing.Color.FromArgb(CType(0, Byte), CType(0, Byte), CType(192, Byte))
Me.Label3.Location = New System.Drawing.Point(72, 173)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(64, 16)
Me.Label3.TabIndex = 2
Me.Label3.Text = "密码:"
Me.Label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
'
'TextBox1
'
Me.TextBox1.BackColor = System.Drawing.SystemColors.Info
Me.TextBox1.Location = New System.Drawing.Point(144, 128)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.Size = New System.Drawing.Size(128, 21)
Me.TextBox1.TabIndex = 3
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.BackColor = System.Drawing.SystemColors.Info
Me.TextBox2.Location = New System.Drawing.Point(144, 168)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
Me.TextBox2.Size = New System.Drawing.Size(128, 21)
Me.TextBox2.TabIndex = 4
Me.TextBox2.Text = ""
'
'Button1
'
Me.Button1.Font = New System.Drawing.Font("华文新魏", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button1.ForeColor = System.Drawing.Color.Blue
Me.Button1.Location = New System.Drawing.Point(128, 208)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(64, 24)
Me.Button1.TabIndex = 5
Me.Button1.Text = "登录"
'
'Button2
'
Me.Button2.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Button2.Font = New System.Drawing.Font("华文新魏", 10.5!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Button2.ForeColor = System.Drawing.Color.Blue
Me.Button2.Location = New System.Drawing.Point(208, 208)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(64, 24)
Me.Button2.TabIndex = 6
Me.Button2.Text = "取消"
'
'Login
'
Me.AcceptButton = Me.Button1
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.CancelButton = Me.Button2
Me.ClientSize = New System.Drawing.Size(384, 333)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.TextBox2, Me.TextBox1, Me.Label3, Me.Label2, Me.Label1})
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.MaximizeBox = False
Me.Name = "Login"
Me.Text = "登录高速公路收费系统"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
UserID = Me.TextBox1.Text.Trim
Password = Me.TextBox2.Text.Trim
If UserID = "" Then
MessageBox.Show("请首先输入您的账号,然后再进行登录。", "登录失败", _
MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
'如果账号为空则提醒用户输入账号
End If
'获取用户输入的账号和密码,并自动清除左右两边的空格。
LoginSQLstr = "SELECT * FROM Login WHERE User='" & UserID & " '"
'查询账号是否存在。
Message = "没有该账号,请检查您输入的账号,并请重新输入。"
Caption = "登录失败"
'定义没有该账号的消息
Call ConnToDB(LoginSQLstr, Message, Caption)
'调用模块中数据库访问函数来查询。
If IsError = False Then
'没有发生错误时继续进行二级验证。
Else
Me.TextBox1.Text = "" : Me.TextBox2.Text = ""
'清空两个文本框,为重新输入做准备。
Exit Sub
'退出子过程。
'发生错误时需要触发的事件。
End If
'错误处理
LoginSQLstr = "SELECT * FROM Login WHERE User='" & UserID & " 'AND Pwd='" & Password & " '"
'查询账号和密码是否一致。
Message = "对不起,您输入的密码与账号不一致,请您重新输入的密码。"
Caption = "登录失败"
'定义没有账号与密码不一致的消息
Call ConnToDB(LoginSQLstr, Message, Caption)
'调用模块中数据库访问函数来查询。
If IsError = False Then
DR = DS.Tables.Item(0).Rows.Item(0)
'逐行获取数据集中的数据记录
IsAdmin = DR.Item(2)
'获取是否是系统管理员
If IsAdmin = False Then
User = Me.TextBox1.Text
'如果不是系统管理员,则获取当前操作员的账号
Else
AdminId = Me.TextBox1.Text
'如果是系统管理员,则获取当前系统管理员的账号
End If
DS.Clear()
'没有发生错误时的需要触发的事件。
Else
Me.TextBox2.Text = ""
'清空密码文本框,准备重新输入密码。
Exit Sub
'退出子过程。
'发生错误时需要触发的事件。
End If
'错误处理
Me.Hide()
MainForm = New Form1()
MainForm.ShowDialog()
'打开收费主窗体,并隐藏登录窗体
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click
Me.Close()
'关闭本窗体
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -