diff --git a/AirFighter/AirFighter/CollectionGenericObjects/CollectionType.cs b/AirFighter/AirFighter/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..62b303c --- /dev/null +++ b/AirFighter/AirFighter/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,22 @@ +namespace ProjectAirFighter.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..daf6f3c --- /dev/null +++ b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,60 @@ +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? pos = _collection[position]; + _collection.RemoveAt(position); + return pos; + } +} \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..c1cc672 --- /dev/null +++ b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,73 @@ +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 (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]; + } + } +} \ No newline at end of file diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs index 2b99441..9c271e1 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.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(); + textBoxCollectionName = new TextBox(); + radioButtonMassive = new RadioButton(); + radioButtonList = new RadioButton(); + labelCollectionName = new Label(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); buttonRemoveMilitaryAircraft = new Button(); @@ -37,33 +46,125 @@ buttonAddMilitaryAircraft = 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(buttonRemoveMilitaryAircraft); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddAirFighter); - groupBoxTools.Controls.Add(buttonAddMilitaryAircraft); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(610, 0); + groupBoxTools.Location = new Point(744, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(190, 450); + groupBoxTools.Size = new Size(206, 667); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(7, 322); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(191, 29); + 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(textBoxCollectionName); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(200, 256); + panelStorage.TabIndex = 8; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(6, 224); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(189, 29); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удаление коллекции"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 20; + listBoxCollection.Location = new Point(6, 131); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(189, 84); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(6, 96); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(189, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(6, 33); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(189, 27); + textBoxCollectionName.TabIndex = 3; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(6, 66); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(82, 24); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(115, 66); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(80, 24); + radioButtonList.TabIndex = 1; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(17, 10); + 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(9, 389); + buttonRefresh.Location = new Point(3, 252); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(175, 49); + buttonRefresh.Size = new Size(192, 49); buttonRefresh.TabIndex = 7; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +173,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(9, 316); + buttonGoToCheck.Location = new Point(3, 197); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(175, 49); + buttonGoToCheck.Size = new Size(192, 49); buttonGoToCheck.TabIndex = 6; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +184,9 @@ // buttonRemoveMilitaryAircraft // buttonRemoveMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveMilitaryAircraft.Location = new Point(9, 234); + buttonRemoveMilitaryAircraft.Location = new Point(4, 142); buttonRemoveMilitaryAircraft.Name = "buttonRemoveMilitaryAircraft"; - buttonRemoveMilitaryAircraft.Size = new Size(175, 49); + buttonRemoveMilitaryAircraft.Size = new Size(191, 49); buttonRemoveMilitaryAircraft.TabIndex = 5; buttonRemoveMilitaryAircraft.Text = "Удаление военного самолёта"; buttonRemoveMilitaryAircraft.UseVisualStyleBackColor = true; @@ -94,19 +195,19 @@ // maskedTextBoxPosition // maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBoxPosition.Location = new Point(9, 201); + maskedTextBoxPosition.Location = new Point(3, 109); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(175, 27); + maskedTextBoxPosition.Size = new Size(192, 27); maskedTextBoxPosition.TabIndex = 4; maskedTextBoxPosition.ValidatingType = typeof(int); // // buttonAddAirFighter // buttonAddAirFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirFighter.Location = new Point(9, 128); + buttonAddAirFighter.Location = new Point(3, 54); buttonAddAirFighter.Name = "buttonAddAirFighter"; - buttonAddAirFighter.Size = new Size(175, 49); + buttonAddAirFighter.Size = new Size(192, 49); buttonAddAirFighter.TabIndex = 2; buttonAddAirFighter.Text = "Добавление истребителя"; buttonAddAirFighter.UseVisualStyleBackColor = true; @@ -115,9 +216,9 @@ // buttonAddMilitaryAircraft // buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddMilitaryAircraft.Location = new Point(9, 73); + buttonAddMilitaryAircraft.Location = new Point(4, 3); buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft"; - buttonAddMilitaryAircraft.Size = new Size(175, 49); + buttonAddMilitaryAircraft.Size = new Size(191, 49); buttonAddMilitaryAircraft.TabIndex = 1; buttonAddMilitaryAircraft.Text = "Добавление военного самолёта"; buttonAddMilitaryAircraft.UseVisualStyleBackColor = true; @@ -129,9 +230,9 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(9, 26); + comboBoxSelectorCompany.Location = new Point(7, 285); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(175, 28); + comboBoxSelectorCompany.Size = new Size(193, 28); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // @@ -140,22 +241,40 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(610, 450); + pictureBox.Size = new Size(744, 667); pictureBox.TabIndex = 3; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRemoveMilitaryAircraft); + panelCompanyTools.Controls.Add(buttonAddMilitaryAircraft); + panelCompanyTools.Controls.Add(buttonAddAirFighter); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 357); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(200, 307); + panelCompanyTools.TabIndex = 10; + // // FormMilitaryAircraftCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(950, 667); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormMilitaryAircraftCollection"; Text = "Коллекция военных самолётов"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -170,5 +289,15 @@ private Button buttonRefresh; private Button buttonGoToCheck; private Button buttonRemoveMilitaryAircraft; + private Panel panelStorage; + private TextBox textBoxCollectionName; + private RadioButton radioButtonMassive; + private RadioButton radioButtonList; + private Label labelCollectionName; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs index 20434d1..5f83bc8 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs @@ -5,6 +5,11 @@ namespace ProjectAirFighter; public partial class FormMilitaryAircraftCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -16,6 +21,7 @@ public partial class FormMilitaryAircraftCollection : Form public FormMilitaryAircraftCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -25,12 +31,7 @@ public partial class FormMilitaryAircraftCollection : Form /// private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Angar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -178,4 +179,81 @@ public partial class FormMilitaryAircraftCollection : 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.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + + 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 Angar(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } }