Esempio n. 1
0
        private void NewQuestion(object sender, EventArgs e)
        {
            SectionNode nodeToBeAddedTo = trv_view_exam.SelectedNode.GetType() == typeof(SectionNode) ? (SectionNode)trv_view_exam.SelectedNode : (SectionNode)trv_view_exam.SelectedNode.Parent;
            Question    question        = new Question()
            {
                No = nodeToBeAddedTo.Nodes.Count + 1
            };
            //
            QuestionNode questionNode = new QuestionNode(question)
            {
                ContextMenuStrip = cms_question
            };

            nodeToBeAddedTo.Nodes.Add(questionNode);
            //
            trv_view_exam.ExpandAll();
            //
            ChangeRepresentationObject obj = new ChangeRepresentationObject()
            {
                Action       = ActionType.Add,
                Question     = question,
                SectionTitle = nodeToBeAddedTo.Title
            };

            undoRedo.InsertObjectforUndoRedo(obj);
            //
            IsDirty = true;
        }
Esempio n. 2
0
        private void DeleteQuestion(object sender, EventArgs e)
        {
            var sectionNode = trv_view_exam.SelectedNode.Parent;
            //
            ChangeRepresentationObject obj = new ChangeRepresentationObject()
            {
                Action       = ActionType.Delete,
                Question     = ((QuestionNode)trv_view_exam.SelectedNode).Question,
                SectionTitle = ((SectionNode)sectionNode).Title
            };

            undoRedo.InsertObjectforUndoRedo(obj);
            //
            sectionNode.Nodes.Remove(trv_view_exam.SelectedNode);
            //
            int i = 1;

            foreach (QuestionNode questionNode in sectionNode.Nodes)
            {
                questionNode.Question.No = 1;
                questionNode.Text        = "Question " + i;
                i++;
            }
            //
            IsDirty = true;
        }
Esempio n. 3
0
        private void QuestionChanged(object sender, EventArgs e)
        {
            IsDirty = true;
            //
            ChangeRepresentationObject obj = new ChangeRepresentationObject();

            obj.Action = ActionType.Modify;
            //
            Question question   = new Question();
            var      answerCtrl = pan_options.Controls.OfType <OptionControl>().FirstOrDefault(s => s.Checked);

            question.Answer      = answerCtrl == null ? '\0' : answerCtrl.Letter;
            question.Explanation = txt_explanation.Text;
            question.Image       = (Bitmap)pct_image.Image;
            question.No          = trv_view_exam.SelectedNode.Index + 1;
            question.Options.Clear();
            foreach (var ctrl in pan_options.Controls.OfType <OptionControl>())
            {
                Option option = new Option();
                option.Alphabet = ctrl.Letter;
                option.Text     = ctrl.Text;
                question.Options.Add(option);
            }
            question.Text = txt_question_text.Text;
            //
            obj.Question     = question;
            obj.SectionTitle = ((SectionNode)trv_view_exam.SelectedNode.Parent).Title;
            undoRedo.InsertObjectforUndoRedo(obj);
        }
Esempio n. 4
0
        public ChangeRepresentationObject Undo()
        {
            if (UndoCollection.Count == 0)
            {
                return(null);
            }
            ChangeRepresentationObject undoObject = UndoCollection.Pop();

            RedoCollection.Push(undoObject);
            return(undoObject);
        }
Esempio n. 5
0
        public ChangeRepresentationObject Redo()
        {
            if (RedoCollection.Count == 0)
            {
                return(null);
            }
            ChangeRepresentationObject redoObject = RedoCollection.Pop();

            UndoCollection.Push(redoObject);
            return(redoObject);
        }
Esempio n. 6
0
        private void Redo(object sender, EventArgs e)
        {
            ChangeRepresentationObject redoObject = undoRedo.Redo();

            if (redoObject == null)
            {
                return;
            }
            else
            {
                switch (redoObject.Action)
                {
                case ActionType.Add:
                    SectionNode sectionNode = trv_view_exam.Nodes[0].Nodes.Cast <SectionNode>().FirstOrDefault(s => s.Title == redoObject.SectionTitle);
                    if (sectionNode == null)
                    {
                        sectionNode = new SectionNode(redoObject.SectionTitle)
                        {
                            ContextMenuStrip = cms_section
                        };
                        //
                        QuestionNode questionNode = new QuestionNode(redoObject.Question)
                        {
                            ContextMenuStrip = cms_question
                        };
                        sectionNode.Nodes.Add(questionNode);
                        //
                        trv_view_exam.Nodes[0].Nodes.Add(sectionNode);
                        trv_view_exam.ExpandAll();
                    }
                    else
                    {
                        sectionNode.ContextMenuStrip = cms_section;
                        //
                        QuestionNode questionNode = new QuestionNode(redoObject.Question)
                        {
                            ContextMenuStrip = cms_question
                        };
                        sectionNode.Nodes.Add(questionNode);
                        //
                        trv_view_exam.ExpandAll();
                    }
                    //
                    int i = 1;
                    foreach (QuestionNode questionNode_ in sectionNode.Nodes)
                    {
                        questionNode_.Text        = "Question " + i;
                        questionNode_.Question.No = i;
                        i++;
                    }
                    break;

                case ActionType.Delete:
                    SectionNode _sectionNode = trv_view_exam.Nodes[0].Nodes.Cast <SectionNode>().FirstOrDefault(s => s.Title == redoObject.SectionTitle);
                    if (_sectionNode != null)
                    {
                        if (_sectionNode.Nodes.Count >= redoObject.Question.No)
                        {
                            exam.Sections.First(s => s.Title == redoObject.SectionTitle).Questions.RemoveAt(redoObject.Question.No - 1);
                            _sectionNode.Nodes.RemoveAt(redoObject.Question.No - 1);
                        }
                    }
                    //
                    int j = 1;
                    foreach (QuestionNode questionNode_ in _sectionNode.Nodes)
                    {
                        questionNode_.Text        = "Question " + j;
                        questionNode_.Question.No = j;
                        j++;
                    }
                    break;

                case ActionType.Modify:
                    SectionNode sectionNode_ = trv_view_exam.Nodes[0].Nodes.Cast <SectionNode>().FirstOrDefault(s => s.Title == redoObject.SectionTitle);
                    if (sectionNode_ != null)
                    {
                        QuestionNode questionNode = (QuestionNode)sectionNode_.Nodes[redoObject.Question.No - 1];
                        questionNode.Question = redoObject.Question;
                        //
                        txt_explanation.Text      = redoObject.Question.Explanation;
                        txt_question_text.Text    = redoObject.Question.Text;
                        lbl_section_question.Text = "Section: " + trv_view_exam.SelectedNode.Parent.Text + " Question " + redoObject.Question.No;
                        pct_image.Image           = redoObject.Question.Image;
                        //
                        pan_options.Controls.Clear();
                        //
                        int k = 0;
                        if (redoObject.Question.IsMultipleChoice)
                        {
                            foreach (var option in redoObject.Question.Options)
                            {
                                OptionsControl ctrl = new OptionsControl()
                                {
                                    Letter   = option.Alphabet,
                                    Text     = option.Text,
                                    Location = new Point(2, k * 36)
                                };
                                if (redoObject.Question.Answers.Contains(option.Alphabet))
                                {
                                    ctrl.Checked = true;
                                }
                                pan_options.Controls.Add(ctrl);
                                k++;
                            }
                        }
                        else
                        {
                            foreach (var option in redoObject.Question.Options)
                            {
                                OptionControl ctrl = new OptionControl()
                                {
                                    Letter   = option.Alphabet,
                                    Text     = option.Text,
                                    Location = new Point(2, k * 36)
                                };
                                if (option.Alphabet == redoObject.Question.Answer)
                                {
                                    ctrl.Checked = true;
                                }
                                pan_options.Controls.Add(ctrl);
                                k++;
                            }
                        }
                    }
                    break;
                }
            }
        }
Esempio n. 7
0
        private void QuestionChanged(object sender, EventArgs e)
        {
            IsDirty = true;
            //
            ChangeRepresentationObject obj = new ChangeRepresentationObject()
            {
                Action = ActionType.Modify
            };
            //
            Question question = new Question()
            {
                IsMultipleChoice = chkMulipleChoice.Checked
            };

            if (question.IsMultipleChoice)
            {
                var answerCtrls = pan_options.Controls.OfType <OptionsControl>().Where(s => s.Checked);
                question.Answers = answerCtrls.Select(x => x.Letter).ToArray();
            }
            else
            {
                var answerCtrl = pan_options.Controls.OfType <OptionControl>().FirstOrDefault(s => s.Checked);
                question.Answer = answerCtrl == null ? '\0' : answerCtrl.Letter;
            }
            question.Explanation = txt_explanation.Text;
            question.Image       = (Bitmap)pct_image.Image;
            question.No          = trv_view_exam.SelectedNode.Index + 1;
            question.Options.Clear();
            if (question.IsMultipleChoice)
            {
                var ctrls = pan_options.Controls.OfType <OptionsControl>();
                foreach (var ctrl in ctrls)
                {
                    Option option = new Option()
                    {
                        Alphabet = ctrl.Letter,
                        Text     = ctrl.Text
                    };
                    question.Options.Add(option);
                }
            }
            else
            {
                var ctrls = pan_options.Controls.OfType <OptionControl>();
                foreach (var ctrl in ctrls)
                {
                    Option option = new Option()
                    {
                        Alphabet = ctrl.Letter,
                        Text     = ctrl.Text
                    };
                    question.Options.Add(option);
                }
            }

            question.Text = txt_question_text.Text;
            //
            obj.Question     = question;
            obj.SectionTitle = ((SectionNode)trv_view_exam.SelectedNode.Parent).Title;
            undoRedo.InsertObjectforUndoRedo(obj);
        }
Esempio n. 8
0
 //
 public void InsertObjectforUndoRedo(ChangeRepresentationObject dataobject)
 {
     UndoCollection.Push(dataobject);
     RedoCollection.Clear();
 }