Ejemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string name = tbxQuestionName.Text;
            //Dictionary<string, bool> answers = new Dictionary<string, bool>();
            //answers.Add(txbAnswer1.Text, chbxTrue1.Checked);
            //answers.Add(txbAnswer2.Text, chbxTrue2.Checked);
            //answers.Add(txbAnswer3.Text, chbxTrue3.Checked);
            //answers.Add(txbAnswer4.Text, chbxTrue4.Checked);

            List<Answer> answers = new List<Answer>();
            answers.Add(new Answer(txbAnswer1.Text, chbxTrue1.Checked));
            answers.Add(new Answer(txbAnswer2.Text, chbxTrue2.Checked));
            answers.Add(new Answer(txbAnswer3.Text, chbxTrue3.Checked));
            answers.Add(new Answer(txbAnswer4.Text, chbxTrue4.Checked));
            QuestionPrice price = (QuestionPrice)cbxPrice.SelectedItem; // .ValueMember;

            int id = 0;//qbase.LastId;
            Question question = new Question(id, name, answers, price);

            lblId.Text = id.ToString();

            //qbase = new QuestionsBase();
            //_qbase.Add(question);
            _questions.Add(question);
        }
Ejemplo n.º 2
0
        public void FifityFifty()
        {
            List<Answer> answers = new List<Answer>();
            int countOfHiden = 0;
            foreach (var answer in CurrentQuestion.Answers)
            {
                if (!answer.IsTrue && countOfHiden != 2)
                {
                    answer.Hide();
                    countOfHiden++;
                }
                answers.Add(answer);
            }

            CurrentQuestion = new Question(CurrentQuestion.Id, CurrentQuestion.Name, answers, CurrentQuestion.Price);
        }
Ejemplo n.º 3
0
        public void GetQuestionsFromFile()
        {
            this.Questions = new List<Question>();

            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(_fileName);
            XmlElement xRoot = xDoc.DocumentElement;
            foreach (XmlElement xnode in xRoot)
            {
                foreach (XmlNode childnodes in xnode.ChildNodes)
                {
                    Question quiz = new Question();
                    foreach (XmlNode childnode in childnodes)
                    {
                        if (childnode.Name == "Name")
                            quiz.Name = childnode.InnerText;

                        if (childnode.Name == "Price")
                            quiz.Price = (QuestionPrice)Enum.Parse(typeof(QuestionPrice), childnode.InnerText);

                        if (childnode.Name == "Id")
                            quiz.Id = Convert.ToInt32(childnode.InnerText);

                        if (childnode.Name == "Answers")
                        {
                            List<Answer> answers = new List<Answer>();
                            foreach (XmlNode chAnswer in childnode.ChildNodes)
                            {
                                Answer answ = new Answer();
                                foreach (XmlNode answerElm in chAnswer)
                                {
                                    if (answerElm.Name == "Name")
                                        answ.Name = answerElm.InnerText;
                                    if (answerElm.Name == "IsTrue")
                                        answ.IsTrue = Convert.ToBoolean(answerElm.InnerText);
                                }
                                answers.Add(answ);
                            }
                            quiz.Answers = answers;
                        }
                    }
                    this.Questions.Add(quiz);
                }
            }
        }
Ejemplo n.º 4
0
 public void Remove(Question question)
 {
     int index = 0;
     foreach (var quiz in Questions)
     {
         if (question.Name == quiz.Name)
         {
             this.Questions.RemoveAt(index);
             break;
         }
         index++;
     }
     //this.Questions.Remove(question);
 }