//Gets a random QA to be displayed. Changes control based on user input private void ShowQA() { QA qa = dataPool.GetQA(); string question = "Question:" + Environment.NewLine + qa.getQuestion(); DialogResult result = new DialogResult(); qaForm.SetQA(question, qa.getAnswers(), qa.getCorrectIndex()); result = qaForm.ShowDialog(); if (qaForm.GuessedCorrect) { qaForm.GuessedCorrect = false; EmailMsg.Append("Q: ").Append(qa.getQuestion()).Append("\n").Append("A: ").Append(qaForm.CorrectAnswer).Append("\n\n"); ShowMsg(); } else { ExitApp(); } }
public void LoadData(string fileName) { //Load XML file XDocument xmlDoc; try { //Load XML file xmlDoc = XDocument.Load(fileName); //Load messages MsgArray = xmlDoc.Root.Elements("msgscreen").Elements("msg").Select(element => element.Value).ToArray(); //Check # of messages int MsgIndexRange = MsgArray.Count() - 1; if (MsgIndexRange < 1) //Unsuccessful if fewer than 2 entries in xml file { throw new IOException("Fewer than two messages exist!"); } else { MsgArrayNextRandNdx = MsgIndexRange; } //Load images ImgArray = Directory.GetFiles(@"Pictures\"); //Check # of images int ImgIndexRange = ImgArray.Count() - 1; if (ImgIndexRange < 1) //Unsuccessful if fewer than 2 pictures available { throw new IOException("Fewer than two images exist!"); } else { ImgArrayNextRandNdx = ImgIndexRange; } //Load questions and answers int QASize = xmlDoc.Root.Elements("qascreen").Elements("qa").Count(); QAArray = new QA[QASize]; //Check # of QAs int QAArrayIndexRange = QAArray.Count() - 1; if (QAArrayIndexRange < 1) //Unsuccessful if fewer than 2 pictures available { throw new IOException("Fewer than two question/answers exist!"); } else { QAArrayNextRandNdx = QAArrayIndexRange; } int i = 0; foreach (XElement qa in xmlDoc.Root.Elements("qascreen").Elements("qa")) { string question = qa.Element("question").Value.ToString(); string answer = qa.Element("answer").Value.ToString(); string[] decoys = qa.Elements("decoy").Select(element => element.Value).ToArray(); if (decoys.Count() != 3) { throw new IOException("Exactly three decoy answers must exist for every QA!"); } QAArray[i] = new QA(question, answer, decoys); i++; } } catch (IOException e) { throw new IOException(e.ToString()); } }