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

📄 login.vb

📁 Beginning VB.NET DatabasesAll_Code.rar
💻 VB
字号:
Public Class Login
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents txtLoginName As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtPassword As System.Windows.Forms.TextBox
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents btnCancel As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Label1 = New System.Windows.Forms.Label
        Me.txtLoginName = New System.Windows.Forms.TextBox
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtPassword = New System.Windows.Forms.TextBox
        Me.btnOK = New System.Windows.Forms.Button
        Me.btnCancel = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(24, 24)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(64, 20)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "User Name"
        '
        'txtLoginName
        '
        Me.txtLoginName.Location = New System.Drawing.Point(96, 24)
        Me.txtLoginName.Name = "txtLoginName"
        Me.txtLoginName.Size = New System.Drawing.Size(152, 20)
        Me.txtLoginName.TabIndex = 1
        Me.txtLoginName.Text = ""
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(24, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(64, 20)
        Me.Label2.TabIndex = 2
        Me.Label2.Text = "Password"
        '
        'txtPassword
        '
        Me.txtPassword.Location = New System.Drawing.Point(96, 48)
        Me.txtPassword.Name = "txtPassword"
        Me.txtPassword.PasswordChar = Microsoft.VisualBasic.ChrW(42)
        Me.txtPassword.Size = New System.Drawing.Size(152, 20)
        Me.txtPassword.TabIndex = 3
        Me.txtPassword.Text = ""
        '
        'btnOK
        '
        Me.btnOK.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.btnOK.Location = New System.Drawing.Point(96, 80)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.TabIndex = 4
        Me.btnOK.Text = "OK"
        '
        'btnCancel
        '
        Me.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.btnCancel.Location = New System.Drawing.Point(176, 80)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.TabIndex = 5
        Me.btnCancel.Text = "Cancel"
        '
        'Login
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(266, 119)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.txtPassword)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtLoginName)
        Me.Controls.Add(Me.Label1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Login"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Time Tracker Login"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private intAttemptCount As Integer = 0
    Private blnAllowClosing As Boolean = False

    Private Sub btnOK_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnOK.Click
        'Initialize a new instance of the business logic component
        Dim objUsers As New WroxBusinessLogic.WBLUsers("Wrox", "Time Tracker")
        'Validate the user and get their role
        Dim objDataSet As DataSet = objUsers.ValidateLogin( _
            txtLoginName.Text, txtPassword.Text)
        If objDataSet.Tables("User").Rows.Count > 0 Then
            If objDataSet.Tables("User").Rows(0).Item("Status") Then
                g_strUserRole = objDataSet.Tables("User").Rows(0).Item( _
                    "RoleName")
                g_strUserID = objDataSet.Tables("User").Rows(0).Item( _
                    "UserID").ToString
                g_strUserName = objDataSet.Tables("User").Rows(0).Item( _
                    "UserName").ToString
            Else
                MessageBox.Show("Your account has been suspended." & _
                    ControlChars.CrLf & "Please contact your administrator.", _
                   "Time Tracker", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
            blnAllowClosing = True
        Else
            MessageBox.Show("Your credentials were not validated.", _
                "Time Tracker", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If
        'Clean up
        objDataSet.Dispose()
        objDataSet = Nothing
        objUsers.Dispose()
        objUsers = Nothing
        'Increment attempt count
        intAttemptCount += 1
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles btnCancel.Click
        blnAllowClosing = True
        Me.Close()
    End Sub

    Private Sub Login_Closing(ByVal sender As Object, _
        ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If Not blnAllowClosing Then
            If intAttemptCount < 3 Then
                e.Cancel = True
            End If
        End If
    End Sub

    Private Sub txtPassword_KeyUp(ByVal sender As Object, _
        ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyUp
        If e.KeyCode = Keys.Enter Then
            Call btnOK_Click(sender, e)
        End If
        If blnAllowClosing Then
            Me.Close()
        End If
    End Sub

End Class

⌨️ 快捷键说明

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