From 95a176686a2759c4bcf5168d337a6e1acc7f854c Mon Sep 17 00:00:00 2001 From: sqdselo <147947144+sqdselo@users.noreply.github.com> Date: Mon, 1 Apr 2024 02:01:34 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B5=20=D0=BF=D1=80=D0=BE=D0=BF=D0=B8?= =?UTF-8?q?=D1=81=D0=B0=D0=BD=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BE=D0=BA=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D1=8B.=20=D0=B4=D0=BE=D0=BF=D0=B8?= =?UTF-8?q?=D1=88=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 8 + .../ListGenericObjects.cs | 89 +++++++++++ .../StorageCollection.cs | 73 +++++++++ .../FormCarCollection.Designer.cs | 147 ++++++++++++++++-- .../HoistingCrane/FormCarCollection.cs | 21 ++- 5 files changed, 319 insertions(+), 19 deletions(-) create mode 100644 HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs create mode 100644 HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..22ffa84 --- /dev/null +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,8 @@ +using System; +namespace HoistingCrane.CollectionGenericObjects +{ + public enum CollectionType + { + None = 0, Massive = 1, List = 2 + } +} diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..f70ddbc --- /dev/null +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,89 @@ +using System; +namespace HoistingCrane.CollectionGenericObjects +{ + public class ListGenericObjects : ICollectionGenericObjects where T : class + { + /// + /// Список объектов, которые храним + /// + readonly List list; + /// + /// Конструктор + /// + public ListGenericObjects() + { + list = new List(); + } + /// + /// Максимально допустимое число объектов в списке + /// + private int _maxCount; + public int Count + { + get { return list.Count; } + } + + public int SetMaxCount + { + set + { + if(value > 0) + { + _maxCount = value; + } + } + } + + public T? Get(int position) + { + // TODO проверка позиции + if(position >= 0 && position < list.Count) + { + return list[position]; + } + return null; + } + + + public bool Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + if(list.Count < _maxCount) + { + list.Add(obj); + return true; + } + return false; + } + + public bool Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if(list.Count < _maxCount && position >= 0 && position < list.Count) + { + if (list[position] == null) + { + list[position] = obj; + return true; + } + } + return false; + + } + + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + if(position >= 0 && position < list.Count) + { + list.RemoveAt(position); + return true; + } + return false; + } + } +} diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..49e28b5 --- /dev/null +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,73 @@ +using System; +namespace HoistingCrane.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 (!string.IsNullOrEmpty(name) && !Keys.Contains(name)) + { + if(collectionType == CollectionType.Massive) + { + _storages.Add(name, new MassivGenericObjects ()); + } + if(collectionType == CollectionType.List) + { + _storages.Add(name, new ListGenericObjects ()); + } + } + } + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // TODO Прописать логику для удаления коллекции + if(Keys.Contains(name)) + { + _storages.Remove(name); + } + } + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + if (Keys.Contains(name)) + { + return _storages[name]; + } + return null; + } + } + } + +} diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs index 60eb2d0..d56e52d 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs @@ -37,12 +37,24 @@ buttonCreateTrackedVehicle = new Button(); buttonCreateHoistingCrane = new Button(); pictureBox = new PictureBox(); + panelStorage = new Panel(); + labelCollectionName = new Label(); + textBoxCollectionName = new TextBox(); + radioButtonMassive = new RadioButton(); + radioButtonList = new RadioButton(); + buttonCollectionAdd = new Button(); + listBoxCollection = new ListBox(); + buttonDeleteCollection = new Button(); + buttonCreateCompany = new Button(); groupBoxTools.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelStorage.SuspendLayout(); SuspendLayout(); // // groupBoxTools // + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(buttonGoToChek); groupBoxTools.Controls.Add(buttonRefresh); groupBoxTools.Controls.Add(buttonDeleteCar); @@ -51,9 +63,9 @@ groupBoxTools.Controls.Add(buttonCreateTrackedVehicle); groupBoxTools.Controls.Add(buttonCreateHoistingCrane); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(716, 0); + groupBoxTools.Location = new Point(763, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(210, 450); + groupBoxTools.Size = new Size(210, 509); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -61,9 +73,9 @@ // buttonGoToChek // buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(12, 298); + buttonGoToChek.Location = new Point(12, 440); buttonGoToChek.Name = "buttonGoToChek"; - buttonGoToChek.Size = new Size(192, 34); + buttonGoToChek.Size = new Size(192, 24); buttonGoToChek.TabIndex = 6; buttonGoToChek.Text = "Передать на тесты"; buttonGoToChek.UseVisualStyleBackColor = true; @@ -72,9 +84,9 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(12, 375); + buttonRefresh.Location = new Point(12, 470); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(192, 34); + buttonRefresh.Size = new Size(192, 27); buttonRefresh.TabIndex = 5; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -83,9 +95,9 @@ // buttonDeleteCar // buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDeleteCar.Location = new Point(12, 233); + buttonDeleteCar.Location = new Point(12, 411); buttonDeleteCar.Name = "buttonDeleteCar"; - buttonDeleteCar.Size = new Size(192, 34); + buttonDeleteCar.Size = new Size(192, 23); buttonDeleteCar.TabIndex = 4; buttonDeleteCar.Text = "Удалить автомобиль"; buttonDeleteCar.UseVisualStyleBackColor = true; @@ -94,7 +106,7 @@ // maskedTextBox // maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBox.Location = new Point(12, 204); + maskedTextBox.Location = new Point(12, 382); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(192, 23); @@ -106,7 +118,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(12, 28); + comboBoxSelectorCompany.Location = new Point(12, 266); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(192, 23); comboBoxSelectorCompany.TabIndex = 2; @@ -115,9 +127,9 @@ // buttonCreateTrackedVehicle // buttonCreateTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonCreateTrackedVehicle.Location = new Point(12, 129); + buttonCreateTrackedVehicle.Location = new Point(12, 352); buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle"; - buttonCreateTrackedVehicle.Size = new Size(192, 34); + buttonCreateTrackedVehicle.Size = new Size(192, 24); buttonCreateTrackedVehicle.TabIndex = 1; buttonCreateTrackedVehicle.Text = "Добавить гусеничную машину"; buttonCreateTrackedVehicle.UseVisualStyleBackColor = true; @@ -126,9 +138,9 @@ // buttonCreateHoistingCrane // buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonCreateHoistingCrane.Location = new Point(12, 89); + buttonCreateHoistingCrane.Location = new Point(12, 324); buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; - buttonCreateHoistingCrane.Size = new Size(192, 34); + buttonCreateHoistingCrane.Size = new Size(192, 22); buttonCreateHoistingCrane.TabIndex = 0; buttonCreateHoistingCrane.Text = "Добавить подъемный кран"; buttonCreateHoistingCrane.UseVisualStyleBackColor = true; @@ -139,15 +151,107 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(716, 450); + pictureBox.Size = new Size(763, 509); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelStorage + // + panelStorage.Controls.Add(buttonDeleteCollection); + 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(204, 229); + panelStorage.TabIndex = 7; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(35, 0); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(135, 15); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(9, 18); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(192, 23); + textBoxCollectionName.TabIndex = 1; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(18, 56); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(69, 19); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(128, 56); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(67, 19); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(9, 81); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(192, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(9, 118); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(192, 79); + listBoxCollection.TabIndex = 5; + // + // buttonDeleteCollection + // + buttonDeleteCollection.Location = new Point(9, 199); + buttonDeleteCollection.Name = "buttonDeleteCollection"; + buttonDeleteCollection.Size = new Size(192, 27); + buttonDeleteCollection.TabIndex = 6; + buttonDeleteCollection.Text = "Удалить коллекцию"; + buttonDeleteCollection.UseVisualStyleBackColor = true; + buttonDeleteCollection.Click += buttonDeleteCollection_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(12, 295); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(192, 23); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // // FormCarCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(926, 450); + ClientSize = new Size(973, 509); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormCarCollection"; @@ -155,6 +259,8 @@ groupBoxTools.ResumeLayout(false); groupBoxTools.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ResumeLayout(false); } @@ -169,5 +275,14 @@ private MaskedTextBox maskedTextBox; private PictureBox pictureBox; private Button buttonGoToChek; + private Panel panelStorage; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private Button buttonCreateCompany; + private Button buttonDeleteCollection; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 7175e29..0b01400 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -77,7 +77,7 @@ namespace HoistingCrane private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); - + private void buttonDeleteCar_Click(object sender, EventArgs e) { @@ -120,12 +120,27 @@ namespace HoistingCrane if (count <= 0) break; } if (car == null) return; - FormHoistingCrane form = new() + FormHoistingCrane form = new() { SetCar = car }; form.ShowDialog(); - + + } + + private void buttonCollectionAdd_Click(object sender, EventArgs e) + { + + } + + private void buttonDeleteCollection_Click(object sender, EventArgs e) + { + + } + + private void buttonCreateCompany_Click(object sender, EventArgs e) + { + } } }