diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/CollectionType.cs b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..ffad19c
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace ProjectHoistingCrane.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/Garage.cs b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/Garage.cs
index 01ae82b..9dd7184 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/Garage.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/Garage.cs
@@ -1,6 +1,4 @@
using ProjectHoistingCrane.Drawnings;
-using static System.Windows.Forms.AxHost;
-using System.Drawing;
namespace ProjectHoistingCrane.CollectionGenericObjects;
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..42655ba
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,85 @@
+namespace ProjectHoistingCrane.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)
+ {
+ return _collection[position];
+ }
+ return null;
+ }
+ public int Insert(T obj)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ if(Count + 1 > _maxCount)
+ {
+ return -1;
+ }
+
+ // TODO вставка в конец набора
+ _collection.Add(obj);
+
+ return _collection.Count-1;
+ }
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ if (Count + 1 > _maxCount)
+ {
+ return -1;
+ }
+
+ // TODO проверка позиции
+ if (position < 0)
+ {
+ return -1;
+ }
+
+ // TODO вставка по позиции
+ _collection.Insert(position, obj);
+ return 1;
+ }
+ public T? Remove(int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ // TODO удаление объекта из списка
+ T? temp = _collection[position];
+ _collection.RemoveAt(position);
+ return temp;
+ }
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/MassiveGenericObjects.cs
index a992d38..b2014c0 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -19,8 +19,23 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public int Count => _collection.Length;
- public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
-
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (_collection.Length > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
///
/// Конструктор
///
@@ -32,7 +47,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects
{
// TODO проверка позиции
- if (0 <= position && position <= Count) {
+ if (0 <= position && position < Count) {
+
return _collection[position];
}
return null;
@@ -61,7 +77,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects
// если нет после, ищем до
// TODO вставка
- if (0 <= position && position <= Count && _collection[position] != null)
+ if (0 <= position && position < Count)
{
if (_collection[position] == null) {
_collection[position] = obj;
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/StorageCollection.cs b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..d1d69db
--- /dev/null
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,77 @@
+namespace ProjectHoistingCrane.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) || _storages.ContainsKey(name))
+ return;
+ switch (collectionType)
+ {
+ case CollectionType.None:
+ return;
+ case CollectionType.Massive:
+ _storages[name] = new MassiveGenericObjects();
+ return;
+ case CollectionType.List:
+ _storages[name] = new ListGenericObjects();
+ return;
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ // TODO Прописать логику для удаления коллекции
+ if (_storages.ContainsKey(name)) _storages.Remove(name);
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ // TODO Продумать логику получения объекта
+ if (string.IsNullOrEmpty(name) || !_storages.ContainsKey(name))
+ return null;
+ return _storages[name];
+ }
+ }
+
+}
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.Designer.cs b/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.Designer.cs
index 9d07998..8f73641 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.Designer.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.Designer.cs
@@ -29,52 +29,107 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ panelCompanyTools = new Panel();
+ buttonAddCrane = new Button();
+ buttonAddHoistingCrane = new Button();
buttonRefresh = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button();
buttonRemoveCrane = new Button();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonAddHoistingCrane = new Button();
- buttonAddCrane = new Button();
+ 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();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonRemoveCrane);
- groupBoxTools.Controls.Add(maskedTextBoxPosition);
- groupBoxTools.Controls.Add(buttonAddHoistingCrane);
- groupBoxTools.Controls.Add(buttonAddCrane);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(738, 0);
+ groupBoxTools.Location = new Point(771, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(222, 618);
+ groupBoxTools.Size = new Size(222, 690);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddCrane);
+ panelCompanyTools.Controls.Add(buttonAddHoistingCrane);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonRemoveCrane);
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(6, 395);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(210, 293);
+ panelCompanyTools.TabIndex = 2;
+ //
+ // buttonAddCrane
+ //
+ buttonAddCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddCrane.Location = new Point(3, 3);
+ buttonAddCrane.Name = "buttonAddCrane";
+ buttonAddCrane.Size = new Size(204, 37);
+ buttonAddCrane.TabIndex = 1;
+ buttonAddCrane.Text = "Добавление крана";
+ buttonAddCrane.UseVisualStyleBackColor = true;
+ buttonAddCrane.Click += ButtonAddCrane_Click;
+ //
+ // buttonAddHoistingCrane
+ //
+ buttonAddHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddHoistingCrane.Location = new Point(3, 46);
+ buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
+ buttonAddHoistingCrane.Size = new Size(199, 55);
+ buttonAddHoistingCrane.TabIndex = 2;
+ buttonAddHoistingCrane.Text = "Добавление подъёмного крана";
+ buttonAddHoistingCrane.UseVisualStyleBackColor = true;
+ buttonAddHoistingCrane.Click += ButtonAddHoistingCrane_Click;
+ //
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(24, 513);
+ buttonRefresh.Location = new Point(3, 229);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(163, 53);
+ buttonRefresh.Size = new Size(199, 53);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBoxPosition.Location = new Point(0, 107);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(204, 27);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(24, 382);
+ buttonGoToCheck.Location = new Point(3, 182);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(163, 53);
+ buttonGoToCheck.Size = new Size(199, 41);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -83,44 +138,106 @@
// buttonRemoveCrane
//
buttonRemoveCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveCrane.Location = new Point(24, 277);
+ buttonRemoveCrane.Location = new Point(3, 140);
buttonRemoveCrane.Name = "buttonRemoveCrane";
- buttonRemoveCrane.Size = new Size(163, 53);
+ buttonRemoveCrane.Size = new Size(199, 36);
buttonRemoveCrane.TabIndex = 4;
buttonRemoveCrane.Text = "Удалить кран";
buttonRemoveCrane.UseVisualStyleBackColor = true;
buttonRemoveCrane.Click += ButtonRemoveCrane_Click;
//
- // maskedTextBoxPosition
+ // buttonCreateCompany
//
- maskedTextBoxPosition.Location = new Point(6, 244);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(210, 27);
- maskedTextBoxPosition.TabIndex = 3;
- maskedTextBoxPosition.ValidatingType = typeof(int);
+ buttonCreateCompany.Location = new Point(6, 349);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(216, 29);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
- // buttonAddHoistingCrane
+ // panelStorage
//
- buttonAddHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddHoistingCrane.Location = new Point(24, 139);
- buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
- buttonAddHoistingCrane.Size = new Size(163, 53);
- buttonAddHoistingCrane.TabIndex = 2;
- buttonAddHoistingCrane.Text = "Добавление подъёмного крана";
- buttonAddHoistingCrane.UseVisualStyleBackColor = true;
- buttonAddHoistingCrane.Click += ButtonAddHoistingCrane_Click;
+ 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(216, 276);
+ panelStorage.TabIndex = 7;
//
- // buttonAddCrane
+ // buttonCollectionDel
//
- buttonAddCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddCrane.Location = new Point(24, 80);
- buttonAddCrane.Name = "buttonAddCrane";
- buttonAddCrane.Size = new Size(163, 53);
- buttonAddCrane.TabIndex = 1;
- buttonAddCrane.Text = "Добавление крана";
- buttonAddCrane.UseVisualStyleBackColor = true;
- buttonAddCrane.Click += ButtonAddCrane_Click;
+ buttonCollectionDel.Location = new Point(0, 243);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(216, 29);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.Location = new Point(3, 133);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(210, 104);
+ listBoxCollection.TabIndex = 5;
+ listBoxCollection.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(0, 98);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(216, 29);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(125, 68);
+ 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(21, 68);
+ 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(0, 35);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(216, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(26, 12);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(158, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
//
// comboBoxSelectorCompany
//
@@ -128,7 +245,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 26);
+ comboBoxSelectorCompany.Location = new Point(6, 315);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(210, 28);
comboBoxSelectorCompany.TabIndex = 0;
@@ -139,7 +256,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(738, 618);
+ pictureBox.Size = new Size(771, 690);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -147,13 +264,16 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(960, 618);
+ ClientSize = new Size(993, 690);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormCraneCollection";
Text = "Коллекция кранов";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -169,5 +289,15 @@
private PictureBox pictureBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.cs b/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.cs
index 14a77bd..b42ff8b 100644
--- a/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.cs
+++ b/ProjectHoistingCrane/ProjectHoistingCrane/FormCraneCollection.cs
@@ -17,6 +17,12 @@ namespace ProjectHoistingCrane;
///
public partial class FormCraneCollection : Form
{
+ ///
+ /// Хранилище компании
+ ///
+ private readonly StorageCollection _storageCollection;
+
+
///
/// Компания
///
@@ -28,6 +34,7 @@ public partial class FormCraneCollection : Form
public FormCraneCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -37,12 +44,7 @@ public partial class FormCraneCollection : Form
///
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
@@ -195,4 +197,99 @@ public partial class FormCraneCollection : 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 ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ // TODO прописать логику удаления элемента из коллекции
+ // нужно убедиться, что есть выбранная коллекция
+ // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
+ // удалить и обновить ListBox
+
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ if (MessageBox.Show("Вы действительно хотите удалить коллекцию?", "Да", MessageBoxButtons.YesNo) == 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;
+ }
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+
+ }
+
+ ///
+ /// Обновление списка в 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);
+ }
+ }
+ }
}