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

📄 login.vb

📁 VB.NET开发的计算机机房管理系统
💻 VB
字号:
Public Class Login
    Inherits System.Windows.Forms.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 BtLogin As System.Windows.Forms.Button
    Friend WithEvents BtCancel As System.Windows.Forms.Button
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents TxtPassword As System.Windows.Forms.TextBox
    Friend WithEvents TxtName As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.BtLogin = New System.Windows.Forms.Button
        Me.BtCancel = New System.Windows.Forms.Button
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.TxtName = New System.Windows.Forms.TextBox
        Me.TxtPassword = New System.Windows.Forms.TextBox
        Me.Label3 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'BtLogin
        '
        Me.BtLogin.Location = New System.Drawing.Point(80, 200)
        Me.BtLogin.Name = "BtLogin"
        Me.BtLogin.Size = New System.Drawing.Size(72, 32)
        Me.BtLogin.TabIndex = 0
        Me.BtLogin.Text = "登录"
        '
        'BtCancel
        '
        Me.BtCancel.Location = New System.Drawing.Point(216, 200)
        Me.BtCancel.Name = "BtCancel"
        Me.BtCancel.Size = New System.Drawing.Size(80, 32)
        Me.BtCancel.TabIndex = 1
        Me.BtCancel.Text = "取消"
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(72, 96)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(56, 24)
        Me.Label1.TabIndex = 2
        Me.Label1.Text = "用户名:"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(72, 152)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(48, 24)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "密码:"
        '
        'TxtName
        '
        Me.TxtName.Location = New System.Drawing.Point(168, 96)
        Me.TxtName.Name = "TxtName"
        Me.TxtName.Size = New System.Drawing.Size(120, 21)
        Me.TxtName.TabIndex = 4
        Me.TxtName.Text = ""
        '
        'TxtPassword
        '
        Me.TxtPassword.Location = New System.Drawing.Point(168, 152)
        Me.TxtPassword.Name = "TxtPassword"
        Me.TxtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.TxtPassword.Size = New System.Drawing.Size(120, 21)
        Me.TxtPassword.TabIndex = 5
        Me.TxtPassword.Text = ""
        '
        'Label3
        '
        Me.Label3.Font = New System.Drawing.Font("幼圆", 21.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.Desktop
        Me.Label3.Location = New System.Drawing.Point(48, 32)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(304, 40)
        Me.Label3.TabIndex = 6
        Me.Label3.Text = "计算机机房管理系统"
        '
        'Login
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
        Me.ClientSize = New System.Drawing.Size(384, 254)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.TxtPassword)
        Me.Controls.Add(Me.TxtName)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.BtCancel)
        Me.Controls.Add(Me.BtLogin)
        Me.MaximizeBox = False
        Me.Name = "Login"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "登录系统"
        Me.ResumeLayout(False)

    End Sub

#End Region


    Private Sub BtLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtLogin.Click
        Dim SQLString As String
        SQLString = "SELECT * FROM tbManager WHERE Name='" & TxtName.Text & "'"
        'SQL查询语句
        Dim ObjectdsDataSet As New DataSet()
        Dim oleconn As New OleDb.OleDbConnection(CONN) '定义数据库连接
        Dim adapter As New OleDb.OleDbDataAdapter() '定义数据库适配器
        adapter.TableMappings.Add("Table", "User")
        Dim cmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(SQLString, oleconn)
        cmd.CommandType = CommandType.Text
        adapter.SelectCommand = cmd
        If oleconn.State <> ConnectionState.Open Then
            oleconn.Open()   '打开数据库连接
        End If
        cmd.ExecuteNonQuery()
        If oleconn.State <> ConnectionState.Closed Then
            oleconn.Close()   '关闭数据库连接
        End If
        adapter.Fill(ObjectdsDataSet)
        If ObjectdsDataSet.Tables("User").Rows.Count = 0 Then    '判断用户是否存在
            MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Exclamation, Me.Text)
            Exit Sub
        End If
        If ObjectdsDataSet.Tables("User").Rows(0)("Pwd").ToString = TxtPassword.Text Then
            '判断用户密码是否正确
            ManagerName = Trim(TxtName.Text)
            Password = Trim(TxtPassword.Text)
            AddLog("登录系统")
            Dim Frmobj As New Form1()
            Frmobj.Show() '显示主窗体
            Me.Finalize()
        Else
            MsgBox("输入用户名或密码有误,请重试", MsgBoxStyle.Critical, Me.Text)
            Exit Sub
        End If
    End Sub


    Private Sub BtCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtCancel.Click
        End
    End Sub

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

    End Sub
End Class

⌨️ 快捷键说明

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