Пример #1
0
 private void ListBox_tests_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listBox_tests.SelectedIndex >= 0)
     {
         string name = listBox_tests.SelectedItem.ToString();
         Test   TEST = new Test();
         TEST.Creat_test($"{name}.txt");
         Form_header AddForm = new Form_header(TEST);
         this.Close();
     }
 }
Пример #2
0
 private void Add_new_test_Click(object sender, EventArgs e)//add new test
 {
     Test        TEST    = new Test();
     Form_header AddForm = new Form_header(TEST);
 }
Пример #3
0
        internal Form_Questions(Test TEST)
        {
            InitializeComponent();
            Design_for_Form_Questions();
            Show();
            CoQ_textbox.Text            = Convert.ToString(TEST._Questions.Count);
            CoQ_textbox.KeyPress       += new KeyPressEventHandler(TextBox_KeyPress_integers);
            button_add_answer.Click    += new EventHandler(button_add_answer_click);
            button_remove_answer.Click += new EventHandler(button_remove_answer_click);
            button_left.Click          += new EventHandler(button_left_click);
            button_right.Click         += new EventHandler(button_right_click);
            button_create.Click        += new EventHandler(button_create_click);
            button_next.Click          += new EventHandler(button_next_click);
            button_back.Click          += new EventHandler(button_back_click);

            if (TEST._Questions.Count > 0)
            {
                Create_questions(TEST);
            }

            void button_create_click(object sender, EventArgs e)
            {
                try
                {
                    int tmp = Convert.ToInt32(CoQ_textbox.Text);
                    if (tmp > 0)
                    {
                        if (tmp > TEST._Questions.Count)
                        {
                            for (int i = TEST._Questions.Count; i < tmp; i++)
                            {
                                TEST._Questions.Add(new Question());
                            }
                            Create_questions(TEST);
                        }
                        if (tmp < TEST._Questions.Count)
                        {
                            for (int i = TEST._Questions.Count - 1; i >= tmp; i--)
                            {
                                TEST._Questions.RemoveAt(i);
                            }
                            if (Question_number >= TEST._Questions.Count)
                            {
                                Question_number = TEST._Questions.Count - 1;
                            }
                            Create_questions(TEST);
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("Ошибка: некорректно задано число вопросов. OS");
                }
            }

            void button_add_answer_click(object sender, EventArgs e)
            {
                TEST._Questions[Question_number]._Answer.Add("");
                Answer_form.Add(new TextBox());
                Create_answer(TEST, TEST._Questions[Question_number]._Answer.Count - 1);
            }

            void button_remove_answer_click(object sender, EventArgs e)
            {
                if (TEST._Questions[Question_number]._Answer.Count <= 0)
                {
                    return;
                }
                Delete_last_answer_on_panel();
                TEST._Questions[Question_number]._Answer.RemoveAt(TEST._Questions[Question_number]._Answer.Count - 1);
                Answer_form.RemoveAt(Answer_form.Count - 1);
                CA_label.Text = $"Количество ответов {Convert.ToString(TEST._Questions[Question_number]._Answer.Count)}";
            }

            void button_left_click(object sender, EventArgs e)
            {
                //check for the last question
                if (Question_number <= 0)
                {
                    return;
                }
                //go to the previous question
                Question_number--;
                Clear_panel();
                Answer_form = new List <TextBox>();
                Create_questions(TEST);
            }

            void button_right_click(object sender, EventArgs e)
            {
                //check for the correctness of the question and answers
                if (question_textBox.Text.Trim() == "" || question_textBox.Text.Contains('>') || question_textBox.Text.Contains('<'))
                {
                    MessageBox.Show("Ошибка: вопрос пуст или содержит символы '<', '>'");
                    return;
                }
                if (Answer_form.Count == 0)
                {
                    MessageBox.Show("Ошибка: вопрос должен иметь хотя бы один ответ");
                    return;
                }
                for (int i = 0; i < Answer_form.Count; i++)
                {
                    if (Answer_form[i].Text.Trim() == "" || Answer_form[i].Text.Contains('>') || Answer_form[i].Text.Contains('<'))
                    {
                        MessageBox.Show("Ошибка: ответы пусты или содержат символы '<', '>'");
                        return;
                    }
                }

                TEST._Questions[Question_number]._Question = question_textBox.Text.Trim();
                for (int i = 0; i < Answer_form.Count; i++)
                {
                    TEST._Questions[Question_number]._Answer[i] = Answer_form[i].Text.Trim();
                }

                //check for the last question
                if (Question_number >= TEST._Questions.Count - 1)
                {
                    MessageBox.Show("Добавлен последний вопрос");
                    return;
                }
                //update and add text box on the panel

                Question_number++;
                Clear_panel();
                Create_questions(TEST);
            }

            void button_next_click(object sender, EventArgs e)
            {
                if (TEST._Questions.Count > 0 && TEST._Questions[TEST._Questions.Count - 1]._Answer.Count > 0 && TEST._Questions[TEST._Questions.Count - 1]._Answer[TEST._Questions[TEST._Questions.Count - 1]._Answer.Count - 1] != "")
                {
                    this.Close();
                    Form_Keys FK = new Form_Keys(TEST);
                }
                else
                {
                    MessageBox.Show("Ошибка: не все вопросы заданы");
                }
            }

            void button_back_click(object sender, EventArgs e)
            {
                this.Close();
                Form_header FH = new Form_header(TEST);
            }
        }