From 94df8ca4969abab1e7261e98896dbd2ac026b608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B8=D1=8F=20=D0=9A=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Wed, 27 Mar 2024 20:09:27 +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=204?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 19 ++ .../ListGenericObjects.cs | 56 ++++++ .../StorageCollection.cs | 67 +++++++ .../FormExcavatorCollection.Designer.cs | 166 ++++++++++++++++-- .../FormExcavatorCollection.cs | 103 ++++++++++- 5 files changed, 385 insertions(+), 26 deletions(-) create mode 100644 WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/CollectionType.cs create mode 100644 WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/CollectionType.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..40dac65 --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,19 @@ +namespace WinFormsAppExcavator.CollectionGenericObjects; +/// +/// тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 +} diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..1f360bd --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,56 @@ +namespace WinFormsAppExcavator.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 (position >= Count || position < 0) return null; + return _collection[position]; + } + public int Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + if (Count == _maxCount) return -1; + _collection.Add(obj); + return Count; + } + public int Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if (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/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..c78be6f --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,67 @@ +namespace WinFormsAppExcavator.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; + } + } +} diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs index e9ed37f..8bbbc7e 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); buttonRemoveExcavator = new Button(); @@ -37,18 +46,18 @@ buttonAddExcavatorEmpty = 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(buttonRemoveExcavator); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddExcavator); - groupBoxTools.Controls.Add(buttonAddExcavatorEmpty); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(722, 0); @@ -58,12 +67,103 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 292); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(208, 29); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(214, 233); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 200); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(208, 29); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.Location = new Point(3, 130); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(208, 64); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 95); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(208, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(97, 65); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(80, 24); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(13, 65); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(82, 24); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 32); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(202, 27); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(33, 9); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(155, 20); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 476); + buttonRefresh.Location = new Point(5, 198); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(208, 53); + buttonRefresh.Size = new Size(206, 27); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +172,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 306); + buttonGoToCheck.Location = new Point(5, 163); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(208, 53); + buttonGoToCheck.Size = new Size(206, 29); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Отправление на тест"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +183,9 @@ // buttonRemoveExcavator // buttonRemoveExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveExcavator.Location = new Point(6, 247); + buttonRemoveExcavator.Location = new Point(5, 127); buttonRemoveExcavator.Name = "buttonRemoveExcavator"; - buttonRemoveExcavator.Size = new Size(208, 53); + buttonRemoveExcavator.Size = new Size(206, 30); buttonRemoveExcavator.TabIndex = 4; buttonRemoveExcavator.Text = "Удаление экскаватора"; buttonRemoveExcavator.UseVisualStyleBackColor = true; @@ -93,7 +193,7 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(12, 203); + maskedTextBox.Location = new Point(3, 96); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(208, 27); @@ -103,9 +203,9 @@ // buttonAddExcavator // buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddExcavator.Location = new Point(6, 134); + buttonAddExcavator.Location = new Point(0, 59); buttonAddExcavator.Name = "buttonAddExcavator"; - buttonAddExcavator.Size = new Size(208, 53); + buttonAddExcavator.Size = new Size(214, 31); buttonAddExcavator.TabIndex = 2; buttonAddExcavator.Text = "Добавление экскаватора"; buttonAddExcavator.UseVisualStyleBackColor = true; @@ -114,9 +214,9 @@ // buttonAddExcavatorEmpty // buttonAddExcavatorEmpty.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddExcavatorEmpty.Location = new Point(6, 75); + buttonAddExcavatorEmpty.Location = new Point(5, 0); buttonAddExcavatorEmpty.Name = "buttonAddExcavatorEmpty"; - buttonAddExcavatorEmpty.Size = new Size(208, 53); + buttonAddExcavatorEmpty.Size = new Size(209, 53); buttonAddExcavatorEmpty.TabIndex = 1; buttonAddExcavatorEmpty.Text = "Добавление экскаватора простого"; buttonAddExcavatorEmpty.UseVisualStyleBackColor = true; @@ -128,7 +228,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 26); + comboBoxSelectorCompany.Location = new Point(6, 258); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(208, 28); comboBoxSelectorCompany.TabIndex = 0; @@ -143,6 +243,21 @@ pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonAddExcavator); + panelCompanyTools.Controls.Add(buttonAddExcavatorEmpty); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRemoveExcavator); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 324); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(214, 228); + panelCompanyTools.TabIndex = 9; + // // FormExcavatorCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -153,8 +268,11 @@ Name = "FormExcavatorCollection"; 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 Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs index 8d94319..a6fac6a 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs @@ -2,9 +2,15 @@ using WinFormsAppExcavator.Drawings; namespace WinFormsAppExcavator; - +/// +/// форма работы с компанией и коллекцией +/// public partial class FormExcavatorCollection : Form { + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; /// /// компания /// @@ -15,6 +21,7 @@ public partial class FormExcavatorCollection : Form public FormExcavatorCollection() { InitializeComponent(); + _storageCollection = new(); } /// /// Выбор компании @@ -23,12 +30,7 @@ public partial class FormExcavatorCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new ExcavatorSharingServise(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -172,4 +174,91 @@ public partial class FormExcavatorCollection : 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 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 buttonCollectionDel_Click(object sender, EventArgs e) + { + 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 ExcavatorSharingServise(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + + } } + -- 2.25.1