diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
index 36f5c38..0173f6e 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
@@ -17,7 +17,7 @@ public abstract class AbstractCompany
///
/// Размер места (высота)
///
- protected readonly int _placeSizeHeight = 64;
+ protected readonly int _placeSizeHeight = 60;
///
/// Ширина окна
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/CollectionType.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..d8959b0
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..27a8078
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.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)
+ {
+ // проверка позиции
+ if (position >= Count || position < 0)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+
+ public int Insert(T obj)
+ {
+
+ if (Count == _maxCount) return -1;
+ _collection.Add(obj);
+ return Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // проверка, что не превышено максимальное количество элементов
+ // проверка позиции
+ // вставка по позиции
+
+ if (position >= Count || position < 0)
+ {
+ return -1;
+ }
+ if (Count == _maxCount)
+ {
+ return -1;
+ }
+ _collection.Insert(position, obj);
+ return position;
+
+ }
+
+ public T Remove(int position)
+ {
+ // проверка позиции
+ // удаление объекта из списка
+ if (position >= Count || position < 0) return null;
+ T obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
+
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs
index 0cdc767..386ef83 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepot.cs
@@ -29,8 +29,8 @@ public class LocomotiveDepot : AbstractCompany
{
for (int j = 0; j < count_height + 1; ++j)
{
- g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 1, i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight+1);
- g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 5 , i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight + 5);
+ g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight , i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight );
}
}
}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
index c1c6c32..8e31670 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -20,7 +20,7 @@ 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 (Count > 0) { Array.Resize(ref _collection, value); } else { _collection = new T?[value]; } } }
///
/// Конструктор
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..f869a1b
--- /dev/null
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.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)
+ {
+ // проверка что name не пустой и нет в словаре записи с таким ключом
+ // логика добавления
+ if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name) || collectionType == CollectionType.None) return;
+ if (collectionType == CollectionType.Massive)
+ {
+ _storages[name] = new MassiveGenericObjects();
+ }
+ else if (collectionType == CollectionType.List)
+ {
+ _storages[name] = new ListGenericObjects();
+ }
+
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Имя коллекции
+ public void DelCollection(string name)
+ {
+ if (_storages.ContainsKey(name))
+ {
+ _storages.Remove(name);
+ }
+ }
+
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ // логика получения объекта (если есть запись с ключом мы должны вернуть объект иначе значение словаря по ключу)
+ if (_storages.ContainsKey(name))
+ {
+ return _storages[name];
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
index b85a000..ee4e46f 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
@@ -29,95 +29,54 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ buttonCreateCompany = new Button();
+ comboBoxSelectorCompany = new ComboBox();
+ panelCompanyTools = new Panel();
+ buttonAddLocomotive = new Button();
+ buttonAddElectricLocomotiv = new Button();
buttonRefresh = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button();
buttonRemoveLocomotive = new Button();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonAddElectricLocomotiv = new Button();
- buttonAddLocomotive = new Button();
- comboBoxSelectorCompany = new ComboBox();
+ panelStorage = new Panel();
+ buttonCollectionDel = new Button();
+ listBoxCollection = new ListBox();
+ buttonCollectionAdd = new Button();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
pictureBox = new PictureBox();
colorDialog1 = new ColorDialog();
groupBoxTools.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonRemoveLocomotive);
- groupBoxTools.Controls.Add(maskedTextBoxPosition);
- groupBoxTools.Controls.Add(buttonAddElectricLocomotiv);
- groupBoxTools.Controls.Add(buttonAddLocomotive);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(600, 0);
+ groupBoxTools.Location = new Point(640, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(200, 450);
+ groupBoxTools.Size = new Size(200, 593);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
- // buttonRefresh
+ // buttonCreateCompany
//
- buttonRefresh.Location = new Point(6, 336);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(188, 32);
- buttonRefresh.TabIndex = 6;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += ButtonRefresh_Click;
- //
- // buttonGoToCheck
- //
- buttonGoToCheck.Location = new Point(6, 265);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(188, 32);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Поставить на пути";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += ButtonGoToCheck_Click;
- //
- // buttonRemoveLocomotive
- //
- buttonRemoveLocomotive.Location = new Point(6, 193);
- buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
- buttonRemoveLocomotive.Size = new Size(188, 32);
- buttonRemoveLocomotive.TabIndex = 4;
- buttonRemoveLocomotive.Text = "Удалить локомотив";
- buttonRemoveLocomotive.UseVisualStyleBackColor = true;
- buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
- //
- // maskedTextBoxPosition
- //
- maskedTextBoxPosition.Location = new Point(6, 164);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(188, 23);
- maskedTextBoxPosition.TabIndex = 3;
- maskedTextBoxPosition.ValidatingType = typeof(int);
- //
- // buttonAddElectricLocomotiv
- //
- buttonAddElectricLocomotiv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddElectricLocomotiv.Location = new Point(6, 104);
- buttonAddElectricLocomotiv.Name = "buttonAddElectricLocomotiv";
- buttonAddElectricLocomotiv.Size = new Size(188, 32);
- buttonAddElectricLocomotiv.TabIndex = 2;
- buttonAddElectricLocomotiv.Text = "Добавить электровоз";
- buttonAddElectricLocomotiv.UseVisualStyleBackColor = true;
- buttonAddElectricLocomotiv.Click += ButtonAddElectricLocomotive_Click;
- //
- // buttonAddLocomotive
- //
- buttonAddLocomotive.Location = new Point(6, 66);
- buttonAddLocomotive.Name = "buttonAddLocomotive";
- buttonAddLocomotive.Size = new Size(188, 32);
- buttonAddLocomotive.TabIndex = 1;
- buttonAddLocomotive.Text = "Добавить локомотив";
- buttonAddLocomotive.UseVisualStyleBackColor = true;
- buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
+ buttonCreateCompany.Location = new Point(6, 336);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(188, 22);
+ buttonCreateCompany.TabIndex = 7;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// comboBoxSelectorCompany
//
@@ -125,18 +84,175 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 307);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(188, 23);
+ comboBoxSelectorCompany.Size = new Size(182, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddLocomotive);
+ panelCompanyTools.Controls.Add(buttonAddElectricLocomotiv);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonRemoveLocomotive);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 364);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(194, 226);
+ panelCompanyTools.TabIndex = 8;
+ //
+ // buttonAddLocomotive
+ //
+ buttonAddLocomotive.Location = new Point(3, 3);
+ buttonAddLocomotive.Name = "buttonAddLocomotive";
+ buttonAddLocomotive.Size = new Size(188, 31);
+ buttonAddLocomotive.TabIndex = 1;
+ buttonAddLocomotive.Text = "Добавить локомотив";
+ buttonAddLocomotive.UseVisualStyleBackColor = true;
+ buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
+ //
+ // buttonAddElectricLocomotiv
+ //
+ buttonAddElectricLocomotiv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddElectricLocomotiv.Location = new Point(3, 40);
+ buttonAddElectricLocomotiv.Name = "buttonAddElectricLocomotiv";
+ buttonAddElectricLocomotiv.Size = new Size(188, 31);
+ buttonAddElectricLocomotiv.TabIndex = 2;
+ buttonAddElectricLocomotiv.Text = "Добавить электровоз";
+ buttonAddElectricLocomotiv.UseVisualStyleBackColor = true;
+ buttonAddElectricLocomotiv.Click += ButtonAddElectricLocomotive_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(3, 180);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(188, 37);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(3, 77);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(188, 23);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(3, 143);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(188, 31);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Поставить на пути";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveLocomotive
+ //
+ buttonRemoveLocomotive.Location = new Point(3, 106);
+ buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
+ buttonRemoveLocomotive.Size = new Size(188, 31);
+ buttonRemoveLocomotive.TabIndex = 4;
+ buttonRemoveLocomotive.Text = "Удалить локомотив";
+ buttonRemoveLocomotive.UseVisualStyleBackColor = true;
+ buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_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, 19);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(194, 282);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(3, 245);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(188, 23);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(3, 130);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(188, 109);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(3, 101);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(188, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(97, 76);
+ 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(15, 76);
+ 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(3, 47);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(188, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(27, 15);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(122, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции";
+ //
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(600, 450);
+ pictureBox.Size = new Size(640, 593);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -144,13 +260,16 @@
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(800, 450);
+ ClientSize = new Size(840, 593);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormLocomotiveCollection";
Text = "FormLocomotiveCollection";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -167,5 +286,15 @@
private Button buttonGoToCheck;
private Button buttonRefresh;
private ColorDialog colorDialog1;
+ private Panel panelStorage;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private Button buttonCreateCompany;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs
index 5ee6f91..d3d093d 100644
--- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs
+++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollection.cs
@@ -15,6 +15,11 @@ namespace ProjectElectricLocomotive;
public partial class FormLocomotiveCollection : Form
{
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -26,6 +31,7 @@ public partial class FormLocomotiveCollection : Form
public FormLocomotiveCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -35,12 +41,7 @@ public partial class FormLocomotiveCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new LocomotiveDepot(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
/// Добавление грузовика
@@ -151,7 +152,6 @@ public partial class FormLocomotiveCollection : Form
///
///
///
-
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
@@ -180,5 +180,96 @@ public partial class FormLocomotiveCollection : Form
form.ShowDialog();
}
-
+ ///
+ ///
+ ///
+ ///
+ ///
+ 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);
+ RefreshListBoxItems();
+ }
+
+ ///
+ /// Добавление коллекции
+ ///
+ ///
+ ///
+ private void ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ //TODO логика удаления элемента из коллекции
+ //убедиться что есть выбранная коллекция
+ //спросить через месседжбокс что он пождтверждает что хочет удалить запись
+ //удалить и обновить ListBox
+ if (listBoxCollection.SelectedIndex < 0)
+ {
+ MessageBox.Show("Коллекция не существует");
+ return;
+ }
+ if (MessageBox.Show("Вы хотите удалить коллекцию?", "Коллекция удалена", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem?.ToString() ?? string.Empty);
+ RefreshListBoxItems();
+ }
+
+ ///
+ /// Обновление списка в listBoxCollection
+ ///
+ private void RefreshListBoxItems()
+ {
+ 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 ButtonCreateCompany_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+
+ ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
+ if (collection == null)
+ {
+ MessageBox.Show("Коллекция не проиннициализирована");
+ return;
+ }
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new LocomotiveDepot(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RefreshListBoxItems();
+ }
}