diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..de79c68
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace ProjectSeaplane.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..3e94174
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,60 @@
+namespace ProjectSeaplane.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 > _collection.Count)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+ public int Insert(T obj)
+ {
+ return Insert(obj, _collection.Count);
+ }
+ public int Insert(T obj, int position)
+ {
+ if (_maxCount == _collection.Count || position < 0 || position > _collection.Count)
+ {
+ return -1;
+ }
+ _collection.Insert(position, obj);
+ return _collection.Count;
+ }
+ public T? Remove(int position)
+ {
+ if (position < 0 || position > _collection.Count)
+ {
+ return null;
+ }
+ T obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
+ }
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs
index 405596c..840ea93 100644
--- a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -56,19 +56,21 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public int Insert(T obj)
{
- for (int i = 0; i < Count; ++i)
- {
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return i;
- }
- }
- return -1;
+ return Insert(obj, 0);
}
public int Insert(T obj, int position)
{
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+
for (int i = position; i < Count; i++)
{
if (_collection[i] == null)
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..5950c32
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,85 @@
+namespace ProjectSeaplane.CollectionGenericObjects;
+
+///
+/// Класс-хранилище коллекций
+///
+///
+public class StorageCollection
+ where T : class
+{
+ ///
+ /// Словарь (хранилище) с коллекциями
+ ///
+ readonly Dictionary> _storage;
+
+ ///
+ /// Возвращение списка названий коллекций
+ ///
+ public List Keys => _storage.Keys.ToList();
+
+ ///
+ /// Конструктор
+ ///
+ public StorageCollection()
+ {
+ _storage = new Dictionary>();
+ }
+
+ ///
+ /// Добавление коллекции в хранилище
+ ///
+ /// Название коллекции
+ /// тип коллекции
+ public void AddCollection(string name, CollectionType collectionType)
+ {
+ if (string.IsNullOrEmpty(name) || _storage.ContainsKey(name))
+ {
+ return;
+ }
+ if (collectionType == CollectionType.None)
+ {
+ return;
+ }
+ if (collectionType == CollectionType.Massive)
+ {
+ _storage[name] = new MassiveGenericObjects();
+ }
+ else if (collectionType == CollectionType.List)
+ {
+ _storage[name] = new ListGenericObjects();
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ if (name == null || !_storage.ContainsKey(name))
+ {
+ return;
+ }
+ _storage.Remove(name);
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ if (_storage.ContainsKey(name))
+ {
+ return _storage[name];
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
index c25addc..cd005c1 100644
--- a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
+++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.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();
buttonRemovePlane = new Button();
@@ -37,33 +46,126 @@
buttonAddPlane = 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(buttonRemovePlane);
- groupBoxTools.Controls.Add(maskedTextBoxPosition);
- groupBoxTools.Controls.Add(buttonAddSeaplane);
- groupBoxTools.Controls.Add(buttonAddPlane);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(710, 0);
+ groupBoxTools.Location = new Point(793, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(144, 529);
+ groupBoxTools.Size = new Size(144, 571);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCreateCompany.Location = new Point(7, 285);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(126, 30);
+ buttonCreateCompany.TabIndex = 9;
+ 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, 19);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(138, 231);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCollectionDel.Location = new Point(3, 196);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(126, 30);
+ buttonCollectionDel.TabIndex = 8;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(3, 126);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(126, 64);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(4, 81);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(125, 39);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(69, 56);
+ 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(4, 56);
+ 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, 27);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(126, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(4, 9);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(125, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
// buttonRefresh
//
- buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(6, 429);
+ buttonRefresh.Location = new Point(3, 202);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(126, 44);
+ buttonRefresh.Size = new Size(126, 42);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -71,10 +173,9 @@
//
// buttonGoToCheck
//
- buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(6, 346);
+ buttonGoToCheck.Location = new Point(4, 166);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(126, 44);
+ buttonGoToCheck.Size = new Size(126, 30);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -82,10 +183,9 @@
//
// buttonRemovePlane
//
- buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemovePlane.Location = new Point(6, 265);
+ buttonRemovePlane.Location = new Point(4, 130);
buttonRemovePlane.Name = "buttonRemovePlane";
- buttonRemovePlane.Size = new Size(126, 44);
+ buttonRemovePlane.Size = new Size(126, 30);
buttonRemovePlane.TabIndex = 4;
buttonRemovePlane.Text = "Удалить самолёт";
buttonRemovePlane.UseVisualStyleBackColor = true;
@@ -93,7 +193,7 @@
//
// maskedTextBoxPosition
//
- maskedTextBoxPosition.Location = new Point(6, 208);
+ maskedTextBoxPosition.Location = new Point(4, 101);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(126, 23);
@@ -102,8 +202,7 @@
//
// buttonAddSeaplane
//
- buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddSeaplane.Location = new Point(6, 126);
+ buttonAddSeaplane.Location = new Point(3, 51);
buttonAddSeaplane.Name = "buttonAddSeaplane";
buttonAddSeaplane.Size = new Size(126, 44);
buttonAddSeaplane.TabIndex = 2;
@@ -113,8 +212,7 @@
//
// buttonAddPlane
//
- buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddPlane.Location = new Point(6, 78);
+ buttonAddPlane.Location = new Point(4, 3);
buttonAddPlane.Name = "buttonAddPlane";
buttonAddPlane.Size = new Size(126, 42);
buttonAddPlane.TabIndex = 1;
@@ -128,7 +226,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 256);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(126, 23);
comboBoxSelectorCompany.TabIndex = 0;
@@ -139,22 +237,40 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(710, 529);
+ pictureBox.Size = new Size(793, 571);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddPlane);
+ panelCompanyTools.Controls.Add(buttonAddSeaplane);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonRemovePlane);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 320);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(138, 248);
+ panelCompanyTools.TabIndex = 10;
+ //
// FormPlaneCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(854, 529);
+ ClientSize = new Size(937, 571);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormPlaneCollection";
Text = "Коллекция самолётов";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@@ -169,5 +285,15 @@
private PictureBox pictureBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionDel;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
index d6367d8..a953ae7 100644
--- a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
+++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
@@ -8,6 +8,11 @@ namespace ProjectSeaplane;
///
public partial class FormPlaneCollection : Form
{
+ ///
+ /// Хранилише коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -19,6 +24,7 @@ public partial class FormPlaneCollection : Form
public FormPlaneCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -28,12 +34,7 @@ public partial class FormPlaneCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
@@ -183,4 +184,97 @@ public partial class FormPlaneCollection : 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 ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ 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 || 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 PlaneSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RefreshListBoxItems();
+ }
+}
\ No newline at end of file