// Method which handles the user clicking the 'Update Record' button
        private void UpdateRecordButton_Click(object sender, RoutedEventArgs e)
        {
            // Initialises a connection to the Database based on the path which is stored as the string 'SimplyRugbyDBConnectionString'.
            SQLiteConnection sqliteConnection = new SQLiteConnection(SimplyRugbyDatabaseConnectionString);

            // If the user hasn't selected an existing member record from the combobox, then the value for the textbox 'MembershipNoTxt'
            // Will be blank and the program will enter this IF statement
            if (MembershipNoTxt.Text == "")
            {
                MessageBox.Show("You must select a member record to update.");
                return;
            }

            // An ELSE IF statment which handles if the Member Name input fails it's validation
            // Calls the MemberNameValidation() method from the Validation class
            // Passes the value entered in the 'MemberNameTxt' textbox.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.MemberNameValidation(MemberNameTxt.Text) == false)
            {
                // Returns focus to the 'MemberNameTxt' text box, if validation has failed.
                MemberNameTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the User tries to update the record with a
            // Playing Member having N/A as their SRU No
            else if (membershipType == "Playing Member" && SRUNoTxt.Text == "N/A")
            {
                MessageBox.Show("A Playing Member must have a SRU No.");
                return;
            }

            // An ELSE IF statment which handles if the SRU Number input fails it's validation
            // Calls the SRUNoValidation() method from the Validation class
            // Passes the value entered in the 'SRUNoTxt' textbox and the current value for membershipType
            // Set by the selected radiobutton.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.SRUNoValidation(SRUNoTxt.Text) == false)
            {
                // Returns focus to the 'SRUNoTxt' text box, if validation has failed.
                SRUNoTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Email Address input fails it's validation
            // Calls the EmailValidation() method from the Validation class
            // Passes the value entered in the 'EmailAddressTxt' textbox.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.EmailValidation(EmailAddressTxt.Text) == false)
            {
                // Returns focus to the 'EmailAddressTxt' text box, if validation has failed.
                EmailAddressTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Phone Number input fails it's validation
            // Calls the PhoneNoValidation() method from the Validation class
            // Passes the value entered in the 'PhoneNoTxt' textbox.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.PhoneNoValidation(PhoneNoTxt.Text) == false)
            {
                // Returns focus to the 'PhoneNoTxt' text box, if validation has failed.
                PhoneNoTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Date of Birth Year input fails it's validation
            // Calls the DateOfBirthYearValidation() method from the Validation class
            // Passes the value entered in the 'DateOfBirthYearTxt' textbox.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.DateOfBirthYearValidation(DateOfBirthYearTxt.Text) == false)
            {
                // Returns focus to the 'DateOfBirthYearTxt' text box, if validation has failed.
                DateOfBirthYearTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Date of Birth Month input fails it's validation
            // Calls the DateOfBirthMonthValidation() method from the Validation class
            // Passes the value entered in the 'DateOfBirthMonthTxt' textbox.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.DateOfBirthMonthValidation(DateOfBirthMonthTxt.Text) == false)
            {
                // Returns focus to the 'DateOfBirthMonthTxt' text box, if validation has failed.
                DateOfBirthMonthTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Date of Birth Day input fails it's validation
            // Calls the DateOfBirthDayValidation() method from the Validation class
            // Passes the value entered in the 'DateOfBirthDayTxt' textbox and the validated values entered in the
            // 'DateOfBirthYearTxt' and 'DateOfBirthMonthTxt' textboxes.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.DateOfBirthDayValidation(DateOfBirthDayTxt.Text, DateOfBirthMonthTxt.Text, DateOfBirthYearTxt.Text) == false)
            {
                // Returns focus to the 'DateOfBirthDayTxt' text box, if validation has failed.
                DateOfBirthDayTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Membership Type input fails it's validation
            // Calls the MembershipTypeValidation() method from the Validation class
            // Passes the value stored in the 'membershipType' variable string.
            // Enters the IF statement when the boolean value 'false' is returned
            else if (updateDataValidation.MembershipTypeValidation(membershipType) == false)
            {
                return;
            }

            // Concatenates the day value, month value and the year value together with forward slashes to seperate the values.
            // Stores the concatenated value as a string called fullDateOfBirth
            string updatedFullDateOfBirth = string.Format("{0}/{1}/{2}", DateOfBirthYearTxt.Text, DateOfBirthMonthTxt.Text, DateOfBirthDayTxt.Text);

            // Calls the UpdateRecord() method from the Database class
            // Sends the database connection, validated Member Name, validated Email Address,
            // validated Phone No, validated concatenated Date of Birth
            // validated SRU No and validated Membership Type.
            simplyRugbyDatabaseAdminUpdatePage.UpdateRecord
                (sqliteConnection, MembershipNoTxt.Text, MemberNameTxt.Text, EmailAddressTxt.Text, PhoneNoTxt.Text, updatedFullDateOfBirth, SRUNoTxt.Text, membershipType);

            // MessageBox displays a message informing the user that the record has been added to the database, successfully.
            MessageBox.Show("The record for '" + MemberNameTxt.Text + "' has been successfully updated.");

            // Sets the textboxes MembershipNoTxt, MemberNameTxt, EmailAddressTxt, PhoneNoTxt, DateOfBirthMonthTxt, DateOfBirthYearTxt, DateOfBirthDayTxt and SRUNoTxt to display their default values (an empty string).
            MembershipNoTxt.Text = MemberNameTxt.Text = EmailAddressTxt.Text = PhoneNoTxt.Text = DateOfBirthDayTxt.Text = DateOfBirthMonthTxt.Text = DateOfBirthYearTxt.Text = SRUNoTxt.Text = "";

            // Sets both radiobuttons to default selection (none).
            PlayingMemberRadioButton.IsChecked    = false;
            NonPlayingMemberRadioButton.IsChecked = false;

            // Calls the Clear() method from the ItemCollection class to remove all the enteries in the comboboxes
            MemberNameComboBox.Items.Clear();
            MembershipNoComboBox.Items.Clear();

            // Calls the PopulateAdminUpdateMemberNameComboBox() and PopulateAdminUpdateMembershipNoComboBox() methods
            // to repopulate the comboboxes 'MemberNameComboBox' and 'MembershipNoComboBox' with their current values.
            PopulateAdminUpdateMemberNameComboBox();
            PopulateAdminUpdateMembershipNoComboBox();
        }
Exemple #2
0
        // Method which handles the user clicking the 'Add Record' button.
        private void AddRecordButton_Click(object sender, RoutedEventArgs e)
        {
            // Initialises a connection to the Database based on the path which is stored as the string 'SimplyRugbyDBConnectionString'.
            SQLiteConnection sqliteConnection = new SQLiteConnection(SimplyRugbyDBConnectionString);

            // An ELSE IF statment which handles if the Member Name input fails it's validation
            // Calls the MemberNameValidation() method from the Validation class
            // Passes the value entered in the 'MemberNameTxt' textbox.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            if (inputDataValidation.MemberNameValidation(MemberNameTxt.Text) == false)
            {
                // Returns focus to the 'MemberNameTxt' text box, if validation has failed.
                MemberNameTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the SRU Number input fails it's validation
            // Calls the SRUNoValidation() method from the Validation class
            // Passes the value entered in the 'SRUNoTxt' textbox and the current value for membershipType
            // Set by the selected radiobutton.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            else if (inputDataValidation.SRUNoValidation(SRUNoTxt.Text) == false)
            {
                // Returns focus to the 'SRUNoTxt' text box, if validation has failed.
                SRUNoTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the User tries to create the record with a
            // Playing Member having N/A as their SRU No
            else if (membershipType == "Playing Member" && SRUNoTxt.Text == "N/A")
            {
                MessageBox.Show("A Playing Member must have a SRU No.");
                return;
            }

            // An ELSE IF statment which handles if the SRU Number already exists on the database
            // Calls the DoesItExist() method from the Validation class
            // Passes a string of the query with the value entered in the 'SRUNoTxt' textbox
            // Enters the ELSE IF statement when the boolean value 'true' is returned, meaning the value in 'SRUNoTxt'
            // textbox has been found in the database.
            else if (inputDataValidation.DoesItExist(SRUNoTxt.Text, "SELECT * FROM members WHERE SRUno='" + SRUNoTxt.Text + "'") == true)
            {
                MessageBox.Show("The SRU No you have entered is already stored on the database, please try again.");
                // Returns focus to the 'SRUNoTxt' text box, if validation has failed.
                SRUNoTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Email Address input fails it's validation
            // Calls the EmailValidation() method from the Validation class
            // Passes the value entered in the 'EmailAddressTxt' textbox.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            else if (inputDataValidation.EmailValidation(EmailAddressTxt.Text) == false)
            {
                // Returns focus to the 'EmailAddressTxt' text box, if validation has failed.
                EmailAddressTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Phone Number input fails it's validation
            // Calls the PhoneNoValidation() method from the Validation class
            // Passes the value entered in the 'PhoneNoTxt' textbox.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            else if (inputDataValidation.PhoneNoValidation(PhoneNoTxt.Text) == false)
            {
                // Returns focus to the 'PhoneNoTxt' text box, if validation has failed.
                PhoneNoTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Date of Birth Year input fails it's validation
            // Calls the DateOfBirthYearValidation() method from the Validation class
            // Passes the value entered in the 'DateOfBirthYearTxt' textbox.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            //else
            if (inputDataValidation.DateOfBirthYearValidation(DateOfBirthYearTxt.Text) == false)
            {
                // Returns focus to the 'DateOfBirthYearTxt' text box, if validation has failed.
                DateOfBirthYearTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Date of Birth Month input fails it's validation
            // Calls the DateOfBirthMonthValidation() method from the Validation class
            // Passes the value entered in the 'DateOfBirthMonthTxt' textbox.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            else if (inputDataValidation.DateOfBirthMonthValidation(DateOfBirthMonthTxt.Text) == false)
            {
                // Returns focus to the 'DateOfBirthMonthTxt' text box, if validation has failed.
                DateOfBirthMonthTxt.Focus();
                return;
            }

            // An IF statment which handles if the Date of Birth Day input fails it's validation
            // Calls the DateOfBirthDayValidation() method from the Validation class
            // Passes the value entered in the 'DateOfBirthDayTxt' textbox and the validated values entered in the
            // 'DateOfBirthYearTxt' and 'DateOfBirthMonthTxt' textboxes.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            else if (inputDataValidation.DateOfBirthDayValidation(DateOfBirthDayTxt.Text, DateOfBirthMonthTxt.Text, DateOfBirthYearTxt.Text) == false)
            {
                // Returns focus to the 'DateOfBirthDayTxt' text box, if validation has failed.
                DateOfBirthDayTxt.Focus();
                return;
            }

            // An ELSE IF statment which handles if the Membership Type input fails it's validation
            // Calls the MembershipTypeValidation() method from the Validation class
            // Passes the value stored in the 'membershipType' variable string.
            // Enters the ELSE IF statement when the boolean value 'false' is returned
            else if (inputDataValidation.MembershipTypeValidation(membershipType) == false)
            {
                return;
            }

            // The program will only enter this ELSE statement when all the input information meets the validation criteria set. ELSE
            else
            {
                // Concatenates the day string value, month string value and the year string value together with forward slashes to seperate the values.
                // Stores the concatenated value as a string called fullDateOfBirth.
                string fullDateOfBirth = string.Format("{0}/{1}/{2}", DateOfBirthYearTxt.Text, DateOfBirthMonthTxt.Text, DateOfBirthDayTxt.Text);

                // Calls the AddRecord() method from the Database class
                // Sends the database connection, validated Member Name, validated Email Address,
                // validated Phone No, validated concatenated Date of Birth
                // validated SRU No and validated Membership Type.
                simplyRubgyDatabaseAdminAddPage.AddRecord
                    (sqliteConnection, MemberNameTxt.Text, EmailAddressTxt.Text, PhoneNoTxt.Text, fullDateOfBirth, SRUNoTxt.Text, membershipType);

                // MessageBox displays a message informing the user that the record has been added to the database, successfully.
                MessageBox.Show("A record for '" + MemberNameTxt.Text + "' has been successfully added.");

                // Sets the textboxes MemberNameTxt, EmailAddressTxt, PhoneNoTxt and SRUNoTxt to display their defualt values (an empty string).
                MemberNameTxt.Text = EmailAddressTxt.Text = PhoneNoTxt.Text = SRUNoTxt.Text = "";

                // Sets the DateOfBirthYearTxt textbox to display the default value (constant string 'dateOfBirthYearText').
                DateOfBirthYearTxt.Text = dateOfBirthYearText;

                // Sets the DateOfBirthMonthTxt textbox to display the default value (constant string 'dateOfBirthMonthText').
                DateOfBirthMonthTxt.Text = dateOfBirthMonthText;

                // Sets the DateOfBirthDayTxt textbox to display the default value (constant string 'dateOfBirthDayText').
                DateOfBirthDayTxt.Text = dateOfBirthDayText;

                // Sets both radiobuttons to default selection (none).
                PlayingMemberRadioButton.IsChecked    = false;
                NonPlayingMemberRadioButton.IsChecked = false;

                // Sets the variable string 'membershipType' to null, this avoids any validation conflictions
                // With adding multiple records in the same sitting.
                membershipType = null;
            }
        }