diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..5c3ee7b --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,23 @@ +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..a01d4d6 --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,52 @@ +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 (Count + 1 > _maxCount) return -1; + 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/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..5889dae --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,69 @@ +namespace ProjectAirFighter.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)) return; + if (collectionType == CollectionType.None) return; + else if (collectionType == CollectionType.Massive) + _storages[name] = new MassiveGenericObjects(); + else if (collectionType == CollectionType.List) + _storages[name] = new ListGenericObjects(); + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + 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; + } + } +} + diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs index 0df1b57..3823280 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.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(); buttonRemoveAirCraft = new Button(); @@ -36,13 +45,17 @@ buttonAddAirFighter = new Button(); buttonAddAirCraft = new Button(); comboBoxSelectorCompany = new ComboBox(); + panelCompanyTools = new Panel(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(buttonRefresh); groupBoxTools.Controls.Add(buttonGoToCheck); groupBoxTools.Controls.Add(buttonRemoveAirCraft); @@ -50,6 +63,7 @@ groupBoxTools.Controls.Add(buttonAddAirFighter); groupBoxTools.Controls.Add(buttonAddAirCraft); groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(828, 0); groupBoxTools.Name = "groupBoxTools"; @@ -58,12 +72,105 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonCreateCompany.Location = new Point(17, 316); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(186, 35); + buttonCreateCompany.TabIndex = 8; + 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, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(209, 248); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 217); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(203, 28); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 20; + listBoxCollection.Location = new Point(3, 127); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(203, 84); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 93); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(203, 28); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(120, 63); + 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(14, 63); + 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(203, 27); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(26, 9); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(158, 20); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(17, 536); + buttonRefresh.Location = new Point(17, 585); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(186, 49); + buttonRefresh.Size = new Size(186, 31); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +179,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(17, 381); + buttonGoToCheck.Location = new Point(17, 544); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(186, 49); + buttonGoToCheck.Size = new Size(186, 35); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +190,9 @@ // buttonRemoveAirCraft // buttonRemoveAirCraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveAirCraft.Location = new Point(17, 287); + buttonRemoveAirCraft.Location = new Point(17, 500); buttonRemoveAirCraft.Name = "buttonRemoveAirCraft"; - buttonRemoveAirCraft.Size = new Size(186, 49); + buttonRemoveAirCraft.Size = new Size(186, 38); buttonRemoveAirCraft.TabIndex = 4; buttonRemoveAirCraft.Text = "Удаление самолёта"; buttonRemoveAirCraft.UseVisualStyleBackColor = true; @@ -93,7 +200,7 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(17, 222); + maskedTextBoxPosition.Location = new Point(17, 467); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(186, 27); @@ -103,7 +210,7 @@ // buttonAddAirFighter // buttonAddAirFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirFighter.Location = new Point(17, 147); + buttonAddAirFighter.Location = new Point(17, 412); buttonAddAirFighter.Name = "buttonAddAirFighter"; buttonAddAirFighter.Size = new Size(186, 49); buttonAddAirFighter.TabIndex = 2; @@ -114,7 +221,7 @@ // buttonAddAirCraft // buttonAddAirCraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirCraft.Location = new Point(17, 92); + buttonAddAirCraft.Location = new Point(17, 357); buttonAddAirCraft.Name = "buttonAddAirCraft"; buttonAddAirCraft.Size = new Size(186, 49); buttonAddAirCraft.TabIndex = 1; @@ -128,12 +235,20 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Ангар" }); - comboBoxSelectorCompany.Location = new Point(17, 26); + comboBoxSelectorCompany.Location = new Point(17, 277); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(186, 28); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // + // panelCompanyTools + // + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(6, 352); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(203, 270); + panelCompanyTools.TabIndex = 9; + // // pictureBox // pictureBox.Dock = DockStyle.Fill; @@ -154,6 +269,8 @@ Text = "Коллекция самолётов"; groupBoxTools.ResumeLayout(false); groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -169,5 +286,15 @@ private MaskedTextBox maskedTextBoxPosition; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private Label labelCollectionName; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCreateCompany; + private Button buttonCollectionDel; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs index 6906aa9..050634f 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs @@ -8,6 +8,10 @@ namespace ProjectAirFighter; /// public partial class FormAirCraftCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; /// /// Компания /// @@ -19,6 +23,7 @@ public partial class FormAirCraftCollection : Form public FormAirCraftCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -28,12 +33,7 @@ public partial class FormAirCraftCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Ангар": - _company = new AirCraftAngar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -69,7 +69,6 @@ public partial class FormAirCraftCollection : Form drawningAirCraft = new DrawningAirCraft(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningAirFighter): - // TODO вызов диалогового окна для выбора цвета drawningAirCraft = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), @@ -186,4 +185,98 @@ public partial class FormAirCraftCollection : 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); + RerfreshListBoxItems(); + } + + /// + /// Удаление коллекции + /// + /// + /// + 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()); + 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 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 AirCraftAngar(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } }