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);
         }
     }
 }
Example #2
0
 public static string LoadAnswers(int question_ID, out Answer[] items)
 {
     List<Answer> itemsList = new List<Answer>();
     items = null;
     if (con == null)
         return "Connection is not initialized";
     try
     {
         SqlCommand command2 = new SqlCommand("Select * from Answer where Answer.Question_ID=" + question_ID + ";", con);
         SqlDataReader sdr1 = command2.ExecuteReader();
         while (sdr1.Read())
         {
             Answer item = new Answer();
             item.ID = (int)sdr1["Answer_ID"];
             item.Question_ID = (int)sdr1["Question_ID"];
             NumberFormatInfo info = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
             info.CurrencyDecimalSeparator = ".";
             item.Correctness = (float)float.Parse(sdr1["Correctness"].ToString(), info);
             item.Description = sdr1["Description"].ToString();
             itemsList.Add(item);
         }
         sdr1.Close();
     }
     catch (Exception e)
     {
         return e.ToString();
     }
     items = itemsList.ToArray();
     if (items.Length != 1)
         return items.Length + " records loaded";
     else
         return items.Length + " record loaded";
 }
Example #3
0
 public static string LoadAnswers(int answer_id, out Answer item)
 {
     item = null;
     if (con == null)
         return "Connection is not initialized";
     try
     {
         SqlCommand command2 = new SqlCommand("Select * from Answer where Answer.Answer_id=" + answer_id + ";", con);
         SqlDataReader sdr1 = command2.ExecuteReader();
         while (sdr1.Read())
         {
             item = new Answer();
             item.ID = (int)sdr1["Answer_ID"];
             item.Question_ID = (int)sdr1["Question_ID"];
             NumberFormatInfo info = (NumberFormatInfo)NumberFormatInfo.CurrentInfo.Clone();
             info.CurrencyDecimalSeparator = ".";
             item.Correctness = (float)float.Parse(sdr1["Correctness"].ToString(), info);
             item.Description = sdr1["Description"].ToString();
         }
         sdr1.Close();
     }
     catch (Exception e)
     {
         return e.ToString();
     }
     if (item == null)
     {
         return "0 record loaded";
     }
     return "1 record loaded";
 }
        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();
        }