/// <summary>
        /// Verifys that the user input data is valid.
        /// </summary>
        /// <returns>A boolean indicating whether the components
        /// have validated correctly or not.</returns>
        private bool ValidateForm()
        {
            bool isValid = true;
            //Lamda expression that compares an input to null data.
            //Returns true if the supplied input is null.
            Func <string, bool> compareString = s => s == "";

            ClassLibrary.CheckNameIsValid(TextBoxFirstNameValue, ErrorProvider);
            //Alternative to writing IF statements to improve readability.
            //isValid remains the same (in this case, TRUE) if the ErrorProvider
            //has no error set, otherwise it is set to false
            isValid = compareString(ErrorProvider.GetError(TextBoxFirstNameValue)) ? isValid : false;
            ClassLibrary.CheckNameIsValid(TextBoxLastNameValue, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxLastNameValue)) ? isValid : false;
            ClassLibrary.CheckEmailIsValid(TextBoxStaffEmailValue, ErrorProvider);
            isValid = compareString(ErrorProvider.GetError(TextBoxStaffEmailValue)) ? isValid : false;

            //Returns true if all components validate successfully
            return(isValid);
        }
        private void ButtonSendEmail_Click(object sender, EventArgs e)
        {
            ClassLibrary.CheckEmailIsValid(TextBoxEmail, ErrorProvider);

            //If the ErrorProvider has an error set, then display a message
            if (ErrorProvider.GetError(TextBoxEmail) != "")
            {
                MyMessageBox.ShowMessage("Not all components validated successfully. Please check the flagged entries and try again.");
                return;
            }
            else if (RadioButtonStudent.Checked == true)
            {
                List <StudentModel> students = new List <StudentModel>();

                try
                {
                    SqlConnector db = new SqlConnector();
                    students = db.GetStudent_All();
                }
                catch
                {
                    MyMessageBox.ShowMessage("Access to database failed.");
                    return;
                }

                //Search each StudentModel in the student list.
                //If the email the user input matches an email in the
                //database, send the email.
                for (int i = 0; i < students.Count; i++)
                {
                    if (students[i].StudentEmail == TextBoxEmail.Text)
                    {
                        ErrorProvider.SetError(TextBoxEmail, null);
                        //Send email
                        SendEmail(students[i].StudentEmail, students[i].StudentFirstName, students[i].StudentID, students[i].StudentPassword);
                        MyMessageBox.ShowMessage("Email successfully sent.");
                        return;
                    }
                }
            }
            else if (RadioButtonStaff.Checked)
            {
                List <StaffModel> staffMembers = new List <StaffModel>();

                try
                {
                    SqlConnector db = new SqlConnector();
                    staffMembers = db.GetStaff_All();
                }
                catch
                {
                    MyMessageBox.ShowMessage("Access to database failed.");
                    return;
                }

                for (int i = 0; i < staffMembers.Count; i++)
                {
                    if (staffMembers[i].StaffEmail == TextBoxEmail.Text)
                    {
                        ErrorProvider.SetError(TextBoxEmail, null);
                        //Send email
                        SendEmail(staffMembers[i].StaffEmail, staffMembers[i].StaffFirstName, staffMembers[i].StaffEmail, staffMembers[i].StaffPassword);
                        MyMessageBox.ShowMessage("Email successfully sent.");
                        return;
                    }
                }
            }

            MyMessageBox.ShowMessage("This email doesn't exist in the database.");
        }
 private void TextBoxEmail_Validating(object sender, CancelEventArgs e)
 {
     ClassLibrary.CheckEmailIsValid(TextBoxEmail, ErrorProvider);
 }