diff --git a/AirBomber/CollectionGenericObjects/CollectionType.cs b/AirBomber/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..95543b7
--- /dev/null
+++ b/AirBomber/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber.CollectionGenericObjects;
+
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/AirBomber/CollectionGenericObjects/ListGenericObjects.cs b/AirBomber/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..994f56e
--- /dev/null
+++ b/AirBomber/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber.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 >= 0 && position < Count)
+ {
+ return _collection[position];
+ }
+ else
+ {
+ return null;
+ }
+
+ }
+
+ public int Insert(T obj)
+ {
+ if (Count == _maxCount) { return -1; }
+ _collection.Add(obj);
+ return Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ if (position < 0 || position >= Count || 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;
+ }
+}
\ No newline at end of file
diff --git a/AirBomber/CollectionGenericObjects/MassiveGenericObjects.cs b/AirBomber/CollectionGenericObjects/MassiveGenericObjects.cs
index 6daabe1..51ce63d 100644
--- a/AirBomber/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/AirBomber/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -5,7 +5,6 @@ using System.Text;
using System.Threading.Tasks;
namespace AirBomber.CollectionGenericObjects;
-
public class MassiveGenericObjects : ICollectionGenericObjects
where T : class
{
diff --git a/AirBomber/CollectionGenericObjects/StorageCollection.cs b/AirBomber/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..affbd6d
--- /dev/null
+++ b/AirBomber/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber.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)
+ {
+ if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
+ {
+ return;
+ }
+ switch (collectionType)
+ {
+ case CollectionType.Massive:
+ _storages[name] = new MassiveGenericObjects();
+ break;
+ case CollectionType.List:
+ _storages[name] = new ListGenericObjects();
+ break;
+ default:
+ return;
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ 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];
+ }
+ return null;
+ }
+ }
+}
\ No newline at end of file
diff --git a/AirBomber/FormAirPlaneCollection.Designer.cs b/AirBomber/FormAirPlaneCollection.Designer.cs
index fce231a..72ec465 100644
--- a/AirBomber/FormAirPlaneCollection.Designer.cs
+++ b/AirBomber/FormAirPlaneCollection.Designer.cs
@@ -29,6 +29,15 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ 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();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonDelAirPlane = new Button();
@@ -37,35 +46,127 @@
buttonAddAirPlane = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
+ panelCompanyTools = new Panel();
groupBoxTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ panelCompanyTools.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonDelAirPlane);
- groupBoxTools.Controls.Add(maskedTextBox);
- groupBoxTools.Controls.Add(buttonAddAirBomber);
- groupBoxTools.Controls.Add(buttonAddAirPlane);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(906, 0);
+ groupBoxTools.Location = new Point(859, 0);
groupBoxTools.Margin = new Padding(3, 4, 3, 4);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Padding = new Padding(3, 4, 3, 4);
- groupBoxTools.Size = new Size(191, 859);
+ groupBoxTools.Size = new Size(238, 859);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструманты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(16, 366);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(207, 49);
+ buttonCreateCompany.TabIndex = 7;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += buttonCreateCompany_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, 24);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(232, 304);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(13, 271);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(210, 29);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллецию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += buttonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 20;
+ listBoxCollection.Location = new Point(3, 161);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(220, 104);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(13, 126);
+ 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(101, 96);
+ 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(13, 96);
+ 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, 53);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(226, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(13, 12);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(151, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллеции:";
+ //
// buttonRefresh
//
- buttonRefresh.Location = new Point(14, 617);
+ buttonRefresh.Location = new Point(7, 243);
buttonRefresh.Margin = new Padding(3, 4, 3, 4);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(163, 57);
+ buttonRefresh.Size = new Size(200, 29);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -73,10 +174,10 @@
//
// buttonGoToCheck
//
- buttonGoToCheck.Location = new Point(14, 493);
+ buttonGoToCheck.Location = new Point(7, 205);
buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(163, 55);
+ buttonGoToCheck.Size = new Size(200, 30);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -85,10 +186,10 @@
// buttonDelAirPlane
//
buttonDelAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonDelAirPlane.Location = new Point(14, 367);
+ buttonDelAirPlane.Location = new Point(7, 166);
buttonDelAirPlane.Margin = new Padding(3, 4, 3, 4);
buttonDelAirPlane.Name = "buttonDelAirPlane";
- buttonDelAirPlane.Size = new Size(163, 52);
+ buttonDelAirPlane.Size = new Size(200, 31);
buttonDelAirPlane.TabIndex = 4;
buttonDelAirPlane.Text = "Удалить Самолет";
buttonDelAirPlane.UseVisualStyleBackColor = true;
@@ -96,21 +197,21 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(14, 328);
+ maskedTextBox.Location = new Point(7, 131);
maskedTextBox.Margin = new Padding(3, 4, 3, 4);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
- maskedTextBox.Size = new Size(163, 27);
+ maskedTextBox.Size = new Size(200, 27);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddAirBomber
//
buttonAddAirBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddAirBomber.Location = new Point(14, 165);
+ buttonAddAirBomber.Location = new Point(7, 67);
buttonAddAirBomber.Margin = new Padding(3, 4, 3, 4);
buttonAddAirBomber.Name = "buttonAddAirBomber";
- buttonAddAirBomber.Size = new Size(163, 56);
+ buttonAddAirBomber.Size = new Size(200, 56);
buttonAddAirBomber.TabIndex = 2;
buttonAddAirBomber.Text = "Добавление Бомбардировщика";
buttonAddAirBomber.UseVisualStyleBackColor = true;
@@ -119,10 +220,10 @@
// buttonAddAirPlane
//
buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddAirPlane.Location = new Point(14, 103);
+ buttonAddAirPlane.Location = new Point(7, 4);
buttonAddAirPlane.Margin = new Padding(3, 4, 3, 4);
buttonAddAirPlane.Name = "buttonAddAirPlane";
- buttonAddAirPlane.Size = new Size(163, 55);
+ buttonAddAirPlane.Size = new Size(200, 55);
buttonAddAirPlane.TabIndex = 1;
buttonAddAirPlane.Text = "Добавление самолета";
buttonAddAirPlane.UseVisualStyleBackColor = true;
@@ -134,10 +235,10 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(14, 41);
+ comboBoxSelectorCompany.Location = new Point(16, 331);
comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(163, 28);
+ comboBoxSelectorCompany.Size = new Size(210, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
@@ -147,10 +248,23 @@
pictureBox.Location = new Point(0, 0);
pictureBox.Margin = new Padding(3, 4, 3, 4);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(906, 859);
+ pictureBox.Size = new Size(859, 859);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddAirPlane);
+ panelCompanyTools.Controls.Add(buttonAddAirBomber);
+ panelCompanyTools.Controls.Add(maskedTextBox);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonDelAirPlane);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Location = new Point(16, 456);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(210, 285);
+ panelCompanyTools.TabIndex = 8;
+ //
// FormAirPlaneCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
@@ -163,8 +277,11 @@
Text = "FormAirPlaneCollection";
Load += FormAirPlaneCollection_Load;
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@@ -179,5 +296,15 @@
private Button buttonDelAirPlane;
private MaskedTextBox maskedTextBox;
private Button buttonRefresh;
+ private Panel panelStorage;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Button buttonCollectionAdd;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/AirBomber/FormAirPlaneCollection.cs b/AirBomber/FormAirPlaneCollection.cs
index 3d7b7f1..fa58111 100644
--- a/AirBomber/FormAirPlaneCollection.cs
+++ b/AirBomber/FormAirPlaneCollection.cs
@@ -14,6 +14,11 @@ namespace AirBomber
{
public partial class FormAirPlaneCollection : Form
{
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -25,6 +30,7 @@ namespace AirBomber
public FormAirPlaneCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -34,12 +40,7 @@ namespace AirBomber
///
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new AirPlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
@@ -194,5 +195,84 @@ namespace AirBomber
{
}
+
+ 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.SelectedItems == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RefreshListBoxItems();
+ }
+ ///
+ /// Создание компании
+ ///
+ ///
+ ///
+ 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 AirPlaneSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+
+ panelCompanyTools.Enabled = true;
+ RefreshListBoxItems();
+ }
}
}