⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 login.vb

📁 图书管理系统
💻 VB
字号:
Imports System.Data.SqlClient
Public Class login
    Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    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 GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TextBox1 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()
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.ComboBox1 = New System.Windows.Forms.ComboBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button2 = New System.Windows.Forms.Button
        Me.GroupBox1.SuspendLayout()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.TextBox1)
        Me.GroupBox1.Controls.Add(Me.Label2)
        Me.GroupBox1.Controls.Add(Me.ComboBox1)
        Me.GroupBox1.Controls.Add(Me.Label1)
        Me.GroupBox1.Location = New System.Drawing.Point(40, 32)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(296, 152)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "管理员登陆"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(128, 88)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TextBox1.Size = New System.Drawing.Size(120, 21)
        Me.TextBox1.TabIndex = 3
        Me.TextBox1.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 88)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "密码"
        '
        'ComboBox1
        '
        Me.ComboBox1.Location = New System.Drawing.Point(128, 32)
        Me.ComboBox1.Name = "ComboBox1"
        Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
        Me.ComboBox1.TabIndex = 1
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 32)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "姓名"
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(80, 224)
        Me.Button1.Name = "Button1"
        Me.Button1.TabIndex = 1
        Me.Button1.Text = "登陆"
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(216, 224)
        Me.Button2.Name = "Button2"
        Me.Button2.TabIndex = 2
        Me.Button2.Text = "取消"
        '
        'login
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.BackColor = System.Drawing.SystemColors.ScrollBar
        Me.ClientSize = New System.Drawing.Size(394, 287)
        Me.ControlBox = False
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.Button1)
        Me.Controls.Add(Me.GroupBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "login"
        Me.Text = "欢迎登陆"
        Me.GroupBox1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '将管理员姓名读入到ComboBox1中
        'Dim mycon As New SqlConnection(constr)
        If mycon.State = ConnectionState.Closed Then
            mycon.Open()
        End If
        Dim myread As SqlDataReader
        Dim sqlstr As String = "select Name from Administrator"
        Dim mycom As New SqlCommand(sqlstr, mycon)
        myread = mycom.ExecuteReader
        '从数据阅读器中读数据到ComboBox1中,注意条件的判定
        While myread.Read
            ComboBox1.Items.Add(myread("Name"))
        End While
        ComboBox1.SelectedIndex = 0
        ad = ComboBox1.Text
        ComboBox1.Focus()
        mycon.Close()
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If Asc(e.KeyChar) = System.Windows.Forms.Keys.Enter Then
            Button1.PerformClick()
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        '登陆按钮的代码
        '首先验证输入数据的合法性
        If ComboBox1.Text = "" Or TextBox1.Text = "" Then
            MessageBox.Show("用户名或密码不能为空", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            Exit Sub
        End If
        If mycon.State = ConnectionState.Closed Then
            mycon.Open()
        End If
        '    Dim i As Integer
        '   Dim t As Integer = 3
        '  For i = 0 To 2
        Dim sqlstr As String = "select Count(*) from Administrator Where Name='" & ComboBox1.SelectedItem & "' and Password='" & TextBox1.Text & "'"
        Dim mycom As New SqlCommand(sqlstr, mycon)
        If mycom.ExecuteScalar <> 1 Then
            '  MessageBox.Show("恭喜你登陆成功!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information)
            ' If t <> i + 1 Then
            MessageBox.Show("密码错误!请重新输入!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            TextBox1.Text = ""
            ComboBox1.SelectedIndex = 0
            Exit Sub

        ' ElseIf t = i + 1 Then
        '    MessageBox.Show("你已经输入错误的密码三次,请下次登陆!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        '   Me.Close()
        '  Application.Exit() '这段代码不能执行成功,好好
        ' End If
        '  End If
        '       Next i
        Else
            MessageBox.Show("恭喜你登陆成功!", "提醒", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End If
        Me.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub

    Private Sub login_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -