From 60e7881cb07333a513cb8a174ac1670515950545 Mon Sep 17 00:00:00 2001 From: Baryshev Dmitry Date: Fri, 5 Apr 2024 01:27:26 +0400 Subject: [PATCH] well done --- .../CollectionGenericObject/CollectionType.cs | 27 ++ .../ListGenericObjects.cs | 80 +++++ .../MassiveGenericObjects.cs | 31 +- .../StorageCollection.cs | 84 ++++++ .../FormTruckCollection.Designer.cs | 276 +++++++++++++----- .../ProjectDumpTruck/FormTruckCollection.cs | 120 +++++++- 6 files changed, 522 insertions(+), 96 deletions(-) create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs create mode 100644 ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs new file mode 100644 index 0000000..48b1c2f --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck.CollectionGenericObject; + +public enum CollectionType +{ + + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 + +} diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs new file mode 100644 index 0000000..f50ee76 --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck.CollectionGenericObject; + +public class ListGenericObjects : ICollectionGenericObject + where T: class +{ + + /// + /// Список объектов, которые храним + /// + private readonly List _collection; + + /// + /// Максимально допустимое число объектов в списке + /// + private int _maxCount; + + public int Count => _collection.Count; + + public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + + /// + /// Конструктор + /// + public ListGenericObjects() + { + _collection = new(); + } + + public T? Get(int position) + { + if (position < 0 || position >= Count) + { + return null; + } + + return _collection[position]; + } + + public int Insert(T obj) + { + if (Count == _maxCount) + { + return -1; + } + + _collection.Add(obj); + return _collection.Count; + } + + public int Insert(T obj, int position) + { + if (Count == _maxCount || position < 0 || position > Count) + { + return -1; + } + + _collection.Insert(position, obj); + return position; + } + + public T? Remove(int position) + { + if (position < 0 || position > Count) + { + return null; + } + + T? obj = _collection[position]; + _collection.RemoveAt(position); + + return obj; + } + +} diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs index 81b9332..12d0ce8 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/MassiveGenericObjects.cs @@ -18,7 +18,23 @@ public class MassiveGenericObjects : ICollectionGenericObject public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } /// /// Конструктор @@ -31,7 +47,7 @@ public class MassiveGenericObjects : ICollectionGenericObject public T? Get(int position) { // TODO проверка позиции - if (position < 0 || position > Count) + if (position < 0 || position >= Count) { return null; } @@ -54,12 +70,7 @@ public class MassiveGenericObjects : ICollectionGenericObject public int Insert(T obj, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до - // TODO вставка - if (position < 0 || position > Count) + if (position < 0 || position >= Count) { return -1; } @@ -75,7 +86,7 @@ public class MassiveGenericObjects : ICollectionGenericObject if (_collection[i] == null) { _collection[i] = obj; - return position; + return i; } } @@ -84,7 +95,7 @@ public class MassiveGenericObjects : ICollectionGenericObject if (_collection[i] == null) { _collection[i] = obj; - return position; + return i; } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs new file mode 100644 index 0000000..3bb32cf --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectDumpTruck.CollectionGenericObject; + +public class StorageCollection + where T : class +{ + /// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> _storages; + + /// + /// Возвращение списка названий коллекций + /// + public List Keys => _storages.Keys.ToList(); + + /// + /// Конструктор + /// + public StorageCollection() + { + _storages = new Dictionary>(); + } + + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// Тип коллекции + public void AddCollection(string name, CollectionType collectionType) + { + if (name == null || _storages.ContainsKey(name)) + { + return; + } + + if (collectionType == CollectionType.Massive) + { + _storages.Add(name, new MassiveGenericObjects()); + } + + if (collectionType == CollectionType.List) + { + _storages.Add(name, new ListGenericObjects()); + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if (name == null || !_storages.ContainsKey(name)) + { + return; + } + + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObject? this[string name] + { + get + { + if (_storages.ContainsKey(name)) + { + return _storages[name]; + } + + return null; + } + } +} diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs index bc2bbf2..b157e32 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs @@ -29,27 +29,36 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveTruck = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddDumpTruck = new Button(); - buttonAddTruck = new Button(); + buttonCreteCompany = new Button(); comboBoxSelectorCompany = new ComboBox(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionalName = new Label(); + panelCompanyTools = new Panel(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonAddTruck = new Button(); + buttonGoToCheck = new Button(); + buttonAddDumpTruck = new Button(); + buttonRemoveTruck = new Button(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); + panelCompanyTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveTruck); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddDumpTruck); - groupBoxTools.Controls.Add(buttonAddTruck); + groupBoxTools.Controls.Add(buttonCreteCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(panelStorage); + groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(888, 0); groupBoxTools.Name = "groupBoxTools"; @@ -58,64 +67,15 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonRefresh + // buttonCreteCompany // - buttonRefresh.Location = new Point(6, 517); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(226, 48); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Location = new Point(6, 360); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(226, 48); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тест"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveTruck - // - buttonRemoveTruck.Location = new Point(6, 258); - buttonRemoveTruck.Name = "buttonRemoveTruck"; - buttonRemoveTruck.Size = new Size(226, 48); - buttonRemoveTruck.TabIndex = 4; - buttonRemoveTruck.Text = "Удаление\r\n"; - buttonRemoveTruck.UseVisualStyleBackColor = true; - buttonRemoveTruck.Click += ButtonRemoveTruck_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Location = new Point(6, 225); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(226, 27); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddDumpTruck - // - buttonAddDumpTruck.Location = new Point(6, 150); - buttonAddDumpTruck.Name = "buttonAddDumpTruck"; - buttonAddDumpTruck.Size = new Size(226, 48); - buttonAddDumpTruck.TabIndex = 2; - buttonAddDumpTruck.Text = "Добавление самосвала"; - buttonAddDumpTruck.UseVisualStyleBackColor = true; - buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click; - // - // buttonAddTruck - // - buttonAddTruck.Location = new Point(6, 96); - buttonAddTruck.Name = "buttonAddTruck"; - buttonAddTruck.Size = new Size(226, 48); - buttonAddTruck.TabIndex = 1; - buttonAddTruck.Text = "Добавление грузовика"; - buttonAddTruck.UseVisualStyleBackColor = true; - buttonAddTruck.Click += ButtonAddTruck_Click; + buttonCreteCompany.Location = new Point(7, 313); + buttonCreteCompany.Name = "buttonCreteCompany"; + buttonCreteCompany.Size = new Size(225, 29); + buttonCreteCompany.TabIndex = 10; + buttonCreteCompany.Text = "Создать компанию"; + buttonCreteCompany.UseVisualStyleBackColor = true; + buttonCreteCompany.Click += ButtonCreteCompany_Click; // // comboBoxSelectorCompany // @@ -123,11 +83,166 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 35); + comboBoxSelectorCompany.Location = new Point(6, 348); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(226, 28); - comboBoxSelectorCompany.TabIndex = 0; - comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + comboBoxSelectorCompany.TabIndex = 9; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Controls.Add(labelCollectionalName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(232, 280); + panelStorage.TabIndex = 8; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 241); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(219, 29); + buttonCollectionDel.TabIndex = 7; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 20; + listBoxCollection.Location = new Point(4, 131); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(219, 104); + listBoxCollection.TabIndex = 6; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(4, 96); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(219, 29); + buttonCollectionAdd.TabIndex = 5; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(122, 66); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(80, 24); + radioButtonList.TabIndex = 4; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(25, 66); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(82, 24); + radioButtonMassive.TabIndex = 3; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 33); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(226, 27); + textBoxCollectionName.TabIndex = 2; + // + // labelCollectionalName + // + labelCollectionalName.AutoSize = true; + labelCollectionalName.Location = new Point(38, 10); + labelCollectionalName.Name = "labelCollectionalName"; + labelCollectionalName.Size = new Size(155, 20); + labelCollectionalName.TabIndex = 1; + labelCollectionalName.Text = "Название коллекции"; + // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonAddTruck); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonAddDumpTruck); + panelCompanyTools.Controls.Add(buttonRemoveTruck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 382); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(232, 303); + panelCompanyTools.TabIndex = 7; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(3, 115); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(226, 27); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(3, 256); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(226, 48); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonAddTruck + // + buttonAddTruck.Location = new Point(3, 3); + buttonAddTruck.Name = "buttonAddTruck"; + buttonAddTruck.Size = new Size(226, 52); + buttonAddTruck.TabIndex = 1; + buttonAddTruck.Text = "Добавление грузовика"; + buttonAddTruck.UseVisualStyleBackColor = true; + buttonAddTruck.Click += ButtonAddTruck_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(3, 202); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(226, 48); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тест"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonAddDumpTruck + // + buttonAddDumpTruck.Location = new Point(3, 61); + buttonAddDumpTruck.Name = "buttonAddDumpTruck"; + buttonAddDumpTruck.Size = new Size(226, 48); + buttonAddDumpTruck.TabIndex = 2; + buttonAddDumpTruck.Text = "Добавление самосвала"; + buttonAddDumpTruck.UseVisualStyleBackColor = true; + buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click; + // + // buttonRemoveTruck + // + buttonRemoveTruck.Location = new Point(3, 148); + buttonRemoveTruck.Name = "buttonRemoveTruck"; + buttonRemoveTruck.Size = new Size(226, 48); + buttonRemoveTruck.TabIndex = 4; + buttonRemoveTruck.Text = "Удаление\r\n"; + buttonRemoveTruck.UseVisualStyleBackColor = true; + buttonRemoveTruck.Click += ButtonRemoveTruck_Click; // // pictureBox // @@ -148,7 +263,10 @@ Name = "FormTruckCollection"; Text = "Коллекция грузовиков"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -156,7 +274,6 @@ #endregion private GroupBox groupBoxTools; - private ComboBox comboBoxSelectorCompany; private Button buttonAddTruck; private Button buttonAddDumpTruck; private Button buttonGoToCheck; @@ -164,5 +281,16 @@ private MaskedTextBox maskedTextBoxPosition; private PictureBox pictureBox; private Button buttonRefresh; + private Panel panelCompanyTools; + private Panel panelStorage; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionalName; + private Button buttonCreteCompany; + private ComboBox comboBoxSelectorCompany; + private Button buttonCollectionDel; + private ListBox listBoxCollection; } } \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs index a4d6706..ba2ef96 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs @@ -6,9 +6,11 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Resources; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar; namespace ProjectDumpTruck; @@ -17,6 +19,9 @@ namespace ProjectDumpTruck; /// public partial class FormTruckCollection : Form { + + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -28,6 +33,7 @@ public partial class FormTruckCollection : Form public FormTruckCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -37,12 +43,7 @@ public partial class FormTruckCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Autopark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -64,14 +65,14 @@ public partial class FormTruckCollection : Form case nameof(DrawningDumpTruck): drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random),GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } - if (_company + drawningTruck!=-1) + if (_company + drawningTruck != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -107,7 +108,7 @@ public partial class FormTruckCollection : Form if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return; int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos!=null) + if (_company - pos != null) { MessageBox.Show("Объект удален"); @@ -140,14 +141,109 @@ public partial class FormTruckCollection : Form counter--; if (counter <= 0) break; } - + if (truck == null) return; - FormDumpTruck form = new() + FormDumpTruck form = new() { SetTruck = truck }; form.ShowDialog(); } - + + /// + /// Добавление коллекции + /// + /// + /// + private void ButtonCollectionAdd_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } + + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + RefreshListBoxItems(); + } + + /// + /// Обновление списка в listBoxCollection + /// + private void RefreshListBoxItems() + { + listBoxCollection.Items.Clear(); + for (int i = 0; i < _storageCollection.Keys?.Count; ++i) + { + string? colName = _storageCollection.Keys?[i]; + if (!string.IsNullOrEmpty(colName)) + { + listBoxCollection.Items.Add(colName); + } + } + } + + /// + /// Удаление коллекции + /// + /// + /// + private void ButtonCollectionDel_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + if (MessageBox.Show("Вы уверены, что хотите удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RefreshListBoxItems(); + } + + /// + /// Создание компании + /// + /// + /// + private void ButtonCreteCompany_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + ICollectionGenericObject? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Autopark(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RefreshListBoxItems(); + } + } +