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

📄 login.vb

📁 详细介绍了系统的设计过程,对于初学者是一个不错的参考资料
💻 VB
字号:
Imports System.Data.OleDb
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 Label1 As System.Windows.Forms.Label
    Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
    Friend WithEvents Button2 As System.Windows.Forms.Button
    Friend WithEvents Button3 As System.Windows.Forms.Button
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label4 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.TextBox2 = New System.Windows.Forms.TextBox
        Me.Button2 = New System.Windows.Forms.Button
        Me.Button3 = New System.Windows.Forms.Button
        Me.Label2 = New System.Windows.Forms.Label
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Label3 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.Label4 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(8, 152)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 21)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "用户名:"
        '
        'TextBox2
        '
        Me.TextBox2.Location = New System.Drawing.Point(64, 185)
        Me.TextBox2.Name = "TextBox2"
        Me.TextBox2.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TextBox2.Size = New System.Drawing.Size(64, 21)
        Me.TextBox2.TabIndex = 3
        Me.TextBox2.Text = ""
        '
        'Button2
        '
        Me.Button2.Location = New System.Drawing.Point(152, 184)
        Me.Button2.Name = "Button2"
        Me.Button2.Size = New System.Drawing.Size(48, 23)
        Me.Button2.TabIndex = 4
        Me.Button2.Text = "确认"
        '
        'Button3
        '
        Me.Button3.Location = New System.Drawing.Point(224, 184)
        Me.Button3.Name = "Button3"
        Me.Button3.Size = New System.Drawing.Size(48, 23)
        Me.Button3.TabIndex = 5
        Me.Button3.Text = "退出 "
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(8, 189)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 23)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "口令:"
        '
        'ListView1
        '
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Top
        Me.ListView1.Location = New System.Drawing.Point(0, 0)
        Me.ListView1.MultiSelect = False
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(296, 136)
        Me.ListView1.TabIndex = 9
        Me.ListView1.View = System.Windows.Forms.View.Details
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(120, 152)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(64, 24)
        Me.Label3.TabIndex = 10
        Me.Label3.Text = "用户类型:"
        '
        'Label5
        '
        Me.Label5.BackColor = System.Drawing.Color.PeachPuff
        Me.Label5.Location = New System.Drawing.Point(184, 149)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(88, 18)
        Me.Label5.TabIndex = 12
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.Color.PeachPuff
        Me.Label4.Location = New System.Drawing.Point(64, 149)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(48, 18)
        Me.Label4.TabIndex = 11
        '
        'login
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(296, 221)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.ListView1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Button3)
        Me.Controls.Add(Me.Button2)
        Me.Controls.Add(Me.TextBox2)
        Me.Controls.Add(Me.Label1)
        Me.Location = New System.Drawing.Point(800, 800)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "login"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "登陆"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If Trim(GetPsw(Trim(Me.Label4.Text))) = Trim(Me.TextBox2.Text) Then
            Dim mf As New FrmMain(Label4.Text, Label5.Text)
            mf.Show()
            Me.Hide()
        Else
            MsgBox("密码错误,请重新输入!")
        End If
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()

    End Sub
    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        GetUser()
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If (ListView1.SelectedItems.Count > 0) Then
            Me.Label4.Text = ListView1.SelectedItems(0).Text
            Me.Label5.Text = ListView1.SelectedItems(0).SubItems(1).Text
        End If
    End Sub

    Private Sub GetUser()
        Dim connstr As New String("provider=SQLOLEDB.1;User ID=sa;PassWord=110;Persist Security Info=false;Initial Catalog=wage;Data Source=.;")
        Dim Cn As New OleDbConnection
        Dim searchSql As String
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader

        searchSql = "select * from 用户信息表"
        ' 定义两个数据列
        ListView1.View = View.Details
        ListView1.Columns.Add("用户名", 100, HorizontalAlignment.Left)
        ListView1.Columns.Add("用户类型", 100, HorizontalAlignment.Left)
        Try

            Cn.ConnectionString = connstr
            Cn.Open()
            cmd = New OleDbCommand(searchSql, Cn)
            dr = cmd.ExecuteReader()
            Dim i As Integer = 0
            Do While dr.Read()
                ListView1.Items.Add(dr.GetString(0))
                If dr.GetInt32(2) = 1 Then
                    ListView1.Items(i).SubItems.Add("系统用户")
                Else
                    ListView1.Items(i).SubItems.Add("普通用户")
                End If
                i = i + 1
            Loop
            dr.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Cn.Dispose()
        cmd.Dispose()
    End Sub

    Private Function GetPsw(ByVal PassWord As String)
        Dim connstr As New String("provider=SQLOLEDB.1;User ID=sa;PassWord=110;Persist Security Info=false;Initial Catalog=wage;Data Source=.;")
        Dim Cn As New OleDbConnection
        Dim searchSql As String
        Dim cmd As OleDbCommand
        Dim dr As OleDbDataReader

        searchSql = "select * from 用户信息表 where 用户名='" & PassWord & "'"
        Try

            Cn.ConnectionString = connstr
            Cn.Open()
            cmd = New OleDbCommand(searchSql, Cn)
            dr = cmd.ExecuteReader()
            Do While dr.Read()
                Return Trim(dr.GetString(1))
            Loop
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Function
End Class

⌨️ 快捷键说明

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