Exemple #1
0
        public static string InsertQuestionResults(QuestionResult item)
        {
            SqlCommand command = new SqlCommand("Insert Into QuestionResult (Results_ID, Answer_ID) values(" + item.Results_ID + ", " + item.Answer_ID
                                                + ");", con);
            string s = ExecuteCommand(command);

            SqlCommand    command2 = new SqlCommand("Select * from QuestionResult where QuestionResult.Results_ID='" + item.Results_ID + "' AND QuestionResult.Answer_ID='" + item.Answer_ID + "';", con);
            SqlDataReader sdr1     = command2.ExecuteReader();

            while (sdr1.Read())
            {
                item.ID = (int)sdr1["QuestionResult_ID"];
            }
            sdr1.Close();

            return(s);
        }
Exemple #2
0
        public static string LoadQuestionResultsByAnswer(int answer_id, out QuestionResult[] items)
        {
            List <QuestionResult> itemsList = new List <QuestionResult>();

            items = null;
            if (con == null)
            {
                return("Connection is not initialized");
            }
            try
            {
                SqlCommand    command2 = new SqlCommand("Select * from QuestionResult where QuestionResult.Answer_id='" + answer_id + "';", con);
                SqlDataReader sdr1     = command2.ExecuteReader();
                while (sdr1.Read())
                {
                    QuestionResult item = new QuestionResult();
                    item.ID         = (int)sdr1["QuestionResult_ID"];
                    item.Answer_ID  = (int)sdr1["Answer_ID"];
                    item.Results_ID = (int)sdr1["Results_ID"];
                    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");
            }
        }
Exemple #3
0
 public static string LoadQuestionResultsByAnswer(int answer_id, out QuestionResult[] items)
 {
     List<QuestionResult> itemsList = new List<QuestionResult>();
     items = null;
     if (con == null)
         return "Connection is not initialized";
     try
     {
         SqlCommand command2 = new SqlCommand("Select * from QuestionResult where QuestionResult.Answer_id='" + answer_id + "';", con);
         SqlDataReader sdr1 = command2.ExecuteReader();
         while (sdr1.Read())
         {
             QuestionResult item = new QuestionResult();
             item.ID = (int)sdr1["QuestionResult_ID"];
             item.Answer_ID = (int)sdr1["Answer_ID"];
             item.Results_ID = (int)sdr1["Results_ID"];
             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";
 }
Exemple #4
0
        public static string InsertQuestionResults(QuestionResult item)
        {
            SqlCommand command = new SqlCommand("Insert Into QuestionResult (Results_ID, Answer_ID) values(" + item.Results_ID + ", " + item.Answer_ID
                + ");", con);
            string s = ExecuteCommand(command);

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

            return s;
        }
        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();
        }
 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();
 }