Ejemplo n.º 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);
         }
     }
 }
Ejemplo n.º 2
0
        public static string InsertResults(ref Results item)
        {
            SqlCommand command = new SqlCommand("Insert Into Results (Quiz_ID, User_ID) values(" + item.Quiz_ID + ", " + item.User_ID
                + ");", con);
            string s = ExecuteCommand(command);

            SqlCommand command2 = new SqlCommand("Select * from Results where Results.Quiz_ID='" + item.Quiz_ID + "' AND Results.User_ID='" + item.User_ID + "';", con);
            SqlDataReader sdr1 = command2.ExecuteReader();
            while (sdr1.Read())
            {
                item.ID = (int)sdr1["Results_ID"];
            }
            sdr1.Close();

            return s;
        }
Ejemplo n.º 3
0
 public static string LoadResult(int quiz_id, int user_id, out Results user)
 {
     user = null;
     if (con == null)
         return "Connection is not initialized";
     try
     {
         SqlCommand command2 = new SqlCommand("Select * from Results where Results.Quiz_ID='" + quiz_id + "' AND Results.User_ID='" + user_id + "';", con);
         SqlDataReader sdr1 = command2.ExecuteReader();
         while (sdr1.Read())
         {
             user = new Results();
             user.ID = (int)sdr1["Results_ID"];
             user.Quiz_ID = quiz_id;
             user.User_ID = user_id;
         }
         sdr1.Close();
     }
     catch (Exception e)
     {
         return e.ToString();
     }
     if (user == 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();
 }