public static ResponseVariant Clone(ResponseVariant responseVariant)
        {
            var newResponseVariant = new ResponseVariant(responseVariant.question)
            {
                Responses = (ArrayList)responseVariant.Responses.Clone(),
                Weight = responseVariant.Weight,
                Hint = responseVariant.Hint,
                NextQuestion = responseVariant.NextQuestion
            };

            return newResponseVariant;
        }
 private void addVariantButton_Click(object sender, EventArgs e)
 {
     variantNumber++;
     var rv = new ResponseVariant(question);
     question.ResponseVariants.Add(rv);
     variantsTabControl.TabPages.Add(string.Concat("Вариант ", variantNumber));
     variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1].AutoScroll = true;
     FillTabPageWithResponses(variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1]);
     Check();
     variantsTabControl.SelectedTab = variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1];
     selectedTabIndex = variantsTabControl.TabPages.IndexOf(variantsTabControl.SelectedTab);
     viewVariantButton.Enabled = true;
     Warehouse.Warehouse.IsProjectModified = true;
 }
        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);
        }
        /// <summary>
        /// Чтение информации из файла формата IMS QTI 2.1.
        /// </summary>
        /// <param name="qfPath">Путь к файлу.</param>
        public override bool ReadQti(string qfPath)
        {
            XmlTextReader reader = new XmlTextReader(qfPath);
            bool result = true;
            Id = Guid.NewGuid();
            string HtmlText = "<HTML>\n<HEAD>\n<BASE href=\"" + Application.StartupPath + // раньше было определено где-то там
                "\\\">\n</HEAD>\n<BODY>\n<P>";

            try
            {
                //"вынимаем" элементы ответа 
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name.Equals("simpleChoice"))
                        {
                            Response r = new Response();
                            r.DocumentHtml = "<HTML>\n<HEAD>\n<BASE href=\"" + Application.StartupPath +
                                         "\\\">\n</HEAD>\n<BODY>\n<P>";
                            if (reader.GetAttribute("identifier") != null)
                            {
                                try
                                {
                                    r.Id = Guid.NewGuid();//new Guid(reader.GetAttribute("identifier"));
                                    r.Text = reader.GetAttribute("identifier");
                                    r.Identifier = reader.GetAttribute("identifier");
                                }
                                catch
                                {
                                    r.Identifier = reader.GetAttribute("identifier");
                                    r.Id = Guid.NewGuid();
                                    r.Text = reader.GetAttribute("identifier");
                                }
                            }
                            if (reader.GetAttribute("fixed") != null)
                            {
                                r.IsFixed = bool.Parse(reader.GetAttribute("fixed"));
                            }
                            string s = reader.ReadInnerXml();
                            r.DocumentHtml += ConvertXmlStringToHtml(s, qfPath);
                            r.DocumentHtml += "</P>\n</BODY>\n</HTML>";
                            // реализовать 
                            //  r.FillImagesArray();
                            // this.Responses.Add(r);
                            Nodes.Add(r);
                            //  Responses.Add(r);
                        }
                    }
                }
                reader.Close();

                //затем "вынимаем" всё остальное
                reader = new XmlTextReader(qfPath);
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.Name.Equals("assessmentItem", StringComparison.OrdinalIgnoreCase))
                        {
                            if (reader.GetAttribute("timeDependent") != null)
                            {
                                bool.TryParse(reader.GetAttribute("timeDependent"), out isTimeDependent);
                            }
                            if (reader.GetAttribute("identifier") != null)
                            {
                                identifier = reader.GetAttribute("identifier"); //был с заглавной
                            }
                            if (reader.GetAttribute("adaptive") != null)
                            {
                                bool.TryParse(reader.GetAttribute("adaptive"), out isAdaptive);
                            }
                            if (reader.GetAttribute("title") != null)
                            {
                                Text = reader.GetAttribute("title");
                            }
                            else Text = reader.GetAttribute("identifier");
                        }

                        if (reader.Name.Equals("correctResponse", StringComparison.OrdinalIgnoreCase))
                        {
                            bool endCycle = false;
                            ResponseVariant rv = new ResponseVariant(this);
                            rv.Weight = 1.0;

                            while (!endCycle && reader.Read())
                            {
                                if (reader.Name.Equals("value", StringComparison.OrdinalIgnoreCase))
                                {
                                    string value = reader.ReadString();
                                    foreach (Response response in Responses)
                                    {
                                        if ((response.Id.ToString() == value) || response.Identifier == value)
                                        {
                                            rv.Responses.Add(response);
                                        }
                                    }
                                }
                                else if (reader.NodeType == XmlNodeType.EndElement)
                                {
                                    if (reader.Name.Equals("correctResponse", StringComparison.OrdinalIgnoreCase))
                                    {
                                        endCycle = true;
                                    }
                                }
                            }
                            ResponseVariants.Add(rv);
                        }

                        if (reader.Name.Equals("mapping", StringComparison.OrdinalIgnoreCase))
                        {
                            if (reader.GetAttribute("lowerBound") != null)
                                LowerBound = int.Parse(reader.GetAttribute("lowerBound"));
                            if (reader.GetAttribute("upperBound") != null)
                                Marks = int.Parse(reader.GetAttribute("upperBound"));
                            if (reader.GetAttribute("defaultValue") != null)
                                DefaultValue = int.Parse(reader.GetAttribute("defaultValue"));
                        }

                        if (reader.Name.Equals("mapEntry", StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (Response response in Responses)
                            {
                                if (response.Id.ToString() == reader.GetAttribute("mapKey"))
                                {
                                    if (reader.GetAttribute("mappedValue") != null)
                                    {
                                        string s = reader.GetAttribute("mappedValue");
                                        // разделитель, используемый в системе
                                        string decimalSeparator = NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator;
                                        // подменяем точки и запятые на разделитель, используемый в системе, чтобы преобразовать строку в число без ошибок
                                        s = s.Replace(".", decimalSeparator);
                                        s = s.Replace(",", decimalSeparator);
                                        double d;
                                        Double.TryParse(s, out d);
                                        response.MappedValue = d;
                                    }
                                }
                            }
                        }

                        if (reader.Name.Equals("itemBody", StringComparison.OrdinalIgnoreCase))
                        {
                            // считываем содержимое тега itemBody
                            while (!reader.Name.Equals("choiceInteraction", StringComparison.OrdinalIgnoreCase) && reader.Read())
                            {
                                if (reader.Name.Equals("p", StringComparison.OrdinalIgnoreCase))
                                {
                                    string xml = reader.ReadInnerXml();
                                    string html = ConvertXmlStringToHtml(xml, qfPath);
                                    if (html != " ")
                                    {
                                        HtmlText += "<P>" + html + "</P>";
                                    }
                                }

                                if (reader.Name.Equals("img", StringComparison.OrdinalIgnoreCase))
                                {
                                    try
                                    {
                                        // создаём папку для картинок проекта
                                        if (!Directory.Exists(Warehouse.Warehouse.RelativeImagesDirectory))
                                        {
                                            Directory.CreateDirectory(Warehouse.Warehouse.RelativeImagesDirectory);
                                        }
                                        // копируем туда картинку
                                        var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorImagesDirectory, Path.GetFileName(reader.GetAttribute("src")));

                                        // var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorImagesDirectory, Path.GetFileName(reader.GetAttribute("src")));
                                        File.Copy(Path.GetDirectoryName(qfPath) + "\\" + reader.GetAttribute("src"), destPath, true);
                                        // var inner = TagNames.ImageTagName;
                                        string height = reader.GetAttribute("height");
                                        string width = reader.GetAttribute("width");
                                        string align = reader.GetAttribute("align");
                                        string border = reader.GetAttribute("border");
                                        string hspace = reader.GetAttribute("hspace");
                                        string sf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName(reader.GetAttribute("src")));
                                        HtmlText += "<IMG" + " border=\"" + border + "\" hspace=\"" + hspace + "\" align=\"" + align + "\" sdocument=\"0\" src=\"" + sf + "\" height=\"" + height + "\" width=\"" + width + "\"" + ">";
                                    }
                                    catch (FileNotFoundException)
                                    {
                                        MessageBox.Show("Изображение " + reader.GetAttribute("src") + " не найдено.",
                                                        "Visual Editor",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                                    }
                                }
                                #region самодеятельность с медиа
                                if (reader.Name.Equals("object", StringComparison.OrdinalIgnoreCase))
                                {
                                    try
                                    {
                                        if (Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".mp4" || Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".flv")
                                        {
                                            if (!Directory.Exists(Warehouse.Warehouse.RelativeVideosDirectory))
                                            {
                                                Directory.CreateDirectory(Warehouse.Warehouse.RelativeVideosDirectory);
                                            }
                                            // копируем туда картинку
                                            string data = reader.GetAttribute("data");
                                            var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorVideosDirectory, Path.GetFileName(data));
                                            var sourcePath = Path.Combine(Path.GetDirectoryName(qfPath), Path.GetFileName(data));

                                            File.Copy(sourcePath, destPath, true);

                                            string asf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName("\\Images\\Vid.png"));
                                            string sf = Path.Combine(Warehouse.Warehouse.RelativeVideosDirectory, Path.GetFileName(data));
                                            HtmlText += string.Concat("<IMG src=\"" + asf + "\" width=\"16\" height=\"16\" sdocument=\"0\" src_=\"" + sf + "\" >");
                                        }

                                        else if (Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".mp3")
                                        {
                                            if (!Directory.Exists(Warehouse.Warehouse.RelativeAudiosDirectory))
                                            {
                                                Directory.CreateDirectory(Warehouse.Warehouse.RelativeAudiosDirectory);
                                            }
                                            // копируем туда картинку
                                            var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorAudiosDirectory, Path.GetFileName(reader.GetAttribute("data")));
                                            var sourcePath = Path.Combine(Path.GetDirectoryName(qfPath), Path.GetFileName(reader.GetAttribute("data")));

                                            File.Copy(sourcePath, destPath, true);

                                            string asf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName("\\Images\\Aud.png"));
                                            string sf = Path.Combine(Warehouse.Warehouse.RelativeAudiosDirectory, Path.GetFileName(reader.GetAttribute("data")));

                                            HtmlText += string.Concat("<IMG src=\"" + asf + "\" width=\"16\" height=\"16\" sdocument=\"0\" src_=\"" + sf + "\" >");
                                        }

                                        else if (Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".swf")
                                        {
                                            if (!Directory.Exists(Warehouse.Warehouse.RelativeFlashesDirectory))
                                            {
                                                Directory.CreateDirectory(Warehouse.Warehouse.RelativeFlashesDirectory);
                                            }
                                            // копируем туда картинку
                                            string data = reader.GetAttribute("data");
                                            var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorFlashesDirectory, Path.GetFileName(data));
                                            var sourcePath = Path.Combine(Path.GetDirectoryName(qfPath), Path.GetFileName(data));

                                            File.Copy(sourcePath, destPath, true);

                                            string asf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName("\\Images\\Anim.png"));
                                            string sf = Path.Combine(Warehouse.Warehouse.RelativeFlashesDirectory, Path.GetFileName(data));
                                            HtmlText += string.Concat("<IMG src=\"" + asf + "\" width=\"16\" height=\"16\" sdocument=\"0\" src_=\"" + sf + "\" >");

                                        }
                                    }
                                    catch (FileNotFoundException)
                                    {
                                        MessageBox.Show("Изображение " + reader.GetAttribute("src") + " не найдено.",
                                                        "Visual Editor",
                                                        MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                                    }
                                }
                                #endregion
                            }
                        }

                        if (reader.Name.Equals("choiceInteraction", StringComparison.OrdinalIgnoreCase))
                        {
                            if (reader.GetAttribute("responseIdentifier") != null)
                            {
                                identifier = reader.GetAttribute("responseIdentifier");
                            }
                            if (reader.GetAttribute("shuffle") != null)
                            {
                                IsShuffle = bool.Parse(reader.GetAttribute("shuffle"));
                            }
                            if (reader.GetAttribute("maxChoices") != null)
                            {
                                MaxChoices = int.Parse(reader.GetAttribute("maxChoices"));
                            }
                        }

                        if (reader.Name.Equals("prompt", StringComparison.OrdinalIgnoreCase))
                        {
                            string s = reader.ReadInnerXml();
                            HtmlText += "<P>" + ConvertXmlStringToHtml(s, qfPath) + "</P>";
                        }
                        //////////////////////                     \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
                       /*
                        if (reader.Name.Equals("object", StringComparison.OrdinalIgnoreCase))
                        {
                            try
                            {
                                if (Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".mp4" || Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".flv")
                                {
                                    if (!Directory.Exists(Warehouse.Warehouse.RelativeVideosDirectory))
                                    {
                                        Directory.CreateDirectory(Warehouse.Warehouse.RelativeVideosDirectory);
                                    }
                                    // копируем туда картинку
                                    // копируем туда картинку
                                    string data = reader.GetAttribute("data");
                                    var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorVideosDirectory, Path.GetFileName(data));
                                    var sourcePath = Path.Combine(Path.GetDirectoryName(qfPath), Path.GetFileName(data));

                                    File.Copy(sourcePath, destPath, true);

                                    string asf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName("\\Images\\Vid.png"));
                                    string sf = Path.Combine(Warehouse.Warehouse.RelativeVideosDirectory, Path.GetFileName(data));
                                    HtmlText += string.Concat("<IMG src=\"" + asf + "\" width=\"16\" height=\"16\" sdocument=\"0\" src_=\"" + sf + "\" >");
                                }

                                else if (Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".mp3")
                                {
                                    if (!Directory.Exists(Warehouse.Warehouse.RelativeAudiosDirectory))
                                    {
                                        Directory.CreateDirectory(Warehouse.Warehouse.RelativeAudiosDirectory);
                                    }
                                    // копируем туда картинку
                                    var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorAudiosDirectory, Path.GetFileName(reader.GetAttribute("data")));
                                    var sourcePath = Path.Combine(Path.GetDirectoryName(qfPath), Path.GetFileName(reader.GetAttribute("data")));

                                    File.Copy(sourcePath, destPath, true);

                                    string asf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName("\\Images\\Aud.png"));
                                    string sf = Path.Combine(Warehouse.Warehouse.RelativeAudiosDirectory, Path.GetFileName(reader.GetAttribute("data")));

                                    HtmlText += string.Concat("<IMG src=\"" + asf + "\" width=\"16\" height=\"16\" sdocument=\"0\" src_=\"" + sf + "\" >");
                                }

                                else if (Path.GetExtension(Path.GetFileName(reader.GetAttribute("data"))) == ".swf")
                                {
                                    if (!Directory.Exists(Warehouse.Warehouse.RelativeFlashesDirectory))
                                    {
                                        Directory.CreateDirectory(Warehouse.Warehouse.RelativeFlashesDirectory);
                                    }
                                    // копируем туда картинку
                                    string data = reader.GetAttribute("data");
                                    var destPath = Path.Combine(Warehouse.Warehouse.AbsoluteEditorFlashesDirectory, Path.GetFileName(data));
                                    var sourcePath = Path.Combine(Path.GetDirectoryName(qfPath), Path.GetFileName(data));

                                    File.Copy(sourcePath, destPath, true);

                                    string asf = Path.Combine(Warehouse.Warehouse.RelativeImagesDirectory, Path.GetFileName("\\Images\\Anim.png"));
                                    string sf = Path.Combine(Warehouse.Warehouse.RelativeFlashesDirectory, Path.GetFileName(data));
                                    HtmlText += string.Concat("<IMG src=\"" + asf + "\" width=\"16\" height=\"16\" sdocument=\"0\" src_=\"" + sf + "\" >");

                                }
                            }
                            catch (FileNotFoundException)
                            {
                                MessageBox.Show("Изображение " + reader.GetAttribute("src") + " не найдено.",
                                                "Visual Editor",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Error);
                            }
                        }*/
                        ////////////////////----------------------------------------------------------------

                        if (reader.Name.Equals("responseIf", StringComparison.OrdinalIgnoreCase) ||
                            reader.Name.Equals("responseElseIf", StringComparison.OrdinalIgnoreCase) ||
                            reader.Name.Equals("responseElse", StringComparison.OrdinalIgnoreCase))
                        {
                            ArrayList list = new ArrayList(0);
                            string mark = string.Empty;
                            bool endCycle = false;
                            string name = reader.Name;

                            while (!endCycle && reader.Read())
                            {
                                if (reader.Name.Equals("baseValue", StringComparison.OrdinalIgnoreCase))
                                {
                                    if (reader.GetAttribute("baseType").Equals("identifier", StringComparison.OrdinalIgnoreCase))
                                    {
                                        string response = reader.ReadString();
                                        // разбиваем строку на слова
                                        Match match = Regex.Match(response, @"\w+");
                                        // цикл по всем словам
                                        while (match.Success)
                                        {
                                            list.Add(match.ToString());
                                            match = match.NextMatch();
                                        }
                                    }
                                    else if (reader.GetAttribute("baseType").Equals("integer", StringComparison.OrdinalIgnoreCase) ||
                                             reader.GetAttribute("baseType").Equals("float", StringComparison.OrdinalIgnoreCase))
                                    {
                                        if (name.Equals("responseIf", StringComparison.OrdinalIgnoreCase))
                                        {
                                            string m = reader.ReadString();
                                            m = m.Replace(".", NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
                                            m = m.Replace(",", NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
                                            Marks = int.Parse(m);// Double.Parse(m);
                                            mark = m;
                                        }
                                        else
                                        {
                                            mark = reader.ReadString();
                                        }
                                    }
                                }
                                else if (reader.NodeType == XmlNodeType.EndElement)
                                {
                                    if (reader.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                                    {
                                        endCycle = true;
                                    }
                                }
                            }

                            if (list.Count > 0)
                            {
                                ResponseVariant rv = new ResponseVariant(this);
                                foreach (Response r in Responses)
                                {
                                    foreach (string id in list)
                                    {
                                        if (r.Identifier == id && !rv.Responses.Contains(id))
                                        {
                                            rv.Responses.Add(r);
                                        }
                                    }
                                }
                                if (mark != string.Empty)
                                {
                                    if (!name.Equals("responseElse", StringComparison.OrdinalIgnoreCase))
                                    {
                                        mark = mark.Replace(".", NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
                                        mark = mark.Replace(",", NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
                                        if (Marks != 0)
                                            rv.Weight = Double.Parse(mark) / Marks;
                                        else rv.Weight = 0;
                                    }
                                }
                                ResponseVariants.Add(rv);
                            }
                        }
                    }
                }
            }
            catch
            {
                MessageBox.Show("При чтении файла вопроса произошла ошибка. (" + qfPath + ")",
                                "Visual Editor",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                result = false;
            }
            finally
            {
                reader.Close();
                HtmlText += "</P>\n</BODY>\n</HTML>";
                //решить 
                //FillImagesArray();
            }

            // мои художества
            this.DocumentHtml = HtmlText;

            success = true;
            return result;
        }
예제 #5
0
        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 ReadXml(XmlTextReader xmlReader)
        {
            try
            {
                var isEndCycle = false;

                while (!isEndCycle && xmlReader.Read())
                {
                    if (xmlReader.NodeType == XmlNodeType.Element)
                    {
                        #region Контент вопроса

                        if (xmlReader.Name.Equals("html_text"))
                        {
                            var s = xmlReader.ReadElementString();
                            if (s != null)
                            {
                                question.DocumentHtml = XmlToHtml(s);
                            }
                        }

                        #endregion

                        #region Варианты ответа

                        if (xmlReader.Name.Equals("answer_variants"))
                        {
                            var rv = new ResponseVariant(question);
                            //rv.Type = reader.GetAttribute("type");
                            var weight = xmlReader.GetAttribute("weight");
                            weight = weight.Replace(".", NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
                            weight = weight.Replace(",", NumberFormatInfo.CurrentInfo.CurrencyDecimalSeparator);
                            rv.Weight = double.Parse(weight);

                            var gh = xmlReader.GetAttribute("next_question");


                            if (xmlReader.GetAttribute("next_question") != null)
                            {

                                rv.NextQuestion = xmlReader.GetAttribute("next_question");

                            }

                            rv.Responses.Add(xmlReader.GetAttribute("value"));
                            question.ResponseVariants.Add(rv);
                        }

                        #endregion

                        #region Подсказка

                        if (xmlReader.Name.Equals("hint", StringComparison.OrdinalIgnoreCase))
                        {
                            try
                            {
                                var s = xmlReader.ReadString();
                                if (s != null)
                                {
                                    question.Hint = XmlToHtml(s);
                                }
                            }
                            catch { }
                        }

                        #endregion

                        if (xmlReader.Name.Equals("mark"))
                        {
                            question.Marks = int.Parse(xmlReader.GetAttribute("value"));

                            try
                            {
                                var id = new Guid(xmlReader.GetAttribute("concept_id").Substring(6, 36));

                                foreach (Concept c in Warehouse.Warehouse.Instance.ConceptTree.Nodes)
                                {
                                    if (c.Id.Equals(id))
                                    {
                                        question.Profile = c;

                                        break;
                                    }
                                }
                            }
                            catch
                            {
                                question.Profile = null;
                            }
                        }
                    }
                    else if (xmlReader.NodeType == XmlNodeType.EndElement)
                    {
                        if (xmlReader.Name.ToLower().Equals("question"))
                        {
                            isEndCycle = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionManager.Instance.LogException(ex);
            }
        }
        /// <summary>
        /// Отображает на вкладке все элементы ответа, содержащиеся в вопросе, с
        /// выделением тех, которые входят в вариант ответа.
        /// </summary> 
        private void FillTabPageWithResponseVariants(TabPage tp, ResponseVariant rv)
        {
            int i = 1;

            if (question is ChoiceQuestion)
            {
                foreach (var response in question.Responses)
                {
                    var rb = new RadioButton();
                    rb.Text = response.Text;
                    rb.Location = new Point(20, i * 20);
                    foreach (Response r in rv.Responses)
                    {
                        if (r.Text == response.Text)
                        {
                            rb.Checked = true;
                            break;
                        }
                    }
                    tp.Controls.Add(rb);

                    i++;
                }
            }
            else if (question is MultichoiceQuestion)
            {
                foreach (var response in question.Responses)
                {
                    var chb = new CheckBox();
                    chb.Text = response.Text;
                    chb.Location = new Point(20, i * 20);
                    foreach (Response r in rv.Responses)
                    {
                        if (r.Text == response.Text)
                        {
                            chb.Checked = true;
                            break;
                        }
                    }
                    tp.Controls.Add(chb);

                    i++;
                }
            }
            else if (question is OrderingQuestion)
            {
                foreach (var response in question.Responses)
                {
                    var cb = new ComboBox();
                    for (int j = 1; j <= question.Responses.Count; j++)
                    {
                        cb.Items.Add(j);
                    }
                    cb.Width = 50;
                    cb.Location = new Point(20, i * 25);
                    if ((int)rv.Responses[i - 1] != 0)
                    {
                        cb.Text = ((int)rv.Responses[i - 1]).ToString();
                    }
                    cb.DropDownStyle = ComboBoxStyle.DropDownList;
                    tp.Controls.Add(cb);

                    var lb = new Label();
                    lb.Text = response.Text;
                    lb.Location = new System.Drawing.Point(80, i * 25 + 5);
                    tp.Controls.Add(lb);

                    i++;
                }
            }
            else if (question is OpenQuestion)
            {
                if (((OpenQuestion)question).IsAnswerNumeric)
                {
                    var nud = new NumericUpDown();
                    nud.Location = new Point(20, 20);
                    nud.Increment = 0.1M;
                    nud.DecimalPlaces = 2;
                    nud.Maximum = 1000000;
                    decimal temp;
                    if (decimal.TryParse(rv.Responses[0].ToString(), out temp))
                    {
                        nud.Value = decimal.Parse(rv.Responses[0].ToString());
                    }
                    else
                    {
                        nud.Value = 0;
                    }
                    tp.Controls.Add(nud);
                }
                else
                {
                    var tb = new RichTextBox();
                    tb.Location = new Point(10, 10);
                    tb.Width = 325;
                    tb.Height = 207;
                    tb.ScrollBars = RichTextBoxScrollBars.Both;
                    tb.Text = rv.Responses[0].ToString();
                    tp.Controls.Add(tb);
                }
            }
        }
        /// <summary>
        /// Отображает варианты ответа, содержащиеся в вопросе.
        /// </summary>
        private void InitializeTabPages()
        {
            if (question.ResponseVariants.Count == 0)
            {
                var rv = new ResponseVariant(question);
                question.ResponseVariants.Add(rv);
                variantNumber++;
                variantsTabControl.TabPages.Add(string.Concat("Вариант ", variantNumber));
                variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1].AutoScroll = true;
                FillTabPageWithResponses(variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1]);
                weightNumericUpDown.Value = 1;
            }
            else
            {
                foreach (ResponseVariant rv in question.ResponseVariants)
                {
                    variantNumber++;
                    variantsTabControl.TabPages.Add(string.Concat("Вариант ", variantNumber));
                    variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1].AutoScroll = true;
                    FillTabPageWithResponseVariants(variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1], rv);
                }

                weightNumericUpDown.Value = (decimal)((ResponseVariant)question.ResponseVariants[0]).Weight;


                var wt = Warehouse.Warehouse.Instance.CourseTree.CurrentNode.Parent as TestModule;

                foreach (var question1 in wt.Questions)

                    if ("#module{" + question1.Id.ToString().ToUpper() + "}" == ((ResponseVariant)question.ResponseVariants[0]).NextQuestion)
                    {
                        nextQuestionComboBox.Text = question1.Text;
                        int t = 0;
                        ((ResponseVariant)question.ResponseVariants[0]).NextQuestion = question1.Text;
                    }
                  nextQuestionComboBox.Text = ((ResponseVariant)question.ResponseVariants[0]).NextQuestion;
            }
        }
        /// <summary>
        /// Отображает на вкладке все элементы ответа, содержащиеся в вопросе, с
        /// выделением тех, которые входят в вариант ответа.
        /// </summary> 
        private void FillTabPageWithResponseVariants(TabPage tp, ResponseVariant rv)
        {
            int i = 1;

            if (question is ChoiceQuestion)
            {
                foreach (var response in question.Responses)
                {
                    var rb = new RadioButton();
                    rb.Text = response.Text;
                    rb.Location = new Point(20, i * 20);
                    foreach (Response r in rv.Responses)
                    {
                        if (r.Text == response.Text)
                        {
                            rb.Checked = true;
                            break;
                        }
                    }
                    tp.Controls.Add(rb);

                    i++;
                }
            }
            else if (question is MultichoiceQuestion)
            {
                foreach (var response in question.Responses)
                {
                    var chb = new CheckBox();
                    chb.Text = response.Text;
                    chb.Location = new Point(20, i * 20);
                    foreach (Response r in rv.Responses)
                    {
                        if (r.Text == response.Text)
                        {
                            chb.Checked = true;
                            break;
                        }
                    }
                    tp.Controls.Add(chb);

                    i++;
                }
            }
            else if (question is OrderingQuestion)
            {
                foreach (var response in question.Responses)
                {
                    var cb = new ComboBox();
                    for (int j = 1; j <= question.Responses.Count; j++)
                    {
                        cb.Items.Add(j);
                    }
                    cb.Width = 50;
                    cb.Location = new Point(20, i * 25);
                    if ((int)rv.Responses[i - 1] != 0)
                    {
                        cb.Text = ((int)rv.Responses[i - 1]).ToString();
                    }
                    cb.DropDownStyle = ComboBoxStyle.DropDownList;
                    tp.Controls.Add(cb);

                    var lb = new Label();
                    lb.Text = response.Text;
                    lb.Location = new System.Drawing.Point(80, i * 25 + 5);
                    tp.Controls.Add(lb);

                    i++;
                }
            }
            else if (question is OpenQuestion)
            {
                var tb = new TextBox();
                tb.Location = new Point(10, 10);
                tb.Width = 325;
                tb.Text = rv.Responses[0].ToString();
                tp.Controls.Add(tb);
                if (((OpenQuestion)question).IsAnswerNumeric)
                {
                    tb.KeyPress += tb_KeyPress;
                }
            }
        }
        /// <summary>
        /// Отображает варианты ответа, содержащиеся в вопросе.
        /// </summary>
        private void InitializeTabPages()
        {
            if (question.ResponseVariants.Count == 0)
            {
                var rv = new ResponseVariant(question);
                question.ResponseVariants.Add(rv);
                variantNumber++;
                variantsTabControl.TabPages.Add(string.Concat("Вариант ", variantNumber));
                variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1].AutoScroll = true;
                FillTabPageWithResponses(variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1]);
                weightNumericUpDown.Value = 1;
            }
            else
            {
                foreach (ResponseVariant rv in question.ResponseVariants)
                {
                    variantNumber++;
                    variantsTabControl.TabPages.Add(string.Concat("Вариант ", variantNumber));
                    variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1].AutoScroll = true;
                    FillTabPageWithResponseVariants(variantsTabControl.TabPages[variantsTabControl.TabPages.Count - 1], rv);
                }

                weightNumericUpDown.Value = (decimal)((ResponseVariant)question.ResponseVariants[0]).Weight;
            }
        }
 public ResponseVariantXmlReader(Question question, ResponseVariant responseVariant)
 {
     this.question = question;
     this.responseVariant = responseVariant;
 }