예제 #1
0
        public MakerScreen(string quizDate)
        {
            // Call this contructor with a filename to open a quiz for editing
            // Note: the main functionality here should be moved to the Quiz Class for reueseability
            InitializeComponent();

            isEdit = true;

            currentlyMakingQuiz = new Quiz();

            currentlyMakingQuiz.AddDataFromFile("LocalQuizzes.xml", quizDate);

            textboxTitle.Text = currentlyMakingQuiz.GetTitle();

            for (int i = 0; i < currentlyMakingQuiz.GetNumQuestions(); i++)
            {
                listboxQuestions.Items.Add(currentlyMakingQuiz.GetQuestion(i).GetPrompt());
            }
            if (currentlyMakingQuiz.GetNumQuestions() <= 0)
            {
                addBlankQuestion(0);
            }
            else
            {
                listboxQuestions.SelectedIndex = 0;
            }
        }
예제 #2
0
        private void TakerScreen_Load(object sender, EventArgs e)
        {
            labelQuizTitle.Text = currentlyTakingQuiz.GetTitle();

            for (int iter = 1; iter < currentlyTakingQuiz.GetNumQuestions() + 1; iter++)
            {
                comboBoxQuestionSelect.Items.Add("Question #" + iter);
            }
            currentQuestionIndex = 0;

            DisplayQuestion();
        }
예제 #3
0
        private void buttonSaveQuiz_Click(object sender, EventArgs e)
        {
            // TODO: test saving for multiple choice questions

            // Save the quiz.  To an xml file
            // add a file location for it to save to for now

            // In the future, add a blank field checker that checks the title, author, other fields, and questions and answers for blank or default values,
            // and asks the user if they want to fill them in before saving
            if (isEdit)
            {
                XDocument xmlDoc = XDocument.Load("LocalQuizzes.xml");

                xmlDoc.Root.Elements().Where(x => x.Attribute("date").Value == currentlyMakingQuiz.GetModifiedDate()).Remove();

                currentlyMakingQuiz.SetModifiedNow();

                xmlDoc.Save("LocalQuizzes.xml");
            }

            XDocument xmlDocument = XDocument.Load("LocalQuizzes.xml");

            xmlDocument.Element("Quizzes").Add(
                new XElement("Quiz",
                             new XAttribute("name", currentlyMakingQuiz.GetTitle()),
                             new XAttribute("date", currentlyMakingQuiz.GetModifiedDate())
                             ));

            for (int index = 0; index < currentlyMakingQuiz.GetNumQuestions(); index++)
            {
                if (currentlyMakingQuiz.GetQuestion(index).GetQuestionType() == "FITB")
                {
                    xmlDocument.Element("Quizzes").Elements("Quiz")
                    .First(c => (string)c.Attribute("date") == currentlyMakingQuiz.GetModifiedDate()).Add
                    (
                        new XElement("Question", new XAttribute("type", currentlyMakingQuiz.GetQuestion(index).GetQuestionType()),
                                     new XElement("Prompt", currentlyMakingQuiz.GetQuestion(index).GetPrompt()),
                                     new XElement("Answer", currentlyMakingQuiz.GetQuestion(index).GetAnswer())
                                     ));
                }

                else if (currentlyMakingQuiz.GetQuestion(index).GetQuestionType() == "MC")
                {
                    xmlDocument.Element("Quizzes").Elements("Quiz")
                    .First(c => (string)c.Attribute("date") == currentlyMakingQuiz.GetModifiedDate()).Add
                    (
                        new XElement("Question", new XAttribute("type", currentlyMakingQuiz.GetQuestion(index).GetQuestionType()),
                                     new XElement("Prompt", currentlyMakingQuiz.GetQuestion(index).GetPrompt()),
                                     new XElement("Answer", currentlyMakingQuiz.GetQuestion(index).GetAnswer()),
                                     new XElement("Choices")
                                     ));
                    for (int j = 0; j < ((MCQuestion)currentlyMakingQuiz.GetQuestion(index)).GetNumChoices(); j++)
                    {
                        xmlDocument.Element("Quizzes").Elements("Quiz")
                        .First(c => (string)c.Attribute("date") == currentlyMakingQuiz.GetModifiedDate()).Elements("Question").ElementAt(index).Elements("Choices").FirstOrDefault().Add
                        (
                            new XElement("Choice", ((MCQuestion)currentlyMakingQuiz.GetQuestion(index)).GetChoice(j))
                        );
                    }
                }
            }
            xmlDocument.Save("LocalQuizzes.xml");

            MessageBox.Show("Quiz saved successfully!");

            Close();
        }