コード例 #1
0
        private void cboQorAChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (cboQorAs.SelectedItem != null)
                {
                    //Copy the value of the cboBox into the textbox for editing
                    switch (qaMode)
                    {
                    case QAMode.Answer:
                        txtText.Text = answers.ElementAt(cboQorAs.SelectedIndex).Text;
                        break;

                    case QAMode.Question:
                        txtText.Text = questions.ElementAt(cboQorAs.SelectedIndex).Text;
                        break;

                    default:
                        break;
                    }


                    //Update the edit button
                    btnSave.Content = "Update " + qaMode.ToString();
                    editMode        = EditMode.Update;
                }
                else
                {
                    //If null clear the textbox and update the edit button to read add and update the editMode
                    txtText.Text    = String.Empty;
                    btnSave.Content = "Add " + qaMode.ToString();
                    editMode        = EditMode.Add;
                }
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }
コード例 #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Question question = questions.ElementAt(cboQuestion.SelectedIndex);

                //Clear out the current answers on the question
                question.Answers.Clear();

                //Save the currently selected answers to the question's answer list
                if (cboCorrectAnswer.SelectedItem != null)
                {
                    //Check to make sure that duplicate answers aren't selected
                    CheckSameSelection(cboCorrectAnswer, cboWrongAnswer1);
                    CheckSameSelection(cboCorrectAnswer, cboWrongAnswer2);
                    CheckSameSelection(cboCorrectAnswer, cboWrongAnswer3);

                    //Find the answer in the master answer list and add a copy to this question's answer list
                    Answer masterAnswer = answers.ElementAt(cboCorrectAnswer.SelectedIndex);
                    Answer newAnswer    = new Answer {
                        Id = masterAnswer.Id, Text = masterAnswer.Text, IsCorrect = true
                    };
                    question.Answers.Add(newAnswer);

                    newAnswer = null;
                }
                if (cboWrongAnswer1.SelectedItem != null)
                {
                    CheckSameSelection(cboWrongAnswer1, cboWrongAnswer2);
                    CheckSameSelection(cboWrongAnswer1, cboWrongAnswer3);



                    //Find the answer in the master answer list and add a copy to this question's answer list
                    Answer masterAnswer = answers.ElementAt(cboWrongAnswer1.SelectedIndex);
                    Answer newAnswer    = new Answer {
                        Id = masterAnswer.Id, Text = masterAnswer.Text, IsCorrect = false
                    };
                    question.Answers.Add(newAnswer);

                    newAnswer = null;
                }
                if (cboWrongAnswer2.SelectedItem != null)
                {
                    CheckSameSelection(cboWrongAnswer2, cboWrongAnswer3);


                    //Find the answer in the master answer list and add a copy to this question's answer list
                    Answer masterAnswer = answers.ElementAt(cboWrongAnswer2.SelectedIndex);
                    Answer newAnswer    = new Answer {
                        Id = masterAnswer.Id, Text = masterAnswer.Text, IsCorrect = false
                    };
                    question.Answers.Add(newAnswer);

                    newAnswer = null;
                }
                if (cboWrongAnswer3.SelectedItem != null)
                {
                    //Find the answer in the master answer list and add a copy to this question's answer list
                    Answer masterAnswer = answers.ElementAt(cboWrongAnswer3.SelectedIndex);
                    Answer newAnswer    = new Answer {
                        Id = masterAnswer.Id, Text = masterAnswer.Text, IsCorrect = false
                    };
                    question.Answers.Add(newAnswer);

                    newAnswer = null;
                }
                //Save the question answers to the database
                question.SaveAnswers();

                //update the status label
                lblStatus.Content = "Saved: Updated the answers on the question!";
            }
            catch (Exception ex)
            {
                lblStatus.Content = ex.Message;
            }
        }