diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..64adb12
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace ProjectAirbus.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределенно
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..5721d43
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,84 @@
+namespace ProjectAirbus.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)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position >= Count)
+ {
+ 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 (Count == _maxCount)
+ {
+ return -1;
+ }
+ if (position >= Count || position < 0)
+ {
+ 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/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..ab39190
--- /dev/null
+++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,78 @@
+namespace ProjectAirbus.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 (_storages.ContainsKey(name) || collectionType == CollectionType.None)
+ {
+ return;
+ }
+
+ switch (collectionType)
+ {
+ case CollectionType.Massive:
+ _storages[name] = new MassiveGenericObjects();
+ break;
+ case CollectionType.List:
+ _storages[name] = new ListGenericObjects();
+ break;
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ if (_storages.ContainsKey(name) && name != null)
+ {
+ _storages.Remove(name);
+ }
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ if (_storages.ContainsKey(name))
+ {
+ return _storages[name];
+ }
+ return null;
+ }
+ }
+}
diff --git a/ProjectAirbus/ProjectAirbus/FormAirbusCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormAirbusCollection.Designer.cs
index 761286f..46b38f8 100644
--- a/ProjectAirbus/ProjectAirbus/FormAirbusCollection.Designer.cs
+++ b/ProjectAirbus/ProjectAirbus/FormAirbusCollection.Designer.cs
@@ -29,26 +29,35 @@
private void InitializeComponent()
{
groupBocTools = new GroupBox();
- maskedTextBoxPosition = new MaskedTextBox();
- buttonRefresh = new Button();
- buttonGoToCheck = new Button();
- buttonRemoveAirbus = new Button();
- buttonAddBigAirbus = new Button();
+ panelCompanyTools = new Panel();
buttonAddAirbus = new Button();
+ buttonAddBigAirbus = new Button();
+ buttonRemoveAirbus = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonGoToCheck = new Button();
+ buttonRefresh = new Button();
+ 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();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBocTools.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
+ panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBocTools
//
- groupBocTools.Controls.Add(maskedTextBoxPosition);
- groupBocTools.Controls.Add(buttonRefresh);
- groupBocTools.Controls.Add(buttonGoToCheck);
- groupBocTools.Controls.Add(buttonRemoveAirbus);
- groupBocTools.Controls.Add(buttonAddBigAirbus);
- groupBocTools.Controls.Add(buttonAddAirbus);
+ groupBocTools.Controls.Add(panelCompanyTools);
+ groupBocTools.Controls.Add(buttonCreateCompany);
+ groupBocTools.Controls.Add(panelStorage);
groupBocTools.Controls.Add(comboBoxSelectorCompany);
groupBocTools.Dock = DockStyle.Right;
groupBocTools.Location = new Point(867, 0);
@@ -58,61 +67,25 @@
groupBocTools.TabStop = false;
groupBocTools.Text = "Инструменты";
//
- // maskedTextBoxPosition
+ // panelCompanyTools
//
- maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBoxPosition.Location = new Point(6, 205);
- maskedTextBoxPosition.Mask = "00";
- maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- maskedTextBoxPosition.Size = new Size(160, 23);
- maskedTextBoxPosition.TabIndex = 7;
- maskedTextBoxPosition.ValidatingType = typeof(int);
- //
- // buttonRefresh
- //
- buttonRefresh.Location = new Point(6, 413);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(160, 23);
- buttonRefresh.TabIndex = 6;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += buttonRefresh_Click;
- //
- // buttonGoToCheck
- //
- buttonGoToCheck.Location = new Point(6, 328);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(160, 23);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Передать на тесты";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += buttonGoToCheck_Click;
- //
- // buttonRemoveAirbus
- //
- buttonRemoveAirbus.Location = new Point(6, 234);
- buttonRemoveAirbus.Name = "buttonRemoveAirbus";
- buttonRemoveAirbus.Size = new Size(160, 23);
- buttonRemoveAirbus.TabIndex = 4;
- buttonRemoveAirbus.Text = "Удалить аэробус";
- buttonRemoveAirbus.UseVisualStyleBackColor = true;
- buttonRemoveAirbus.Click += buttonRemoveAirbus_Click;
- //
- // buttonAddBigAirbus
- //
- buttonAddBigAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddBigAirbus.Location = new Point(6, 105);
- buttonAddBigAirbus.Name = "buttonAddBigAirbus";
- buttonAddBigAirbus.Size = new Size(160, 47);
- buttonAddBigAirbus.TabIndex = 2;
- buttonAddBigAirbus.Text = "Добавление большого аэробуса";
- buttonAddBigAirbus.UseVisualStyleBackColor = true;
- buttonAddBigAirbus.Click += buttonAddBigAirbus_Click;
+ panelCompanyTools.Controls.Add(buttonAddAirbus);
+ panelCompanyTools.Controls.Add(buttonAddBigAirbus);
+ panelCompanyTools.Controls.Add(buttonRemoveAirbus);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 335);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(166, 198);
+ panelCompanyTools.TabIndex = 10;
//
// buttonAddAirbus
//
buttonAddAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddAirbus.Location = new Point(6, 76);
+ buttonAddAirbus.Location = new Point(3, 3);
buttonAddAirbus.Name = "buttonAddAirbus";
buttonAddAirbus.Size = new Size(160, 23);
buttonAddAirbus.TabIndex = 1;
@@ -120,13 +93,158 @@
buttonAddAirbus.UseVisualStyleBackColor = true;
buttonAddAirbus.Click += buttonAddAirbus_Click;
//
+ // buttonAddBigAirbus
+ //
+ buttonAddBigAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddBigAirbus.Location = new Point(3, 32);
+ buttonAddBigAirbus.Name = "buttonAddBigAirbus";
+ buttonAddBigAirbus.Size = new Size(160, 47);
+ buttonAddBigAirbus.TabIndex = 2;
+ buttonAddBigAirbus.Text = "Добавление большого аэробуса";
+ buttonAddBigAirbus.UseVisualStyleBackColor = true;
+ buttonAddBigAirbus.Click += buttonAddBigAirbus_Click;
+ //
+ // buttonRemoveAirbus
+ //
+ buttonRemoveAirbus.Location = new Point(3, 114);
+ buttonRemoveAirbus.Name = "buttonRemoveAirbus";
+ buttonRemoveAirbus.Size = new Size(160, 23);
+ buttonRemoveAirbus.TabIndex = 4;
+ buttonRemoveAirbus.Text = "Удалить аэробус";
+ buttonRemoveAirbus.UseVisualStyleBackColor = true;
+ buttonRemoveAirbus.Click += buttonRemoveAirbus_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBoxPosition.Location = new Point(3, 85);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(160, 23);
+ maskedTextBoxPosition.TabIndex = 7;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(3, 143);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(160, 23);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += buttonGoToCheck_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(3, 172);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(160, 23);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCreateCompany.Location = new Point(6, 309);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(160, 23);
+ 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(166, 255);
+ panelStorage.TabIndex = 8;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonCollectionDel.Location = new Point(3, 229);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(160, 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, 113);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(160, 109);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(3, 84);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(160, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += buttonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(97, 59);
+ 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(3, 59);
+ 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, 30);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(160, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(20, 12);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(125, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
// 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, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 280);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(160, 23);
comboBoxSelectorCompany.TabIndex = 0;
@@ -150,7 +268,10 @@
Name = "FormAirbusCollection";
Text = "Коллекция аэробусов";
groupBocTools.ResumeLayout(false);
- groupBocTools.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -166,5 +287,15 @@
private Button buttonRefresh;
private PictureBox pictureBox;
private MaskedTextBox maskedTextBoxPosition;
+ private Panel panelStorage;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectAirbus/ProjectAirbus/FormAirbusCollection.cs b/ProjectAirbus/ProjectAirbus/FormAirbusCollection.cs
index 1b40267..d77726c 100644
--- a/ProjectAirbus/ProjectAirbus/FormAirbusCollection.cs
+++ b/ProjectAirbus/ProjectAirbus/FormAirbusCollection.cs
@@ -8,6 +8,11 @@ namespace ProjectAirbus;
///
public partial class FormAirbusCollection : Form
{
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -19,6 +24,7 @@ public partial class FormAirbusCollection : Form
public FormAirbusCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -28,12 +34,7 @@ public partial class FormAirbusCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(Object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new AirbusAerodromeService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
@@ -184,4 +185,101 @@ public partial class FormAirbusCollection : 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 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+
+ if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ 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.SelectedItems == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+
+ ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
+ if (collection == null)
+ {
+ MessageBox.Show("Коллекция не проинициализирована");
+ return;
+ }
+
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new AirbusAerodromeService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+
+ panelCompanyTools.Enabled = true;
+ RefreshListBoxItems();
+ }
}