Beispiel #1
0
        private void btnLog_Click(object sender, EventArgs e)
        {
            try
            {
                userName = txtUser.Text; // Gets the Username from Text Box
                password = txtPass.Text; // Gets Password from Text box

                if (userName.Equals(""))
                {
                    MessageBox.Show("Please enter Username");
                }
                else
                {
                    if (password.Equals(""))
                    {
                        MessageBox.Show("Please enter Password");
                    }
                    else
                    {
                        try// runs through the code unless exception is thrown
                        {
                            CheckExisting();

                            if (found == false)
                            {
                                MessageBox.Show("Cannot find user is system, please check username or register account");
                            }
                            else
                            {
                                if (found == true)
                                {
                                    CheckValid();

                                    if (checkValid == true)
                                    {
                                        frmMenu mnu = new frmMenu();

                                        this.Hide();
                                        mnu.Show();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Invalid password entered. Please Try Again");
                                    }
                                }
                            }
                        }
                        catch (IOException ex)
                        {
                            MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                        }

                        catch (ArgumentOutOfRangeException ex)
                        {
                            MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                        }

                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
                        }
                    }
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show("Error Cannot Login: " + ex.Message); // Shows an error message
            }
        }