private void InitializeDialog()
        {
            question = Warehouse.Warehouse.Instance.CourseTree.CurrentNode as Question;
            FillNextQuestions(question);

            foreach (ResponseVariant rv in question.ResponseVariants)
            {
                rvs.Add(ResponseVariant.Clone(rv));
            }

            #region Кнопка Редактировать подсказку

            if (question.Parent is TestModule)
            {
                var tm = question.Parent as TestModule;

                hintButton.Enabled = tm.Trainer;
            }

            if (question.Parent is Group)
            {
                var tm = question.Parent.Parent as TestModule;

                hintButton.Enabled = tm.Trainer;
            }

            #endregion

            InitializeTabPages();
        }
        public ResponseVariant(Question question)
        {
            this.question = question;
            Responses = new ArrayList();

            XmlReader = new ResponseVariantXmlReader(question, this);
        }
        private void FillNextQuestions(Question q)
        {
            nextQuestionComboBox.Items.Clear();
            nextQuestionComboBox.Items.Add("");

            var tm = q.Parent as TestModule;
            foreach (var question in tm.Questions)
            {
                if (!question.Id.Equals(q.Id))
                {
                    nextQuestionComboBox.Items.Add(question.Text);
                }
            }

            //  nextQuestionComboBox.Text = q.NextQuestion == null ? "" : q.NextQuestion.Text;

           // nextQuestionComboBox.Text = "";
        }
 public MultichoiceQuestionXmlWriter(Question question)
 {
     this.question = question;
 }
 public OuterQuestionXmlReader(Question question)
 {
     this.question = question;
 }
 public OrderingQuestionXmlReader(Question question)
 {
     this.question = question;
 }
        private static QuestionDocument CreateQuestionDocument(Question q)
        {
            q.QuestionDocument = new QuestionDocument
                                     {
                                         Question = q,
                                         Text = q.Text,
                                         HtmlEditingTool =
                                             {Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design}
                                     };

            //q.QuestionDocument.VisualHtmlEditor.SetDefaultFont();
            HtmlEditingToolHelper.SetDefaultDocumentHtml(q.QuestionDocument.HtmlEditingTool);
            q.QuestionDocument.HtmlEditingTool.BodyInnerHtml = q.DocumentHtml;
            q.QuestionDocument.HtmlEditingTool.SetDefaultHtml();
            // Блокирует команду Undo.
            //q.QuestionDocument.HtmlEditingTool.Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Preview;
            q.QuestionDocument.HtmlEditingTool.Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design;
            q.QuestionDocument.Show();

            if (q.Text.Length > 22)
            {
                q.QuestionDocument.Text = q.Text.Substring(0, 22) + "...";
            }
            else
            {
                q.QuestionDocument.Text = q.Text;
            }

            return q.QuestionDocument;
        }
        public static Question GetQuestionById(Guid id)
        {
            question = null;

            WalkTree(Instance.CourseTree.Nodes, id);

            return question;
        }
        private void FillProfiles(Question q)
        {
            // Вопрос в контроле.
            if (q.Parent is TestModule)
            {
                var tm = q.Parent as TestModule;

                // Контроль в учебном курсе.
                if (tm.Parent is CourseRoot)
                {
                    // Входной контроль.
                    if (tm.TestType.Equals(Enums.TestType.InTest))
                    {
                        foreach (Concept c in Warehouse.Warehouse.Instance.ConceptTree.Nodes)
                        {
                            if (c.IsProfile && c.InDummyConcepts.Count > 0)
                            {
                                profileComboBox.Items.Add(c.Text);
                            }
                        }
                    }
                    // Выходной контроль.
                    else
                    {
                        foreach (Concept c in Warehouse.Warehouse.Instance.ConceptTree.Nodes)
                        {
                            if (c.IsProfile && c.OutDummyConcept != null)
                            {
                                profileComboBox.Items.Add(c.Text);
                            }
                        }
                    }
                }

                // Контроль в учебном модуле.
                if (tm.Parent is TrainingModule)
                {
                    var trm = tm.Parent as TrainingModule;

                    // Входной контроль.
                    if (tm.TestType.Equals(Enums.TestType.InTest))
                    {
                        foreach (var idc in trm.InConceptParent.InDummyConcepts)
                        {
                            if (idc.Concept.IsProfile)
                            {
                                profileComboBox.Items.Add(idc.Concept.Text);
                            }
                        }
                    }
                    // Выходной контроль.
                    else
                    {
                        foreach (var odc in trm.OutConceptParent.OutDummyConcepts)
                        {
                            if (odc.Concept.IsProfile)
                            {
                                profileComboBox.Items.Add(odc.Concept.Text);
                            }
                        }
                    }
                }
            }

            // Вопрос в группе.
            if (q.Parent is Group)
            {
                var tm = q.Parent.Parent as TestModule;

                // Контроль в учебном курсе.
                if (tm.Parent is CourseRoot)
                {
                    // Входной контроль.
                    if (tm.TestType.Equals(Enums.TestType.InTest))
                    {
                        foreach (Concept c in Warehouse.Warehouse.Instance.ConceptTree.Nodes)
                        {
                            if (c.IsProfile && c.InDummyConcepts.Count > 0)
                            {
                                profileComboBox.Items.Add(c.Text);
                            }
                        }
                    }
                    // Выходной контроль.
                    else
                    {
                        foreach (Concept c in Warehouse.Warehouse.Instance.ConceptTree.Nodes)
                        {
                            if (c.IsProfile && c.OutDummyConcept != null)
                            {
                                profileComboBox.Items.Add(c.Text);
                            }
                        }
                    }
                }

                // Контроль в учебном модуле.
                if (tm.Parent is TrainingModule)
                {
                    var trm = tm.Parent as TrainingModule;

                    // Входной контроль.
                    if (tm.TestType.Equals(Enums.TestType.InTest))
                    {
                        foreach (var idc in trm.InConceptParent.InDummyConcepts)
                        {
                            if (idc.Concept.IsProfile)
                            {
                                profileComboBox.Items.Add(idc.Concept.Text);
                            }
                        }
                    }
                    // Выходной контроль.
                    else
                    {
                        foreach (var odc in trm.OutConceptParent.OutDummyConcepts)
                        {
                            if (odc.Concept.IsProfile)
                            {
                                profileComboBox.Items.Add(odc.Concept.Text);
                            }
                        }
                    }
                }
            }
        }
        public static void ConvertQuestionDocument(HtmlEditingTool htmlEditingTool, Question q)
        {
            var testModuleText = string.Empty;
            if (q.Parent is TestModule)
            {
                testModuleText = q.Parent.Text;
            }
            else
            {
                testModuleText = q.Parent.Parent.Text;
            }

            var questionHtml = q.DocumentHtml;
            if (q.QuestionDocument != null)
            {
                questionHtml = q.QuestionDocument.HtmlEditingTool.BodyInnerHtml;
            }

            var html = string.Empty;

            html = "<table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n" +
                   "<tr>\n" +
                   "<td>" +
                   "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" +
                   "<tr align=\"center\" bgcolor=\"#CCCCFF\">\n" +
                // имя и время теста
                   "<td bgcolor=\"#eeeeee\" width=\"70%\" align=\"center\">" +
                   "<b>" + testModuleText +
                   "</b>" +
                   "</td>\n" +
                   "<td bgcolor=\"#ffeeee\"></td>\n" +
                   "</tr>\n" +
                   "<tr>\n" +
                // имя и время вопроса
                   "<td bgcolor=\"#f5f5f5\" width=\"70%\" align=\"center\">" +
                   "<i>" + q.Text +
                   "</i> " +
                   "</td>\n" +
                   "<td bgcolor=\"#ffeeee\"></td>\n" +
                   "</tr>\n" +
                   "</table>\n" +
                   "</td>\n" +
                   "</tr>\n" +
                   "<tr>\n" +
                   "<td>\n" +
                   "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" +
                   "<tr bgcolor=\"#eeeeff\">\n" +
                // вопрос
                   "<td colspan=\"3\">\n" + questionHtml +
                   "</td>\n" +
                   "</tr>\n" +
                   "</table>\n" +
                   "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n";

            if (q is OpenQuestion)
            {
                html += "<tr bgcolor=\"#f5f5f5\">\n" +
                        "<td width=\"100%\" align=\"left\">\n" +
                        "<input type=\"text\"/>\n" +
                        "</td>\n" +
                        "</tr>\n";
            }
            else
            {
                char letter = 'a';
                foreach (var response in q.Responses)
                {
                    html += "<tr bgcolor=\"#f5f5f5\">\n" +
                            "<td width=\"5%\" align=\"center\">\n" +
                            letter +
                            "</td>\n" +
                            "<td width=\"5%\" align=\"center\">\n";

                    if (q is ChoiceQuestion)
                    {
                        html += "<input type=\"radio\" />\n";
                    }
                    else if (q is MultichoiceQuestion)
                    {
                        html += "<input type=\"checkbox\" />\n";
                    }

                    else if (q is OrderingQuestion)
                    {
                        html += "<input type=\"hidden\" value=\"c\" />\n";
                        html += "<select name=\"c\">\n";
                        html += "<option></option>\n";

                        for (int i = 1; i <= q.Responses.Count; i++)
                        {
                            html += "<option value=\"" + i + "\">" + i + "</option>\n";
                        }

                        html += "</select>\n";
                    }

                    var responseHtml = response.DocumentHtml;
                    if (response.ResponseDocument != null)
                    {
                        responseHtml = response.ResponseDocument.HtmlEditingTool.BodyInnerHtml;
                    }

                    html += "</td>\n" +
                            "<td>\n" + responseHtml +
                            "</td>\n" +
                            "</tr>\n";

                    letter++;
                }
            }

            html += "</table>";

            htmlEditingTool.BodyInnerHtml = html;
        }
 public OuterQuestionXmlWriter(Question question)
 {
     this.question = question;
 }
 public OrderingQuestionXmlWriter(Question question)
 {
     this.question = question;
 }
 public MultichoiceQuestionXmlReader(Question question)
 {
     this.question = question;
 }
 public ResponseVariantXmlReader(Question question, ResponseVariant responseVariant)
 {
     this.question = question;
     this.responseVariant = responseVariant;
 }
        public static Question Clone(Question question)
        {
            Question newQuestion = null;

            #region Инициализация вопроса

            if (question is ChoiceQuestion)
            {
                newQuestion = new ChoiceQuestion();
            }
            else if (question is MultichoiceQuestion)
            {
                newQuestion = new MultichoiceQuestion();
            }
            else if (question is InteractiveQuestion)
            {
                newQuestion = new InteractiveQuestion();
            }
            else if (question is OrderingQuestion)
            {
                newQuestion = new OrderingQuestion();
            }
            else if (question is OpenQuestion)
            {
                newQuestion = new OpenQuestion();
            }
            else if (question is CorrespondenceQuestion)
            {
                newQuestion = new CorrespondenceQuestion();
            }
            else if (question is OuterQuestion)
            {
                newQuestion = new OuterQuestion();
                (newQuestion as OuterQuestion).TaskId = (question as OuterQuestion).TaskId;
                (newQuestion as OuterQuestion).TaskName = (question as OuterQuestion).TaskName;
                (newQuestion as OuterQuestion).TestName = (question as OuterQuestion).TestName;
                (newQuestion as OuterQuestion).SubjectName = (question as OuterQuestion).SubjectName;
                (newQuestion as OuterQuestion).Declaration = (question as OuterQuestion).Declaration;
                (newQuestion as OuterQuestion).Url = (question as OuterQuestion).Url;
            }

            #endregion

            newQuestion.LowerBound = question.LowerBound;
            newQuestion.Cardinality = question.Cardinality;
            newQuestion.Text = question.Text;
            newQuestion.Id = Guid.NewGuid();
            newQuestion.DocumentHtml = string.Copy(question.DocumentHtml);
            newQuestion.TimeRestriction = question.TimeRestriction;
            newQuestion.Profile = question.Profile;
            newQuestion.Marks = question.Marks;
            newQuestion.Hint = question.Hint;
            newQuestion.NextQuestion = question.NextQuestion;
            newQuestion.IsAdaptive = question.IsAdaptive;
            newQuestion.BaseType = question.BaseType;
            newQuestion.DefaultValue = question.DefaultValue;
            //newQuestion.Mark = question.Mark;
            newQuestion.IsShuffle = question.IsShuffle;
            newQuestion.MaxChoices = question.MaxChoices;
            //  newQuestion.timeRestriction = question.timeRestriction;
            newQuestion.identifier = question.identifier;    // идентификатор вопроса ("VE-" + questionNumber + questionType)  

            foreach (var questionResponse in question.Responses)
            {
                var response = Response.Clone(questionResponse);
                newQuestion.Nodes.Add(response);
            }

            foreach (ResponseVariant questionResponseVariant in question.ResponseVariants)
            {
                var responseVariant = new ResponseVariant(question);

                if (!(question is OrderingQuestion) && !(question is OpenQuestion))
                {
                    foreach (Response response in questionResponseVariant.Responses)
                    {
                        for (var i = 0; i < question.Responses.Count; i++)
                        {
                            if ((question.Responses[i]).Text.Equals(response.Text))
                            {
                                responseVariant.Responses.Add(question.Responses[i]);

                                break;
                            }
                        }
                    }
                }
                else
                {
                    for (var i = 0; i < questionResponseVariant.Responses.Count; i++)
                    {
                        responseVariant.Responses.Add(questionResponseVariant.Responses[i]);
                    }
                }

                responseVariant.Weight = questionResponseVariant.Weight;
                responseVariant.Hint = questionResponseVariant.Hint;
                responseVariant.NextQuestion = questionResponseVariant.NextQuestion; // моё 


                newQuestion.ResponseVariants.Add(responseVariant);
            }

            return newQuestion;
        }
        public override void Execute(object @object)
        {
            if (!Enabled)
            {
                return;
            }

            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            if (Warehouse.Warehouse.Instance.CourseTree.CurrentNode is TrainingModule || Warehouse.Warehouse.Instance.CourseTree.CurrentNode is CourseRoot)
            {
                using (var openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.Title = "Импортировать тест из упаковки IMS QTI";
                    openFileDialog.InitialDirectory = AppSettingsHelper.GetInitialDirectory();
                    openFileDialog.Filter = "ZIP (*.zip)|*.zip";

                    if (openFileDialog.ShowDialog().Equals(DialogResult.OK))
                    {
                        tmd = new TestModule();
                        string path = openFileDialog.FileName;
                        ImportTestFromQtiPackage(path);

                        tmd.Text = testName;
                        tmd.Id = Guid.NewGuid();
                        tmd.QuestionSequence = questionSequence;
                        tmd.TestType = Enums.TestType.OutTest;

                        if (groups.Count > 0)
                            foreach (Group gr in groups)
                            {
                                if (gr!=null)
                                    tmd.Nodes.Add(gr);
                                if (!Warehouse.Warehouse.Instance.CourseTree.CurrentNode.IsExpanded)
                                {
                                    Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Toggle();
                                }
                            }

                        if (questions.Count > 0)
                            foreach (Question qu in questions)
                            {
                                if (qu!=null)
                                    tmd.Nodes.Add(qu);
                                if (!Warehouse.Warehouse.Instance.CourseTree.CurrentNode.IsExpanded)
                                {
                                    Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Toggle();
                                }
                            }
                        if (tmd!=null)
                        {
                            Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Nodes.Add(tmd);
                            Warehouse.Warehouse.IsProjectModified = true;
                        }
                    }
                }
            }


            if (Warehouse.Warehouse.Instance.CourseTree.CurrentNode is TestModule || Warehouse.Warehouse.Instance.CourseTree.CurrentNode is Group)
            {
                using (var openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.Title = "Импортировать вопрос из IMS QTI";
                    openFileDialog.InitialDirectory = AppSettingsHelper.GetInitialDirectory();
                    openFileDialog.Filter = "XML (*.xml)|*.xml";

                    if (openFileDialog.ShowDialog().Equals(DialogResult.OK))
                    {
                        tmd = new TestModule();
                        string path = openFileDialog.FileName;
                       
                        qn = ReadQuestionFile(path, tmd);

                        if (Warehouse.Warehouse.Instance.CourseTree.CurrentNode is Group)
                        {
                            var g = Warehouse.Warehouse.Instance.CourseTree.CurrentNode as Group;
                            qn.Text = string.Concat("Вопрос ", g.Questions.Count + 1);

                            qn.TimeRestriction = g.TimeRestriction;
                            qn.Profile = g.Profile;
                            qn.Marks = g.Marks;
                        }

                        if (qn!=null)
                        {
                            Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Nodes.Add(qn);
                            Warehouse.Warehouse.IsProjectModified = true;
                        }
                    }
                }
               
                
            }

            IsBusy = false;
        }
 public OpenQuestionXmlReader(Question question)
 {
     this.question = question;
 }
        public static void ConvertResponseVariantDocument(HtmlEditingTool htmlEditingTool, Question question, ResponseVariant rv)
        {
            string html = string.Empty;

            var testModuleText = string.Empty;
            if (question.Parent is TestModule)
            {
                testModuleText = question.Parent.Text;
            }
            else
            {
                testModuleText = question.Parent.Parent.Text;
            }

            var questionHtml = question.DocumentHtml;
            if (question.QuestionDocument != null)
            {
                questionHtml = question.QuestionDocument.HtmlEditingTool.BodyInnerHtml;
            }

            html += "<table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n" +
                    "<tr>\n" +
                    "<td>" +
                    "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" +
                    "<tr align=\"center\" bgcolor=\"#CCCCFF\">\n" +
                // имя и время теста
                    "<td bgcolor=\"#eeeeee\" width=\"70%\" align=\"center\">" +
                        "<b>" + testModuleText +
                        "</b>" +
                    "</td>\n" +
                    "<td bgcolor=\"#ffeeee\"></td>\n" +
                    "</tr>\n" +
                    "<tr>\n" +
                // имя и время вопроса
                    "<td bgcolor=\"#f5f5f5\" width=\"70%\" align=\"center\">" +
                        "<i>" + question.Text +
                        "</i> " +
                    "</td>\n" +
                    "<td bgcolor=\"#ffeeee\"></td>\n" +
                    "</tr>\n" +
                    "</table>\n" +
                    "</td>\n" +
                    "</tr>\n" +
                    "<tr>\n" +
                    "<td>\n" +
                    "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" +
                    "<tr bgcolor=\"#eeeeff\">\n" +
                // сам вопрос
                    "<td colspan=\"3\">\n" + questionHtml +
                    "</td>\n" +
                    "</tr>\n" +
                    "</table>\n" +
                    "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n";

            if (question is OpenQuestion)
            {
                html += "<tr bgcolor=\"#f5f5f5\">\n" +
                        "<td width=\"100%\" align=\"left\">\n" +
                        "<input type=\"text\" value=\"" + rv.Responses[0].ToString() + "\"/>\n" +
                        "</td>\n" +
                        "</tr>\n";
            }
            else
            {
                char letter = 'a';

                foreach (Response response in question.Responses)
                {
                    html += "<tr bgcolor=\"#f5f5f5\">\n" +
                            "<td width=\"5%\" align=\"center\">\n" +
                            letter +
                            "</td>\n" +
                            "<td width=\"5%\" align=\"center\">\n";

                    if (question is ChoiceQuestion)
                    {
                        if (rv.Responses.Contains(response))
                        {
                            html += "<input type=\"radio\" checked/>\n";
                        }
                        else
                        {
                            html += "<input type=\"radio\" />\n";
                        }
                    }
                    else if (question is MultichoiceQuestion)
                    {
                        if (rv.Responses.Contains(response))
                        {
                            html += "<input type=\"checkbox\" checked/>\n";
                        }
                        else
                        {
                            html += "<input type=\"checkbox\" />\n";
                        }
                    }

                    else if (question is OrderingQuestion)
                    {
                        html += "<input type=\"hidden\" value=\"c\" />\n";
                        html += "<select name=\"c\">\n";
                        html += "<option>" + (int)rv.Responses[question.Responses.IndexOf(response)] + "</option>\n";

                        for (int i = 1; i <= question.Responses.Count; i++)
                        {
                            html += "<option value=\"" + i + "\">" + i + "</option>\n";
                        }

                        html += "</select>\n";
                    }

                    var responseHtml = response.DocumentHtml;
                    if (response.ResponseDocument != null)
                    {
                        responseHtml = response.ResponseDocument.HtmlEditingTool.BodyInnerHtml;
                    }

                    html += "</td>\n" +
                            "<td>\n" + responseHtml +
                            "</td>\n" +
                            "</tr>\n";

                    letter++;
                }
            }

            html += "</table>\n" +
                    "</BODY>\n" +
                    "</HTML>";

            htmlEditingTool.BodyInnerHtml = html;

            ConvertImages(htmlEditingTool);
            ConvertFlashes(htmlEditingTool);
        }
        public void InitializeData(Question q)
        {
            #region Тип вопроса

            if (q is ChoiceQuestion)
            {
                questionTypeTextBox.Text = "Одновариантный выбор";
            }

            if (q is MultichoiceQuestion)
            {
                questionTypeTextBox.Text = "Множественный выбор";
            }

            if (q is InteractiveQuestion)
            {
                questionTypeTextBox.Text = "Интерактивная картинка";
            }

            if (q is OrderingQuestion)
            {
                questionTypeTextBox.Text = "Ранжирование";
            }

            if (q is OpenQuestion)
            {
                questionTypeTextBox.Text = "Открытый вопрос";
            }

            if (q is CorrespondenceQuestion)
            {
                questionTypeTextBox.Text = "Парное соответствие";
            }

            if (q is OuterQuestion)
            {
                questionTypeTextBox.Text = "Внешний вопрос";
            }

            #endregion

            timeRestriction = q.TimeRestriction;
            RefreshTimeRestriction();
            timeRestrictionCheckBox.Checked = minutesUpDown.Enabled =
            secondsUpDown.Enabled = !timeRestriction.Equals(0);

            if (q.Profile != null)
            {
                profileComboBox.Text = q.Profile.Text;
            }

            marksUpDown.Value = Convert.ToDecimal(q.Marks);

            #region Кнопка Редактировать подсказку

            if (q.Parent is TestModule)
            {
                var tm = q.Parent as TestModule;

                hintButton.Enabled = tm.Trainer;
            }

            if (q.Parent is Group)
            {
                var tm = q.Parent.Parent as TestModule;

                hintButton.Enabled = tm.Trainer;
            }

            #endregion

            CheckState();
        }