Пример #1
0
        public void Init()
        {
            QuizEntities qe = new QuizEntities();

            List <QuizInfo> qi = new List <QuizInfo>();

            var quiz = from q in qe.Quiz
                       select q;

            foreach (var q in quiz)
            {
                int answeredquestion = q.Question.Count(n => n.Answered == true);

                int totalquestion = q.Question.Count;

                double finishedpercentage = (double)answeredquestion / (double)totalquestion * 100;

                int answered_and_correct_question = q.Question.Count(n => n.Answered == true && n.Correct == true);

                double correctpercentage = 0;

                if (answeredquestion == 0 && answered_and_correct_question == 0)
                {
                    correctpercentage = 100;
                }
                else
                {
                    correctpercentage = (double)answered_and_correct_question / (double)answeredquestion * 100;
                }

                qi.Add(new QuizInfo(q.ID, q.Title, q.Question.Count, finishedpercentage, correctpercentage, q.Completed));
            }

            lstview_Quiz.ItemsSource = qi;
        }
Пример #2
0
        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (lstview_Quiz.SelectedItem != null)
            {
                int quizid = (lstview_Quiz.SelectedItem as QuizInfo).QuizID;

                string title = (lstview_Quiz.SelectedItem as QuizInfo).QuizTitle;

                if ((lstview_Quiz.SelectedItem as QuizInfo).FinishedPercentageText == "Completed")
                {
                    QuizEntities qe = new QuizEntities();

                    var quiz = qe.Quiz.Find(quizid);

                    foreach (var q in quiz.Question)
                    {
                        q.Answered = false;
                        q.Correct  = false;
                    }

                    qe.SaveChanges();
                }

                QuizWindow qw = new QuizWindow(this, quizid, title);

                qw.Show();

                this.Hide();
            }
        }