From 5e7a5b684dd16b261b5daaf93489923b45a7a711 Mon Sep 17 00:00:00 2001 From: MariaBelkina <89656988623@mail.ru> Date: Mon, 22 Apr 2024 19:42:45 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=204=20=D0=B1=D0=B5?= =?UTF-8?q?=D0=B7=20TODO.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 28 +++ .../ListGenericObjects.cs | 64 ++++++ .../StorageCollection.cs | 66 +++++++ .../FormBulldozerCollection.Designer.cs | 182 +++++++++++++++--- .../FormBulldozerCollection.cs | 108 +++++++++-- 5 files changed, 407 insertions(+), 41 deletions(-) create mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..0e85ab4 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..d622439 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.CollectionGenericObjects; + +/// +/// Параметрезированный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class ListGenericObjects :ICollectoinGenericObjects 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 проверка позиции + return _collection[position]; + } + public bool Insert(T obj) + { + //TODO проверка, что не привышено максимальное колличество элементов + //TODO вставка в конец набора + return true; + } + + public bool Insert(T obj, int position) + { + //TODO проверка, что не превышено максимальное колличество элементов + //TODO проверка позиции + //TODO вставка по позиции + return true; + } + + + public bool Remove(int position) + { + //TODO проверка позиции + //TODO удаление объекта из спписка + return true; + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..29aa40a --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.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 прописать логику для добавления + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectoinGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + return null; + } + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs index a9ff02a..c3209d1 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelStorage = new Panel(); + listBoxCollection = new ListBox(); + buttonCollectionDel = new Button(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); + buttonCreateCompany = new Button(); maskedTextBox = new MaskedTextBox(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); @@ -37,40 +46,135 @@ buttonAddDozer = 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(maskedTextBox); - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonDelBulldozer); - groupBoxTools.Controls.Add(buttonAddBulldozer); - groupBoxTools.Controls.Add(buttonAddDozer); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(panelStorage); + groupBoxTools.Controls.Add(buttonCreateCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); groupBoxTools.Location = new Point(1290, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(358, 914); + groupBoxTools.Size = new Size(358, 1051); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // panelStorage + // + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionDel); + 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, 37); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(352, 465); + panelStorage.TabIndex = 6; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 33; + listBoxCollection.Location = new Point(11, 219); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(332, 169); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(11, 407); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(332, 46); + buttonCollectionDel.TabIndex = 4; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(11, 157); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(332, 46); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(183, 115); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(129, 37); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(38, 115); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(130, 37); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(11, 59); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(332, 41); + textBoxCollectionName.TabIndex = 1; + textBoxCollectionName.Text = " "; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(57, 13); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(263, 33); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(14, 572); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(332, 46); + buttonCreateCompany.TabIndex = 4; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // // maskedTextBox // - maskedTextBox.Location = new Point(14, 340); + maskedTextBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(11, 169); maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(332, 39); + maskedTextBox.Size = new Size(332, 41); maskedTextBox.TabIndex = 5; maskedTextBox.ValidatingType = typeof(int); // // buttonRefresh // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonRefresh.Location = new Point(14, 719); + buttonRefresh.Location = new Point(11, 354); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(332, 63); buttonRefresh.TabIndex = 3; @@ -80,9 +184,9 @@ // // buttonGoToCheck // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonGoToCheck.Location = new Point(14, 520); + buttonGoToCheck.Location = new Point(11, 285); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(332, 63); buttonGoToCheck.TabIndex = 3; @@ -92,9 +196,9 @@ // // buttonDelBulldozer // - buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonDelBulldozer.Location = new Point(14, 385); + buttonDelBulldozer.Location = new Point(11, 216); buttonDelBulldozer.Name = "buttonDelBulldozer"; buttonDelBulldozer.Size = new Size(332, 63); buttonDelBulldozer.TabIndex = 3; @@ -104,9 +208,9 @@ // // buttonAddBulldozer // - buttonAddBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonAddBulldozer.Location = new Point(14, 210); + buttonAddBulldozer.Location = new Point(11, 84); buttonAddBulldozer.Name = "buttonAddBulldozer"; buttonAddBulldozer.Size = new Size(332, 79); buttonAddBulldozer.TabIndex = 3; @@ -116,9 +220,9 @@ // // buttonAddDozer // - buttonAddDozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddDozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonAddDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonAddDozer.Location = new Point(14, 140); + buttonAddDozer.Location = new Point(11, 14); buttonAddDozer.Name = "buttonAddDozer"; buttonAddDozer.Size = new Size(332, 64); buttonAddDozer.TabIndex = 2; @@ -128,12 +232,12 @@ // // comboBoxSelectorCompany // - comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(14, 52); + comboBoxSelectorCompany.Location = new Point(14, 525); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(332, 41); comboBoxSelectorCompany.TabIndex = 1; @@ -141,24 +245,42 @@ // // pictureBox // - pictureBox.Location = new Point(12, 12); + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1272, 890); + pictureBox.Size = new Size(1290, 1051); pictureBox.TabIndex = 4; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddDozer); + panelCompanyTools.Controls.Add(buttonAddBulldozer); + panelCompanyTools.Controls.Add(buttonDelBulldozer); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 624); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(400, 449); + panelCompanyTools.TabIndex = 7; + // // FormBulldozerCollection // AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1648, 914); + ClientSize = new Size(1648, 1051); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormBulldozerCollection"; Text = "Коллекция бульдозеров"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -173,5 +295,15 @@ private Button buttonDelBulldozer; 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 buttonCollectionDel; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs index 6e42ba8..513da19 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs @@ -18,6 +18,9 @@ namespace ProjectBulldozer; /// public partial class FormBulldozerCollection : Form { + + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -29,6 +32,7 @@ public partial class FormBulldozerCollection : Form public FormBulldozerCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -38,23 +42,9 @@ public partial class FormBulldozerCollection : Form /// private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); - break; - } + panelCompanyTools.Enabled = false; } -/* private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e) - { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); - break; - } - }*/ /// /// Добавление обычного бульдозера @@ -94,7 +84,7 @@ public partial class FormBulldozerCollection : Form case nameof(DrawningBulldozer): //Вызов диалогового окна для выбора цвета drawningDozer = new DrawningBulldozer(random.Next(100, 300), random.Next(1000, 3000), - GetBodyColor(random), GetWheelsColor(random), + GetBodyColor(random), GetWheelsColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -223,4 +213,90 @@ public partial class FormBulldozerCollection : 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); + RefreshListBoxItems(); + } + + /// + /// Удаление коллекции + /// + /// + /// + private void ButtonCollectionDel_Click(object sender, EventArgs e) + { + // TODO Прописать логику удаления элемента из коллекции + //нужно убедиться, что есть выбранная коллекция + //спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + //удалить и обновить ListBox + } + + /// + /// Обновление списка в ListBoxCollection + /// + private void RefreshListBoxItems() + { + 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) + { + MessageBox.Show("Коллекция не выбрана!"); + return; + } + + ICollectoinGenericObjects? collectoin = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collectoin == null) + { + MessageBox.Show("Коллекция не проинициализирована!"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); + break; + } + + panelCompanyTools.Enabled = true; + } }