private void UserControl_Initialized(object sender, EventArgs e)
        {
            UIElement indexPart = CommonControlCreator.CreateUIPart(new QuestionTextPart(string.Format("{0}. ", this.index + 1)), this.Foreground);

            if (indexPart is Control)
            {
                ((Control)indexPart).VerticalAlignment = System.Windows.VerticalAlignment.Top;
            }
            this.questionBodyPanel.Children.Add(indexPart);
            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Vertical;
            this.questionBodyPanel.Children.Add(stackPanel);
            CommonControlCreator.CreateContentControl(mcQuestion.Content, stackPanel, this.Foreground, null);

            List <int> optionIndexList = new List <int>();

            if (this.mcQuestion.RandomOption)
            {
                Random rand = new Random((int)DateTime.Now.Ticks);
                while (true)
                {
                    int  index = rand.Next(mcQuestion.QuestionOptionCollection.Count * 10) % mcQuestion.QuestionOptionCollection.Count;
                    bool found = false;
                    foreach (int temp in optionIndexList)
                    {
                        if (temp == index)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        optionIndexList.Add(index);
                    }

                    if (optionIndexList.Count == mcQuestion.QuestionOptionCollection.Count)
                    {
                        break;
                    }

                    Thread.Sleep(10);
                }
            }
            else
            {
                for (int i = 0; i < mcQuestion.QuestionOptionCollection.Count; i++)
                {
                    optionIndexList.Add(i);
                }
            }

            for (int i = 0; i < mcQuestion.QuestionOptionCollection.Count; i++)
            {
                this.AppendOption(mcQuestion.QuestionOptionCollection[optionIndexList[i]], i);
            }
        }
Beispiel #2
0
        private void AppendOption(QuestionOption option, int index)
        {
            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Horizontal;
            stackPanel.Margin      = new Thickness(20, 3, 0, 3);

            Label indexLabel = new Label();

            indexLabel.Content           = string.Format("{0}. ", (char)('A' + index));
            indexLabel.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            indexLabel.FontSize          = 20;
            stackPanel.Children.Add(indexLabel);

            ToggleButton toggleButton = null;

            if (this.selectableQuestion is MCQuestion)
            {
                toggleButton = new RadioButton();
                ((RadioButton)toggleButton).GroupName = this.selectableQuestion.Id;
            }
            else if (this.selectableQuestion is MRQuestion)
            {
                toggleButton = new CheckBox();
            }
            else if (this.selectableQuestion is TFQuestion)
            {
                toggleButton = new RadioButton();
                ((RadioButton)toggleButton).GroupName = this.selectableQuestion.Id;
            }
            toggleButton.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            toggleButton.Tag = option;
            if (this.response != null)
            {
                if (this.response.OptionIdList.Count > 0)
                {
                    if (option.Id == this.response.OptionIdList[0])
                    {
                        toggleButton.IsChecked = true;
                        this.isCorrect         = true;
                    }
                }
            }
            toggleButton.Checked   += toggleButtonCheckedHandler;
            toggleButton.Unchecked += this.toggleButtonUnCheckedHandler;
            this.toggleButtonList.Add(toggleButton);
            stackPanel.Children.Add(toggleButton);

            Panel contentControl = CommonControlCreator.CreateContentControl(option.OptionContent, null, this.Foreground, null);

            if (contentControl != null)
            {
                contentControl.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                contentControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                toggleButton.Content = contentControl;
            }

            this.optionPanel.Children.Add(stackPanel);
        }
        private void solutionButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.solutionWrapPanel.Children.Count == 0)
            {
                CommonControlCreator.CreateContentControl(this.exercise.CurrentSection.CurrentQuestion.Solution,
                                                          this.solutionWrapPanel,
                                                          new SolidColorBrush(Colors.White),
                                                          null);
            }

            this.solutionPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Center;
            this.solutionPopup.IsOpen    = true;
        }
        private static void replaceTextBoxWithText(FlowDocument document, QuestionContent content, ContentPartCreated contentPartCreated)
        {
            List <InlineUIContainer> tempList = new List <InlineUIContainer>();

            foreach (var block in document.Blocks)
            {
                if (block is Paragraph)
                {
                    Paragraph para = block as Paragraph;
                    foreach (var inline in para.Inlines)
                    {
                        if (inline is InlineUIContainer)
                        {
                            tempList.Add(inline as InlineUIContainer);
                        }
                    }
                }
            }

            foreach (var inlineUIContainer in tempList)
            {
                if (inlineUIContainer.Child is Image) // replace image url with local url.
                {
                    Image image = inlineUIContainer.Child as Image;

                    Image newImage = new Image();

                    Uri         newUri = new Uri(CommonControlCreator.getImageFile(image.Tag as string, content));
                    BitmapImage newBi  = new BitmapImage(newUri);
                    newImage.Source         = newBi;
                    newImage.Width          = (1.0 == newBi.Width ? 50 : newBi.Width);
                    newImage.Height         = (1.0 == newBi.Height ? 50 : newBi.Height);
                    newImage.Tag            = image.Tag;
                    inlineUIContainer.Child = newImage;
                }
                else if (inlineUIContainer.Child is TextBox) // replace textbox with richtextbox
                {
                    TextBox textBox = inlineUIContainer.Child as TextBox;

                    TextBlock richTextBox = new TextBlock();
                    richTextBox.Text        = "(                )";
                    richTextBox.Tag         = textBox.Tag;
                    inlineUIContainer.Child = richTextBox;
                    if (contentPartCreated != null)
                    {
                        contentPartCreated(richTextBox);
                    }
                }
            }
        }
Beispiel #5
0
        private void ShowQuestionWithBlankInContent()
        {
            Label indexLabel = new Label();

            indexLabel.FontSize          = 20;
            indexLabel.Margin            = new Thickness(0);
            indexLabel.Content           = string.Format("{0}. ", this.index + 1);
            indexLabel.FontWeight        = FontWeights.Medium;
            indexLabel.VerticalAlignment = System.Windows.VerticalAlignment.Top;
            this.questionBodyPanel.Children.Add(indexLabel);

            Panel panel = CommonControlCreator.CreateContentControl(this.fibQuestion.Content, null, this.Foreground, OnContentPartCreated);

            this.questionBodyPanel.Children.Add(panel);
        }
        private void AppendOption(QuestionOption option, int index)
        {
            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Horizontal;
            stackPanel.Margin      = new Thickness(20, 3, 0, 3);

            Label indexLabel = new Label();

            indexLabel.Content           = string.Format("{0}. ", (char)('A' + index));
            indexLabel.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            indexLabel.FontSize          = 20;
            stackPanel.Children.Add(indexLabel);

            RadioButton radioBtn = new RadioButton();

            radioBtn.VerticalAlignment = System.Windows.VerticalAlignment.Center;
            radioBtn.GroupName         = this.mcQuestion.Id;
            radioBtn.Tag = option;
            if (this.response != null)
            {
                if (this.response.OptionIdList.Count > 0)
                {
                    if (option.Id == this.response.OptionIdList[0])
                    {
                        radioBtn.IsChecked = true;
                        this.isCorrect     = true;
                    }
                }
            }
            radioBtn.Checked += new RoutedEventHandler(radioBtn_Checked);
            stackPanel.Children.Add(radioBtn);

            Panel contentControl = CommonControlCreator.CreateContentControl(option.OptionContent, null, this.Foreground, null);

            if (contentControl != null)
            {
                contentControl.VerticalAlignment   = System.Windows.VerticalAlignment.Center;
                contentControl.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                radioBtn.Content = contentControl;
            }

            this.optionPanel.Children.Add(stackPanel);
        }
Beispiel #7
0
        internal override System.Windows.Documents.FlowDocument GetKnowledgeDefinition()
        {
            if (this.assessmentApp.Knowledge.Content == null)
            {
                return(new System.Windows.Documents.FlowDocument());
            }

            if (this.assessmentApp.Knowledge.Content.ContentType == Assessment.Data.ContentType.Html)
            {
                return(HtmlToXamlConverter.ConvertHtmlToXaml(this.assessmentApp.Knowledge.Content.Content));
            }
            else if (this.assessmentApp.Knowledge.Content.ContentType == Assessment.Data.ContentType.FlowDocument)
            {
                FlowDocument doc = HtmlToXamlConverter.DeserializeFlowDocument(this.assessmentApp.Knowledge.Content.Content);
                CommonControlCreator.replaceTextBoxWithRichTextBox(doc, this.assessmentApp.Knowledge.Content, null);
                return(doc);
            }

            throw new NotSupportedException("Knowledge must be HTML or FlowDocument format!");
        }
Beispiel #8
0
        private void solutionButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.solutionWrapPanel.Children.Count == 0)
            {
                if (this.exercise.CurrentSection.CurrentQuestion.Solution != null)
                {
                    if (!string.IsNullOrEmpty(this.exercise.CurrentSection.CurrentQuestion.Solution.Content))
                    {
                        CommonControlCreator.CreateContentControl(this.exercise.CurrentSection.CurrentQuestion.Solution,
                                                                  this.solutionWrapPanel,
                                                                  new SolidColorBrush(Colors.White),
                                                                  null);
                    }
                    else if (!string.IsNullOrEmpty(this.exercise.CurrentSection.CurrentQuestion.Tip))
                    {
                        TextBlock noSolutionTextBlock = new TextBlock();
                        noSolutionTextBlock.Text       = this.exercise.CurrentSection.CurrentQuestion.Tip;
                        noSolutionTextBlock.FontSize   = 20;
                        noSolutionTextBlock.FontWeight = FontWeights.Medium;
                        noSolutionTextBlock.Foreground = Brushes.White;
                        this.solutionWrapPanel.Children.Add(noSolutionTextBlock);
                    }
                }

                if (this.solutionWrapPanel.Children.Count == 0)
                {
                    TextBlock noSolutionTextBlock = new TextBlock();
                    noSolutionTextBlock.Text       = "抱歉,该题没有解题方法!";
                    noSolutionTextBlock.FontSize   = 20;
                    noSolutionTextBlock.FontWeight = FontWeights.Medium;
                    noSolutionTextBlock.Foreground = Brushes.White;
                    this.solutionWrapPanel.Children.Add(noSolutionTextBlock);
                }
            }

            this.solutionPopup.Placement = System.Windows.Controls.Primitives.PlacementMode.Center;
            this.solutionPopup.IsOpen    = true;
        }
        private void UserControl_Initialized(object sender, EventArgs e)
        {
            UIElement indexPart = CommonControlCreator.CreateUIPart(new QuestionTextPart(string.Format("{0}. ", this.index + 1)), this.Foreground);

            if (indexPart is Control)
            {
                ((Control)indexPart).VerticalAlignment = System.Windows.VerticalAlignment.Top;
            }

            this.questionBodyPanel.Children.Add(indexPart);
            StackPanel stackPanel = new StackPanel();

            stackPanel.Orientation = Orientation.Vertical;
            this.questionBodyPanel.Children.Add(stackPanel);
            CommonControlCreator.CreateContentControl(this.esQuestion.Content, stackPanel, this.Foreground, null);

            if (!string.IsNullOrEmpty(this.response.Answer.FlowDocument))
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(this.response.Answer.FlowDocument));
                this.answerEditControl.Document = this.response.Answer.FlowDocument;
            }

            this.answerEditControl.TextChangedEvent += answerEditorControl_TextChanged;
        }
Beispiel #10
0
        private void ShowQuestion()
        {
            this.correctOptionList.Clear();

            this.optionGrid.RowDefinitions.Clear();
            this.optionGrid.ColumnDefinitions.Clear();
            this.optionGrid.Children.Clear();

            QuestionContent contentContent = this.mrQuestion.Content;

            this.questionContentLabel.Content = contentContent.Content;

            //     this.solutionTextBlock.Text = this.mrQuestion.Tip;

            int rowCount = (int)System.Math.Sqrt(this.mrQuestion.QuestionOptionCollection.Count);

            System.Drawing.Size monitorSize = System.Windows.Forms.SystemInformation.PrimaryMonitorSize;
            double rowWidth  = 135f;
            double rowHeight = 110f / ((float)monitorSize.Width / (float)monitorSize.Height);

            for (int i = 0; i < rowCount; i++)
            {
                RowDefinition rowDef = new RowDefinition();
                rowDef.Height = new GridLength(1, GridUnitType.Star);
                this.optionGrid.RowDefinitions.Add(rowDef);

                ColumnDefinition colDef = new ColumnDefinition();
                colDef.Width = new GridLength(rowWidth, GridUnitType.Pixel);
                this.optionGrid.ColumnDefinitions.Add(colDef);
            }

            Random rand  = new Random((int)DateTime.Now.Ticks);
            int    index = 0;

            for (int i = 0; i < rowCount; i++)
            {
                for (int j = 0; j < rowCount; j++)
                {
                    QuestionOption option = this.mrQuestion.QuestionOptionCollection[index++];
                    bool           found  = false;
                    foreach (string optionId in this.response.OptionIdList)
                    {
                        if (option.Id == optionId)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        continue;
                    }

                    Button btn = new Button();
                    btn.Content = CommonControlCreator.CreateContentControl(option.OptionContent, null, this.Foreground, null);
                    btn.Style   = this.FindResource("ButtonStyle_Sub2") as Style;
                    btn.Tag     = option;
                    btn.Click  += new RoutedEventHandler(btn_Click);

                    if (option.IsCorrect)
                    {
                        this.correctOptionList.Add(option);
                    }

                    Grid.SetRow(btn, i);
                    Grid.SetColumn(btn, j);

                    this.optionGrid.Children.Add(btn);

                    btn.BeginAnimation(Button.OpacityProperty, new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(rand.Next(200, 800)))));
                }
            }
        }
Beispiel #11
0
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            Button btn = sender as Button;

            if (btn == null)
            {
                return;
            }

            QuestionOption option = btn.Tag as QuestionOption;

            if (option == null)
            {
                return;
            }

            if (option.IsCorrect)
            {
                this.correctOptionList.Remove(option);
                this.hideButton(btn);

                bool found = false;
                foreach (string id in this.response.OptionIdList)
                {
                    if (id == option.Id)
                    {
                        found = true;
                        break;
                    }
                }

                if (!found)
                {
                    this.response.OptionIdList.Add(option.Id);
                }
            }
            else
            {
                this.failedCount++;
                if (this.resetFailCount == this.failedCount)
                {
                    Panel contentPanel = CommonControlCreator.CreateContentControl(option.OptionContent, null, Brushes.White, null);

                    StackPanel line1Panel = new StackPanel();
                    line1Panel.Orientation = Orientation.Horizontal;
                    line1Panel.Children.Add(contentPanel);

                    Label label1 = new Label();
                    label1.Content    = "不是正确答案!";
                    label1.FontSize   = 24;
                    label1.Foreground = Brushes.White;
                    label1.FontWeight = FontWeights.Medium;
                    line1Panel.Children.Add(label1);

                    this.infoPanel.Children.Clear();
                    this.infoPanel.Children.Add(line1Panel);

                    Label label = new Label();
                    label.FontSize   = 24;
                    label.FontWeight = FontWeights.Medium;
                    label.Foreground = Brushes.White;
                    label.Content    = string.Format("你已经答错{0}次, 本题将重新开始!", this.resetFailCount);
                    this.infoPanel.Children.Add(label);

                    this.infoPopup.IsOpen = true;
                    Thread.Sleep(500);
                    this.ResetQuestion();
                }
                else
                {
                    Panel contentPanel = CommonControlCreator.CreateContentControl(option.OptionContent, null, Brushes.White, null);

                    StackPanel line1Panel = new StackPanel();
                    line1Panel.Orientation = Orientation.Horizontal;
                    line1Panel.Children.Add(contentPanel);

                    Label label = new Label();
                    label.FontSize   = 24;
                    label.FontWeight = FontWeights.Medium;
                    label.Content    = "不是正确答案!";
                    label.Foreground = Brushes.White;
                    line1Panel.Children.Add(label);

                    this.infoPanel.Children.Clear();
                    this.infoPanel.Children.Add(line1Panel);

                    this.infoPopup.IsOpen = true;
                }
                Thread.Sleep(200);
            }
        }