Exemple #1
0
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            int val = ListBox_Quest.SelectedIndex;

            if (val == 0 && EditionTXT.if_ThereQuest(input_Quest.Text))
            {
                MessageBox.Show("Такой вопрос уже был добавлен ранее", "Добавление не возможно!");
                return;
            }
            if (input_Quest.Text == "")
            {
                MessageBox.Show("Поле с вопросом не заполнено", "Добавление не возможно!");
                return;
            }
            if (input_Answer.Text == "")
            {
                MessageBox.Show("Поле с верным ответом не заполнено", "Добавление не возможно!");
                return;
            }



            QuestItem questItem = new QuestItem();

            questItem.quest   = input_Quest.Text;
            questItem.comment = input_Comment.Text;
            questItem.InputAnswerList(input_Answer.Text, input_AnAnswer.Text);
            questItem.Description = questItem.ToolTypeListBox();

            if (ListBox_Quest.SelectedIndex != 0)
            {
                QuestsBox.questItems.Insert(val + 1, questItem);
                QuestsBox.questItems.RemoveAt(val);
                ListBox_Quest.SelectedIndex = val;
                EditionTXT.WriteInTXT("TEMPTXT.txt");
            }
            else
            {
                QuestsBox.questItems.Add(questItem);
                EditionTXT.WriteInTXT("TEMPTXT.txt");
            }
            NewTitle();
        }
        public static int HTMLParsingQuest(string str)
        {
            /*Строковые метки*/
            string questBegin    = $"<div class=\"questBox__quest\">";
            string questEnd      = "</div>";
            string AnswerBegin   = $"   <div class=\"questBox__answer\"><div> &#10004;</div>";
            string UnAnswerBegin = $"   <div class=\"questBox__unanwser\"><div> &#10008;</div>";
            string AnswerEnd     = "</div>" + "\n";
            string comentBegin   = "<summary>ПОЯСНЕНИЕ:</summary><div>";
            string comentEnd     = "</div></details>";

            /*Старт*/
            string[]  separator = { "\n", "\r" };
            string[]  lineItem  = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
            QuestItem questItem = null;
            int       count     = 0;

            foreach (string line in lineItem)
            {
                string temp;
                try
                {
                    if (line.IndexOf(questBegin) >= 0)
                    {
                        if (questItem != null && !EditionTXT.if_ThereQuest(questItem.quest))
                        {
                            questItem.Description = questItem.ToolTypeListBox(); QuestsBox.questItems.Add(questItem); count++;
                        }
                        questItem       = new QuestItem();
                        temp            = line.Replace(questBegin, "");
                        temp            = temp.Replace(questEnd, "");
                        temp            = temp.Remove(0, temp.IndexOf(')') + 2);
                        questItem.quest = temp;
                    }
                    else if (line.IndexOf(AnswerBegin) == 0)
                    {
                        temp = line.Replace(AnswerBegin, "");
                        temp = temp.Replace(AnswerEnd, "");
                        Answer tempAns = new Answer(temp, true);
                        questItem.answerItem.Add(tempAns);
                    }
                    else if (line.IndexOf(UnAnswerBegin) == 0)
                    {
                        temp = line.Replace(UnAnswerBegin, "");
                        temp = temp.Replace(AnswerEnd, "");
                        Answer tempAns = new Answer(temp, false);
                        questItem.answerItem.Add(tempAns);
                    }
                    else if (line.IndexOf("КОММЕНТАРИЙ:") == 0)
                    {
                        temp = line.Replace(comentBegin, "");
                        temp = temp.Replace(comentEnd, "");
                        questItem.comment = temp;
                    }
                }
                catch (Exception e)
                {
                    System.Windows.MessageBox.Show(e.ToString());
                    /*Просто игнорируем*/
                }
            }
            if (questItem != null && !EditionTXT.if_ThereQuest(questItem.quest))
            {
                questItem.Description = questItem.ToolTypeListBox(); QuestsBox.questItems.Add(questItem); count++;
            }
            return(count);
        }