diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs
new file mode 100644
index 0000000..48b1c2f
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/CollectionType.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.CollectionGenericObject;
+
+public enum CollectionType
+{
+
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+
+}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs
new file mode 100644
index 0000000..f50ee76
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/ListGenericObjects.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.CollectionGenericObject;
+
+public class ListGenericObjects : ICollectionGenericObject
+ 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 < 0 || position >= Count)
+ {
+ return null;
+ }
+
+ return _collection[position];
+ }
+
+ public int Insert(T obj)
+ {
+ if (Count == _maxCount)
+ {
+ return -1;
+ }
+
+ _collection.Add(obj);
+ return _collection.Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ if (Count == _maxCount || position < 0 || position > Count)
+ {
+ return -1;
+ }
+
+ _collection.Insert(position, obj);
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ if (position < 0 || position > Count)
+ {
+ return null;
+ }
+
+ T? obj = _collection[position];
+ _collection.RemoveAt(position);
+
+ return obj;
+ }
+
+}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs
new file mode 100644
index 0000000..3bb32cf
--- /dev/null
+++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObject/StorageCollection.cs
@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectDumpTruck.CollectionGenericObject;
+
+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)
+ {
+ if (name == null || _storages.ContainsKey(name))
+ {
+ return;
+ }
+
+ if (collectionType == CollectionType.Massive)
+ {
+ _storages.Add(name, new MassiveGenericObjects());
+ }
+
+ if (collectionType == CollectionType.List)
+ {
+ _storages.Add(name, new ListGenericObjects());
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ if (name == null || !_storages.ContainsKey(name))
+ {
+ return;
+ }
+
+ _storages.Remove(name);
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObject? this[string name]
+ {
+ get
+ {
+ if (_storages.ContainsKey(name))
+ {
+ return _storages[name];
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
index f8c83f6..e25c083 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.Designer.cs
@@ -29,27 +29,36 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
- buttonAddTruck = new Button();
- buttonRefresh = new Button();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonGoToCheck = new Button();
- comboBoxSelectorCompany = new ComboBox();
- buttonRemoveTruck = new Button();
+ panelStorage = new Panel();
+ buttonCollectionDel = new Button();
+ buttonCollectionAdd = new Button();
+ listBoxCollection = new ListBox();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
+ buttonCompanyCreate = new Button();
+ panelCompanyTools = new Panel();
buttonAddDumpTruck = new Button();
+ buttonAddTruck = new Button();
+ buttonRemoveTruck = new Button();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
+ panelStorage.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(buttonAddTruck);
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(maskedTextBoxPosition);
- groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(panelStorage);
+ groupBoxTools.Controls.Add(buttonCompanyCreate);
+ groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
- groupBoxTools.Controls.Add(buttonRemoveTruck);
- groupBoxTools.Controls.Add(buttonAddDumpTruck);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(888, 0);
groupBoxTools.Name = "groupBoxTools";
@@ -58,59 +67,132 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // panelStorage
+ //
+ panelStorage.Controls.Add(buttonCollectionDel);
+ panelStorage.Controls.Add(buttonCollectionAdd);
+ panelStorage.Controls.Add(listBoxCollection);
+ 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(232, 274);
+ panelStorage.TabIndex = 12;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(0, 226);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(226, 35);
+ buttonCollectionDel.TabIndex = 13;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(3, 95);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(226, 35);
+ buttonCollectionAdd.TabIndex = 12;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 20;
+ listBoxCollection.Location = new Point(3, 136);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(226, 84);
+ listBoxCollection.TabIndex = 4;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(124, 65);
+ 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(27, 65);
+ 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(3, 32);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(226, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(39, 9);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(155, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции";
+ //
+ // buttonCompanyCreate
+ //
+ buttonCompanyCreate.Location = new Point(6, 337);
+ buttonCompanyCreate.Name = "buttonCompanyCreate";
+ buttonCompanyCreate.Size = new Size(226, 42);
+ buttonCompanyCreate.TabIndex = 11;
+ buttonCompanyCreate.Text = "Создание компанию\r\n";
+ buttonCompanyCreate.Click += ButtonCompanyCreate_Click;
+ //
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddDumpTruck);
+ panelCompanyTools.Controls.Add(buttonAddTruck);
+ panelCompanyTools.Controls.Add(buttonRemoveTruck);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 385);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(232, 300);
+ panelCompanyTools.TabIndex = 10;
+ //
+ // buttonAddDumpTruck
+ //
+ buttonAddDumpTruck.Location = new Point(3, 51);
+ buttonAddDumpTruck.Name = "buttonAddDumpTruck";
+ buttonAddDumpTruck.Size = new Size(226, 48);
+ buttonAddDumpTruck.TabIndex = 2;
+ buttonAddDumpTruck.Text = "Добавление самосвала";
+ buttonAddDumpTruck.UseVisualStyleBackColor = true;
+ buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click;
+ //
// buttonAddTruck
//
- buttonAddTruck.Location = new Point(6, 140);
+ buttonAddTruck.Location = new Point(3, 3);
buttonAddTruck.Name = "buttonAddTruck";
buttonAddTruck.Size = new Size(226, 42);
buttonAddTruck.TabIndex = 0;
buttonAddTruck.Text = "Добваление грузовика";
buttonAddTruck.Click += ButtonAddTruck_Click;
//
- // buttonRefresh
- //
- buttonRefresh.Location = new Point(6, 634);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(226, 48);
- buttonRefresh.TabIndex = 6;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += ButtonRefresh_Click;
- //
- // maskedTextBoxPosition
- //
- maskedTextBoxPosition.Location = new Point(6, 269);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(226, 27);
- maskedTextBoxPosition.TabIndex = 3;
- maskedTextBoxPosition.ValidatingType = typeof(int);
- //
- // buttonGoToCheck
- //
- buttonGoToCheck.Location = new Point(6, 438);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(226, 48);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Передать на тест";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += ButtonGoToCheck_Click;
- //
- // 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(6, 26);
- comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(226, 28);
- comboBoxSelectorCompany.TabIndex = 9;
- comboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged_1;
- //
// buttonRemoveTruck
//
- buttonRemoveTruck.Location = new Point(6, 302);
+ buttonRemoveTruck.Location = new Point(3, 138);
buttonRemoveTruck.Name = "buttonRemoveTruck";
buttonRemoveTruck.Size = new Size(226, 48);
buttonRemoveTruck.TabIndex = 4;
@@ -118,15 +200,46 @@
buttonRemoveTruck.UseVisualStyleBackColor = true;
buttonRemoveTruck.Click += ButtonRemoveTruck_Click;
//
- // buttonAddDumpTruck
+ // buttonRefresh
//
- buttonAddDumpTruck.Location = new Point(6, 188);
- buttonAddDumpTruck.Name = "buttonAddDumpTruck";
- buttonAddDumpTruck.Size = new Size(226, 48);
- buttonAddDumpTruck.TabIndex = 2;
- buttonAddDumpTruck.Text = "Добавление самосвала";
- buttonAddDumpTruck.UseVisualStyleBackColor = true;
- buttonAddDumpTruck.Click += ButtonAddDumpTruck_Click;
+ buttonRefresh.Location = new Point(3, 246);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(226, 48);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(3, 192);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(226, 48);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тест";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(3, 105);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(226, 27);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // 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(6, 303);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(226, 28);
+ comboBoxSelectorCompany.TabIndex = 9;
+ comboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged_1;
//
// pictureBox
//
@@ -147,7 +260,10 @@
Name = "FormTruckCollection";
Text = "Коллекция грузовиков";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -163,5 +279,15 @@
private Button buttonRefresh;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddTruck;
+ private Panel panelCompanyTools;
+ private Button buttonCompanyCreate;
+ private Panel panelStorage;
+ private Button buttonCollectionAdd;
+ private ListBox listBoxCollection;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private Button buttonCollectionDel;
}
}
\ No newline at end of file
diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
index c20919b..ec67500 100644
--- a/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
+++ b/ProjectDumpTruck/ProjectDumpTruck/FormTruckCollection.cs
@@ -19,6 +19,12 @@ namespace ProjectDumpTruck;
///
public partial class FormTruckCollection : Form
{
+
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -30,6 +36,7 @@ public partial class FormTruckCollection : Form
public FormTruckCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -39,12 +46,7 @@ public partial class FormTruckCollection : Form
///
private void СomboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new Autopark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
@@ -67,7 +69,7 @@ public partial class FormTruckCollection : Form
break;
case nameof(DrawningDumpTruck):
drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000),
- GetColor(random), GetColor(random),Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
@@ -192,7 +194,81 @@ public partial class FormTruckCollection : 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);
+ RefreshListBoxItems();
+ }
+
+ 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 ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+
+ if (MessageBox.Show("Вы уверены, что хотите удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RefreshListBoxItems();
+ }
+
+ private void ButtonCompanyCreate_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+
+ ICollectionGenericObject? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
+ if (collection == null)
+ {
+ MessageBox.Show("Коллекция не проинициализирована");
+ return;
+ }
+
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new Autopark(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RefreshListBoxItems();
+ }
}
+