diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..f891363
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.CollectionGenericObjects;
+
+///
+/// Перечисление типов коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+
+}
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..9d43c01
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,83 @@
+using ProjectAirFighter.CollectionGenericObject;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.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 + 1 > _maxCount)
+ {
+ return -1;
+ }
+ //вставка в конец набора
+ _collection.Add(obj);
+ return Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ //проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+ //вставка по позиции
+ _collection.Insert(position,obj);
+ return 1;
+ }
+
+ public T? Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ T? temp = _collection[position];
+ _collection.RemoveAt(position);
+ return temp;
+ }
+}
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
index b398a65..24add23 100644
--- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -17,11 +17,26 @@ public class MassiveGenericObjects : ICollectionGenericObjects
///
/// Массив объектов, которые хроним
///
- private T[] _collection;
+ private T?[] _collection;
public int Count => _collection.Length;
- public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (Count > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
///
/// Конструктор
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..cc7d23f
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,96 @@
+using ProjectAirFighter.CollectionGenericObject;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.CollectionGenericObjects;
+
+///
+/// Класс-хранилище коллекций
+///
+///
+public class StorageCollection
+ where T : class
+{
+ ///
+ /// Словарь (хранилище) с коллекциями
+ ///
+ private 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;
+ }
+
+ 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)
+ {
+ if (_storages.ContainsKey(name))
+ {
+ _storages.Remove(name);
+ }
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ ///
+ ///
+ public ICollectionGenericObjects this[string name]
+ {
+ get
+ {
+ //логика получения объекта
+ if(name == null || !_storages.ContainsKey(name))
+ return null;
+
+ return _storages[name];
+ }
+ }
+
+ public ICollectionGenericObjects? this[int index]
+ {
+ get
+ {
+ //логика получения объекта
+ if (index > Keys.Count || index < 0)
+ return null;
+
+ return _storages[Keys[index]];
+ }
+ }
+}
diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs
index fe4b41d..3124f9a 100644
--- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs
+++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs
@@ -29,93 +29,224 @@
private void InitializeComponent()
{
groupBox1 = new GroupBox();
- button1 = new Button();
- buttonGoToCheck = new Button();
+ panelCompanyTools = new Panel();
buttonRemove = new Button();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonAddAirFighter = new Button();
buttonAddWarPlane = new Button();
+ button1 = new Button();
+ buttonAddAirFighter = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonGoToCheck = new Button();
+ buttonCreateCompany = new Button();
+ panelStorage = new Panel();
+ buttonCollectionRemove = 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();
groupBox1.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBox1
//
- groupBox1.Controls.Add(button1);
- groupBox1.Controls.Add(buttonGoToCheck);
- groupBox1.Controls.Add(buttonRemove);
- groupBox1.Controls.Add(maskedTextBoxPosition);
- groupBox1.Controls.Add(buttonAddAirFighter);
- groupBox1.Controls.Add(buttonAddWarPlane);
+ groupBox1.Controls.Add(panelCompanyTools);
+ groupBox1.Controls.Add(buttonCreateCompany);
+ groupBox1.Controls.Add(panelStorage);
groupBox1.Controls.Add(comboBoxSelectorCompany);
groupBox1.Dock = DockStyle.Right;
- groupBox1.Location = new Point(626, 0);
+ groupBox1.Location = new Point(753, 0);
+ groupBox1.Margin = new Padding(3, 4, 3, 4);
groupBox1.Name = "groupBox1";
- groupBox1.Size = new Size(174, 450);
+ groupBox1.Padding = new Padding(3, 4, 3, 4);
+ groupBox1.Size = new Size(199, 884);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
- // button1
+ // panelCompanyTools
//
- button1.Location = new Point(6, 400);
- button1.Name = "button1";
- button1.Size = new Size(162, 44);
- button1.TabIndex = 6;
- button1.Text = "Обновить";
- button1.UseVisualStyleBackColor = true;
- button1.Click += ButtonRefresh_Click;
- //
- // buttonGoToCheck
- //
- buttonGoToCheck.Location = new Point(6, 326);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(162, 44);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Передать на тест";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ panelCompanyTools.Controls.Add(buttonRemove);
+ panelCompanyTools.Controls.Add(buttonAddWarPlane);
+ panelCompanyTools.Controls.Add(button1);
+ panelCompanyTools.Controls.Add(buttonAddAirFighter);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(0, 497);
+ panelCompanyTools.Margin = new Padding(3, 4, 3, 4);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(199, 371);
+ panelCompanyTools.TabIndex = 9;
//
// buttonRemove
//
- buttonRemove.Location = new Point(6, 249);
+ buttonRemove.Location = new Point(7, 193);
+ buttonRemove.Margin = new Padding(3, 4, 3, 4);
buttonRemove.Name = "buttonRemove";
- buttonRemove.Size = new Size(162, 44);
+ buttonRemove.Size = new Size(185, 59);
buttonRemove.TabIndex = 4;
buttonRemove.Text = "Удалить самолет";
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += ButtonRemove_Click;
//
- // maskedTextBoxPosition
+ // buttonAddWarPlane
//
- maskedTextBoxPosition.Location = new Point(6, 220);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(162, 23);
- maskedTextBoxPosition.TabIndex = 3;
- maskedTextBoxPosition.ValidatingType = typeof(int);
+ buttonAddWarPlane.Location = new Point(7, 4);
+ buttonAddWarPlane.Margin = new Padding(3, 4, 3, 4);
+ buttonAddWarPlane.Name = "buttonAddWarPlane";
+ buttonAddWarPlane.Size = new Size(185, 69);
+ buttonAddWarPlane.TabIndex = 1;
+ buttonAddWarPlane.Text = "Добавление военного самолета";
+ buttonAddWarPlane.UseVisualStyleBackColor = true;
+ buttonAddWarPlane.Click += ButtonAddWarPlane_Click;
+ //
+ // button1
+ //
+ button1.Location = new Point(7, 327);
+ button1.Margin = new Padding(3, 4, 3, 4);
+ button1.Name = "button1";
+ button1.Size = new Size(185, 40);
+ button1.TabIndex = 6;
+ button1.Text = "Обновить";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += ButtonRefresh_Click;
//
// buttonAddAirFighter
//
- buttonAddAirFighter.Location = new Point(6, 130);
+ buttonAddAirFighter.Location = new Point(7, 81);
+ buttonAddAirFighter.Margin = new Padding(3, 4, 3, 4);
buttonAddAirFighter.Name = "buttonAddAirFighter";
- buttonAddAirFighter.Size = new Size(162, 44);
+ buttonAddAirFighter.Size = new Size(185, 59);
buttonAddAirFighter.TabIndex = 2;
buttonAddAirFighter.Text = "Добавление истребителя";
buttonAddAirFighter.UseVisualStyleBackColor = true;
buttonAddAirFighter.Click += ButtonAddAirFighter_Click;
//
- // buttonAddWarPlane
+ // maskedTextBoxPosition
//
- buttonAddWarPlane.Location = new Point(6, 72);
- buttonAddWarPlane.Name = "buttonAddWarPlane";
- buttonAddWarPlane.Size = new Size(162, 52);
- buttonAddWarPlane.TabIndex = 1;
- buttonAddWarPlane.Text = "Добавление военного самолета";
- buttonAddWarPlane.UseVisualStyleBackColor = true;
- buttonAddWarPlane.Click += ButtonAddWarPlane_Click;
+ maskedTextBoxPosition.Location = new Point(9, 148);
+ maskedTextBoxPosition.Margin = new Padding(3, 4, 3, 4);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(185, 27);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(7, 260);
+ buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(185, 59);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тест";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(7, 459);
+ buttonCreateCompany.Margin = new Padding(3, 4, 3, 4);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(185, 31);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += buttonCreateCompany_Click;
+ //
+ // panelStorage
+ //
+ panelStorage.Controls.Add(buttonCollectionRemove);
+ 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.Margin = new Padding(3, 4, 3, 4);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(193, 361);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionRemove
+ //
+ buttonCollectionRemove.Location = new Point(3, 280);
+ buttonCollectionRemove.Margin = new Padding(3, 4, 3, 4);
+ buttonCollectionRemove.Name = "buttonCollectionRemove";
+ buttonCollectionRemove.Size = new Size(185, 31);
+ buttonCollectionRemove.TabIndex = 6;
+ buttonCollectionRemove.Text = "Удалить коллекцию";
+ buttonCollectionRemove.UseVisualStyleBackColor = true;
+ buttonCollectionRemove.Click += buttonCollectionRemove_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.Location = new Point(3, 147);
+ listBoxCollection.Margin = new Padding(3, 4, 3, 4);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(185, 124);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(3, 108);
+ buttonCollectionAdd.Margin = new Padding(3, 4, 3, 4);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(185, 31);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += buttonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(105, 75);
+ radioButtonList.Margin = new Padding(3, 4, 3, 4);
+ 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(3, 75);
+ radioButtonMassive.Margin = new Padding(3, 4, 3, 4);
+ 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, 36);
+ textBoxCollectionName.Margin = new Padding(3, 4, 3, 4);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(185, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(24, 12);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(158, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
//
// comboBoxSelectorCompany
//
@@ -123,9 +254,10 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 22);
+ comboBoxSelectorCompany.Location = new Point(7, 416);
+ comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(162, 23);
+ comboBoxSelectorCompany.Size = new Size(185, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
@@ -133,22 +265,28 @@
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
+ pictureBox.Margin = new Padding(3, 4, 3, 4);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(626, 450);
+ pictureBox.Size = new Size(753, 884);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
+
//
// FormWarPlaneCollection
//
- AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(800, 450);
+ ClientSize = new Size(952, 884);
Controls.Add(pictureBox);
Controls.Add(groupBox1);
+ Margin = new Padding(3, 4, 3, 4);
Name = "FormWarPlaneCollection";
Text = "Коллекция военных самолетов";
groupBox1.ResumeLayout(false);
- groupBox1.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -164,5 +302,15 @@
private Button buttonRemove;
private Button buttonGoToCheck;
private Button button1;
+ private Panel panelStorage;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Button buttonCreateCompany;
+ private Button buttonCollectionRemove;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs
index aa641ff..0a9b329 100644
--- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs
+++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs
@@ -1,4 +1,5 @@
-using ProjectAirFighter.CollectionGenericObjects;
+using ProjectAirFighter.CollectionGenericObject;
+using ProjectAirFighter.CollectionGenericObjects;
using ProjectAirFighter.Drawning;
using System;
using System.Collections.Generic;
@@ -14,20 +15,33 @@ namespace ProjectAirFighter;
public partial class FormWarPlaneCollection : Form
{
+ ///
+ /// Хранилище коолекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
+ ///
+ /// Компания
+ ///
private AbstractCompany? _company;
+
+ ///
+ /// Конструктор
+ ///
public FormWarPlaneCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new WarPlaneBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
private void CreateObject(string type)
@@ -45,7 +59,7 @@ public partial class FormWarPlaneCollection : Form
break;
case nameof(DrawningAirFighter):
drawningWarPlane = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000),
- GetColor(random), GetColor(random),
+ GetColor(random),GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
@@ -91,7 +105,7 @@ public partial class FormWarPlaneCollection : Form
return;
}
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
@@ -118,7 +132,7 @@ public partial class FormWarPlaneCollection : Form
DrawningWarPlane? warPlane = null;
int counter = 100;
- while(warPlane == null)
+ while (warPlane == null)
{
warPlane = _company.GetRandomObject();
counter--;
@@ -128,7 +142,8 @@ public partial class FormWarPlaneCollection : Form
}
}
- if (warPlane == null) {
+ if (warPlane == null)
+ {
return;
}
@@ -145,9 +160,103 @@ public partial class FormWarPlaneCollection : Form
{
return;
}
-
+
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();
+ }
+ ///
+ /// Обновление списка в 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 buttonCollectionRemove_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ 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 WarPlaneBase(pictureBox.Width,
+ pictureBox.Height, collection);
+ break;
+ }
+
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+
+ }
+
+
}