diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs index 4bedf0b..377357a 100644 --- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/AbstractCompany.cs @@ -59,7 +59,7 @@ public abstract class AbstractCompany /// public static int operator +(AbstractCompany company, DrawningWarship warship) { - return company._collection.Insert(warship); + return company._collection.Insert(warship, 0); } /// diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/CollectionType.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..2110f55 --- /dev/null +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,22 @@ +namespace ProjectAircraftCarrier_.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs index c242008..d193837 100644 --- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -21,7 +21,7 @@ public interface ICollectionGenericObjects /// Добавление объекта в коллекцию /// /// Добавляемый объект - /// true - вставка прошла удачно, false - вставка не удалась + /// индекс добавленного элемента - вставка прошла удачно, -1 - вставка не удалась int Insert(T obj); /// @@ -29,14 +29,14 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// Позиция - /// true - вставка прошла удачно, false - вставка не удалась + /// индекс добавленного элемента - вставка прошла удачно, -1 - вставка не удалась int Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция - /// true - удаление прошло удачно, false - удаление не удалось + /// удаленный объект - удаление прошло удачно, null - удаление не удалось T? Remove(int position); /// diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ListGenericObject.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ListGenericObject.cs new file mode 100644 index 0000000..565ec2d --- /dev/null +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/ListGenericObject.cs @@ -0,0 +1,78 @@ +using System.CodeDom.Compiler; + +namespace ProjectAircraftCarrier_.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class ListGenericObject : ICollectionGenericObjects + 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 ListGenericObject() + { + _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/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs index a3c5478..851a207 100644 --- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/MassiveGenericObjects.cs @@ -14,7 +14,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects 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]; + } + } + } + } /// /// Конструктор @@ -26,8 +42,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - // TODO проверка позиции - if (position < 0 || position > Count) + if (position < 0 || position >= Count) { return null; } @@ -36,7 +51,6 @@ public class MassiveGenericObjects : ICollectionGenericObjects public int Insert(T obj) { - // TODO вставка в свободное место набора for (int i = 0; i < Count; i++) { if (_collection[i] == null) @@ -50,12 +64,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public int Insert(T obj, int position) { - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до - // TODO вставка - if (position < 0 || position > Count) + if (position < 0 || position >= Count) { return -1; } @@ -71,7 +80,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return position; + return i; } } @@ -80,7 +89,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return position; + return i; } } @@ -89,9 +98,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - if (position < 0 || position > Count || _collection[position] == null) + if (position < 0 || position >= Count || _collection[position] == null) { return null; } diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/StorageCollection.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..e49e591 --- /dev/null +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,86 @@ +using ProjectAircraftCarrier_.Drawnings; +using ProjectAircraftCarrier_.CollectionGenericObjects; +using System.Xml.Linq; + +namespace ProjectAircraftCarrier_.CollectionGenericObjects; + +/// +/// Класс-хранилище коллекций +/// +/// +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 ListGenericObject()); + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if (name == null || !_storages.ContainsKey(name)) + { + return; + } + + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (_storages.ContainsKey(name)) + { + return _storages[name]; + } + + return null; + } + } +} \ No newline at end of file diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs index f3ba626..c977f39 100644 --- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.Designer.cs @@ -29,81 +29,63 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveWarship = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); + panelCompanyTools = new Panel(); buttonAddAircraftCarrier = new Button(); buttonAddWarship = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonRemoveWarship = new Button(); + buttonGoToCheck = new Button(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveWarship); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddAircraftCarrier); - groupBoxTools.Controls.Add(buttonAddWarship); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(1126, 0); + groupBoxTools.Location = new Point(1176, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(326, 912); + groupBoxTools.Size = new Size(326, 961); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonRefresh + // panelCompanyTools // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 767); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(314, 72); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 595); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(314, 72); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveWarship - // - buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveWarship.Location = new Point(6, 432); - buttonRemoveWarship.Name = "buttonRemoveWarship"; - buttonRemoveWarship.Size = new Size(314, 72); - buttonRemoveWarship.TabIndex = 4; - buttonRemoveWarship.Text = "Удаление военного корабля"; - buttonRemoveWarship.UseVisualStyleBackColor = true; - buttonRemoveWarship.Click += ButtonRemoveWarship_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Location = new Point(6, 391); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(314, 35); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); + panelCompanyTools.Controls.Add(buttonAddAircraftCarrier); + panelCompanyTools.Controls.Add(buttonAddWarship); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveWarship); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 529); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(320, 429); + panelCompanyTools.TabIndex = 9; // // buttonAddAircraftCarrier // buttonAddAircraftCarrier.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAircraftCarrier.Location = new Point(6, 232); + buttonAddAircraftCarrier.Location = new Point(3, 81); buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier"; buttonAddAircraftCarrier.Size = new Size(314, 72); buttonAddAircraftCarrier.TabIndex = 2; @@ -114,7 +96,7 @@ // buttonAddWarship // buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddWarship.Location = new Point(6, 154); + buttonAddWarship.Location = new Point(3, 3); buttonAddWarship.Name = "buttonAddWarship"; buttonAddWarship.Size = new Size(314, 72); buttonAddWarship.TabIndex = 1; @@ -122,13 +104,147 @@ buttonAddWarship.UseVisualStyleBackColor = true; buttonAddWarship.Click += ButtonAddWarship_Click; // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(3, 159); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(314, 35); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(3, 356); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(314, 72); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonRemoveWarship + // + buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveWarship.Location = new Point(3, 200); + buttonRemoveWarship.Name = "buttonRemoveWarship"; + buttonRemoveWarship.Size = new Size(314, 72); + buttonRemoveWarship.TabIndex = 4; + buttonRemoveWarship.Text = "Удаление военного корабля"; + buttonRemoveWarship.UseVisualStyleBackColor = true; + buttonRemoveWarship.Click += ButtonRemoveWarship_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(3, 278); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(314, 72); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 472); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(314, 40); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // 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(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 31); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(320, 382); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 331); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(314, 40); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 30; + listBoxCollection.Location = new Point(3, 171); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(314, 154); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 125); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(314, 40); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(193, 85); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(107, 34); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(23, 85); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(111, 34); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 44); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(314, 35); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(58, 11); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(213, 30); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции"; + // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 34); + comboBoxSelectorCompany.Location = new Point(6, 428); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(314, 38); comboBoxSelectorCompany.TabIndex = 0; @@ -139,7 +255,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1126, 912); + pictureBox.Size = new Size(1176, 961); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -147,13 +263,16 @@ // AutoScaleDimensions = new SizeF(12F, 30F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1452, 912); + ClientSize = new Size(1502, 961); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormWarshipCollection"; Text = "Коллекция военных кораблей"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -169,5 +288,15 @@ private Button buttonGoToCheck; private Button buttonRemoveWarship; private MaskedTextBox maskedTextBoxPosition; + private Panel panelStorage; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs index 577429a..7d45fa5 100644 --- a/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs +++ b/ProjectAircraftCarrier_/ProjectAircraftCarrier_/FormWarshipCollection.cs @@ -8,6 +8,11 @@ namespace ProjectAircraftCarrier_; /// public partial class FormWarshipCollection : Form { + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -19,6 +24,7 @@ public partial class FormWarshipCollection : Form public FormWarshipCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -28,12 +34,7 @@ public partial class FormWarshipCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Docks(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -55,8 +56,7 @@ public partial class FormWarshipCollection : Form drawningWarship = new DrawningWarship(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningAircraftCarrier): - // TODO вызов диалогового окна для выбора цвета - drawningWarship = new DrawningAircraftCarrier(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), + drawningWarship = new DrawningAircraftCarrier(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -117,7 +117,7 @@ public partial class FormWarshipCollection : Form return; } - if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } @@ -184,4 +184,98 @@ public partial class FormWarshipCollection : Form pictureBox.Image = _company.Show(); } + + /// + /// Добавление коллекции + /// + /// + /// + 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); + RerfreshListBoxItems(); + } + + /// + /// Удаление коллекции + /// + /// + /// + 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()); + RerfreshListBoxItems(); + } + + /// + /// Обновление списка в listBoxCollection + /// + private void RerfreshListBoxItems() + { + 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 ButtonCreateCompany_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Docks(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } }