From 87c20a458730a126f7436810d5129f6354638645 Mon Sep 17 00:00:00 2001 From: Vladislav_396ntk Date: Sun, 5 May 2024 22:32:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B5=D1=82=D0=B2=D0=B5=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 26 ++ .../ListGenericObjects.cs | 73 ++++++ .../LocomotiveStation.cs | 4 +- .../StorageCollection.cs | 86 +++++++ .../parameterizedClass.cs | 15 -- .../LocomotiveProjectCollection.Designer.cs | 237 ++++++++++++++---- .../LocomotiveProjectCollection.cs | 135 ++++++++-- ...r.cs => LocomotiveProjectForm.Designer.cs} | 4 +- ...iveProject.cs => LocomotiveProjectForm.cs} | 4 +- ...roject.resx => LocomotiveProjectForm.resx} | 0 .../LocomativeProject/Program.cs | 2 + 11 files changed, 488 insertions(+), 98 deletions(-) create mode 100644 LocomativeProject/LocomativeProject/CollectionGenericObjects/CollectionType.cs create mode 100644 LocomativeProject/LocomativeProject/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 LocomativeProject/LocomativeProject/CollectionGenericObjects/StorageCollection.cs delete mode 100644 LocomativeProject/LocomativeProject/CollectionGenericObjects/parameterizedClass.cs rename LocomativeProject/LocomativeProject/{LocomotiveProject.Designer.cs => LocomotiveProjectForm.Designer.cs} (99%) rename LocomativeProject/LocomativeProject/{LocomotiveProject.cs => LocomotiveProjectForm.cs} (98%) rename LocomativeProject/LocomativeProject/{LocomotiveProject.resx => LocomotiveProjectForm.resx} (100%) diff --git a/LocomativeProject/LocomativeProject/CollectionGenericObjects/CollectionType.cs b/LocomativeProject/LocomativeProject/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..cac2e5f --- /dev/null +++ b/LocomativeProject/LocomativeProject/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LocomotiveProject.CollectionGenericObjects; +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 + +} diff --git a/LocomativeProject/LocomativeProject/CollectionGenericObjects/ListGenericObjects.cs b/LocomativeProject/LocomativeProject/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..83bc607 --- /dev/null +++ b/LocomativeProject/LocomativeProject/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LocomotiveProject.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 int Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + if (_collection.Count >= _maxCount) return -1; + _collection.Add(obj); + return Count; + } + + public int Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if (_collection.Count >= _maxCount || _collection[position] == null || position < 0) { return -1; } + _collection.Insert(position, obj); + return Count; + } + + 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 T? Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + if (position >= Count || position < 0) return null; + T obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } +} \ No newline at end of file diff --git a/LocomativeProject/LocomativeProject/CollectionGenericObjects/LocomotiveStation.cs b/LocomativeProject/LocomativeProject/CollectionGenericObjects/LocomotiveStation.cs index 51d344b..97746b4 100644 --- a/LocomativeProject/LocomativeProject/CollectionGenericObjects/LocomotiveStation.cs +++ b/LocomativeProject/LocomativeProject/CollectionGenericObjects/LocomotiveStation.cs @@ -8,9 +8,9 @@ using System.Threading.Tasks; namespace LocomotiveProject.CollectionGenericObjects; -public class LocomotiveDock : AbstractCompany +public class LocomotiveStation : AbstractCompany { - public LocomotiveDock(int picWidth, int pictureHeight, ICollectionGenericObjects collection) : base(picWidth, pictureHeight, collection) + public LocomotiveStation(int picWidth, int pictureHeight, ICollectionGenericObjects collection) : base(picWidth, pictureHeight, collection) { } diff --git a/LocomativeProject/LocomativeProject/CollectionGenericObjects/StorageCollection.cs b/LocomativeProject/LocomativeProject/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..e3f5964 --- /dev/null +++ b/LocomativeProject/LocomativeProject/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LocomotiveProject.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/LocomativeProject/LocomativeProject/CollectionGenericObjects/parameterizedClass.cs b/LocomativeProject/LocomativeProject/CollectionGenericObjects/parameterizedClass.cs deleted file mode 100644 index 0c30b28..0000000 --- a/LocomativeProject/LocomativeProject/CollectionGenericObjects/parameterizedClass.cs +++ /dev/null @@ -1,15 +0,0 @@ -using LocomotiveProject.Drawnings; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace LocomotiveProject.CollectionGenericObjects -{ - /// - /// Параметризованный класс - /// - /// - public class parameterizedClass where T : DrawningLocomotive { } -} diff --git a/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.Designer.cs b/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.Designer.cs index 3e96b1a..3f82068 100644 --- a/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.Designer.cs +++ b/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.Designer.cs @@ -1,4 +1,4 @@ -namespace LocomotiveProject +namespace LocomativeProject { partial class LocomotiveProjectCollection { @@ -29,26 +29,35 @@ private void InitializeComponent() { groupBox1 = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveLocomotive = new Button(); - maskedTextBox = new MaskedTextBox(); + panelCompany = new Panel(); buttonModifLocomotive = new Button(); buttonAddLocomotive = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonRemoveLocomotive = 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(); groupBox1.SuspendLayout(); + panelCompany.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBox1 // - groupBox1.Controls.Add(buttonRefresh); - groupBox1.Controls.Add(buttonGoToCheck); - groupBox1.Controls.Add(buttonRemoveLocomotive); - groupBox1.Controls.Add(maskedTextBox); - groupBox1.Controls.Add(buttonModifLocomotive); - groupBox1.Controls.Add(buttonAddLocomotive); + groupBox1.Controls.Add(panelCompany); + groupBox1.Controls.Add(buttonCreateCompany); + groupBox1.Controls.Add(panelStorage); groupBox1.Controls.Add(comboBoxSelectorCompany); groupBox1.Dock = DockStyle.Right; groupBox1.Location = new Point(912, 0); @@ -58,48 +67,24 @@ groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; // - // buttonRefresh + // panelCompany // - buttonRefresh.Location = new Point(32, 530); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(124, 39); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Location = new Point(32, 349); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(124, 39); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveLocomotive - // - buttonRemoveLocomotive.Location = new Point(18, 207); - buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; - buttonRemoveLocomotive.Size = new Size(150, 23); - buttonRemoveLocomotive.TabIndex = 4; - buttonRemoveLocomotive.Text = "Удалить поезд"; - buttonRemoveLocomotive.UseVisualStyleBackColor = true; - buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click; - // - // maskedTextBox - // - maskedTextBox.Location = new Point(18, 178); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(150, 23); - maskedTextBox.TabIndex = 3; - maskedTextBox.ValidatingType = typeof(int); + panelCompany.Controls.Add(buttonModifLocomotive); + panelCompany.Controls.Add(buttonAddLocomotive); + panelCompany.Controls.Add(maskedTextBox); + panelCompany.Controls.Add(buttonRefresh); + panelCompany.Controls.Add(buttonRemoveLocomotive); + panelCompany.Controls.Add(buttonGoToCheck); + panelCompany.Dock = DockStyle.Bottom; + panelCompany.Enabled = false; + panelCompany.Location = new Point(3, 346); + panelCompany.Name = "panelCompany"; + panelCompany.Size = new Size(174, 232); + panelCompany.TabIndex = 9; // // buttonModifLocomotive // - buttonModifLocomotive.Location = new Point(18, 102); + buttonModifLocomotive.Location = new Point(15, 38); buttonModifLocomotive.Name = "buttonModifLocomotive"; buttonModifLocomotive.Size = new Size(150, 43); buttonModifLocomotive.TabIndex = 2; @@ -110,21 +95,152 @@ // buttonAddLocomotive // buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddLocomotive.Location = new Point(18, 62); + buttonAddLocomotive.Location = new Point(15, 6); buttonAddLocomotive.Name = "buttonAddLocomotive"; - buttonAddLocomotive.Size = new Size(150, 23); + buttonAddLocomotive.Size = new Size(150, 26); buttonAddLocomotive.TabIndex = 1; buttonAddLocomotive.Text = "Добавление поезда"; buttonAddLocomotive.UseVisualStyleBackColor = true; buttonAddLocomotive.Click += ButtonAddLocomotive_Click; // + // maskedTextBox + // + maskedTextBox.Location = new Point(15, 87); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(150, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(27, 190); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(124, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonRemoveLocomotive + // + buttonRemoveLocomotive.Location = new Point(15, 116); + buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; + buttonRemoveLocomotive.Size = new Size(150, 23); + buttonRemoveLocomotive.TabIndex = 4; + buttonRemoveLocomotive.Text = "Удалить поезд"; + buttonRemoveLocomotive.UseVisualStyleBackColor = true; + buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(29, 145); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(124, 39); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(18, 320); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(150, 23); + 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, 19); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(174, 266); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(15, 218); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(150, 23); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(15, 118); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(150, 94); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(15, 89); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(150, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(99, 64); + 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(15, 64); + 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(15, 35); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(150, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(29, 17); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(122, 15); + 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(18, 22); + comboBoxSelectorCompany.Location = new Point(18, 291); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(150, 23); comboBoxSelectorCompany.TabIndex = 0; @@ -147,9 +263,12 @@ Controls.Add(pictureBox); Controls.Add(groupBox1); Name = "LocomotiveProjectCollection"; - Text = "Коллекция Тепловозов"; + Text = "Коллекция Крейсеров"; groupBox1.ResumeLayout(false); - groupBox1.PerformLayout(); + panelCompany.ResumeLayout(false); + panelCompany.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -165,5 +284,15 @@ private PictureBox pictureBox; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private RadioButton radioButtonMassive; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private Button buttonCreateCompany; + private Panel panelCompany; } } \ No newline at end of file diff --git a/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.cs b/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.cs index dd59e46..01d612b 100644 --- a/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.cs +++ b/LocomativeProject/LocomativeProject/LocomotiveProjectCollection.cs @@ -1,4 +1,5 @@ using LocomativeProject.Drawnings; +using LocomotiveProject; using LocomotiveProject.CollectionGenericObjects; using LocomotiveProject.Drawnings; using System; @@ -11,9 +12,14 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace LocomotiveProject; +namespace LocomativeProject; + public partial class LocomotiveProjectCollection : Form { + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; /// /// Компания /// @@ -24,6 +30,7 @@ public partial class LocomotiveProjectCollection : Form public LocomotiveProjectCollection() { InitializeComponent(); + _storageCollection = new(); } /// /// Выбор компании @@ -32,12 +39,7 @@ public partial class LocomotiveProjectCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new LocomotiveDock(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompany.Enabled = false; } /// /// Создание объекта класса-перемещения @@ -50,24 +52,23 @@ public partial class LocomotiveProjectCollection : Form return; } Random rnd = new(); - DrawningBaseLocomotive drawningBaseLocomotive; + DrawningBaseLocomotive DrawningBaseLocomotive; switch (type) { case nameof(DrawningBaseLocomotive): - drawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd)); + DrawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd)); break; case nameof(DrawningLocomotive): - drawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd), + DrawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2))); break; default: return; } - if (_company + drawningBaseLocomotive != -1) + if (_company + DrawningBaseLocomotive != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); - } else { @@ -90,19 +91,19 @@ public partial class LocomotiveProjectCollection : Form return color; } /// - /// Кнопка создания обычного поезда + /// Кнопка создания обычного крейсера /// /// /// private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseLocomotive)); /// - /// Кнопка создания модиф поезда + /// Кнопка создания модиф крейсера /// /// /// private void ButtonModifLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive)); /// - /// Кнопка удаления поезда + /// Кнопка удаления Крейсера /// /// /// @@ -142,11 +143,11 @@ public partial class LocomotiveProjectCollection : Form { return; } - DrawningBaseLocomotive BaseLocomotive = null; + DrawningBaseLocomotive baseLocomotive = null; int counter = 100; - while (BaseLocomotive == null) + while (baseLocomotive == null) { - BaseLocomotive = _company.GetRandomObject(); + baseLocomotive = _company.GetRandomObject(); counter--; if (counter <= 0) { @@ -154,14 +155,14 @@ public partial class LocomotiveProjectCollection : Form } } - if (BaseLocomotive == null) + if (baseLocomotive == null) { return; } - LocomotiveProject form = new() { SetLocomotive = BaseLocomotive }; + LocomotiveProjectForm form = new() { SetLocomotive = baseLocomotive }; form.ShowDialog(); - + } /// /// Кнопка обновления компании @@ -170,10 +171,98 @@ public partial class LocomotiveProjectCollection : Form /// private void ButtonRefresh_Click(object sender, EventArgs e) { - if (_company == null) + if (_company != null) + 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; } - pictureBox.Image = _company.Show(); + + 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) + { + // TODO прописать логику удаления элемента из коллекции + // нужно убедиться, что есть выбранная коллекция + // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + // удалить и обновить ListBox + if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0) + { + MessageBox.Show("Коллекция для удаления не выбрана"); + 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 LocomotiveStation(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompany.Enabled = true; + RerfreshListBoxItems(); } } diff --git a/LocomativeProject/LocomativeProject/LocomotiveProject.Designer.cs b/LocomativeProject/LocomativeProject/LocomotiveProjectForm.Designer.cs similarity index 99% rename from LocomativeProject/LocomativeProject/LocomotiveProject.Designer.cs rename to LocomativeProject/LocomativeProject/LocomotiveProjectForm.Designer.cs index 06802b1..7f6cbed 100644 --- a/LocomativeProject/LocomativeProject/LocomotiveProject.Designer.cs +++ b/LocomativeProject/LocomativeProject/LocomotiveProjectForm.Designer.cs @@ -1,6 +1,6 @@ namespace LocomotiveProject { - partial class LocomotiveProject + partial class LocomotiveProjectForm { /// /// Required designer variable. @@ -28,7 +28,7 @@ /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProject)); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProjectForm)); pictureBox1 = new PictureBox(); pictureBoxLocomotive = new PictureBox(); buttonUp = new Button(); diff --git a/LocomativeProject/LocomativeProject/LocomotiveProject.cs b/LocomativeProject/LocomativeProject/LocomotiveProjectForm.cs similarity index 98% rename from LocomativeProject/LocomativeProject/LocomotiveProject.cs rename to LocomativeProject/LocomativeProject/LocomotiveProjectForm.cs index 3f5fd4c..7b08d55 100644 --- a/LocomativeProject/LocomativeProject/LocomotiveProject.cs +++ b/LocomativeProject/LocomativeProject/LocomotiveProjectForm.cs @@ -15,7 +15,7 @@ using LocomativeProject.MovementStrategy; namespace LocomotiveProject { - public partial class LocomotiveProject : Form + public partial class LocomotiveProjectForm : Form { private DrawningBaseLocomotive? _drawningLocomotive; @@ -33,7 +33,7 @@ namespace LocomotiveProject } } - public LocomotiveProject() + public LocomotiveProjectForm() { InitializeComponent(); _strategy = null; diff --git a/LocomativeProject/LocomativeProject/LocomotiveProject.resx b/LocomativeProject/LocomativeProject/LocomotiveProjectForm.resx similarity index 100% rename from LocomativeProject/LocomativeProject/LocomotiveProject.resx rename to LocomativeProject/LocomativeProject/LocomotiveProjectForm.resx diff --git a/LocomativeProject/LocomativeProject/Program.cs b/LocomativeProject/LocomativeProject/Program.cs index 662fce3..2732666 100644 --- a/LocomativeProject/LocomativeProject/Program.cs +++ b/LocomativeProject/LocomativeProject/Program.cs @@ -1,3 +1,5 @@ +using LocomativeProject; + namespace LocomotiveProject { internal static class Program