Пример #1
0
        private void Login()
        {
            //Check input isn't empty, else error message is shown
            if (usernameBox.TextLength > 0 && passwordBox.TextLength > 0)
            {
                //Sends input to login function, if input is good, sends user to main menu
                //Else error message is shown
                var result = NetworkClasses.Login(usernameBox.Lines[0], passwordBox.Lines[0],
                                                  Helpers.GetLocalIpAddress());
                if (result == "good" || result == "online")
                {
                    NetworkClasses.UpdateUserValue("User_List", "Online", "Online", User.PlayerId);
                    Form form = new MainMenuForm();
                    form.Show();
                    Dispose();
                }
                else if (result == "pass" || result == "user")
                {
                    MessageBox.Show("Invalid Username/Password", "Login error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }

                /*else if (result == "online")
                 * {
                 *  MessageBox.Show("User already logged in", "Login error", MessageBoxButtons.OK,
                 *      MessageBoxIcon.Error);
                 * }*/
            }
            else
            {
                MessageBox.Show("Username and password cannot be blank.", "Login error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// On click, queries the database to check if user exsits, and input is correct
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void loginButton_Click(object sender, EventArgs e)
        {
            //Check input isn't empty, else error message is shown
            if (usernameBox.TextLength > 0 && passwordBox.TextLength > 0)
            {
                //Hide existing error label, if any
                errorLabel.Hide();

                //Sends input to login function, if input is good, sends user to main menu
                //Else error message is shown
                if (NetworkClasses.Login(usernameBox.Lines[0], passwordBox.Lines[0], Helpers.GetLocalIpAddress()))
                {
                    Form form = new MainMenuForm();
                    form.Show();
                    Dispose();
                }
                else
                {
                    errorLabel.Text = "Invalid Username/Password";
                    errorLabel.Show();
                }
            }
            else
            {
                errorLabel.Text = "Username/Password cannot be blank.";
                errorLabel.Show();
            }
        }