public int formGoodText()
        {
            // textbox array is created which holds all the text boxes to fill in on the form
            TextBox[] formText = { txt_sDateOfBirth, txt_sNumber,
                                   txt_sGrade,       txt_sPNumber, txt_sAddressHome,txt_sEmailAddress,
                                   txt_sFirstName,   txt_sLastName,
                                   txt_sParentName,  txt_sPass,    };

            // for loop which goes through the arrays and checks the text boxes
            for (int i = 0; i < formText.Length; i++)
            {
                // if the text box is empty
                if (formText[i].Text == "")
                {
                    // returns 1
                    return(1);
                }
            }

            // for loop which goes through the entries to see if the entries required to be integer are integer or not
            for (int i = 0; i < 3; i++)
            {
                // if it does not pass the try parse test
                if (!Config.TryToParse(formText[i].Text))
                {
                    // returns 2
                    return(2);
                }
            }

            // returns 0 if everything is fine
            return(0);
        }
Пример #2
0
        /// <summary>
        /// This method checks to see if correct information is entered
        /// </summary>
        /// <returns></returns>
        private Boolean infoIsCorrect()
        {
            // text box is created which goes through all the textboxes on the form
            TextBox[] formTxtBoxes = { txt_cAp,        txt_cComm, txt_cCulm,    txt_cExam,
                                       txt_cID,        txt_cKU,   txt_cTeacher, txt_cTI,
                                       txt_CourseRoom, txt_cCode };

            // for loop which goes through the textboxes
            for (int i = 0; i < formTxtBoxes.Length; i++)
            {
                // if the textboxes are empty or have a null value
                if (formTxtBoxes[i].Text == null || formTxtBoxes[i].Text == "")
                {
                    // false is returned
                    return(false);
                }
            }

            // for loop which goes through the the textboxes
            for (int i = 0; i < formTxtBoxes.Length - 1; i++)
            {
                // if textboxes parsed are not integers
                if (!Config.TryToParse(formTxtBoxes[i].Text))
                {
                    // false is returned
                    return(false);
                }
            }

            // true is returned
            return(true);
        }
        private void bttn_NewTeacher_Click(object sender, EventArgs e)
        {
            // if the email contains the character '@'
            if (txt_tEmail.Text.Contains('@') && (Config.TryToParse(txt_tNumber.Text)))
            {
                // for loop which goes through the courses per teacher
                for (int i = 0; i < Config.MAX_COURSES_PER_TEACHER; i++)
                {
                    // assigns the value "0" to each index
                    tCourses[i] = "0";
                }

                // variable created to return for try parse
                int retComp;

                // if the try parse is successful
                if (Int32.TryParse(txt_tNumber.Text, out retComp))
                {
                    // adds teacher information to the database
                    DatabaseConnection.insertTeacher(retComp, txt_tFirstName.Text,
                                                     txt_tLastName.Text, txt_tPass.Text, txt_tEmail.Text, tCourses);


                    txt_tNumber.Text    = "";
                    txt_tLastName.Text  = "";
                    txt_tFirstName.Text = "";
                    txt_tEmail.Text     = "";
                    txt_tPass.Text      = "";

                    MessageBox.Show("Teacher saved successfully!");
                }
            }
            else
            {
                MessageBox.Show("INVALID TEXT ENTERED");
            }
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            // Role depending on teacher, principal or student
            int userRole = 0;

            // Adds one to try added to log on
            tries++;


            // try parses to check if input is integer
            if (Config.TryToParse(txt_Username.Text))
            {
                // if student radio button is checked
                if (rdb_student.Checked == true)
                {
                    // user role 1 is selected
                    userRole = 1;
                }

                // if teacher radio button is checked
                if (rdb_teacher.Checked == true)
                {
                    // user role 2 is selected for teacher
                    userRole = 2;
                }

                // if principal radio button is checked
                if (rdb_principal.Checked == true)
                {
                    // user role 3 is selected for principal
                    userRole = 3;
                }
            }
            else
            {
                // Message box is shown telling about incorrect login
                MessageBox.Show("Please enter your username in the correct format!",
                                "Invalid Login", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                // Resetting text box for user name
                txt_Username.Text = "";

                // Resetting text box for password
                txt_Password.Text = "";
            }

            // Switch case for user role
            switch (userRole)
            {
            // if case 1
            case 1:
                prgbarLoadingLogin.Value  = 0;
                prgbarLoadingLogin.Value += 2;      // progress bar increased by 1

                // if user input is correct
                if (DatabaseConnection.checkUser(txt_Username.Text, txt_Password.Text, 0))
                {
                    // progress bar increased by 1
                    prgbarLoadingLogin.Value += 2;

                    // Student profile is loaded
                    frmStudentProfile sForm = new frmStudentProfile();
                    prgbarLoadingLogin.Value += 2;
                    // Activates student profile form
                    sForm.Activate();

                    // Progress bar increased by 1
                    prgbarLoadingLogin.Value += 2;

                    // Temporarily sets the config file as this student so it can be shared between the classes
                    Config.setStudent(DatabaseConnection.loadStudent(txt_Username.Text));

                    // Progress bar increased by 1
                    prgbarLoadingLogin.Value += 2;

                    // Message box showing successful logon
                    MessageBox.Show("Successfully Logged In");
                    // Student Profile form shown
                    sForm.Show();



                    // Hides logon on form
                    this.Hide();

                    Config.userRole = 1;     // user role is set to 1
                }
                else
                {
                    // Message box is shown login failed
                    MessageBox.Show("Login Failed");
                    // If login tries is above 3
                    if (tries > 3)
                    {
                        // Application is exited
                        Application.Exit();
                    }
                }
                // leaves case
                break;

            // if case 2
            case 2:
                prgbarLoadingLogin.Value  = 0;
                prgbarLoadingLogin.Value += 2;
                // if user input is correct
                if (DatabaseConnection.checkUser(txt_Username.Text, txt_Password.Text, 1))
                {
                    // gets teacher information
                    Teacher getTeacher = DatabaseConnection.getTeacher(Convert.ToInt32(txt_Username.Text));
                    prgbarLoadingLogin.Value += 2;

                    // Sets teacher info
                    Config.setTTeacher(getTeacher);
                    prgbarLoadingLogin.Value += 2;

                    // teacher profile is loaded
                    frmTeacherProfile fTP = new frmTeacherProfile();

                    prgbarLoadingLogin.Value += 2;
                    // teacher profile is activated

                    fTP.Activate();
                    prgbarLoadingLogin.Value += 2;

                    // login screen is hidden
                    this.Hide();

                    // shows teacher profile
                    fTP.Show();

                    Config.userRole = 2;      // user role is set to 2
                }
                else
                {
                    // if login fails shows message box showing so
                    MessageBox.Show("Login Failed");
                    // if tries to login exceeds 3
                    if (tries > 3)
                    {
                        // program is exitted
                        Application.Exit();
                    }
                }

                break;

            // if case 3
            case 3:
                prgbarLoadingLogin.Value  = 0;
                prgbarLoadingLogin.Value += 4;
                // checks to see if user input for principal is correct
                if (DatabaseConnection.checkUser(txt_Username.Text, txt_Password.Text, 2))
                {
                    // principal panel is loaded
                    prgbarLoadingLogin.Value += 2;
                    frmPrincipalPanel pP = new frmPrincipalPanel();

                    prgbarLoadingLogin.Value += 2;
                    // principal panel is activated
                    pP.Activate();

                    prgbarLoadingLogin.Value += 2;
                    // principal panel is shown
                    pP.Show();

                    // login screen is hidden
                    this.Hide();

                    Config.userRole = 3;
                    // Eser role 3 is set
                }
                else
                {
                    // if login fails shows message box saying so
                    MessageBox.Show("Login Failed");
                    // if tries to login exceeds 3
                    if (tries > 3)
                    {
                        // program is exitted
                        Application.Exit();
                    }
                }

                break;
            }
        }