From f51c2c348f6b1638fffa4832842f37561ed62891 Mon Sep 17 00:00:00 2001 From: sqdselo <147947144+sqdselo@users.noreply.github.com> Date: Sun, 5 May 2024 13:08:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=91=D0=BE=D1=80=D1=8E=D1=81=D1=8C=20=D1=81?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BD=D1=84=D0=BB=D0=B8=D0=BA=D1=82=D0=B0=D0=BC?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../CollectionType.cs | 8 + .../CollectionGenericObjects/Garage.cs | 1 - .../ICollectionGenericObjects.cs | 5 + .../ListGenericObjects.cs | 74 ++++++ .../MassivGenericObjects.cs | 33 +-- .../StorageCollection.cs | 63 +++++ .../FormCarCollection.Designer.cs | 237 ++++++++++++++---- .../HoistingCrane/FormCarCollection.cs | 104 ++++++-- 9 files changed, 440 insertions(+), 87 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/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs index 5ed6ee3..8bec219 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs @@ -47,7 +47,7 @@ namespace HoistingCrane.CollectionGenericObjects } public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) { - return company.arr?.Remove(position) ?? null; + return company.arr?.Remove(position); } public DrawningTrackedVehicle? GetRandomObject() 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/Garage.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs index 0839cb8..6ba0162 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/Garage.cs @@ -20,7 +20,6 @@ namespace HoistingCrane.CollectionGenericObjects } } } - protected override void SetObjectsPosition() { int countWidth = pictureWidth / _placeSizeWidth; diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs index 2ca324a..007db42 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -30,6 +30,11 @@ /// /// T? Remove(int position); + /// + /// Получение объекта коллекции + /// + /// + /// T? Get(int position); } } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..1e19784 --- /dev/null +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,74 @@ +using System; +using System.CodeDom.Compiler; +using System.Windows.Forms.VisualStyles; + +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) + { + if (position >= Count || position < 0) return null; + return list[position]; + } + public int Insert(T obj) + { + if (Count == _maxCount) + { + return -1; + } + list.Add(obj); + return Count; + } + + public int Insert(T obj, int position) + { + if (position < 0 || position >= Count || Count == _maxCount) + { + return -1; + } + list.Insert(position, obj); + return position; + } + public T? Remove(int position) + { + if(position >= 0 && position < list.Count) + { + T? temp = list[position]; + list.RemoveAt(position); + return temp; + } + return null; + } + } +} diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs index 39d6839..ed0e4fd 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs @@ -10,7 +10,7 @@ namespace HoistingCrane.CollectionGenericObjects } public int Count { - get { return arr.Length; } + get { return arr.Length; } } public int SetMaxCount { @@ -45,28 +45,33 @@ namespace HoistingCrane.CollectionGenericObjects public int Insert(T obj, int position) { - //todo Проверка позиции - if (position < 0 || position > Count) + + if (position < 0 || position >= Count) { return -1; } - if (arr[position] == null) + int copyPos = position - 1; + + while (position < Count) { - arr[position] = obj; - return position; - } - else - { - if (Insert(obj, position + 1) != -1) - { - return position; - } - if (Insert(obj, position - 1) != -1) + if (arr[position] == null) { + arr[position] = obj; return position; } + position++; } + while (copyPos > 0) + { + if (arr[copyPos] == null) + { + arr[copyPos] = obj; + return copyPos; + } + copyPos--; + } + return -1; } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..1e2b74b --- /dev/null +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,63 @@ +using System; +namespace HoistingCrane.CollectionGenericObjects +{ + public class StorageCollection where T : class + { + /// + /// Словарь (хранилище) с коллекциями + /// + readonly Dictionary> dict; + /// + /// Возвращение списка названий коллекций + /// + public List Keys => dict.Keys.ToList(); + /// + /// Конструктор + /// + public StorageCollection() + { + dict = new Dictionary>(); + } + /// + /// Добавление коллекции в хранилище + /// + /// Название коллекции + /// тип коллекции + public void AddCollection(string name, CollectionType collectionType) + { + if (dict.ContainsKey(name)) return; + if (collectionType == CollectionType.None) return; + else if (collectionType == CollectionType.Massive) + dict[name] = new MassivGenericObjects(); + else if (collectionType == CollectionType.List) + dict[name] = new ListGenericObjects(); + } + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if(Keys.Contains(name)) + { + dict.Remove(name); + } + } + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (dict.ContainsKey(name)) + return dict[name]; + return null; + } + } + + } + +} diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs index 60eb2d0..e836b45 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs @@ -29,63 +29,119 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonGoToChek = new Button(); + buttonCreateCompany = new Button(); + panelCompanyTool = new Panel(); buttonRefresh = new Button(); + buttonGoToChek = new Button(); + buttonCreateHoistingCrane = new Button(); + buttonCreateTrackedVehicle = new Button(); buttonDeleteCar = new Button(); maskedTextBox = new MaskedTextBox(); + panelStorage = new Panel(); + buttonDeleteCollection = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); comboBoxSelectorCompany = new ComboBox(); - buttonCreateTrackedVehicle = new Button(); - buttonCreateHoistingCrane = new Button(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelCompanyTool.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonGoToChek); - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonDeleteCar); - groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelCompanyTool); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); - groupBoxTools.Controls.Add(buttonCreateTrackedVehicle); - groupBoxTools.Controls.Add(buttonCreateHoistingCrane); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(716, 0); + groupBoxTools.Location = new Point(759, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(210, 450); + groupBoxTools.Size = new Size(214, 509); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonGoToChek + // buttonCreateCompany // - buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(12, 298); - buttonGoToChek.Name = "buttonGoToChek"; - buttonGoToChek.Size = new Size(192, 34); - buttonGoToChek.TabIndex = 6; - buttonGoToChek.Text = "Передать на тесты"; - buttonGoToChek.UseVisualStyleBackColor = true; - buttonGoToChek.Click += buttonGoToChek_Click; + buttonCreateCompany.Location = new Point(12, 288); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(196, 23); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // + // panelCompanyTool + // + panelCompanyTool.Anchor = AnchorStyles.None; + panelCompanyTool.Controls.Add(buttonRefresh); + panelCompanyTool.Controls.Add(buttonGoToChek); + panelCompanyTool.Controls.Add(buttonCreateHoistingCrane); + panelCompanyTool.Controls.Add(buttonCreateTrackedVehicle); + panelCompanyTool.Controls.Add(buttonDeleteCar); + panelCompanyTool.Controls.Add(maskedTextBox); + panelCompanyTool.Enabled = false; + panelCompanyTool.Location = new Point(3, 317); + panelCompanyTool.Name = "panelCompanyTool"; + panelCompanyTool.Size = new Size(208, 238); + panelCompanyTool.TabIndex = 8; // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(12, 375); + buttonRefresh.Location = new Point(9, 159); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(192, 34); + buttonRefresh.Size = new Size(196, 27); buttonRefresh.TabIndex = 5; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += buttonRefresh_Click; // + // buttonGoToChek + // + buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToChek.Location = new Point(9, 119); + buttonGoToChek.Name = "buttonGoToChek"; + buttonGoToChek.Size = new Size(196, 24); + buttonGoToChek.TabIndex = 6; + buttonGoToChek.Text = "Передать на тесты"; + buttonGoToChek.UseVisualStyleBackColor = true; + buttonGoToChek.Click += buttonGoToChek_Click; + // + // buttonCreateHoistingCrane + // + buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonCreateHoistingCrane.Location = new Point(9, 3); + buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; + buttonCreateHoistingCrane.Size = new Size(196, 22); + buttonCreateHoistingCrane.TabIndex = 0; + buttonCreateHoistingCrane.Text = "Добавить подъемный кран"; + buttonCreateHoistingCrane.UseVisualStyleBackColor = true; + buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click; + // + // buttonCreateTrackedVehicle + // + buttonCreateTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonCreateTrackedVehicle.Location = new Point(9, 31); + buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle"; + buttonCreateTrackedVehicle.Size = new Size(196, 24); + buttonCreateTrackedVehicle.TabIndex = 1; + buttonCreateTrackedVehicle.Text = "Добавить гусеничную машину"; + buttonCreateTrackedVehicle.UseVisualStyleBackColor = true; + buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click; + // // buttonDeleteCar // buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDeleteCar.Location = new Point(12, 233); + buttonDeleteCar.Location = new Point(9, 90); buttonDeleteCar.Name = "buttonDeleteCar"; - buttonDeleteCar.Size = new Size(192, 34); + buttonDeleteCar.Size = new Size(196, 23); buttonDeleteCar.TabIndex = 4; buttonDeleteCar.Text = "Удалить автомобиль"; buttonDeleteCar.UseVisualStyleBackColor = true; @@ -94,52 +150,112 @@ // maskedTextBox // maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBox.Location = new Point(12, 204); + maskedTextBox.Location = new Point(9, 61); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(192, 23); + maskedTextBox.Size = new Size(196, 23); maskedTextBox.TabIndex = 3; // + // 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(208, 229); + panelStorage.TabIndex = 7; + // + // 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; + // + // 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; + // + // 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; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(128, 56); + 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(18, 56); + 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(9, 18); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(192, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(35, 0); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(125, 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(12, 28); + comboBoxSelectorCompany.Location = new Point(12, 259); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(192, 23); + comboBoxSelectorCompany.Size = new Size(196, 23); comboBoxSelectorCompany.TabIndex = 2; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1; - // - // buttonCreateTrackedVehicle - // - buttonCreateTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonCreateTrackedVehicle.Location = new Point(12, 129); - buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle"; - buttonCreateTrackedVehicle.Size = new Size(192, 34); - buttonCreateTrackedVehicle.TabIndex = 1; - buttonCreateTrackedVehicle.Text = "Добавить гусеничную машину"; - buttonCreateTrackedVehicle.UseVisualStyleBackColor = true; - buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click; - // - // buttonCreateHoistingCrane - // - buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonCreateHoistingCrane.Location = new Point(12, 89); - buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; - buttonCreateHoistingCrane.Size = new Size(192, 34); - buttonCreateHoistingCrane.TabIndex = 0; - buttonCreateHoistingCrane.Text = "Добавить подъемный кран"; - buttonCreateHoistingCrane.UseVisualStyleBackColor = true; - buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(716, 450); + pictureBox.Size = new Size(759, 509); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -147,13 +263,16 @@ // 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"; Text = "FormCarCollections"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTool.ResumeLayout(false); + panelCompanyTool.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -169,5 +288,15 @@ 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; + private Panel panelCompanyTool; } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 8854ea1..8ca2035 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -4,20 +4,19 @@ namespace HoistingCrane { public partial class FormCarCollection : Form { - private AbstractCompany? _company; + private AbstractCompany? _company = null; + + private readonly StorageCollection _storageCollection; + public FormCarCollection() { InitializeComponent(); + _storageCollection = new(); } - private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e) + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Garage(pictureBox.Width, pictureBox.Height, new MassivGenericObjects()); - break; - } + panelCompanyTool.Enabled = false; } private void CreateObject(string type) @@ -27,7 +26,6 @@ namespace HoistingCrane Random rand = new(); switch (type) { - case nameof(DrawningHoistingCrane): drawning = new DrawningHoistingCrane(rand.Next(100, 300), rand.Next(1000, 3000), GetColor(rand), GetColor(rand), true, true); break; @@ -48,7 +46,6 @@ namespace HoistingCrane MessageBox.Show("Не удалось добавить объект"); } } - private static Color GetColor(Random random) { Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); @@ -59,12 +56,9 @@ namespace HoistingCrane } return color; } - private void buttonCreateHoistingCrane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningHoistingCrane)); - private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); - private void buttonDeleteCar_Click(object sender, EventArgs e) { @@ -88,13 +82,11 @@ namespace HoistingCrane MessageBox.Show("Не удалось удалить объект"); } } - private void buttonRefresh_Click(object sender, EventArgs e) { if (_company == null) return; pictureBox.Image = _company.Show(); } - private void buttonGoToChek_Click(object sender, EventArgs e) { if (_company == null) return; @@ -107,12 +99,90 @@ namespace HoistingCrane if (count <= 0) break; } if (car == null) return; - FormHoistingCrane form = new() + FormHoistingCrane form = new() { SetCar = car }; form.ShowDialog(); - + } + + /// + /// Обновление списка в 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 buttonDeleteCollection_Click(object sender, EventArgs e) + { + // TODO прописать логику удаления элемента из коллекции + // нужно убедиться, что есть выбранная коллекция + // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + // удалить и обновить ListBox + + 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 Garage(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTool.Enabled = true; + RerfreshListBoxItems(); } } + }