diff --git a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs index 9deb6a9..06e2e1d 100644 --- a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/AbstractCompany.cs @@ -62,9 +62,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningCruiser cruiser) + public static bool operator +(AbstractCompany company, DrawningCruiser cruiser) { - return company._collection.Insert(cruiser); + return company._collection?.Insert(cruiser) ?? false; } /// @@ -73,9 +73,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static DrawningCruiser? operator -(AbstractCompany company, int position) + public static bool operator -(AbstractCompany company, int position) { - return company._collection.Remove(position); + return company._collection?.Remove(position) ?? false; } /// diff --git a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/CollectionType.cs b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..0dea850 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCruiser.CollectionGenericObjects; + +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs index b5ea1f2..b8e38ce 100644 --- a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -27,7 +27,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj); + bool Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -35,14 +35,14 @@ public interface ICollectionGenericObjects /// Добавляемый объект /// Позиция /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj, int position); + bool Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - T? Remove(int position); + bool Remove(int position); /// /// Получение объекта по позиции diff --git a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ListGenericObjects.cs b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..ee170b9 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCruiser.CollectionGenericObjects; + +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class ListGenericObjects : 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 ListGenericObjects() + { + _collection = new(); + } + public T? Get(int position) + { + // TODO проверка позиции + if (!_collection.Any()) { return null; } + if (_collection.Count <= position || position < 0 || position >= _maxCount) { return null; } + return _collection[position]; + } + public bool Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + if (_collection.Count >= _maxCount) return false; + _collection.Add(obj); + return true; + } + public bool Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if (_collection.Count >= _maxCount || _collection[position] == null || position < 0) { return false; } + _collection.Insert(position, obj); + return true; + } + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + if (_collection[position] == null) + { + return false; + } + _collection.RemoveAt(position); + return true; + } +} diff --git a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs index cf2ae55..0372d8f 100644 --- a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/MassiveGenericObjects.cs @@ -52,48 +52,46 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) + public bool Insert(T obj) { // TODO вставка в свободное место набора for (int i = 0; i < Count; i++) { - if (InsertingElementCollection(i, obj)) return i; + if (InsertingElementCollection(i, obj)) return true; } - return -1; + return false; } - public int Insert(T obj, int position) + public bool Insert(T obj, int position) { // TODO проверка позиции // TODO проверка, что элемент массива по этой позиции пустой, если нет, то // ищется свободное место после этой позиции и идет вставка туда // если нет после, ищем до // TODO вставка - if (InsertingElementCollection(position, obj)) return position; + if (InsertingElementCollection(position, obj)) return true; for (int i = position + 1; i < Count; i++) { - if (InsertingElementCollection(i, obj)) return position; + if (InsertingElementCollection(i, obj)) return true; } for (int i = position - 1; i >= 0; i--) { - if (InsertingElementCollection(i, obj)) return position; + if (InsertingElementCollection(i, obj)) return true; } - return -1; + return false; } - public T? Remove(int position) + public bool Remove(int position) { // TODO проверка позиции // TODO удаление объекта из массива, присвоив элементу массива значение null - if (_collection[position] == null) return null; - - T? temp = _collection[position]; + if (_collection[position] == null) return false; _collection[position] = null; - return temp; + return true; } private bool InsertingElementCollection(int index, T obj) diff --git a/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/StorageCollection.cs b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..a624f56 --- /dev/null +++ b/ProjectCruiser/ProjectCruiser/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCruiser.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) + { + // TODO проверка, что name не пустой и нет в словаре записи с таким ключом + // TODO Прописать логику для добавления + if (name.Length <= 0 || _storages.ContainsKey(name)) + { + return; + } + switch (collectionType) + { + case CollectionType.List: + _storages.Add(name, new ListGenericObjects()); + break; + case CollectionType.Massive: + _storages.Add(name, new MassiveGenericObjects()); + break; + default: + return; + } + } + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + if (!_storages.ContainsKey(name)) { return; } + _storages.Remove(name); + } + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + if (!_storages.ContainsKey(name)) { return null; } + return _storages[name]; + } + } +} diff --git a/ProjectCruiser/ProjectCruiser/FormCruiserCollection.Designer.cs b/ProjectCruiser/ProjectCruiser/FormCruiserCollection.Designer.cs index 8054444..e9affd0 100644 --- a/ProjectCruiser/ProjectCruiser/FormCruiserCollection.Designer.cs +++ b/ProjectCruiser/ProjectCruiser/FormCruiserCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + 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(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); buttonRemoveCruiser = new Button(); @@ -37,33 +46,124 @@ buttonAddCruiser = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); + panelCompanyTools = new Panel(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveCruiser); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddMilitaryCruiser); - groupBoxTools.Controls.Add(buttonAddCruiser); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(821, 0); + groupBoxTools.Location = new Point(890, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(250, 602); + groupBoxTools.Size = new Size(250, 728); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(12, 396); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(232, 29); + 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, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(244, 333); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(9, 296); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(226, 29); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.Location = new Point(9, 186); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(226, 104); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(9, 144); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(226, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(140, 103); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(80, 24); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(22, 103); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(82, 24); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(9, 51); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(226, 27); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(41, 10); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(158, 20); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 446); + buttonRefresh.Location = new Point(9, 234); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(232, 40); + buttonRefresh.Size = new Size(226, 40); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +172,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 363); + buttonGoToCheck.Location = new Point(9, 188); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(232, 40); + buttonGoToCheck.Size = new Size(226, 40); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать не тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +183,9 @@ // buttonRemoveCruiser // buttonRemoveCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveCruiser.Location = new Point(6, 267); + buttonRemoveCruiser.Location = new Point(9, 142); buttonRemoveCruiser.Name = "buttonRemoveCruiser"; - buttonRemoveCruiser.Size = new Size(232, 40); + buttonRemoveCruiser.Size = new Size(226, 40); buttonRemoveCruiser.TabIndex = 4; buttonRemoveCruiser.Text = "Удаление крейсера"; buttonRemoveCruiser.UseVisualStyleBackColor = true; @@ -93,7 +193,7 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(6, 234); + maskedTextBoxPosition.Location = new Point(9, 109); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(232, 27); @@ -103,9 +203,9 @@ // buttonAddMilitaryCruiser // buttonAddMilitaryCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddMilitaryCruiser.Location = new Point(6, 142); + buttonAddMilitaryCruiser.Location = new Point(9, 49); buttonAddMilitaryCruiser.Name = "buttonAddMilitaryCruiser"; - buttonAddMilitaryCruiser.Size = new Size(232, 54); + buttonAddMilitaryCruiser.Size = new Size(226, 54); buttonAddMilitaryCruiser.TabIndex = 2; buttonAddMilitaryCruiser.Text = "Добавление военного крейсера"; buttonAddMilitaryCruiser.UseVisualStyleBackColor = true; @@ -114,9 +214,9 @@ // buttonAddCruiser // buttonAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddCruiser.Location = new Point(6, 96); + buttonAddCruiser.Location = new Point(9, 3); buttonAddCruiser.Name = "buttonAddCruiser"; - buttonAddCruiser.Size = new Size(232, 40); + buttonAddCruiser.Size = new Size(226, 40); buttonAddCruiser.TabIndex = 1; buttonAddCruiser.Text = "Добавление крейсера"; buttonAddCruiser.UseVisualStyleBackColor = true; @@ -128,7 +228,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 26); + comboBoxSelectorCompany.Location = new Point(12, 362); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(232, 28); comboBoxSelectorCompany.TabIndex = 0; @@ -139,22 +239,40 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(821, 602); + pictureBox.Size = new Size(890, 728); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddCruiser); + panelCompanyTools.Controls.Add(buttonAddMilitaryCruiser); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveCruiser); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 431); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(244, 294); + panelCompanyTools.TabIndex = 9; + // // FormCruiserCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1071, 602); + ClientSize = new Size(1140, 728); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormCruiserCollection"; Text = "Коллекция Крейсеров"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -169,5 +287,15 @@ private PictureBox pictureBox; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectCruiser/ProjectCruiser/FormCruiserCollection.cs b/ProjectCruiser/ProjectCruiser/FormCruiserCollection.cs index 4c8f4e1..bf729e3 100644 --- a/ProjectCruiser/ProjectCruiser/FormCruiserCollection.cs +++ b/ProjectCruiser/ProjectCruiser/FormCruiserCollection.cs @@ -14,6 +14,7 @@ namespace ProjectCruiser; public partial class FormCruiserCollection : Form { + private readonly StorageCollection _storageCollection; /// /// Компания @@ -24,16 +25,12 @@ public partial class FormCruiserCollection : Form public FormCruiserCollection() { InitializeComponent(); + _storageCollection = new(); } private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new CruiserSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = true; } @@ -45,21 +42,21 @@ public partial class FormCruiserCollection : Form return; } - Random random = new(); DrawningCruiser drawningCruiser; + Random random = new(); switch (type) { case nameof(DrawningCruiser): - drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + drawningCruiser = new DrawningCruiser(random.Next(100, 300), random.Next(1000, 3000), SetColor(random)); break; case nameof(DrawningMilitaryCruiser): drawningCruiser = new DrawningMilitaryCruiser(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + SetColor(random), + SetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); @@ -69,7 +66,7 @@ public partial class FormCruiserCollection : Form default: return; } - if (_company + drawningCruiser != -1) + if (_company + drawningCruiser) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -85,7 +82,7 @@ public partial class FormCruiserCollection : Form /// /// Генератор случайных чисел /// - private static Color GetColor(Random random) + private static Color SetColor(Random random) { Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); ColorDialog dialog = new(); @@ -103,18 +100,17 @@ public partial class FormCruiserCollection : Form private void ButtonRemoveCruiser_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + if (_company == null) { return; } - - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; } - + if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos is DrawningCruiser) + if (_company - pos) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show(); @@ -162,7 +158,76 @@ public partial class FormCruiserCollection : Form { return; } - 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.SelectedItem == null || listBoxCollection.SelectedIndex < 0) + { + MessageBox.Show("Коллекция для удаления не выбрана"); + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + + 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 CruiserSharingService(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } + + 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); + } + } + } }