/// <summary>
        /// Принять характеристики
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            bool isCorrect = true;

            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (!string.IsNullOrWhiteSpace((string)dataGridView1.Rows[i].Cells[1].Value) || !string.IsNullOrWhiteSpace((string)dataGridView1.Rows[i].Cells[2].Value))
                {
                    int territorySize, controlDistance;
                    if (int.TryParse((string)dataGridView1.Rows[i].Cells[1].Value, out territorySize) && int.TryParse((string)dataGridView1.Rows[i].Cells[2].Value, out controlDistance))
                    {
                        if (territorySize < 1 || controlDistance < 1)
                        {
                            isCorrect = false;
                            MessageBox.Show("Некорректное значение в поле/полях района " + MainWindow.Graph.Vertices[(int)dataGridView1.Rows[i].Cells[0].Value].Index,
                                            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            break;
                        }
                        MainWindow.Graph.Vertices[(int)dataGridView1.Rows[i].Cells[0].Value].ControlDistance = controlDistance;
                        MainWindow.Graph.Vertices[(int)dataGridView1.Rows[i].Cells[0].Value].TerritorySize   = territorySize;
                    }
                    else
                    {
                        MessageBox.Show("Некорректное значение в поле/полях района " + MainWindow.Graph.Vertices[(int)dataGridView1.Rows[i].Cells[0].Value].Index,
                                        "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        isCorrect = false;
                        break;
                    }
                }
                else
                {
                    isCorrect = false;
                    MessageBox.Show("Некорректное значение в поле/полях района " + MainWindow.Graph.Vertices[(int)dataGridView1.Rows[i].Cells[0].Value].Index,
                                    "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    break;
                }
            }
            if (isCorrect)
            {
                if (File.Exists("Graph.dat"))
                {
                    File.Delete("Graph.dat");
                }
                MainWindow.Graph.UpdateEdgesData();
                SaverLoader.SaveToFile("Graph.dat", MainWindow.Graph);
                Close();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Обработчик при попытке закрыть главную форму
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EnrolleeForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            // сохраняем базу в локальный файл
            SaverLoader.SaveToFile(Path.ChangeExtension(Application.ExecutablePath, ".bin"), _root);
            tsslStatusLabel.Text = "Сохранение данных на сервере...";
            statusStrip1.Refresh();
            // сохраняем базу на сервере
            SaverLoader.StoreTables(_root, Properties.Settings.Default.ConnectionString);
            var result = SaverLoader.OperationResult;

            // показываем результат
            tsslStatusLabel.Text = string.IsNullOrWhiteSpace(result)
                                ? "Готово" : result.Substring(0, result.IndexOf('.') + 1);
            statusStrip1.Refresh();
            // спрашиваем пользователя, закрывать ли приложение
            e.Cancel = MessageBox.Show(this, "Закрыть приложение?", "Выход", MessageBoxButtons.YesNo,
                                       MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.Yes;
        }
Ejemplo n.º 3
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     SaverLoader.SaveToFile(Path.ChangeExtension(Application.ExecutablePath, ".bin"), _school);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Сохранить в файл
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsmiSaveToFile_Click(object sender, EventArgs e)
        {
            var fileName = Path.ChangeExtension(Application.ExecutablePath, ".dat");

            SaverLoader.SaveToFile(fileName, _hotel);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            bool goOut = false;
            BinomialHeap <int> binomialHeap = null;

            do
            {
                char whatToDo;

                whatToDo = Subroutines.PrintMenu();
                switch (whatToDo)
                {
                //
                // c - создать кучу и заполнить ее случайными величинами
                //
                case 'c':
                {
                    bool isError;
                    int  number;
                    binomialHeap = new BinomialHeap <int>();
                    do
                    {
                        isError = false;
                        do
                        {
                            Console.Write("Сколько элементов будет в куче?\nВаше число ");
                        } while (!Int32.TryParse(Console.ReadLine(), out number));
                        if (number <= 0 || number > 10000)
                        {
                            isError = true;
                        }
                    } while (isError == true);
                    for (int i = 0; i < number; i++)
                    {
                        binomialHeap.Add(new Random().Next(-50, 1000));
                        System.Threading.Thread.Sleep(30);
                    }
                    SaverLoader.SaveToFile("input.dat", binomialHeap);
                    Console.WriteLine("Куча успешно сформирована. Нажмите что-нибудь...");
                    Console.ReadKey();
                    try
                    {
                        binomialHeap.WriteBinomialHeapToFile("output.dat");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("GG in file output.dat");
                        Console.ReadKey();
                    }
                    break;
                }

                //
                //  r - добавить элементы в кучу
                //
                case 'r':
                {
                    int number;
                    do
                    {
                        do
                        {
                            Console.Write("Сколько элементов добавить? (не более 10)\nВаше число ");
                        } while (!Int32.TryParse(Console.ReadLine(), out number));
                    } while (number < 1 || number > 10);

                    if (binomialHeap == null)
                    {
                        binomialHeap = new BinomialHeap <int>();
                    }
                    for (int i = 0; i < number; i++)
                    {
                        int digit;
                        do
                        {
                            Console.Write("\nЧисло №" + (i + 1) + " = ");
                        } while (!Int32.TryParse(Console.ReadLine(), out digit));
                        binomialHeap.Add(digit);
                    }
                    Console.WriteLine("Элементы успешно добавлены. Нажмите что-нибудь...");
                    Console.ReadKey();
                    if (File.Exists("input.dat"))
                    {
                        File.Delete("input.dat");
                    }
                    SaverLoader.SaveToFile("input.dat", binomialHeap);
                    try
                    {
                        binomialHeap.WriteBinomialHeapToFile("output.dat");
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("GG in file output.dat");
                        Console.ReadKey();
                    }
                    break;
                }

                //
                // b - восстановить кучу из файла input.dat
                //
                case 'b':
                {
                    binomialHeap = (BinomialHeap <int>)SaverLoader.LoadFromFile("input.dat");
                    Console.WriteLine("Куча успешно восстановлена. Нажмите что-нибудь...");
                    Console.ReadKey();
                    break;
                }

                //
                //  p - показать кучу
                //
                case 'p':
                {
                    if (binomialHeap == null)
                    {
                        Console.WriteLine("\nКуча не существует. Нажмите что-нибудь...");
                        Console.ReadKey();
                        break;
                    }
                    Console.WriteLine("\n---------------------------");
                    binomialHeap.Print();
                    Console.ReadKey();
                    break;
                }

                //
                //  d - вывести первые К натуральных чисел
                //
                case 'd':
                {
                    if (binomialHeap == null)
                    {
                        Console.WriteLine("\nКуча не существует. Нажмите что-нибудь...");
                        Console.ReadKey();
                        break;
                    }
                    int k;
                    do
                    {
                        do
                        {
                            Console.Write("Сколько элементов вывести?\nВаше число ");
                        } while (!Int32.TryParse(Console.ReadLine(), out k));
                    } while (k < 1);
                    binomialHeap.PrintFirstNaturalElements(k);
                    Console.ReadKey();
                    break;
                }

                //
                //  ESC - выход
                //
                case (char)27:
                {
                    goOut = true;
                    break;
                }
                }
            } while (goOut == false);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Перед закрытием формы
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void BaseEditorForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     // сохраняем состояние в файл
     SaverLoader.SaveToFile(_defaultFileName, _modelRoot);
 }
Ejemplo n.º 7
0
 protected override void OnFormClosed(FormClosedEventArgs e)
 {
     base.OnFormClosed(e);
     //autosave
     SaverLoader.SaveToFile(TempFilePath, grid);
 }