From a92b1f2828ca839a64fb3969a793d617d5962e5e Mon Sep 17 00:00:00 2001 From: Glliza Date: Tue, 16 Apr 2024 11:04:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 23 +++ .../ListGenericObjects.cs | 82 +++++++++ .../StorageCollection.cs | 79 ++++++++ .../FormBusCollection.Designer.cs | 170 +++++++++++++++--- .../ProjectAirbus/FormBusCollection.cs | 129 +++++++++++-- 5 files changed, 450 insertions(+), 33 deletions(-) create mode 100644 ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..1a560e8 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirbus.CollectionGenericObjects; + +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 +} diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..e554736 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirbus.CollectionGenericObjects; + +/// +///Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +internal 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 (position >= Count || position < 0) return null; + return _collection[position]; + } + + public int Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + + if (_collection.Count > _maxCount) + { + return -1; + } + _collection.Add(obj); + return _collection.Count; + } + + public int Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + + if (_collection.Count > _maxCount) + { + return -1; + } + if (position >= Count || position < 0) return -1; + _collection.Insert(position, obj); + return position; + } + + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + + if (position >= Count || position < 0) return null; + T obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } +} diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..cba52e9 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirbus.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 (_storages.ContainsKey(name)) + { + return; + } + if (collectionType == CollectionType.None) return; + else if (collectionType == CollectionType.Massive) + _storages[name] = new MassiveGenericObjects(); + else if (collectionType == CollectionType.List) + _storages[name] = new ListGenericObjects(); + } + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + if (_storages.ContainsKey(name)) + return _storages[name]; + return null; + } + } +} \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs index d9b43a1..1b8676d 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDell = 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(); buttonRemoveBus = new Button(); @@ -37,18 +46,18 @@ buttonAddBus = 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(buttonRemoveBus); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddAirbus); - groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(1081, 0); @@ -58,12 +67,104 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 392); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(188, 23); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDell); + 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, 19); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(194, 311); + panelStorage.TabIndex = 7; + // + // buttonCollectionDell + // + buttonCollectionDell.Location = new Point(3, 263); + buttonCollectionDell.Name = "buttonCollectionDell"; + buttonCollectionDell.Size = new Size(188, 23); + buttonCollectionDell.TabIndex = 6; + buttonCollectionDell.Text = "Удалить коллекцию"; + buttonCollectionDell.UseVisualStyleBackColor = true; + buttonCollectionDell.Click += buttonCollectionDell_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(3, 120); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(188, 124); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 91); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(188, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(119, 56); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(66, 19); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(19, 56); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(67, 19); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 18); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(188, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(38, 0); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(122, 15); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 544); + buttonRefresh.Location = new Point(6, 264); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(182, 43); + buttonRefresh.Size = new Size(176, 43); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +173,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 367); + buttonGoToCheck.Location = new Point(6, 215); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(182, 43); + buttonGoToCheck.Size = new Size(176, 43); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +184,9 @@ // buttonRemoveBus // buttonRemoveBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveBus.Location = new Point(6, 281); + buttonRemoveBus.Location = new Point(6, 166); buttonRemoveBus.Name = "buttonRemoveBus"; - buttonRemoveBus.Size = new Size(182, 43); + buttonRemoveBus.Size = new Size(176, 43); buttonRemoveBus.TabIndex = 4; buttonRemoveBus.Text = "Удалить аэробус"; buttonRemoveBus.UseVisualStyleBackColor = true; @@ -93,19 +194,19 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(6, 233); + maskedTextBoxPosition.Location = new Point(6, 122); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(182, 23); + maskedTextBoxPosition.Size = new Size(179, 23); maskedTextBoxPosition.TabIndex = 3; maskedTextBoxPosition.ValidatingType = typeof(int); // // buttonAddAirbus // buttonAddAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirbus.Location = new Point(6, 140); + buttonAddAirbus.Location = new Point(6, 56); buttonAddAirbus.Name = "buttonAddAirbus"; - buttonAddAirbus.Size = new Size(182, 43); + buttonAddAirbus.Size = new Size(176, 43); buttonAddAirbus.TabIndex = 2; buttonAddAirbus.Text = "Добавление аэробуса"; buttonAddAirbus.UseVisualStyleBackColor = true; @@ -114,9 +215,9 @@ // buttonAddBus // buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBus.Location = new Point(6, 91); + buttonAddBus.Location = new Point(6, 7); buttonAddBus.Name = "buttonAddBus"; - buttonAddBus.Size = new Size(182, 43); + buttonAddBus.Size = new Size(176, 43); buttonAddBus.TabIndex = 1; buttonAddBus.Text = "Добавление базового аэробуса"; buttonAddBus.UseVisualStyleBackColor = true; @@ -128,11 +229,11 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 38); + comboBoxSelectorCompany.Location = new Point(6, 348); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(182, 23); comboBoxSelectorCompany.TabIndex = 1; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // @@ -143,6 +244,20 @@ pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddBus); + panelCompanyTools.Controls.Add(buttonAddAirbus); + panelCompanyTools.Controls.Add(buttonRemoveBus); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Location = new Point(3, 452); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(194, 324); + panelCompanyTools.TabIndex = 8; + // // FormBusCollection // AutoScaleDimensions = new SizeF(7F, 15F); @@ -153,8 +268,11 @@ Name = "FormBusCollection"; 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 Label labelCollectionName; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCollectionAdd; + private ListBox listBoxCollection; + private Button buttonCreateCompany; + private Button buttonCollectionDell; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs index 14806a5..086d438 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs @@ -15,6 +15,11 @@ namespace ProjectAirbus public partial class FormBusCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -26,21 +31,12 @@ namespace ProjectAirbus public FormBusCollection() { 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 BusSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -100,6 +96,11 @@ namespace ProjectAirbus private void buttonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); + /// + /// Удаление объекта + /// + /// + /// private void buttonRemoveBus_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) @@ -123,6 +124,11 @@ namespace ProjectAirbus } } + /// + /// Передача объекта в другую форму + /// + /// + /// private void buttonGoToCheck_Click(object sender, EventArgs e) { if (_company == null) @@ -151,6 +157,11 @@ namespace ProjectAirbus form.ShowDialog(); } + /// + /// Перерисовка коллекции + /// + /// + /// private void buttonRefresh_Click(object sender, EventArgs e) { if (_company == null) @@ -159,5 +170,99 @@ namespace ProjectAirbus } 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(); + } + + /// + /// Обновление списка в 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 buttonCollectionDell_Click(object sender, EventArgs e) + { + // TODO прописать логику удаления элемента из коллекции + // нужно убедиться, что есть выбранная коллекция + // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + // удалить и обновить ListBox + + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + 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 BusSharingService(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } }