Esempio n. 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            Hide();

            AdminConsole login = new AdminConsole();

            login.ShowDialog();

            this.Close();
        }
Esempio n. 2
0
        // Clicked when user decides they are ready to log in,
        // Will get username and password, use that to query database and check that username and password are correct.
        // A message box will be used to state whether or not we logged in successfully
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            string username = "", password = "";

            //It checks that the text boxes has something typed in it using a method
            bool hasText = checkTextBoxes();

            if (!hasText)
            {
                MessageBox.Show("Please make sure all fields have data.");
                comboBoxUserType.Focus();
                return;
            }

            //(1) GET the username and password from the text boxes, is good to put them in a try catch
            try
            {
                username = textBoxUserName.Text.Trim();
                password = textBoxPassword.Text.Trim();
            }
            catch
            {
                //Error message, more useful when you are storing numbers etc. into the database.
                MessageBox.Show("Username or Password given is in an incorrect format.");
                return;
            }

            //(2) SELECT statement getting all data from users, i.e. SELECT * FROM Users
            //(3) IF it returns some data, THEN check each username and password combination, ELSE There are no registered users
            string message = checkLogin(username, password, comboBoxUserType.Text.Trim());

            MessageBox.Show($"{message}");
            if (message.Substring(0, 7) == "Success")
            {
                Hide();
                //Depending on the user type opens one or other form
                switch (comboBoxUserType.Text)
                {
                case "Admins":
                    //InstructorsSchedulePage InstructorSchedule1 = new InstructorsSchedulePage(username, "Admins");
                    //InstructorSchedule1.ShowDialog();
                    //CarAssignationPage CarAssignationPage = new CarAssignationPage();
                    //CarAssignationPage.ShowDialog();
                    AdminConsole WeekResourceAvailability = new AdminConsole();
                    WeekResourceAvailability.ShowDialog();
                    break;

                case "Clients":
                    ClientConsole CustomerAppointment = new ClientConsole(username);
                    CustomerAppointment.ShowDialog();
                    break;

                case "Instructors":
                    InstructorConsole InstructorSchedule2 = new InstructorConsole(username);
                    InstructorSchedule2.ShowDialog();
                    break;

                default:
                    break;
                }
                Close();
            }

            //initialiseTextControls();
        }