Ejemplo n.º 1
0
        internal Form_Fuzzy_Sets(Test TEST)
        {
            InitializeComponent();
            My_bitmap = new Bitmap(pictureBox_Fuzzy_sets.Width, pictureBox_Fuzzy_sets.Height);
            Design_for_Form_Fuzzy_sets();
            Show();

            CoFuzzy_sets_textBox.Text      = Convert.ToString(TEST._Fuzzy_sets.Count);
            CoFuzzy_sets_textBox.KeyPress += new KeyPressEventHandler(TextBox_KeyPress_integers);
            button_create.Click           += new EventHandler(button_create_click);
            button_add_function.Click     += new EventHandler(button_add_function_click);
            button_remove_function.Click  += new EventHandler(button_remove_function_click);
            button_left.Click             += new EventHandler(button_left_click);
            button_right.Click            += new EventHandler(button_right_click);
            button_next.Click             += new EventHandler(button_next_click);
            button_back.Click             += new EventHandler(button_back_click);

            if (TEST._Fuzzy_sets.Count > 0)
            {
                Create_Fuzzy_sets(TEST);
            }

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

            void button_add_function_click(object sender, EventArgs e)
            {
                TEST._Fuzzy_sets[Fuzzy_sets_number].Functions.Add(new Trapeze());

                textBox_left_x1.Add(new TextBox());
                textBox_left_x2.Add(new TextBox());
                textBox_right_x1.Add(new TextBox());
                textBox_right_x2.Add(new TextBox());

                Create_Functions(TEST);
            }

            void button_remove_function_click(object sender, EventArgs e)
            {
                if (TEST._Fuzzy_sets[Fuzzy_sets_number].Functions.Count <= 0)
                {
                    return;
                }
                Delete_last_function_on_panel();
                TEST._Fuzzy_sets[Fuzzy_sets_number].Functions.RemoveAt(TEST._Fuzzy_sets[Fuzzy_sets_number].Functions.Count - 1);
                textBox_left_x1.RemoveAt(textBox_left_x1.Count - 1);
                textBox_left_x2.RemoveAt(textBox_left_x2.Count - 1);
                textBox_right_x1.RemoveAt(textBox_right_x1.Count - 1);
                textBox_right_x2.RemoveAt(textBox_right_x2.Count - 1);
                C_Function_label.Text = $"Количество функций {Convert.ToString(TEST._Fuzzy_sets[Fuzzy_sets_number].Functions.Count)}";
            }

            void button_left_click(object sender, EventArgs e)
            {
                if (Fuzzy_sets_number <= 0)
                {
                    return;
                }
                Fuzzy_sets_number--;
                Clear_panel();
                textBox_left_x1  = new List <TextBox>();
                textBox_left_x2  = new List <TextBox>();
                textBox_right_x1 = new List <TextBox>();
                textBox_right_x2 = new List <TextBox>();
                Create_Functions(TEST);
            }

            void button_right_click(object sender, EventArgs e)
            {
                try
                {
                    bool check = false;
                    for (int i = 0; i < TEST._Scales.Count; i++)
                    {
                        if (TEST._Scales[i].Name_scale.ToLower() == textBox_fuzzy_set_name.Text.Trim().ToLower())
                        {
                            check = true;
                        }
                    }
                    if (!check)
                    {
                        MessageBox.Show($"Ошибка: шкала {textBox_fuzzy_set_name.Text.Trim()} не найдена!");
                        return;
                    }
                    if (textBox_left_x1.Count == 0)
                    {
                        MessageBox.Show("Ошибка: множество должно содержать хотя бы одну функцию");
                        return;
                    }
                    TEST._Fuzzy_sets[Fuzzy_sets_number].Name = textBox_fuzzy_set_name.Text.Trim();
                    for (int i = 0; i < textBox_left_x1.Count; i++)
                    {
                        if (textBox_left_x1[i].Text == "" || textBox_left_x2[i].Text == "" || textBox_right_x1[i].Text == "" || textBox_right_x2[i].Text == "")
                        {
                            return;
                        }
                        float L_x1 = Convert.ToSingle(textBox_left_x1[i].Text);
                        float L_x2 = Convert.ToSingle(textBox_left_x2[i].Text);
                        float R_x1 = Convert.ToSingle(textBox_right_x1[i].Text);
                        float R_x2 = Convert.ToSingle(textBox_right_x2[i].Text);
                        if (L_x1 > L_x2 || L_x2 > R_x1 || R_x1 > R_x2)
                        {
                            MessageBox.Show($"Ошибка: В строке {Convert.ToString(i)}, все элементы должны быть в порядке возрастения!");
                            return;
                        }
                        TEST._Fuzzy_sets[Fuzzy_sets_number].Functions[i].Left_side.A  = new PointF(L_x1, 0);
                        TEST._Fuzzy_sets[Fuzzy_sets_number].Functions[i].Left_side.B  = new PointF(L_x2, 1);
                        TEST._Fuzzy_sets[Fuzzy_sets_number].Functions[i].Right_side.A = new PointF(R_x1, 1);
                        TEST._Fuzzy_sets[Fuzzy_sets_number].Functions[i].Right_side.B = new PointF(R_x2, 0);
                    }
                    if (Fuzzy_sets_number >= TEST._Fuzzy_sets.Count - 1)
                    {
                        MessageBox.Show("Добавлено последнее множество!");
                        return;
                    }
                    Fuzzy_sets_number++;
                    Clear_panel();
                    Create_Fuzzy_sets(TEST);
                }
                catch
                {
                    MessageBox.Show("Ошибка!");
                    return;
                }
            }

            void button_next_click(object sender, EventArgs e)
            {
                if (TEST._Fuzzy_sets.Count == 0)
                {
                    this.Close();
                    Create_file(TEST);
                }
                else if (TEST._Fuzzy_sets[TEST._Fuzzy_sets.Count - 1].Functions.Count > 0)
                {
                    for (int i = 0; i < TEST._Fuzzy_sets[TEST._Fuzzy_sets.Count - 1].Functions.Count; i++)
                    {
                        float L_x1 = TEST._Fuzzy_sets[TEST._Fuzzy_sets.Count - 1].Functions[i].Left_side.A.X;
                        float L_x2 = TEST._Fuzzy_sets[TEST._Fuzzy_sets.Count - 1].Functions[i].Left_side.B.X;
                        float R_x1 = TEST._Fuzzy_sets[TEST._Fuzzy_sets.Count - 1].Functions[i].Right_side.A.X;
                        float R_x2 = TEST._Fuzzy_sets[TEST._Fuzzy_sets.Count - 1].Functions[i].Right_side.B.X;
                        if (L_x1 > L_x2 || L_x2 > R_x1 || R_x1 > R_x2)
                        {
                            MessageBox.Show("Ошибка: не все функции заданы");
                            return;
                        }
                    }
                    this.Close();
                    Create_file(TEST);
                }
                else
                {
                    MessageBox.Show("Ошибка: не все функции заданы");
                }
            }

            void button_back_click(object sender, EventArgs e)
            {
                this.Close();
                Form_Scales FH = new Form_Scales(TEST);
            }
        }
Ejemplo n.º 2
0
        internal Form_Keys(Test TEST)
        {
            InitializeComponent();
            Design_for_Form_Keys();
            Show();

            CoKey_textbox.Text       = Convert.ToString(TEST._Keys.Count);
            CoKey_textbox.KeyPress  += new KeyPressEventHandler(TextBox_KeyPress_integers);
            button_add_row.Click    += new EventHandler(button_add_row_click);
            button_remove_row.Click += new EventHandler(button_remove_row_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._Keys.Count > 0)
            {
                Create_Key(TEST);
            }

            void button_add_row_click(object sender, EventArgs e)
            {
                TEST._Keys[Key_number].Add(new Element());
                Questions_form.Add(new TextBox());
                Answers_form.Add(new TextBox());
                Points_form.Add(new TextBox());
                Create_row(TEST, TEST._Keys[Key_number].Count - 1);
            }

            void button_remove_row_click(object sender, EventArgs e)
            {
                if (TEST._Keys[Key_number].Count <= 0)
                {
                    return;
                }
                Delete_last_row_on_panel();
                TEST._Keys[Key_number].RemoveAt(TEST._Keys[Key_number].Count - 1);

                Questions_form.RemoveAt(Questions_form.Count - 1);
                Answers_form.RemoveAt(Answers_form.Count - 1);
                Points_form.RemoveAt(Points_form.Count - 1);

                C_Row_label.Text = $"Количество строк {Convert.ToString(TEST._Keys[Key_number].Count)}";
            }

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

            void button_left_click(object sender, EventArgs e)
            {
                if (Key_number <= 0)
                {
                    return;
                }
                Key_number--;
                Clear_panel();
                Questions_form = new List <TextBox>();
                Answers_form   = new List <TextBox>();
                Points_form    = new List <TextBox>();
                Create_Key(TEST);
            }

            void button_right_click(object sender, EventArgs e)
            {
                try
                {
                    if (Questions_form.Count == 0)
                    {
                        MessageBox.Show("Ошибка: ключ должен иметь хотя бы одну строку");
                        return;
                    }
                    for (int i = 0; i < Questions_form.Count; i++)
                    {
                        if (Convert.ToInt32(Questions_form[i].Text.Trim()) <= 0 || Convert.ToInt32(Answers_form[i].Text.Trim()) <= 0 || Convert.ToSingle(Points_form[i].Text.Trim()) <= 0)
                        {
                            MessageBox.Show("Ошибка: значения в строках заданы неверно");
                            return;
                        }
                    }
                    for (int i = 0; i < Questions_form.Count; i++)
                    {
                        TEST._Keys[Key_number][i] = new Element(Convert.ToInt32(Questions_form[i].Text.Trim()),
                                                                Convert.ToInt32(Answers_form[i].Text.Trim()),
                                                                Convert.ToSingle(Points_form[i].Text.Trim()));
                    }
                    //check for the last question
                    if (Key_number >= TEST._Keys.Count - 1)
                    {
                        MessageBox.Show("Добавлен последний ключ");
                        return;
                    }
                    //update and add text box on the panel

                    Key_number++;
                    Clear_panel();
                    Create_Key(TEST);
                }
                catch
                {
                    MessageBox.Show("Ошибка: значения в строках заданы неверно GE");
                    return;
                }
            }

            void button_next_click(object sender, EventArgs e)
            {
                if (TEST._Keys.Count > 0 && TEST._Keys[TEST._Keys.Count - 1].Count > 0 && TEST._Keys[TEST._Keys.Count - 1][TEST._Keys[TEST._Keys.Count - 1].Count - 1].Point != 0)
                {
                    this.Close();
                    Form_Scales FS = new Form_Scales(TEST);
                }
                else
                {
                    MessageBox.Show("Ошибка: не все ключи заданы");
                }
            }

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