コード例 #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
ファイル: TakerScreen.cs プロジェクト: bkm98/Quiz-Creator
        private void buttonSubmitQuiz_Click(object sender, EventArgs e)
        {
            // For implementation 1, show results as "you got x/total" in a popup/messagebox
            SaveResponse();

            int numQuestions = currentlyTakingQuiz.GetNumQuestions();

            string summaryString = "";

            for (int index = 0; index < numQuestions; index++)
            {
                summaryString += "\nQuestion #" + (index + 1) + ": ";

                if (currentlyTakingQuiz.GetQuestion(index).CorrectResponse())
                {
                    summaryString += "Correct";
                }
                else
                {
                    summaryString += "Incorrect";
                }
            }
            MessageBox.Show(summaryString);

            // For future implementations, save quiz here
        }
コード例 #3
0
ファイル: IntegrationTest.cs プロジェクト: bkm98/Quiz-Creator
        public void test2()
        {
            string connectionString = "Server=quizcreatordb.ctvd1ztjykvr.us-east-1.rds.amazonaws.com; " +
                                      "Port=3306; Database=QC_database; Uid=admin; Pwd=quizcreator;";

            string quizName = "Quiz 1.2 - Intro to Software Eng.";

            int quizID = Database.GetQuizID(quizName);

            string sql = "SELECT * FROM questions WHERE quiz_id= " + quizID + ";";

            MySqlConnection conn = new MySqlConnection(connectionString);

            conn.Open();

            MySqlDataReader rdr = new MySqlCommand(sql, conn).ExecuteReader();

            Quiz expectedQuiz = new Quiz(quizName);

            while (rdr.Read())
            {
                if (rdr.GetString("type") == "FITB")
                {
                    expectedQuiz.AddQuestion(new Question(rdr.GetString("type"),
                                                          rdr.GetString("prompt"), rdr.GetString("answer")));
                }
                else
                {
                    string[] choices = rdr.GetString("choices").Split(',');

                    expectedQuiz.AddQuestion(new MCQuestion(choices, rdr.GetString("type"),
                                                            rdr.GetString("prompt"), rdr.GetString("answer")));
                }
            }
            conn.Close();

            Quiz actualQuiz = Database.GetQuiz(quizID, quizName);

            for (int questionIndex = 0; questionIndex < expectedQuiz.GetNumQuestions(); questionIndex++)
            {
                string actual   = actualQuiz.GetQuestion(questionIndex).GetPrompt();
                string expected = expectedQuiz.GetQuestion(questionIndex).GetPrompt();

                Assert.AreEqual(expected, actual);

                actual   = actualQuiz.GetQuestion(questionIndex).GetAnswer();
                expected = expectedQuiz.GetQuestion(questionIndex).GetAnswer();

                Assert.AreEqual(expected, actual);
            }
        }
コード例 #4
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();
        }