From af782b1882bdb956f3165c2863007e4f840f632f Mon Sep 17 00:00:00 2001 From: ENDORFIT Date: Sun, 7 Apr 2024 18:24:39 +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=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMonorailCollection.Designer.cs | 191 +++++++++++++++--- ProjectMonorail/FormMonorailCollection.cs | 101 ++++++++- .../CollectionType.cs | 21 ++ .../ListGenericObjects.cs | 76 +++++++ .../StorageCollection.cs | 83 ++++++++ 5 files changed, 445 insertions(+), 27 deletions(-) create mode 100644 ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs diff --git a/ProjectMonorail/FormMonorailCollection.Designer.cs b/ProjectMonorail/FormMonorailCollection.Designer.cs index acbc189..03d8e29 100644 --- a/ProjectMonorail/FormMonorailCollection.Designer.cs +++ b/ProjectMonorail/FormMonorailCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDelete = 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(); buttonRemoveMonorail = new Button(); @@ -37,33 +46,127 @@ buttonAddMonorail = 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(buttonRemoveMonorail); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddModernMonorail); - groupBoxTools.Controls.Add(buttonAddMonorail); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(970, 0); + groupBoxTools.Location = new Point(1109, 0); + groupBoxTools.Margin = new Padding(3, 4, 3, 4); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(241, 662); + groupBoxTools.Padding = new Padding(3, 4, 3, 4); + groupBoxTools.Size = new Size(275, 883); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(7, 388); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(254, 29); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDelete); + 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, 24); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(269, 322); + panelStorage.TabIndex = 7; + // + // buttonCollectionDelete + // + buttonCollectionDelete.Location = new Point(6, 274); + buttonCollectionDelete.Name = "buttonCollectionDelete"; + buttonCollectionDelete.Size = new Size(254, 29); + buttonCollectionDelete.TabIndex = 6; + buttonCollectionDelete.Text = "Удалить коллекцию"; + buttonCollectionDelete.UseVisualStyleBackColor = true; + buttonCollectionDelete.Click += ButtonCollectionDelete_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.Location = new Point(6, 164); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(254, 104); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(6, 129); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(254, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(129, 89); + 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(23, 89); + 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(6, 37); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(254, 27); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(54, 14); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(158, 20); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 581); + buttonRefresh.Location = new Point(4, 356); + buttonRefresh.Margin = new Padding(3, 4, 3, 4); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(229, 48); + buttonRefresh.Size = new Size(259, 64); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +175,10 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 527); + buttonGoToCheck.Location = new Point(1, 284); + buttonGoToCheck.Margin = new Padding(3, 4, 3, 4); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(229, 48); + buttonGoToCheck.Size = new Size(259, 64); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +187,10 @@ // buttonRemoveMonorail // buttonRemoveMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveMonorail.Location = new Point(6, 350); + buttonRemoveMonorail.Location = new Point(1, 212); + buttonRemoveMonorail.Margin = new Padding(3, 4, 3, 4); buttonRemoveMonorail.Name = "buttonRemoveMonorail"; - buttonRemoveMonorail.Size = new Size(229, 48); + buttonRemoveMonorail.Size = new Size(259, 64); buttonRemoveMonorail.TabIndex = 4; buttonRemoveMonorail.Text = "Удалить монорельс"; buttonRemoveMonorail.UseVisualStyleBackColor = true; @@ -93,19 +198,21 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(6, 321); + maskedTextBox.Location = new Point(8, 177); + maskedTextBox.Margin = new Padding(3, 4, 3, 4); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(223, 23); + maskedTextBox.Size = new Size(254, 27); maskedTextBox.TabIndex = 3; maskedTextBox.ValidatingType = typeof(int); // // buttonAddModernMonorail // buttonAddModernMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddModernMonorail.Location = new Point(6, 161); + buttonAddModernMonorail.Location = new Point(2, 105); + buttonAddModernMonorail.Margin = new Padding(3, 4, 3, 4); buttonAddModernMonorail.Name = "buttonAddModernMonorail"; - buttonAddModernMonorail.Size = new Size(229, 48); + buttonAddModernMonorail.Size = new Size(259, 64); buttonAddModernMonorail.TabIndex = 2; buttonAddModernMonorail.Text = "Добавление современного монорельса"; buttonAddModernMonorail.UseVisualStyleBackColor = true; @@ -114,9 +221,10 @@ // buttonAddMonorail // buttonAddMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddMonorail.Location = new Point(6, 107); + buttonAddMonorail.Location = new Point(6, 33); + buttonAddMonorail.Margin = new Padding(3, 4, 3, 4); buttonAddMonorail.Name = "buttonAddMonorail"; - buttonAddMonorail.Size = new Size(229, 48); + buttonAddMonorail.Size = new Size(253, 64); buttonAddMonorail.TabIndex = 1; buttonAddMonorail.Text = "Добавление монорельса"; buttonAddMonorail.UseVisualStyleBackColor = true; @@ -128,9 +236,10 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 46); + comboBoxSelectorCompany.Location = new Point(3, 353); + comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(229, 23); + comboBoxSelectorCompany.Size = new Size(261, 28); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // @@ -138,23 +247,43 @@ // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); + pictureBox.Margin = new Padding(3, 4, 3, 4); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(970, 662); + pictureBox.Size = new Size(1109, 883); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddMonorail); + panelCompanyTools.Controls.Add(buttonAddModernMonorail); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveMonorail); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 450); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(269, 429); + panelCompanyTools.TabIndex = 8; + // // FormMonorailCollection // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1211, 662); + ClientSize = new Size(1384, 883); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Margin = new Padding(3, 4, 3, 4); Name = "FormMonorailCollection"; 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 +298,15 @@ private PictureBox pictureBox; private Button buttonGoToCheck; private Button buttonRefresh; + private Panel panelStorage; + private Label labelCollectionName; + private TextBox textBoxCollectionName; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private Button buttonCollectionDelete; + private ListBox listBoxCollection; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectMonorail/FormMonorailCollection.cs b/ProjectMonorail/FormMonorailCollection.cs index 7ab4a7f..554fc7d 100644 --- a/ProjectMonorail/FormMonorailCollection.cs +++ b/ProjectMonorail/FormMonorailCollection.cs @@ -9,7 +9,12 @@ namespace ProjectMonorail public partial class FormMonorailCollection : Form { /// - /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; + + /// + /// Компания /// private AbstractCompany? _company = null; @@ -19,6 +24,7 @@ namespace ProjectMonorail public FormMonorailCollection() { InitializeComponent(); + _storageCollection = new StorageCollection(); } /// @@ -144,5 +150,98 @@ namespace ProjectMonorail if (_company == null) return; pictureBox.Image = _company.Show(); } + + /// + /// Обновление списка в 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 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 ButtonCollectionDelete_Click(object sender, EventArgs e) + { + // TODO прописать логику удаления элемента из коллекции + // нужно убедиться, что есть выбранная коллекция + // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + // удалить и обновить ListBox + if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0) + { + 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 DepotSharingService(pictureBox.Width, + pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } } diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/CollectionType.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..0158452 --- /dev/null +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,21 @@ +namespace ProjectMonorail.Scripts.Monorail.CollectionGenericObjects +{ + /// + /// Тип коллекции + /// + public enum CollectionType + { + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + /// Параметризованный набор объектов + /// + /// Параметр: ограничение - ссылочный тип + 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 < 0 || position >= _collection.Count) return null; + return _collection[position]; + } + + public int Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + + if (_collection.Count + 1 > _maxCount) return -1; + + _collection.Add(obj); + return _collection.Count + 1; + } + + public int Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if (position < 0 || position > _collection.Count || _collection[position] != null) return -1; + + _collection.Insert(position, obj); + + return position; + } + + public T Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + + if (position < 0 || position > _collection.Count) return null; + + T temp = _collection[position]; + + _collection[position] = null; + + return temp; + } + } +} diff --git a/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..23fe9a6 --- /dev/null +++ b/ProjectMonorail/Scripts/Monorail/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,83 @@ +namespace ProjectMonorail.Scripts.Monorail.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)) { + ICollectionGenericObjects collection; + + switch(collectionType) + { + case CollectionType.List: + collection = new ListGenericObjects(); + break; + case CollectionType.Massive: + collection = new MassiveGenericObjects(); + break; + default: + return; + } + + _storages.Add(name, collection); + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения + + if (_storages.TryGetValue(name, out var value)) return value; + return null; + } + } + } +} \ No newline at end of file