Esempio n. 1
0
        private void cq_btn(object sender, RoutedEventArgs e)
        {
            var _nq = new Question();

            if (a_one_rbn.IsChecked == true)
            {
                _nq.RightAnswer = 1;
            }
            else if (a_two_rbn.IsChecked == true)
            {
                _nq.RightAnswer = 2;
            }
            else if (a_three_rbn.IsChecked == true)
            {
                _nq.RightAnswer = 3;
            }
            else if (a_four_rbn.IsChecked == true)
            {
                _nq.RightAnswer = 4;
            }
            else
            {
                _nq.RightAnswer = 0;
            }

            var textBoxes    = new TextBox[] { q_tbx, a_one_tbx, a_two_tbx, a_three_tbx, a_four_tbx };
            var radioButtons = new RadioButton[] { a_one_rbn, a_two_rbn, a_three_rbn, a_four_rbn };

            if (textBoxes.Any(tb => tb.Text == String.Empty))
            {
                MessageBox.Show("All fields must be filled");
            }
            else if (radioButtons.Any(rb => rb.IsChecked.Value == true))
            {
                _nq.Title       = q_tbx.Text;
                _nq.AnswerOne   = a_one_tbx.Text;
                _nq.AnswerTwo   = a_two_tbx.Text;
                _nq.AnswerThree = a_three_tbx.Text;
                _nq.AnswerFour  = a_four_tbx.Text;

                Questions.Add(_nq);
                UtilityTestVerktyg.QuizQuestions.Add(_nq);

                this.Close();
            }
            else
            {
                MessageBox.Show("All fields must be filled");
            }

            foreach (var item in Questions)
            {
                q_tbx.Clear();
                a_one_tbx.Clear();
                a_two_tbx.Clear();
                a_three_tbx.Clear();
                a_four_tbx.Clear();
            }
        }
Esempio n. 2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            //If any Texbox is empty
            //Show message
            if (questionTextBox.Text == String.Empty || answer1TextBox.Text == String.Empty || answer2TextBox.Text == String.Empty || answer3TextBox.Text == String.Empty || answer4TextBox.Text == String.Empty || feedbackTextBox.Text == String.Empty)
            {
                MessageBox.Show("Enter all data fields.");
                return;
            }

            //Array of radio buttons
            RadioButton[] radioButtons = new RadioButton[] { radioButtonA, radioButtonB, radioButtonC, radioButtonD };

            //If a radio button is not selected
            //Show message
            if (!radioButtons.Any(rb => rb.Checked))
            {
                MessageBox.Show("Please select a correct answer");
                return;
            }

            //If else loop
            //Based on which radio button is selected, if that button is selected
            //correct answer = corresponding textbox
            if (radioButtonA.Checked)
            {
                correctAnswer = answer1TextBox.Text;
            }
            else if (radioButtonB.Checked)
            {
                correctAnswer = answer2TextBox.Text;
            }
            else if (radioButtonC.Checked)
            {
                correctAnswer = answer3TextBox.Text;
            }
            else if (radioButtonD.Checked)
            {
                correctAnswer = answer4TextBox.Text;
            }

            //Create new question object based on user input
            Question tmpQuestion = new Question(questionTextBox.Text, answer1TextBox.Text, answer2TextBox.Text, answer3TextBox.Text, answer4TextBox.Text, feedbackTextBox.Text, correctAnswer);

            //Raise QuestionCreated event
            QuestionCreated(this, tmpQuestion);


            //Clear all textboxes
            //Focus on beginning textbox
            questionTextBox.Clear();
            answer1TextBox.Clear();
            answer2TextBox.Clear();
            answer3TextBox.Clear();
            answer4TextBox.Clear();
            feedbackTextBox.Clear();
            questionTextBox.Focus();
        }
Esempio n. 3
0
        private void submitButton_Click(object sender, EventArgs e)
        {
            //Array of radioButtons
            RadioButton[] radioButtons = new RadioButton[] { radioButtonA, radioButtonB, radioButtonC, radioButtonD };

            //If a radiobutton isnt checked
            if (!radioButtons.Any(rb => rb.Checked))
            {
                MessageBox.Show("Please select an answer");
                return;
            }

            //Foreach loop
            foreach (RadioButton r in radioButtons)
            {
                //If user selects correctAnswer
                //Add score / increment submissions
                //Show MessageBox
                if (r.Checked && r.Text == correctAnswer)
                {
                    MessageBox.Show($"Correct! \n\n\"{message}\"", "Good Job :)", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    totalScore             = totalScore + 1;
                    correctScoreLabel.Text = Convert.ToString(totalScore);
                    submissions++;
                }
                //If user selects wrong answer
                //Increment submissions
                //Show MessageBox
                else if (r.Checked && r.Text != correctAnswer)
                {
                    MessageBox.Show("Wrong answer!", "Sorry :(", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    submissions++;
                }
            }

            //Once submissions = 3
            //Close GameWindow form
            //Display message
            if (submissions == 3)
            {
                Close();
                soundPlayer.Stop();
                MessageBox.Show($"Thank you for playing my game!\nYour total score was {totalScore}/3! v", "Game Complete!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                sP = new SoundPlayer("force.wav");
                sP.Load();
                sP.Play();
            }
            else
            {
                //Method
                questions++;
                questionsLeftNum.Text = Convert.ToString(questions);
                DisplayNextQuestion();
            }
        }
Esempio n. 4
0
        /*
         * validate method, to ensure that there is data inputed
         */
        private void validate()
        {
            RadioButton[] genders = new RadioButton[] { rbMale, rbFemale };
            /* validation */
            if (txtLastname.TextLength == 0)
            {
                MessageBox.Show("Last name required");
            }
            if (txtFirstname.TextLength == 0)
            {
                MessageBox.Show("First name required");
            }
            if (txtMiddlename.TextLength == 0)
            {
                MessageBox.Show("Middle name required");
            }
            if (cbMonth.SelectedIndex == -1)
            {
                MessageBox.Show("Birth month required");
            }
            if (cbDate.SelectedIndex == -1)
            {
                MessageBox.Show("Birth date required");
            }
            if (cbYear.SelectedIndex == -1)
            {
                MessageBox.Show("Birth year required");
            }

            /*
             * No radio buttons are checked
             */
            if (!genders.Any(rb => rb.Checked))
            {
                MessageBox.Show("Gender required");
            }
            if (txtAddress.TextLength == 0)
            {
                MessageBox.Show("Address required");
            }
            if (txtEmail.TextLength == 0)
            {
                MessageBox.Show("Email required");
            }
            if (txtPhonenumber.TextLength == 0)
            {
                MessageBox.Show("Phone number required");
            }
        }
Esempio n. 5
0
        private void bOrder_Click(object sender, EventArgs e)
        {
            RadioButton[] radioButtons = new RadioButton[] { rLarge, rMedium, rSmall };

            if (CBPizzas.SelectedItem == null || !radioButtons.Any(rb => rb.Checked))
            {
                string message = "You need to choose type and size of pizza";
                MessageBox.Show(message);
            }
            else
            {
                bPrice.PerformClick();
                _EntityConnector.Connect();
                lMessage.Text = "Your order was sent to us";
            }
        }
Esempio n. 6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var requisits = new ReqEstados().Obter();

            estadoBox.Items.Add("");
            foreach (var requisit in requisits)
            {
                estadoBox.Items.Add(requisit.Sigla);
            }
            RadioButton[] radioButtons = new RadioButton[] { cepButton, enderecoButton };
            if (!radioButtons.Any(rb => rb.Checked))
            {
                estadoBox.Enabled = false;
                cidadeBox.Enabled = false;
                textCep.Enabled   = false;
            }
        }
Esempio n. 7
0
        private void registerButton_Click(object sender, EventArgs e)
        {
            RadioButton[] rb = new RadioButton[] { occupantRadioButton, officeWorkerRadioButton, contractorRadioButton };

            var checkedButton = rolePanel.Controls.OfType <RadioButton>()
                                .FirstOrDefault(r => r.Checked);

            /**
             * 1) emailCheck is the regular expression for our email field.
             * 2) passwordCheck is the regular expression for our password field. Youa are required to have a password that is at minimum 6 characters long with at least one lowercase letter, one uppercase letter, and one number.
             */
            string emailCheck    = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";
            string passwordCheck = "^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])[0-9a-zA-Z]{6,}$";

            /**
             * Checks the email & password using the RegularExpressions from above, confirms that your entered password matches what you entered when asked to confirm it, and checks that the email you entered has not been used previously.
             * */
            if (Regex.IsMatch(emailEntryTextBox.Text, emailCheck) && Regex.IsMatch(passwordEntryTextBox.Text, passwordCheck) && passwordEntryTextBox.Text == confirmPasswordEntryTextBox.Text && emailAvailable() && rb.Any(radio => radio.Checked))
            {
                /**
                 *  MySQLCommand that will be used to insert the entered first name, last name, email, password, and usertype into the User table into the invoicelogin database.
                 */
                MySqlCommand cmd = new MySqlCommand("insert into User values ('" + 0 + "', '" + firstNameEntryTextBox.Text + "', '" + lastNameEntryTextBox.Text + "', '" + emailEntryTextBox.Text.ToLower() + "', '" + passwordEntryTextBox.Text + "', '" + checkedButton.Text + "', '" + 0 + "')", connection);

                /**
                 * Opens a connection to the MySQL Database
                 */
                connection.Open();

                /**
                 * Executes the above SQL Statement as well as returns an integer of rows that were affected. As long as this value is higher than 0 we know that we have inserted the information & added a new row to the User table.
                 * */
                int i = cmd.ExecuteNonQuery();
                connection.Close();
                if (i > 0)
                {
                    MessageBox.Show("Registration Successful");
                }
            }

            /**
             * If the email that was entered does not meet our requirements then MessageBox will inform you that your entered email is invalid
             */
            else if (!Regex.IsMatch(emailEntryTextBox.Text, emailCheck))
            {
                MessageBox.Show("Email is invalid");
            }

            /**
             * If the password that was entered does not meet our requirements then a MessageBox will inform you that you entered password does not meet the requirements
             */
            else if (!Regex.IsMatch(passwordEntryTextBox.Text, passwordCheck))
            {
                MessageBox.Show("Password does not meet all requirements \n 1) Password Must Be At Minimum 6 Characters\n 2) Password Must Contain At Least One Uppercase Letter\n 3) Password Must Contain At Least One Lowercase Letter\n 4) Password Must Contain At Least One Number");
            }

            /**
             * If the passwords that were entered in the password & confirm password texboxes don't match then a MessageBox will inform you that the passwords do not match.
             */
            else if (passwordEntryTextBox.Text != confirmPasswordEntryTextBox.Text)
            {
                MessageBox.Show("Passwords Do Not Match");
                passwordEntryTextBox.Clear();
                confirmPasswordEntryTextBox.Clear();
                passwordEntryTextBox.Focus();
            }

            /**
             *  If the email has already been used to register then a MessageBox will inform you that it is already in use.
             */
            else if (!emailAvailable())
            {
                MessageBox.Show("Email already in use");
            }

            /**
             * If the registering user hasn't selected a user type then they are informed via a message box that they have to select one.
             */
            else if (!rb.Any(radio => radio.Checked))
            {
                MessageBox.Show("No User Type Selected");
            }
        }
Esempio n. 8
0
 private void btnAdicionar_Click(object sender, EventArgs e)
 {
     RadioButton[] radioButtons = new RadioButton[] { radioComerciante, radioComunicaçaoSocial };
     if (String.IsNullOrEmpty(txtNome.Text) || String.IsNullOrEmpty(txtEmail.Text) || !radioButtons.Any(rb => rb.Checked))
     {
         MessageBox.Show("Uma das seções está vazia!");
     }
     else
     {
     }
 }
Esempio n. 9
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            //If any Texbox is empty
            //Show message
            if (questionTextBox.Text == String.Empty || answer1TextBox.Text == String.Empty || answer2TextBox.Text == String.Empty || answer3TextBox.Text == String.Empty || answer4TextBox.Text == String.Empty || feedbackTextBox.Text == String.Empty)
            {
                MessageBox.Show("Enter all data fields.");
                return;
            }

            //Array of radioButtons
            RadioButton[] radioButtons = new RadioButton[] { radioButtonA, radioButtonB, radioButtonC, radioButtonD };

            //If a radio button is not selected
            //Show message
            if (!radioButtons.Any(rb => rb.Checked))
            {
                MessageBox.Show("Please select a correct answer");
                return;
            }

            //If else loop
            //Based on which radio button is selected, if that button is selected
            //correct answer = corresponding textbox
            if (radioButtonA.Checked)
            {
                correctAnswer = answer1TextBox.Text;
            }
            else if (radioButtonB.Checked)
            {
                correctAnswer = answer2TextBox.Text;
            }
            else if (radioButtonC.Checked)
            {
                correctAnswer = answer3TextBox.Text;
            }
            else if (radioButtonD.Checked)
            {
                correctAnswer = answer4TextBox.Text;
            }
            //Create new question object based on user input
            Question tmpQuestion = new Question(questionTextBox.Text, answer1TextBox.Text, answer2TextBox.Text, answer3TextBox.Text, answer4TextBox.Text, feedbackTextBox.Text, correctAnswer);

            //currentQuetion variables now equal the new inputed data
            currentQuestion.Questions     = questionTextBox.Text;
            currentQuestion.A             = answer1TextBox.Text;
            currentQuestion.B             = answer2TextBox.Text;
            currentQuestion.C             = answer3TextBox.Text;
            currentQuestion.D             = answer4TextBox.Text;
            currentQuestion.Feedback      = feedbackTextBox.Text;
            currentQuestion.CorrectChoice = correctAnswer;

            //Raise QuestionUpdated event appropiately
            if (QuestionUpdated != null)
            {
                QuestionUpdated(this, tmpQuestion);
            }

            //Close form
            this.Close();
        }