我的登录表单不会加载我的主页 [英] My Login Form won't Load my main page

查看:73
本文介绍了我的登录表单不会加载我的主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接收正确的用户名和密码后,如何加载主页?当我尝试同时显示两种形式时?我正在尝试加载我的食品杂货表.

How can I get my main page to load after it receives the correct username and password? When I try both forms show up at the same time? I'm trying to get my Grocery Item Form to load.

Public Class LoginForm
    Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click

        'Call Login subroutine
        Main.Login(txtUsername.Text, txtPassword.Text)

        Try
            Main.Login(txtUsername.Text, txtPassword.Text)

        Catch ex As Exception
            MessageBox.Show("Incorrect password.")
        End Try

        If Main.blnLoggedIn Then

            'Display a thank you box to user
            MessageBox.Show("Thank you for logging in, " & txtUsername.Text, "Logged In.")

        End If


    End Sub



    Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
        'End the program
        Application.Exit()
    End Sub

    Private Sub LoginForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'The code that loads Grocery Item Form after Login Form receives correct password
        'Also, I've been using VS2015 for this course. Not sure if my code wasn't working
        'because it was from VS2012 or not.
        Me.Show()

        lblScanNumber.Show()
    End Sub
End Class


Module Main
    'Declare variable
    Friend basket As New GroceryBasket
    Friend blnLoggedIn As Boolean
    Dim arrUsernames() As String = {"Admin", "Clerk", "Manager"}
    Dim arrPasswords() As String = {"P@ssword", "pa$$word", "passwOrd"}

    'Declare subroutines
    Sub Login(username As String, password As String)

        blnLoggedIn = False

        If VerifyUsername(username) And VerifyPassword(password) Then

            'Find username index
            Dim userIndex As Integer

            For loopIndex = 0 To arrUsernames.Length - 1

                If arrUsernames(loopIndex) = username Then

                    userIndex = loopIndex

                    Exit For

                End If
            Next

            'Check to see if password matches
            If arrPasswords(userIndex) = password Then
                blnLoggedIn = True

            Else

                'Generate the exception
                Throw New LoginException

            End If

        End If

    End Sub

Public Class lblScanNumber
    Private Sub btnAddToBasket_Click(sender As Object, e As EventArgs) Handles btnAddToBasket.Click
        'Set control values for object
        Dim btnAddToBasket As New GroceryBasket




        'Set ScanNumber value
        txtScanNumber.Text =
            txtBrandName.Text.Substring(0, 3) & "1019"


    End Sub

    Private Sub lblScanNumber_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'The code that loads the GroceryItemForm
        Me.Show()
    End Sub

    Private Sub menuExt_Click(sender As Object, e As EventArgs) Handles menuExt.Click
        Close()
    End Sub

    Private Sub menuLoad_Click(sender As Object, e As EventArgs) Handles menuLoad.Click
        'Set the Load properties
        With OpenFileDialog1
            .Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
            .FilterIndex = 1
            .Title = "Grocery Basket"
        End With

        'Load if user clicks Load button
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResults.OK Then
            Try
                'Load from this path and name
                GroceryBasket.String = OpenFileDialog1.FileName
                Dim fileContents As String
                fileContents = My.Computer.FileSystem.ReadAllText(GroceryBasket.String)
            Catch ex As Exception
                MessageBox.Show(ex.Message, My.Application.Info.Title,
                                MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub SaveMenu_Click(sender As Object, e As EventArgs) Handles SaveMenu.Click
        'Setting the Save properties
        With SaveFileDialog1
            .DefaultExt = "txt"
            .FileName = GroceryBasket.String
            .Filter = "Text Documents (*.txt)|*.txt|All Files (*.*)|*.*"
            .FilterIndex = 1
            .OverwritePrompt = True
            .Title = "Grocery Basket"
        End With

        'Save if user clicks Save button
        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResults.OK Then
            Try

                'Save file and name
                GroceryBasket.String = SaveFileDialog1.FileName
                My.Computer.FileSystem.WriteAllText(GroceryBasket.String, txtBrandName.Text, False)
            Catch ex As Exception
                MessageBox.Show(ex.Message, My.Application.Info.Title,
                                MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End If
    End Sub

    Private Sub View_Click(sender As Object, e As EventArgs) Handles View.Click
        'Display items
        MessageBox.Show(cboAisle, txtScanNumber.Text, txtBrandName.Text)
    End Sub
End Class

推荐答案

你好,

我不知道这是否是一项家庭作业,因为这个话题受到老师的高度喜爱.

I don't know if this is a homework assignment because this topic is highly liked by teachers. 

但是,要获取客户端,只需使用Windows的内置安全性.

However, to get the client simply use the inbuild security of Windows. 

您可以通过enviromnent.username来获取用户

You can get then the user by enviromnent.username

https://msdn .microsoft.com/en-us/library/system.environment.username(v = vs.110).aspx


这篇关于我的登录表单不会加载我的主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆