Пример #1
0
        public Form_Scales(Test TEST)
        {
            InitializeComponent();
            Design_for_Form_Scales();
            Show();

            CoScale_textbox.Text      = Convert.ToString(TEST._Scales.Count);
            CoScale_textbox.KeyPress += new KeyPressEventHandler(TextBox_KeyPress_integers);
            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._Scales.Count > 0)
            {
                Create_Scale(TEST);
            }

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

            void button_left_click(object sender, EventArgs e)
            {
                if (Scale_number <= 0)
                {
                    return;
                }
                Scale_number--;
                Create_Scale(TEST);
            }

            void button_right_click(object sender, EventArgs e)
            {
                if (if_textBox.Text.Trim() == "" || if_textBox.Text.Contains('[') || if_textBox.Text.Contains(']'))
                {
                    MessageBox.Show("Ошибка: условие задано неверно! недопустимые символы [ ]");
                    return;
                }

                if (name_Scale_textBox.Text.Trim() == "" || name_Scale_textBox.Text.Contains('(') || name_Scale_textBox.Text.Contains(')'))
                {
                    MessageBox.Show("Ошибка: имя шкалы задано неверно!  недопустимые символы  ( )");
                    return;
                }

                if (description_textBox.Text.Trim() == "" || description_textBox.Text.Contains('<') || description_textBox.Text.Contains('>'))
                {
                    MessageBox.Show("Ошибка: условие задано неверно!");
                    return;
                }

                TEST._Scales[Scale_number] = new Scale(if_textBox.Text.Trim(),
                                                       name_Scale_textBox.Text.Trim(),
                                                       description_textBox.Text.Trim());

                if (Scale_number >= TEST._Questions.Count - 1)
                {
                    MessageBox.Show("Добавлена последная шкала");
                    return;
                }

                Scale_number++;
                Create_Scale(TEST);
            }

            void button_next_click(object sender, EventArgs e)
            {
                if (TEST._Scales.Count > 0 && TEST._Scales[TEST._Scales.Count - 1].If_scale != "" && TEST._Scales[TEST._Scales.Count - 1].Name_scale != "" && TEST._Scales[TEST._Scales.Count - 1].Manifestation != "")
                {
                    this.Close();
                    Form_Fuzzy_Sets FFS = new Form_Fuzzy_Sets(TEST);
                }
                else
                {
                    MessageBox.Show("Ошибка: не все шкалы заданы");
                }
            }

            void button_back_click(object sender, EventArgs e)
            {
                this.Close();
                Form_Keys FK = new Form_Keys(TEST);
            }
        }
Пример #2
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);
            }
        }