From e37875f510cae1a3a0449116c55d3fad1309a418 Mon Sep 17 00:00:00 2001 From: Ctepa Date: Mon, 18 Mar 2024 21:37:11 +0300 Subject: [PATCH] LabWork4 --- .../AbstractCompany.cs | 10 +- .../CollectionType.cs | 19 ++ .../GunSharingService.cs | 10 +- .../ICollectionGenericObjects.cs | 6 +- .../ListGenericObjects.cs | 67 ++++ .../MassiveGenericObjects.cs | 24 +- .../StorageCollection.cs | 73 +++++ .../FormGunCollections.Designer.cs | 290 +++++++++++++----- .../AntiAircraftGun/FormGunCollections.cs | 134 +++++++- 9 files changed, 513 insertions(+), 120 deletions(-) create mode 100644 AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs index 39cd4bf..548d8fd 100644 --- a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/AbstractCompany.cs @@ -49,19 +49,21 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningGun gun) + public static bool operator +(AbstractCompany company, DrawningGun gun) { - return company._collection.Insert(gun); + return company._collection?.Insert(gun) ?? false; } + /// /// Перегрузка оператора удаления для класса /// /// Компания /// Номер удаляемого объекта /// - public static DrawningGun? 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/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..f22d1ba --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,19 @@ +namespace AntiAircraftGun.CollectionGenericObjects; +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 +} diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs index 8ae8bd0..90f4428 100644 --- a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/GunSharingService.cs @@ -48,13 +48,15 @@ public class GunSharingService : AbstractCompany for (int j = 0; j < maxCountY; j++) { - for (int i = 0; i < maxCountX; i++) + for (int i = 0; i < maxCountX; i++) { currentIndex++; - if (_collection.Get(currentIndex) == null) continue; + if (_collection.Get(currentIndex) != null) + { - _collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight); - _collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight); + _collection.Get(currentIndex).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(currentIndex).SetPosition(boarderOffsetX + i * _placeSizeWidth + i * offsetX, boarderOffsetY + j * _placeSizeHeight); + } } } } diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs index 1823d76..95f7f2b 100644 --- a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -21,20 +21,20 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj); + bool Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию /// /// Добавляемый объект /// Позиция /// 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/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..d273c20 --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AntiAircraftGun.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/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs index 9968009..87d6c79 100644 --- a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/MassiveGenericObjects.cs @@ -44,46 +44,44 @@ internal class MassiveGenericObjects : ICollectionGenericObjects return null; 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; } diff --git a/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..d70083c --- /dev/null +++ b/AntiAircraftGun/AntiAircraftGun/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,73 @@ +namespace AntiAircraftGun.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/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs index 670dd83..5fb1598 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.Designer.cs @@ -29,98 +29,67 @@ private void InitializeComponent() { groupBox1 = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveGun = new Button(); - maskedTextBox = new MaskedTextBox(); - buttonAddAntiAircraftGun = new Button(); - buttonAddGun = new Button(); + panelCompanyTools = new Panel(); + buttonCreateCompany = new Button(); comboBoxSelectorCompany = new ComboBox(); + buttonAddGun = new Button(); + buttonRefresh = new Button(); + buttonAddAntiAircraftGun = new Button(); + buttonGoToCheck = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonRemoveGun = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + textBoxCollectionName = new TextBox(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + labelNameCollection = new Label(); pictureBox = new PictureBox(); groupBox1.SuspendLayout(); + panelCompanyTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBox1 // - groupBox1.Controls.Add(buttonRefresh); - groupBox1.Controls.Add(buttonGoToCheck); - groupBox1.Controls.Add(buttonRemoveGun); - groupBox1.Controls.Add(maskedTextBox); - groupBox1.Controls.Add(buttonAddAntiAircraftGun); - groupBox1.Controls.Add(buttonAddGun); - groupBox1.Controls.Add(comboBoxSelectorCompany); + groupBox1.Controls.Add(panelCompanyTools); + groupBox1.Controls.Add(panelStorage); groupBox1.Dock = DockStyle.Right; - groupBox1.Location = new Point(940, 0); + groupBox1.Location = new Point(981, 0); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(235, 669); + groupBox1.Size = new Size(235, 772); groupBox1.TabIndex = 0; groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; // - // buttonRefresh + // panelCompanyTools // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(32, 578); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(171, 70); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; + panelCompanyTools.Controls.Add(buttonCreateCompany); + panelCompanyTools.Controls.Add(comboBoxSelectorCompany); + panelCompanyTools.Controls.Add(buttonAddGun); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonAddAntiAircraftGun); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonRemoveGun); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Location = new Point(3, 395); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(229, 374); + panelCompanyTools.TabIndex = 9; // - // buttonGoToCheck + // buttonCreateCompany // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(32, 465); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(171, 70); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveGun - // - buttonRemoveGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveGun.Location = new Point(32, 364); - buttonRemoveGun.Name = "buttonRemoveGun"; - buttonRemoveGun.Size = new Size(171, 70); - buttonRemoveGun.TabIndex = 4; - buttonRemoveGun.Text = "Удалить установку"; - buttonRemoveGun.UseVisualStyleBackColor = true; - buttonRemoveGun.Click += ButtonRemoveGun_Click; - // - // maskedTextBox - // - maskedTextBox.Location = new Point(32, 292); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(171, 27); - maskedTextBox.TabIndex = 3; - maskedTextBox.ValidatingType = typeof(int); - // - // buttonAddAntiAircraftGun - // - buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAntiAircraftGun.Location = new Point(33, 191); - buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun"; - buttonAddAntiAircraftGun.Size = new Size(171, 70); - buttonAddAntiAircraftGun.TabIndex = 2; - buttonAddAntiAircraftGun.Text = "Добавление зенитной установки"; - buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; - buttonAddAntiAircraftGun.Click += ButtonAddAntiAircraftGun_Click; - // - // buttonAddGun - // - buttonAddGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddGun.Location = new Point(32, 106); - buttonAddGun.Name = "buttonAddGun"; - buttonAddGun.Size = new Size(171, 70); - buttonAddGun.TabIndex = 1; - buttonAddGun.Text = "Добавление установки"; - buttonAddGun.UseVisualStyleBackColor = true; - buttonAddGun.Click += ButtonAddGun_Click; + buttonCreateCompany.Location = new Point(9, 40); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(217, 29); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; // // comboBoxSelectorCompany // @@ -128,18 +97,164 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "База" }); - comboBoxSelectorCompany.Location = new Point(33, 43); + comboBoxSelectorCompany.Location = new Point(9, 6); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(171, 28); + comboBoxSelectorCompany.Size = new Size(214, 28); comboBoxSelectorCompany.TabIndex = 0; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // buttonAddGun + // + buttonAddGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddGun.Location = new Point(9, 87); + buttonAddGun.Name = "buttonAddGun"; + buttonAddGun.Size = new Size(214, 52); + buttonAddGun.TabIndex = 1; + buttonAddGun.Text = "Добавление установки"; + buttonAddGun.UseVisualStyleBackColor = true; + buttonAddGun.Click += ButtonAddGun_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(9, 313); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(214, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonAddAntiAircraftGun + // + buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAntiAircraftGun.Location = new Point(9, 145); + buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun"; + buttonAddAntiAircraftGun.Size = new Size(214, 52); + buttonAddAntiAircraftGun.TabIndex = 2; + buttonAddAntiAircraftGun.Text = "Добавление зенитной установки"; + buttonAddAntiAircraftGun.UseVisualStyleBackColor = true; + buttonAddAntiAircraftGun.Click += ButtonAddAntiAircraftGun_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(9, 274); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(214, 33); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(9, 203); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(217, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonRemoveGun + // + buttonRemoveGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveGun.Location = new Point(9, 236); + buttonRemoveGun.Name = "buttonRemoveGun"; + buttonRemoveGun.Size = new Size(214, 32); + buttonRemoveGun.TabIndex = 4; + buttonRemoveGun.Text = "Удалить установку"; + buttonRemoveGun.UseVisualStyleBackColor = true; + buttonRemoveGun.Click += ButtonRemoveGun_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(labelNameCollection); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(229, 366); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(9, 326); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(217, 29); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 20; + listBoxCollection.Location = new Point(9, 164); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(217, 144); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(9, 120); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(217, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добаваить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(9, 41); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(217, 27); + textBoxCollectionName.TabIndex = 3; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(146, 74); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(80, 24); + radioButtonList.TabIndex = 2; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(9, 74); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(82, 24); + radioButtonMassive.TabIndex = 1; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // labelNameCollection + // + labelNameCollection.AutoSize = true; + labelNameCollection.Location = new Point(41, 11); + labelNameCollection.Name = "labelNameCollection"; + labelNameCollection.Size = new Size(155, 20); + labelNameCollection.TabIndex = 0; + labelNameCollection.Text = "Название коллекции"; // // pictureBox // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(940, 669); + pictureBox.Size = new Size(981, 772); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -147,13 +262,16 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1175, 669); + ClientSize = new Size(1216, 772); Controls.Add(pictureBox); Controls.Add(groupBox1); Name = "FormGunCollections"; Text = "Коллекция установок"; groupBox1.ResumeLayout(false); - groupBox1.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -169,5 +287,15 @@ private Button buttonRemoveGun; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private TextBox textBoxCollectionName; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private Label labelNameCollection; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs index df0e401..02cf27f 100644 --- a/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs +++ b/AntiAircraftGun/AntiAircraftGun/FormGunCollections.cs @@ -5,8 +5,10 @@ namespace AntiAircraftGun; public partial class FormGunCollections : Form { + + private readonly StorageCollection _storageCollection; /// - /// + /// Компания /// private AbstractCompany? _company = null; /// @@ -15,20 +17,16 @@ public partial class FormGunCollections : Form public FormGunCollections() { InitializeComponent(); + _storageCollection = new(); } /// /// /// /// /// - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "База": - _company = new GunSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = true; } /// /// Создание объекта класса перемещения @@ -61,7 +59,7 @@ public partial class FormGunCollections : Form default: return; } - if (_company + _drawningGun!=-1) + if (_company + _drawningGun) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -83,17 +81,29 @@ public partial class FormGunCollections : Form if (dialog.ShowDialog() == DialogResult.OK) { color = dialog.Color; } return color; } - + /// + /// Добавление установки + /// + /// + /// private void ButtonAddGun_Click(object sender, EventArgs e) { CreateObj(nameof(DrawningGun)); } - + /// + /// Добавление зенитной устновки + /// + /// + /// private void ButtonAddAntiAircraftGun_Click(object sender, EventArgs e) { CreateObj(nameof(DrawningAntiAircraftGun)); } - + /// + /// Удаление установки + /// + /// + /// private void ButtonRemoveGun_Click(object sender, EventArgs e) { if (_company == null) @@ -106,7 +116,7 @@ public partial class FormGunCollections : Form } if (MessageBox.Show("Удалить объект", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos is DrawningGun) + if (_company - pos) { MessageBox.Show("Объект удален"); pictureBox.Image = _company.Show(); @@ -117,7 +127,11 @@ public partial class FormGunCollections : Form } } - + /// + /// Передача объекта на тесты + /// + /// + /// private void ButtonGoToCheck_Click(object sender, EventArgs e) { if (_company == null) @@ -148,7 +162,11 @@ public partial class FormGunCollections : Form form.ShowDialog(); } - + /// + /// Обновление экрана + /// + /// + /// private void ButtonRefresh_Click(object sender, EventArgs e) { if (_company == null) @@ -157,4 +175,90 @@ public partial class FormGunCollections : 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.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 GunSharingService(pictureBox.Width, + pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + 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); + } + } + } }