Пример #1
0
 public TestDesigner(ClientObject cl, int testId)
 {
     InitializeComponent();
     _client      = cl;
     _testId      = testId;
     questions    = _client.GetQuestions(testId);
     questionType = _client.GetQuestionTypes();
     if (questions.Count != 0)
     {
         testsGrid.ItemsSource = questions;
     }
 }
Пример #2
0
 public AdminTestQuestions(ClientObject cl, Window _mw, Frame _mn, int testId)
 {
     InitializeComponent();
     _client      = cl;
     _testId      = testId;
     mw           = _mw;
     main         = _mn;
     questions    = _client.GetQuestions(testId);
     questionType = _client.GetQuestionTypes();
     if (questions.Count != 0)
     {
         testsGrid.ItemsSource = questions;
     }
 }
 public void AddItemsToQuestionTypesComboBox()
 {
     types = client.GetQuestionTypes();
     QuestionTypeComboBox.Items.Clear();
     if (types.Count > 0)
     {
         foreach (DTOQuestionType item in types)
         {
             ComboBoxItem gnItem = new ComboBoxItem()
             {
                 Content = item.QuestionTypeName
             };
             QuestionTypeComboBox.Items.Add(gnItem);
         }
     }
     else
     {
         ComboBoxItem gnItem = new ComboBoxItem()
         {
             Content = "No types"
         };
         QuestionTypeComboBox.Items.Add(gnItem);
     }
 }
Пример #4
0
        public StudentPassTest(ClientObject cl, int testId, Window _mw, Frame _mn, StudentTests previousPage)
        {
            InitializeComponent();
            client        = cl;
            mw            = _mw;
            main          = _mn;
            _previousPage = previousPage;
            _userAnswers  = new List <DTOAnswer>();
            dtoTest       = client.GetTest(testId);
            questions     = client.GetQuestions(testId);
            questionType  = client.GetQuestionTypes();
            _testSession  = new DTOTestSession()
            {
                Status = "Continues", StartTime = DateTime.Now, TestId = testId, StudentId = cl.GetClientId()
            };

            Thread.Sleep(500);
            _testSession.TestSessionId = client.AddTestSession(_testSession);

            //IGNORE comments.
            //1. add grid with one column
            //2. add two  containers vertically
            //3. add question text to uppersection
            //4. add container horisontal
            //5. add two containers in both container from step 4.
            //6. paiste horisontal container
            //7. add answer option with certain type.
            var mainStack = new StackPanel();

            mainStack.HorizontalAlignment = HorizontalAlignment.Left;
            var listOfStackPanels = new List <StackPanel>();

            var testNameStacPanel = new StackPanel();
            var testName          = new TextBlock();

            testName.FontSize   = 15;
            testName.FontFamily = new FontFamily("Century Gothic");
            testName.Text       = dtoTest.TestName;
            testNameStacPanel.Children.Add(testName);
            listOfStackPanels.Add(testNameStacPanel);

            int i = 0;

            foreach (var question in questions)
            {
                // Answers logic
                answerDictionary.Add(i, "");

                //
                //questionLogic
                var stackQuestion = new StackPanel();
                stackQuestion.Margin = new Thickness()
                {
                    Bottom = 20, Left = 10, Right = 0, Top = 0
                };
                var stackQuestionText = new StackPanel();
                var stackOptions      = new StackPanel();
                var textElement       = new TextBlock();
                textElement.Text = (i + 1).ToString() + ". " + question.QuestionText;
                stackQuestionText.Children.Add(textElement);
                var options = question.AnswerOption?.Split(';');
                if (options != null && options.Length != 0)
                {
                    if (question.QuestionTypeId == 1)
                    {
                        for (int k = 0; k < options.Length; k++)
                        {
                            RadioButton rb = new RadioButton()
                            {
                                Content = " " + options[k], IsChecked = i != 0
                            };
                            rb.Checked += (sender, args) =>
                            {
                                answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag] = ((System.Windows.Controls.ContentControl)args.Source).Content.ToString();
                            };
                            rb.Unchecked += (sender, args) => { /* Do nothing */ };
                            rb.Tag        = i;
                            rb.IsChecked  = false;
                            mainStackPanel.HorizontalAlignment = HorizontalAlignment;
                            stackOptions.Children.Add(rb);
                        }
                    }
                    else
                    {
                        if (question.QuestionTypeId == 2)
                        {
                            for (int k = 0; k < options.Length; k++)
                            {
                                CheckBox rb = new CheckBox()
                                {
                                    Content = " " + options[k], IsChecked = i != 0
                                };
                                rb.Checked += (sender, args) =>
                                {
                                    if (string.IsNullOrEmpty(answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag]))
                                    {
                                        answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag] = ((System.Windows.Controls.ContentControl)args.Source).Content.ToString();
                                    }
                                    else
                                    {
                                        answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag] += " ; " + ((System.Windows.Controls.ContentControl)args.Source).Content.ToString();
                                    }
                                };
                                rb.Unchecked += (sender, args) => {
                                    /* Do stuff */
                                    var      multipleAnswers   = answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag];
                                    string   elementToRemove   = ((System.Windows.Controls.ContentControl)args.Source).Content.ToString();
                                    string[] separatingStrings = { " ; " };
                                    var      newAnswers        = multipleAnswers.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries).Where(val => val != elementToRemove).ToArray();
                                    answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag] = string.Join(" ; ", newAnswers);
                                };

                                rb.Tag = i;
                                mainStackPanel.HorizontalAlignment = HorizontalAlignment;
                                rb.IsChecked = false;
                                stackOptions.Children.Add(rb);
                            }
                        }
                        else
                        {
                            if (question.QuestionTypeId == 3)
                            {
                                for (int k = 0; k < 2; k++)
                                {
                                    string[]    optionsTrueFalse = { "правда", "неправда" };
                                    RadioButton rb = new RadioButton()
                                    {
                                        Content = " " + optionsTrueFalse[k], IsChecked = i != 0
                                    };
                                    rb.Checked += (sender, args) =>
                                    {
                                        answerDictionary[(int)((System.Windows.FrameworkElement)sender).Tag] = ((System.Windows.Controls.ContentControl)args.Source).Content.ToString();
                                    };
                                    rb.Unchecked += (sender, args) => { /* Do nothing */ };
                                    rb.Tag        = i;
                                    rb.IsChecked  = false;
                                    mainStackPanel.HorizontalAlignment = HorizontalAlignment;
                                    stackOptions.Children.Add(rb);
                                }
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                    }
                }
                else
                {
                    var textElementBox = new TextBlock();
                    textElementBox.Text = "Варіанти відповідей відсутні. ((";
                    stackOptions.Children.Add(textElementBox);
                    stackOptions.Tag = i;
                }
                stackQuestion.Children.Add(stackQuestionText);
                stackQuestion.Children.Add(stackOptions);
                listOfStackPanels.Add(stackQuestion);

                ++i;
            }

            // adding questions to stack.
            foreach (var listOfStackPanel in listOfStackPanels)
            {
                mainStack.Children.Add(listOfStackPanel);
            }

            mainStackPanel.Children.Add(mainStack);


            //add button SUBMIT
            Button buttonSubmit = new Button()
            {
                Content = "Завершити"
            };

            //< Button Content = "Button" HorizontalAlignment = "Left" Margin = "20,10,0,0" VerticalAlignment = "Top" Width = "75" Click = "Button_Click" />
            buttonSubmit.HorizontalAlignment = HorizontalAlignment.Left;
            buttonSubmit.Margin = new Thickness()
            {
                Bottom = 20, Left = 10, Right = 0, Top = 0
            };
            buttonSubmit.VerticalAlignment = VerticalAlignment.Top;
            buttonSubmit.Width             = 75;
            buttonSubmit.Click            += new RoutedEventHandler(Button_Click);

            mainStackPanel.Children.Add(buttonSubmit);
        }