Пример #1
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 3";
            form.SetDefaultVals(new System.Drawing.Size(500, 200));
            form.Controls.Add(BeautyfyForms.AddButton("Инициализация", new Point(0, 45), (o, k) =>
            {
                _inputNumber.Text = rnd.Next(1, 200).ToString();
            }));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(240, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 3. Факторизация числа ( Поллард ρ-1 )");
            }));

            _inputNumber      = BeautyfyForms.CreateTextBox(new Point(150, 70), false);
            _inputNumber.Text = "0";
            form.Controls.Add(_inputNumber);

            _inputFactor      = BeautyfyForms.CreateTextBox(new Point(270, 70), false);
            _inputFactor.Text = "0";
            form.Controls.Add(_inputFactor);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(150, 55), "  Число                               Значение B", false, 5)); //meh~

            form.Controls.Add(BeautyfyForms.AddButton(" Поехали ", new Point(230, 95), (o, k) =>
            {
                ParseAndRunPollardPMinusOne();
            }));
        }
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 1";
            form.SetDefaultVals(new System.Drawing.Size(500, 200));
            form.Controls.Add(BeautyfyForms.AddButton("Инициализация", new Point(0, 45), (o, k) =>
            {
                _inputNumber.Text = rnd.Next(1, 200).ToString();
                _inputCycles.Text = rnd.Next(10, 30).ToString();
            }));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(240, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 1. Тест числа на простоту ( Ферма )");
            }));

            _inputNumber      = BeautyfyForms.CreateTextBox(new Point(150, 70), false);
            _inputNumber.Text = "0";
            form.Controls.Add(_inputNumber);

            _inputCycles      = BeautyfyForms.CreateTextBox(new Point(270, 70), false);
            _inputCycles.Text = "0";
            form.Controls.Add(_inputCycles);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(150, 55), "    Число                             Кол-во итераций", false, 5)); //meh~

            form.Controls.Add(BeautyfyForms.AddButton(" Поехали ", new Point(230, 95), (o, k) =>
            {
                ParseAndRunFermaTest();
            }));
        }
Пример #3
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 2";
            form.SetDefaultVals(new System.Drawing.Size(500, 200));
            form.Controls.Add(BeautyfyForms.AddButton("Инициализация", new Point(0, 45), (o, k) =>
            {
                _inputNumber.Text = rnd.Next(1, 200).ToString();
            }));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(240, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 2. Тест числа на простоту ( Рабин-Миллер )");
            }));

            _inputNumber      = BeautyfyForms.CreateTextBox(new Point(200, 45), false);
            _inputNumber.Text = "0";
            form.Controls.Add(_inputNumber);

            form.Controls.Add(BeautyfyForms.AddButton(" Поехали ", new Point(230, 75), (o, k) =>
            {
                ParseAndRunRabinMillerTest();
            }));
        }
Пример #4
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 2";
            form.SetDefaultVals(new System.Drawing.Size(810, 500));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(170, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 2 Алгоритм разрешения коллизий в хэш-таблицах методом открытой адресации. \r\n Создаётся таблица с заданным кол-вом слотов под каждое значение хеша.");
            }));

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(270, 46), "Хеширующая функция", true, 125));

            _inputValue = BeautyfyForms.CreateTextBox(new Point(200, 66), false);
            form.Controls.Add(_inputValue);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(320, 66), "mod", true, 35));

            _inputMod = BeautyfyForms.CreateTextBox(new Point(360, 66), false);
            form.Controls.Add(_inputMod);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(480, 46), "Кол-во ячеек для 1 хеша", true, 140));

            _cellsPerHash = BeautyfyForms.CreateNumericUpDown(new Point(490, 66), 1, 50, false);
            form.Controls.Add(_cellsPerHash);

            _acceptFunction = BeautyfyForms.AddButton(" Подтвердить выбор ", new Point(620, 33), (o, k) =>
            {
                var value = 0;
                if (int.TryParse(_inputMod.Text, out value))
                {
                    curValue               = value;
                    _inputMod.ReadOnly     = true;
                    _cellsPerHash.ReadOnly = true;
                    _addNew.Visible        = true;

                    size = (int)_cellsPerHash.Value;

                    _table.Rows.Clear();
                    _table.Rows.Add();
                    _table.Rows.AddCopies(0, (curValue * size) - 1);
                    _table.ReadOnly = true;
                }
                else
                {
                    MessageBox.Show("Invalid mod value");
                }
            });
            form.Controls.Add(_acceptFunction);

            _selectNewFunction = BeautyfyForms.AddButton("Выбрать другую функцию", new Point(615, 66), (o, k) =>
            {
                _inputMod.ReadOnly     = false;
                _cellsPerHash.ReadOnly = false;
                _addNew.Visible        = false;
                _table.Rows.Clear();
            });
            form.Controls.Add(_selectNewFunction);

            _addNew = BeautyfyForms.AddButton(" Добавить ", new Point(280, 99), (o, k) =>
            {
                var value = 0;
                if (int.TryParse(_inputValue.Text, out value))
                {
                    var hash       = value % curValue;
                    var tableValue = _table.Rows[hash * size].Cells[0].Value;

                    //No value yet
                    if ((tableValue == null) || (tableValue == ""))
                    {
                        _table.Rows[hash * size].Cells[0].Value = hash;
                        _table.Rows[hash * size].Cells[1].Value = value;
                    }
                    else
                    {
                        if (_table.Rows[hash * size].Cells[1].Value.ToString() == value.ToString())
                        {
                            MessageBox.Show("Such value already exist in table");
                            return;
                        }

                        var firstIndx = hash * size + 1;
                        var lastIndx  = firstIndx + size - 1;
                        for (; firstIndx < lastIndx; firstIndx++)
                        {
                            tableValue = _table.Rows[firstIndx].Cells[0].Value;
                            if ((tableValue == null) || (tableValue == ""))
                            {
                                _table.Rows[firstIndx].Cells[0].Value = hash;
                                _table.Rows[firstIndx].Cells[1].Value = value;
                                return;
                            }
                            else
                            {
                                if (_table.Rows[firstIndx].Cells[1].Value.ToString() == value.ToString())
                                {
                                    MessageBox.Show("Such value already exist in table");
                                    return;
                                }
                            }
                        }
                        MessageBox.Show("Max num of slots reached. Unable to insert hash.");
                    }
                }
                else
                {
                    MessageBox.Show("Invalid x value");
                }
            });
            _addNew.Visible = false;
            form.Controls.Add(_addNew);

            _table = BeautyfyForms.AddDataGridViewHeadersOnUp(new Point(0, 200), form.Size, new string[] { "Значение хеша", "Собственно значение" });
            form.Controls.Add(_table);
        }
Пример #5
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 1 (b)";
            form.SetDefaultVals(new System.Drawing.Size(800, 700));
            var tmpbutt = BeautyfyForms.AddButton("Очистить дерево", new Point(0, 10), (o, k) =>
            {
                _tree = new BranchingTree();
                treeViewer.Clear();
                _addedWords.Items.Clear();
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(200, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 1b. Параграф 6.3, Реализация структуры \"Лес\" ");
            }));

            tmpbutt = BeautyfyForms.AddButton("Добавить значение", new Point(0, 40), (o, k) =>
            {
                if (string.IsNullOrEmpty(_addInput.Text))
                {
                    MessageBox.Show("Нет текста для поиска");
                    return;
                }

                var text = _addInput.Text;
                if (_tree.AddWord(text))
                {
                    if (!_addedWords.Items.Contains(text))
                    {
                        _addedWords.Items.Add(text);
                    }
                }

                treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton("Удалить значение", new Point(0, 70), (o, k) =>
            {
                if (string.IsNullOrEmpty(_deleteInput.Text))
                {
                    MessageBox.Show("Нет текста для поиска");
                    return;
                }

                var text = _deleteInput.Text;
                _tree.DeleteWord(text);
                _addedWords.Items.Remove(text);

                treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton("Проверить значение", new Point(0, 100), (o, k) =>
            {
                if (string.IsNullOrEmpty(_checkInput.Text))
                {
                    MessageBox.Show("Нет текста для поиска");
                    return;
                }

                var text = _checkInput.Text;
                if (_tree.WordExists(text))
                {
                    MessageBox.Show("Существует");
                }
                else
                {
                    MessageBox.Show("Не существует");
                }
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton("Отобразить деревце", new Point(0, 140), (o, k) =>
            {
                treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
            });
            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton(" Импорт ", new Point(0, 180), (o, k) =>
            {
                var keys = new List <string>();
                Helper.LoadFile("Список слов", "wordlst", keys);

                if (keys.Count > 0)
                {
                    _tree = new BranchingTree();
                    treeViewer.Clear();
                    _addedWords.Items.Clear();

                    foreach (var key in keys)
                    {
                        if (_tree.AddWord(key))
                        {
                            if (!_addedWords.Items.Contains(key))
                            {
                                _addedWords.Items.Add(key);
                            }
                        }
                    }
                }

                treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
            });
            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton(" Экспорт ", new Point(80, 180), (o, k) =>
            {
                SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.Filter         = string.Format("{0} (*.{1})|*.{1}", "Луч", "branchview");
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    _buttonsToHide.ForEach(x => x.Enabled = false);
                    _timerProgress.Start();

                    Task.Run(() =>
                    {
                        System.IO.File.WriteAllText(saveFile.FileName, _tree.getTreeView(_addXToEnd.Checked, false));
                    });
                    _buttonsToHide.ForEach(x => x.Enabled = true);
                    _timerProgress.Stop();
                    _progress.Value = _progress.Maximum;
                    MessageBox.Show("Сохранено!");
                }
            });
            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton(" Импорт .index ", new Point(160, 180), async(o, k) =>
            {
                OpenFileDialog openDic = new OpenFileDialog();
                openDic.Multiselect    = false;
                openDic.Filter         = string.Format("{0} (*.{1})|*.{1}", "Index файл", "index");
                if (openDic.ShowDialog() == DialogResult.OK)
                {
                    _buttonsToHide.ForEach(x => x.Enabled = false);
                    var openedFile = System.IO.Path.ChangeExtension(openDic.FileName, null);
                    var indexFile  = openedFile + ".index";
                    var baseFile   = openedFile + ".base";
                    _timerProgress.Start();
                    var state = await Task.Run(() => LoadIndexFile(indexFile, baseFile));

                    if (state != false)
                    {
                        MessageBox.Show("Готово! Дерево загружено.");
                    }
                    else
                    {
                        MessageBox.Show("Ошибка загрузки дерева.");
                        return;
                    }

                    _timerProgress.Stop();
                    _progress.Value = _progress.Maximum;
                    _buttonsToHide.ForEach(x => x.Enabled = true);
                }
            });

            //_buttonsToHide.Add(tmpbutt);
            //form.Controls.Add(tmpbutt);

            _progress = BeautyfyForms.AddProgressBar(new Point(300, 180), form.Size, 0, 10);
            form.Controls.Add(_progress);

            _timerProgress = BeautyfyForms.CreateTimer((sender, EventArgs) =>
            {
                if (_progress.Value >= _progress.Maximum)
                {
                    _progress.Value = 0;
                }
                else
                {
                    _progress.Value = _progress.Value + 1;
                }
            });

            _addInput = BeautyfyForms.CreateTextBox(new Point(150, 43), false);
            form.Controls.Add(_addInput);

            _deleteInput = BeautyfyForms.CreateTextBox(new Point(150, 73), false);
            form.Controls.Add(_deleteInput);

            _checkInput = BeautyfyForms.CreateTextBox(new Point(150, 103), false);
            form.Controls.Add(_checkInput);

            treeViewer = BeautyfyForms.CreateMLTextBox(new Point(5, 250 + 5), 780, 400);
            form.Controls.Add(treeViewer);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(150, 145), "Добавлять Х в качестве null-ветвей", true, 190));

            _addXToEnd = BeautyfyForms.CreateCheckBox(new Point(340, 140), false);
            form.Controls.Add(_addXToEnd);

            _addedWords = BeautyfyForms.AddListBox(new Point(500, 20), new Size(200, 250));
            _addedWords.MouseDoubleClick += (x, y) =>
            {
                if (_addedWords.SelectedItem != null)
                {
                    MessageBox.Show(_addedWords.SelectedItem.ToString());
                }
            };
            form.Controls.Add(_addedWords);
        }
Пример #6
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 1 и 2";
            form.SetDefaultVals(new System.Drawing.Size(800, 500));
            form.Controls.Add(BeautyfyForms.AddButton("Инициализация", new Point(0, 10), (o, k) =>
            {
                _inputG.Text = "64";  //G
                _inputA.Text = "122"; //H
                _inputM.Text = "607"; //P
                if (!_autoFindN.Checked)
                {
                    _inputN.Text = "101";//N
                }

                Log("Инициализовали параметры стандартными значениями");
            }));

            form.Controls.Add(BeautyfyForms.AddButton("Очистить лог", new Point(0, 43), (o, k) =>
            {
                logLstBox.Items.Clear();
            }));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(150, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 1 и 2. ρ - метод Полларда (обычный и параллельный) \r\n Найти такой х, что g^x = a % m ");
            }));

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(310, 10), "g", true, 10));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(410, 10), "a", true, 25));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(520, 10), "m", true, 30));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(640, 10), "n", true, 30));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(705, 10), "Автоподбор n", true, 100));

            _inputG      = BeautyfyForms.CreateTextBox(new Point(270, 33), false);
            _inputG.Text = "0";
            form.Controls.Add(_inputG);

            _inputA      = BeautyfyForms.CreateTextBox(new Point(380, 33), false);
            _inputA.Text = "0";
            form.Controls.Add(_inputA);

            _inputM      = BeautyfyForms.CreateTextBox(new Point(490, 33), false);
            _inputM.Text = "0";
            form.Controls.Add(_inputM);

            _inputN      = BeautyfyForms.CreateTextBox(new Point(600, 33), false);
            _inputN.Text = "0";
            form.Controls.Add(_inputN);

            _autoFindN = BeautyfyForms.CreateCheckBox(new Point(740, 33), false);
            _autoFindN.CheckedChanged += (o, k) =>
            {
                if (_autoFindN.Checked)
                {
                    _inputN.ReadOnly = true;
                    _inputN.Text     = "-1";
                }
                else
                {
                    _inputN.ReadOnly = false;
                    _inputN.Text     = "0";
                }
            };
            form.Controls.Add(_autoFindN);

            logLstBox = BeautyfyForms.AddListBox(new Point(0, 150 + 5), form.Size);
            logLstBox.MouseDoubleClick += (x, y) =>
            {
                if (logLstBox.SelectedItem != null)
                {
                    MessageBox.Show(logLstBox.SelectedItem.ToString());
                }
            };
            form.Controls.Add(logLstBox);

            form.Controls.Add(BeautyfyForms.AddButton(" Поехали (обычный) ", new Point(410, 63), (o, k) =>
            {
                ParseAndRunPollard(false);
            }));

            form.Controls.Add(BeautyfyForms.AddButton(" Поехали (параллельный) ", new Point(410, 93), (o, k) =>
            {
                ParseAndRunPollard(true);
            }));
        }
Пример #7
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 2";
            form.SetDefaultVals(new System.Drawing.Size(800, 500));
            var tmpbutt = BeautyfyForms.AddButton("Очистить дерево", new Point(0, 10), (o, k) =>
            {
                _tree = new BinaryTree <int?, SelfOrganizeIndexNode>(null, default(SelfOrganizeIndexNode));
                treeViewer.Clear();
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(200, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 2. Параграф 6.2.2, алгоритм D (удаление узла дерева)");
            }));

            tmpbutt = BeautyfyForms.AddButton("Сгенерировать дерево (N элементное)", new Point(0, 40), (o, k) =>
            {
                if (string.IsNullOrEmpty(_randomInput.Text))
                {
                    MessageBox.Show("Введите кол-во элементов для добавления");
                    return;
                }

                if (string.IsNullOrEmpty(_randomMin.Text))
                {
                    MessageBox.Show("Введите минимальное число");
                    return;
                }

                if (string.IsNullOrEmpty(_randomMax.Text))
                {
                    MessageBox.Show("Введите максимальное число");
                    return;
                }

                int min = 0, max = 0;
                try
                {
                    min = int.Parse(_randomMin.Text);
                    max = int.Parse(_randomMax.Text);
                }
                catch
                {
                    MessageBox.Show("Пределы не валидны");
                    return;
                }

                var text = _randomInput.Text;
                int res;

                if (int.TryParse(text, out res))
                {
                    if (Math.Abs(min - max) < res)
                    {
                        MessageBox.Show("Cлющай, став нармалные пределы, окда?");
                        return;
                    }

                    _buttonsToHide.ForEach(x => x.Enabled = false);
                    _timerProgress.Start();
                    treeViewer.Clear();

                    Task.Run(() =>
                    {
                        _tree = new BinaryTree <int?, SelfOrganizeIndexNode>(null, default(SelfOrganizeIndexNode));
                        GenerateRandomTree(res, min, max);
                    }).ContinueWith(result =>
                    {
                        treeViewer.BeginInvoke(new MethodInvoker(() => treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : ""));
                    });

                    _buttonsToHide.ForEach(x => x.Enabled = true);
                    _timerProgress.Stop();
                    _progress.Value = _progress.Maximum;
                    MessageBox.Show("Сгенерили!");
                }
                else
                {
                    MessageBox.Show("Это было не число, да?..");
                    return;
                }
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton("Удалить значение", new Point(0, 70), (o, k) =>
            {
                if (string.IsNullOrEmpty(_singleInput.Text))
                {
                    MessageBox.Show("Нет текста для поиска");
                    return;
                }

                var text = _singleInput.Text;
                int res;

                if (int.TryParse(text, out res))
                {
                    //RemoveNode(res);
                    RemoveNodeRewritten(res);

                    if (_tree == null)
                    {
                        _tree = new BinaryTree <int?, SelfOrganizeIndexNode>(null, default(SelfOrganizeIndexNode));
                    }

                    //funny but let`s skip this~
                    treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
                }
                else
                {
                    MessageBox.Show("Это было не число, да?..");
                    return;
                }
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton("Отобразить деревце", new Point(0, 100), (o, k) =>
            {
                treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
            });
            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton(" Импорт ", new Point(0, 140), (o, k) =>
            {
                var keys = new List <int>();
                Helper.LoadFile("Список ключей", "keylst", keys);

                foreach (var key in keys)
                {
                    AddNewValue(key, default(SelfOrganizeIndexNode));
                }

                treeViewer.Text = (_tree != null) ? _tree.getTreeView(_addXToEnd.Checked) : "";
            });
            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton(" Экспорт ", new Point(80, 140), (o, k) =>
            {
                SaveFileDialog saveFile = new SaveFileDialog();
                saveFile.Filter         = string.Format("{0} (*.{1})|*.{1}", "Бинарное деревце", "btree");
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    _buttonsToHide.ForEach(x => x.Enabled = false);
                    _timerProgress.Start();

                    Task.Run(() =>
                    {
                        System.IO.File.WriteAllText(saveFile.FileName, _tree.getTreeView(_addXToEnd.Checked, false));
                    });
                    _buttonsToHide.ForEach(x => x.Enabled = true);
                    _timerProgress.Stop();
                    _progress.Value = _progress.Maximum;
                    MessageBox.Show("Сохранено!");
                }
            });
            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            tmpbutt = BeautyfyForms.AddButton(" Импорт .index ", new Point(160, 140), async(o, k) =>
            {
                OpenFileDialog openDic = new OpenFileDialog();
                openDic.Multiselect    = false;
                openDic.Filter         = string.Format("{0} (*.{1})|*.{1}", "Index файл", "index");
                if (openDic.ShowDialog() == DialogResult.OK)
                {
                    _buttonsToHide.ForEach(x => x.Enabled = false);
                    var openedFile = System.IO.Path.ChangeExtension(openDic.FileName, null);
                    var indexFile  = openedFile + ".index";
                    var baseFile   = openedFile + ".base";
                    _timerProgress.Start();
                    var state = await Task.Run(() => LoadIndexFile(indexFile, baseFile));

                    if (state != false)
                    {
                        MessageBox.Show("Готово! Дерево загружено.");
                    }
                    else
                    {
                        MessageBox.Show("Ошибка загрузки дерева.");
                        return;
                    }

                    _timerProgress.Stop();
                    _progress.Value = _progress.Maximum;
                    _buttonsToHide.ForEach(x => x.Enabled = true);
                }
            });

            _buttonsToHide.Add(tmpbutt);
            form.Controls.Add(tmpbutt);

            _progress = BeautyfyForms.AddProgressBar(new Point(300, 140), form.Size, 0, 10);
            form.Controls.Add(_progress);

            _timerProgress = BeautyfyForms.CreateTimer((sender, EventArgs) =>
            {
                if (_progress.Value >= _progress.Maximum)
                {
                    _progress.Value = 0;
                }
                else
                {
                    _progress.Value = _progress.Value + 1;
                }
            });
            _randomInput      = BeautyfyForms.CreateTextBox(new Point(290, 43), false);
            _randomInput.Text = "20";
            form.Controls.Add(_randomInput);

            _randomMin      = BeautyfyForms.CreateTextBox(new Point(400, 43), false);
            _randomMin.Text = "1";
            form.Controls.Add(_randomMin);

            _randomMax      = BeautyfyForms.CreateTextBox(new Point(510, 43), false);
            _randomMax.Text = "100";
            form.Controls.Add(_randomMax);

            _singleInput = BeautyfyForms.CreateTextBox(new Point(150, 73), false);
            form.Controls.Add(_singleInput);

            treeViewer = BeautyfyForms.CreateMLTextBox(new Point(5, 250 + 5), 780, 200);
            form.Controls.Add(treeViewer);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(150, 105), "Добавлять Х в качестве null-ветвей", true, 190));

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(330, 20), "N", true, 10));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(430, 20), "Min", true, 25));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(540, 20), "Max", true, 30));

            _addXToEnd = BeautyfyForms.CreateCheckBox(new Point(340, 100), false);
            form.Controls.Add(_addXToEnd);
        }
Пример #8
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 3";
            form.SetDefaultVals(new System.Drawing.Size(800, 500));

            var btnOpen = BeautyfyForms.AddButton("Открыть index файл", new Point(0, 10), async(o, k) =>
            {
                OpenFileDialog openDic = new OpenFileDialog();
                openDic.Multiselect    = false;
                openDic.Filter         = string.Format("{0} (*.{1})|*.{1}", "Index файл", "index");
                if (openDic.ShowDialog() == DialogResult.OK)
                {
                    _buttonsToHide.ForEach(x => x.Enabled = false);
                    openedFile    = System.IO.Path.ChangeExtension(openDic.FileName, null);
                    var indexFile = openedFile + ".index";
                    var baseFile  = openedFile + ".base";

                    _timerProgress.Start();

                    logLstBox.Items.Add(DateTime.Now.ToString() + ": Загружаем index файл");

                    var state = await Task.Run(() => LoadIndexFile(indexFile, baseFile));

                    if (state)
                    {
                        logLstBox.Items.Add(DateTime.Now.ToString() + ": index файл загружен");
                    }
                    else
                    {
                        logLstBox.Items.Add(DateTime.Now.ToString() + ": ошибка загрузки");
                    }

                    _timerProgress.Stop();
                    _progress.Value = _progress.Maximum;
                    _buttonsToHide.ForEach(x => x.Enabled = true);
                }
            });

            _buttonsToHide.Add(btnOpen);
            form.Controls.Add(btnOpen);

            logLstBox = BeautyfyForms.AddListBox(new Point(0, 300 + 3), form.Size);
            form.Controls.Add(logLstBox);

            _progress = BeautyfyForms.AddProgressBar(new Point(150, 10), form.Size, 0, 10);
            form.Controls.Add(_progress);

            _timerProgress = BeautyfyForms.CreateTimer((sender, EventArgs) =>
            {
                if (_progress.Value >= _progress.Maximum)
                {
                    _progress.Value = 0;
                }
                else
                {
                    _progress.Value = _progress.Value + 1;
                }
            });

            _timerBackup = BeautyfyForms.CreateTimer(async(sender, EventArgs) =>
            {
                var indexFile = openedFile + ".index";
                var baseFile  = openedFile + ".base";
                var state     = await Task.Run(() => SaveIndexFile(indexFile, baseFile));
            });

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(300, 80), "Слово для поиска"));

            _info = BeautyfyForms.CreateLabel(new Point(400, 100), " Поиск не производился ");
            form.Controls.Add(_info);

            _input = BeautyfyForms.CreateTextBox(new Point(300, 100), false);
            form.Controls.Add(_input);

            var btnSearch = BeautyfyForms.AddButton(" Поиск ", new Point(200, 100), async(o, k) =>
            {
                if (_linkedList == null)
                {
                    MessageBox.Show("Необходимо сначала загрузить index файл");
                    return;
                }

                if (_linkedList.Count <= 0)
                {
                    MessageBox.Show("Нет записей, которые можно было бы обработать. (Пустой файл?)");
                    return;
                }

                if (string.IsNullOrEmpty(_input.Text))
                {
                    MessageBox.Show("Нет текста для поиска");
                    return;
                }

                var text       = _input.Text;
                var hashedText = Helper.GetHash(text, _header.hashType);
                _buttonsToHide.ForEach(x => x.Enabled = false);

                var state = await Task.Run(() => Search(hashedText));

                if (state)
                {
                    logLstBox.Items.Add(DateTime.Now.ToString() + ": Слово `" + text + "` найдено");
                }
                else
                {
                    logLstBox.Items.Add(DateTime.Now.ToString() + ": Слово `" + text + "` не найдено");
                }

                _buttonsToHide.ForEach(x => x.Enabled = true);
            });

            _buttonsToHide.Add(btnSearch);
            form.Controls.Add(btnSearch);
        }
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 1";
            form.SetDefaultVals(new System.Drawing.Size(800, 500));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(370, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 1. Игра с Геометрическим, Биномиальным и Клиновидным распределениями!");
            }));

            logGeometric = BeautyfyForms.AddListBox(new Point(10, 100), new Size(200, 450));
            form.Controls.Add(logGeometric);

            _geometric = BeautyfyForms.CreateTextBox(new Point(40, 420), true);
            form.Controls.Add(_geometric);

            logBinominal = BeautyfyForms.AddListBox(new Point(300, 100), new Size(200, 450));
            form.Controls.Add(logBinominal);

            _binominal = BeautyfyForms.CreateTextBox(new Point(340, 420), true);
            form.Controls.Add(_binominal);

            logWedgeShaped = BeautyfyForms.AddListBox(new Point(590, 100), new Size(200, 450));
            form.Controls.Add(logWedgeShaped);

            _wedgeShaped = BeautyfyForms.CreateTextBox(new Point(625, 420), true);
            form.Controls.Add(_wedgeShaped);

            form.Controls.Add(BeautyfyForms.AddButton("Геометрическое", new Point(30, 70), (o, k) =>
            {
                logGeometric.Items.Clear();
                Task.Run(() =>
                {
                    var listOfElements = new List <KeyValueItem>();
                    var geom           = new MathNet.Numerics.Distributions.Geometric(0.6);
                    for (int i = 0; i <= 1000; i++)
                    {
                        listOfElements.Add(new KeyValueItem(i, geom.Probability(i)));
                    }
                    var sum        = (from element in listOfElements.AsParallel() select element.Probability).Sum();
                    listOfElements = (from element in listOfElements.AsParallel() orderby element.Probability descending select element).ToList();
                    foreach (var item in listOfElements)
                    {
                        logGeometric.BeginInvoke(new MethodInvoker(() => logGeometric.Items.Add(item)));
                    }

                    double average = 0;
                    for (int i = 0; i < 100000; i++)
                    {
                        var search = geom.Sample();
                        for (int j = 0; j < listOfElements.Count; j++)
                        {
                            if (listOfElements[j].Key == search)
                            {
                                average += j;
                            }
                        }
                    }

                    average /= 100000;
                    _geometric.BeginInvoke(new MethodInvoker(() => _geometric.Text = Math.Round(average).ToString()));
                });
            }));

            form.Controls.Add(BeautyfyForms.AddButton("Биноминальное", new Point(335, 70), (o, k) =>
            {
                logBinominal.Items.Clear();
                Task.Run(() =>
                {
                    var listOfElements = new List <KeyValueItem>();
                    var binom          = new MathNet.Numerics.Distributions.Binomial(0.4, 1000);
                    for (int i = 0; i <= 1000; i++)
                    {
                        listOfElements.Add(new KeyValueItem(i, binom.Probability(i)));
                    }
                    listOfElements = (from element in listOfElements.AsParallel() orderby element.Probability descending select element).ToList();
                    foreach (var item in listOfElements)
                    {
                        logBinominal.BeginInvoke(new MethodInvoker(() => logBinominal.Items.Add(item)));
                    }

                    long average = 0;

                    for (int i = 0; i < 100000; i++)
                    {
                        var search = binom.Sample();
                        for (int j = 0; j < listOfElements.Count; j++)
                        {
                            if (listOfElements[j].Key == search)
                            {
                                average += j;
                            }
                        }
                    }

                    average /= 100000;
                    _binominal.BeginInvoke(new MethodInvoker(() => _binominal.Text = Math.Round((decimal)average).ToString()));
                });
            }));

            form.Controls.Add(BeautyfyForms.AddButton("Клиновидное", new Point(630, 70), (o, k) =>
            {
                logWedgeShaped.Items.Clear();
                Task.Run(() =>
                {
                    var listOfElements = new List <KeyValueItem>();
                    Random random      = new Random((int)DateTime.Now.ToBinary());
                    int N = 1000;
                    for (int i = 0; i < 1000; i++)
                    {
                        listOfElements.Add(new KeyValueItem(i, (N - i) * (2.0 / (N * (N + 1)))));
                    }
                    var sum        = (from element in listOfElements.AsParallel() select element.Probability).Sum();
                    listOfElements = (from element in listOfElements.AsParallel() orderby element.Probability descending select element).ToList();
                    foreach (var item in listOfElements)
                    {
                        logWedgeShaped.BeginInvoke(new MethodInvoker(() => logWedgeShaped.Items.Add(item)));
                    }

                    double average = 0;

                    for (int i = 0; i < 100000; i++)
                    {
                        var p      = (N - random.Next(0, 1000)) * (2.0 / (N * (N + 1)));
                        var search = -(1 / 2.0) * N * (N * p + p - 2);
                        for (int j = 0; j < listOfElements.Count; j++)
                        {
                            if (listOfElements[j].Key == search)
                            {
                                average += j;
                            }
                        }
                    }
                    average /= 100000;
                    _wedgeShaped.BeginInvoke(new MethodInvoker(() => _wedgeShaped.Text = Math.Round(average).ToString()));
                });
            }));
        }
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 4";
            form.SetDefaultVals(new System.Drawing.Size(800, 500));
            form.Controls.Add(BeautyfyForms.AddButton("Случайное уравнение", new Point(0, 10), (o, k) =>
            {
                var tuple    = SelectRandomEquation();
                _inputH.Text = tuple.Item1.ToString();
                _inputG.Text = tuple.Item2.ToString();
                _inputP.Text = tuple.Item3.ToString();

                Log("Инициализовали параметры заготовленными значениями");
            }));

            form.Controls.Add(BeautyfyForms.AddButton("Очистить лог", new Point(0, 43), (o, k) =>
            {
                logLstBox.Items.Clear();
            }));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(170, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 4 Алгоритм Полига-Хеллмана \r\n Найти такой х, что H = G^x (mod P) ");
            }));

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(310, 10), "H", true, 10));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(410, 10), "G", true, 25));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(520, 10), "P", true, 30));
            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(705, 100), "Очищать лог", true, 100));

            _inputH      = BeautyfyForms.CreateTextBox(new Point(270, 33), false);
            _inputH.Text = "0";
            form.Controls.Add(_inputH);

            _inputG      = BeautyfyForms.CreateTextBox(new Point(380, 33), false);
            _inputG.Text = "0";
            form.Controls.Add(_inputG);

            _inputP      = BeautyfyForms.CreateTextBox(new Point(490, 33), false);
            _inputP.Text = "0";
            form.Controls.Add(_inputP);

            _keepLog = BeautyfyForms.CreateCheckBox(new Point(740, 115), false);
            form.Controls.Add(_keepLog);

            logLstBox = BeautyfyForms.AddListBox(new Point(0, 150 + 5), form.Size);
            logLstBox.MouseDoubleClick += (x, y) =>
            {
                if (logLstBox.SelectedItem != null)
                {
                    MessageBox.Show(logLstBox.SelectedItem.ToString());
                }
            };
            form.Controls.Add(logLstBox);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(380, 63), "H = G^x (mod P)", true, 100));

            form.Controls.Add(BeautyfyForms.AddButton(" Поехали ", new Point(380, 93), (o, k) =>
            {
                ParseAndRunPohligHellman();
            }));
        }
Пример #11
0
        public void LocateControls(Form form, ConsoleHandler console)
        {
            form.Text = "Задание № 1";
            form.SetDefaultVals(new System.Drawing.Size(810, 500));

            form.Controls.Add(BeautyfyForms.AddButton(" Суть ", new Point(300, 10), (o, k) =>
            {
                MessageBox.Show("Задача № 1 Алгоритм разрешения коллизий в хэш-таблицах методом цепочек.");
            }));

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(370, 46), "Хеширующая функция", true, 125));

            _inputValue = BeautyfyForms.CreateTextBox(new Point(300, 66), false);
            form.Controls.Add(_inputValue);

            form.Controls.Add(BeautyfyForms.CreateLabel(new Point(420, 66), "mod", true, 35));

            _inputMod = BeautyfyForms.CreateTextBox(new Point(460, 66), false);
            form.Controls.Add(_inputMod);

            _acceptFunction = BeautyfyForms.AddButton(" Подтвердить выбор ", new Point(620, 33), (o, k) =>
            {
                var value = 0;
                if (int.TryParse(_inputMod.Text, out value))
                {
                    curValue           = value;
                    _inputMod.ReadOnly = true;
                    _addNew.Visible    = true;
                }
                else
                {
                    MessageBox.Show("Invalid mod value");
                }
            });
            form.Controls.Add(_acceptFunction);

            _selectNewFunction = BeautyfyForms.AddButton("Выбрать другую функцию", new Point(615, 66), (o, k) =>
            {
                _inputMod.ReadOnly = false;
                _addNew.Visible    = false;
                _treeOfData.Nodes.Clear();
                chains.Clear();
            });
            form.Controls.Add(_selectNewFunction);

            _addNew = BeautyfyForms.AddButton(" Добавить ", new Point(380, 99), (o, k) =>
            {
                var value = 0;
                if (int.TryParse(_inputValue.Text, out value))
                {
                    var hash = value % curValue;
                    if (chains.ContainsKey(hash))
                    {
                        if (!(chains[hash].Contains(value)))
                        {
                            chains[hash].Add(value);
                            var node = _treeOfData.Nodes.Find("", true).FirstOrDefault(x => x.Text == hash.ToString() && x.Parent == null);
                            if (node != null)
                            {
                                node.Nodes.Add(new TreeNode(value.ToString()));
                            }
                        }
                        else
                        {
                            MessageBox.Show("Ключ найден - " + hash);
                        }
                    }
                    else
                    {
                        chains.Add(hash, new List <int>()
                        {
                            value
                        });

                        var stringHash = hash.ToString();

                        var hashNode = new TreeNode(stringHash);

                        hashNode.Text     = stringHash;
                        hashNode.ImageKey = stringHash;
                        hashNode.Tag      = stringHash;

                        var valueNode = new TreeNode(value.ToString());
                        hashNode.Nodes.Add(valueNode);

                        _treeOfData.Nodes.Add(hashNode);
                    }
                }
                else
                {
                    MessageBox.Show("Invalid x value");
                }
            });
            _addNew.Visible = false;
            form.Controls.Add(_addNew);

            _treeOfData = BeautyfyForms.AddTreeView(new Point(10, 10), new Size(200, 450));
            form.Controls.Add(_treeOfData);
        }