Пример #1
0
        public void LoadQuiz(int quiz_id, int user_id)
        {
            desc.Children.Clear();
            Results results = new Results();

            QuestionResult[] res;
            Question[]       questions;
            DB.LoadResult(quiz_id, user_id, out results);
            DB.LoadQuestionResults(results.ID, out res);
            DB.LoadQuestions(quiz_id, out questions);
            Answer[] answers = new Answer[res.Length];
            for (int i = 0; i < questions.Length; i++)
            {
                Answer[] a;
                AddLine(questions[i].Description);
                DB.LoadAnswers(questions[i].ID, out a);
                int    total       = 100;
                int    totalCount  = 0;
                int[]  percentages = new int[a.Length];
                bool[] boldText    = new bool[a.Length];
                for (int j = 0; j < a.Length; j++)
                {
                    DB.LoadQuestionResultsByAnswer(a[j].ID, out res);
                    totalCount    += res.Length;
                    percentages[j] = res.Length;
                    boldText[j]    = false;
                    for (int k = 0; k < res.Length; k++)
                    {
                        if (results.ID == res[k].Results_ID)
                        {
                            boldText[j] = true;
                            break;
                        }
                    }
                }
                for (int j = 0; j < a.Length; j++)
                {
                    int perc = (int)Math.Round(100.0f * ((float)percentages[j] / (float)totalCount));
                    total -= perc;
                    if (j == a.Length - 1 && total != 0 && total != 100)
                    {
                        perc += total;
                    }
                    AddLine(a[j].Description, boldText[j], perc, a[j].Correctness > 0 ? Colors.Green : Colors.Red);
                }
            }
        }
Пример #2
0
        void sb_Completed(object sender, EventArgs e)
        {
            if (curMode == UIMode.Questionary)
            {
                title.Text     = currentQuiz.Description;
                button.Content = "Submit";
                ScrollViewer scrollViewer = new ScrollViewer();
                scrollViewer.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
                Border border = new Border();
                border.Padding = new Thickness(1);

                /*border.BorderThickness = new Thickness(1);
                 * border.BorderBrush = List.BorderBrush;
                 * border.Background = Brushes.White;*/
                quizViewer             = new StackPanel();
                quizViewer.Orientation = Orientation.Vertical;
                for (int i = 0; i < currentQuizQuestions.Length; i++)
                {
                    StackPanel answers = new StackPanel();
                    answers.Orientation = Orientation.Vertical;
                    answers.Margin      = new Thickness(0, 0, 0, 5);
                    Answer[] a;
                    DB.LoadAnswers(currentQuizQuestions[i].ID, out a);
                    if (a != null)
                    {
                        answers.Children.Add(new TextBlock()
                        {
                            Text = currentQuizQuestions[i].Description, FontFamily = new FontFamily("Segoe UI"), FontSize = 16, Tag = currentQuizQuestions[i]
                        });
                        for (int j = 0; j < a.Length; j++)
                        {
                            answers.Children.Add(new RadioButton()
                            {
                                Content = a[j].Description, FontFamily = new FontFamily("Segoe UI"), Tag = a[j]
                            });
                        }
                        quizViewer.Children.Add(answers);
                    }
                }
                scrollViewer.Content = quizViewer;
                border.Child         = scrollViewer;
                contentPanel.Children.Clear();
                contentPanel.Children.Add(border);
            }
            else if (curMode == UIMode.ResultsView)
            {
                Results results = new Results(currentQuiz.ID, curUser.ID);
                DB.InsertResults(ref results);
                foreach (object o in quizViewer.Children)
                {
                    if (o is StackPanel)
                    {
                        StackPanel answers  = o as StackPanel;
                        Question   question = null;
                        for (int i = 0; i < answers.Children.Count; i++)
                        {
                            object obj = answers.Children[i];
                            if (obj is TextBlock)
                            {
                                TextBlock tb = obj as TextBlock;
                                question = (Question)tb.Tag;
                            }
                            else if (obj is RadioButton)
                            {
                                RadioButton rb = obj as RadioButton;
                                if (rb.IsChecked.Value)
                                {
                                    Answer         answer = (Answer)rb.Tag;
                                    QuestionResult result = new QuestionResult(answer.ID, results.ID);
                                    DB.InsertQuestionResults(result);
                                }
                            }
                        }
                    }
                }
                contentPanel.Children.Clear();
                Chart ch = new Chart();
                ch.LoadQuiz(currentQuiz.ID, curUser.ID);
                contentPanel.Children.Add(ch);
                title.Text     = "Results:";
                button.Content = "Ok";
            }
            else if (curMode == UIMode.QuizSelection)
            {
                contentPanel.Children.Clear();
                contentPanel.Children.Add(List);
                title.Text     = "Choose quiz:";
                button.Content = "Start";
            }
            else if (curMode == UIMode.Login)
            {
                contentPanel.Children.Clear();
                LoginPage page = new LoginPage();
                page.Submit += Button_Click_1;
                contentPanel.Children.Add(page);
                title.Text     = "Login";
                button.Content = "Ok";
            }
            fadein.Begin();
        }