From dd60ab32197edba715c8c98787ad82ae9053349b Mon Sep 17 00:00:00 2001 From: nezui1 <104579567+nezui1@users.noreply.github.com> Date: Sat, 6 Apr 2024 14:58:10 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../CollectionType.cs | 26 ++ .../ListGenericObjects.cs | 83 ++++++ .../StorageCollection.cs | 84 +++++++ .../FormWarPlaneCollection.Designer.cs | 238 ++++++++++++++---- .../FormWarPlaneCollection.cs | 132 +++++++++- 6 files changed, 497 insertions(+), 68 deletions(-) create mode 100644 ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs index eca1f2e..a703a8e 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -50,7 +50,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount - 4; + _collection.SetMaxCount = GetMaxCount - 3; } /// diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..cb362ec --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,26 @@ +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/StorageCollection.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..a8a4bdd --- /dev/null +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,84 @@ +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]; + } + } +} diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs index fe4b41d..81705da 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs @@ -29,58 +29,61 @@ 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(659, 0); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(174, 450); + groupBox1.Size = new Size(174, 663); 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, 373); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(174, 278); + panelCompanyTools.TabIndex = 9; // // buttonRemove // - buttonRemove.Location = new Point(6, 249); + buttonRemove.Location = new Point(6, 145); buttonRemove.Name = "buttonRemove"; buttonRemove.Size = new Size(162, 44); buttonRemove.TabIndex = 4; @@ -88,28 +91,9 @@ buttonRemove.UseVisualStyleBackColor = true; buttonRemove.Click += ButtonRemove_Click; // - // maskedTextBoxPosition - // - 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); - // - // buttonAddAirFighter - // - buttonAddAirFighter.Location = new Point(6, 130); - buttonAddAirFighter.Name = "buttonAddAirFighter"; - buttonAddAirFighter.Size = new Size(162, 44); - buttonAddAirFighter.TabIndex = 2; - buttonAddAirFighter.Text = "Добавление истребителя"; - buttonAddAirFighter.UseVisualStyleBackColor = true; - buttonAddAirFighter.Click += ButtonAddAirFighter_Click; - // // buttonAddWarPlane // - buttonAddWarPlane.Location = new Point(6, 72); + buttonAddWarPlane.Location = new Point(6, 3); buttonAddWarPlane.Name = "buttonAddWarPlane"; buttonAddWarPlane.Size = new Size(162, 52); buttonAddWarPlane.TabIndex = 1; @@ -117,13 +101,144 @@ buttonAddWarPlane.UseVisualStyleBackColor = true; buttonAddWarPlane.Click += ButtonAddWarPlane_Click; // + // button1 + // + button1.Location = new Point(6, 245); + button1.Name = "button1"; + button1.Size = new Size(162, 30); + button1.TabIndex = 6; + button1.Text = "Обновить"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonRefresh_Click; + // + // buttonAddAirFighter + // + buttonAddAirFighter.Location = new Point(6, 61); + buttonAddAirFighter.Name = "buttonAddAirFighter"; + buttonAddAirFighter.Size = new Size(162, 44); + buttonAddAirFighter.TabIndex = 2; + buttonAddAirFighter.Text = "Добавление истребителя"; + buttonAddAirFighter.UseVisualStyleBackColor = true; + buttonAddAirFighter.Click += ButtonAddAirFighter_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(8, 111); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(162, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(6, 195); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(162, 44); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тест"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 344); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(162, 23); + 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, 19); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(168, 271); + panelStorage.TabIndex = 7; + // + // buttonCollectionRemove + // + buttonCollectionRemove.Location = new Point(3, 210); + buttonCollectionRemove.Name = "buttonCollectionRemove"; + buttonCollectionRemove.Size = new Size(162, 23); + buttonCollectionRemove.TabIndex = 6; + buttonCollectionRemove.Text = "Удалить коллекцию"; + buttonCollectionRemove.UseVisualStyleBackColor = true; + buttonCollectionRemove.Click += buttonCollectionRemove_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(3, 110); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(162, 94); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 81); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(162, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(92, 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(3, 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(162, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(21, 9); + 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, 312); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(162, 23); comboBoxSelectorCompany.TabIndex = 0; @@ -134,7 +249,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(626, 450); + pictureBox.Size = new Size(659, 663); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -142,13 +257,16 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(833, 663); Controls.Add(pictureBox); Controls.Add(groupBox1); 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 +282,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..e442a76 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,8 @@ public partial class FormWarPlaneCollection : Form break; case nameof(DrawningAirFighter): drawningWarPlane = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), GetColor(random), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -91,7 +106,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 +133,7 @@ public partial class FormWarPlaneCollection : Form DrawningWarPlane? warPlane = null; int counter = 100; - while(warPlane == null) + while (warPlane == null) { warPlane = _company.GetRandomObject(); counter--; @@ -128,7 +143,8 @@ public partial class FormWarPlaneCollection : Form } } - if (warPlane == null) { + if (warPlane == null) + { return; } @@ -145,9 +161,101 @@ 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(); + + } } -- 2.25.1 From d3ebbc092dde75e4a8b962c0528ea1003052aba7 Mon Sep 17 00:00:00 2001 From: nezui1 Date: Sat, 6 Apr 2024 14:06:20 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../FormWarPlaneCollection.Designer.cs | 100 +++++++++++------- .../FormWarPlaneCollection.cs | 13 +-- 3 files changed, 68 insertions(+), 47 deletions(-) diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs index a703a8e..eca1f2e 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs @@ -50,7 +50,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount - 3; + _collection.SetMaxCount = GetMaxCount - 4; } /// diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs index 81705da..3124f9a 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.Designer.cs @@ -60,9 +60,11 @@ groupBox1.Controls.Add(panelStorage); groupBox1.Controls.Add(comboBoxSelectorCompany); groupBox1.Dock = DockStyle.Right; - groupBox1.Location = new Point(659, 0); + groupBox1.Location = new Point(753, 0); + groupBox1.Margin = new Padding(3, 4, 3, 4); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(174, 663); + groupBox1.Padding = new Padding(3, 4, 3, 4); + groupBox1.Size = new Size(199, 884); groupBox1.TabIndex = 0; groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; @@ -76,16 +78,18 @@ panelCompanyTools.Controls.Add(maskedTextBoxPosition); panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(0, 373); + panelCompanyTools.Location = new Point(0, 497); + panelCompanyTools.Margin = new Padding(3, 4, 3, 4); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(174, 278); + panelCompanyTools.Size = new Size(199, 371); panelCompanyTools.TabIndex = 9; // // buttonRemove // - buttonRemove.Location = new Point(6, 145); + 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; @@ -93,9 +97,10 @@ // // buttonAddWarPlane // - buttonAddWarPlane.Location = new Point(6, 3); + buttonAddWarPlane.Location = new Point(7, 4); + buttonAddWarPlane.Margin = new Padding(3, 4, 3, 4); buttonAddWarPlane.Name = "buttonAddWarPlane"; - buttonAddWarPlane.Size = new Size(162, 52); + buttonAddWarPlane.Size = new Size(185, 69); buttonAddWarPlane.TabIndex = 1; buttonAddWarPlane.Text = "Добавление военного самолета"; buttonAddWarPlane.UseVisualStyleBackColor = true; @@ -103,9 +108,10 @@ // // button1 // - button1.Location = new Point(6, 245); + button1.Location = new Point(7, 327); + button1.Margin = new Padding(3, 4, 3, 4); button1.Name = "button1"; - button1.Size = new Size(162, 30); + button1.Size = new Size(185, 40); button1.TabIndex = 6; button1.Text = "Обновить"; button1.UseVisualStyleBackColor = true; @@ -113,9 +119,10 @@ // // buttonAddAirFighter // - buttonAddAirFighter.Location = new Point(6, 61); + 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; @@ -123,18 +130,20 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(8, 111); + maskedTextBoxPosition.Location = new Point(9, 148); + maskedTextBoxPosition.Margin = new Padding(3, 4, 3, 4); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(162, 23); + maskedTextBoxPosition.Size = new Size(185, 27); maskedTextBoxPosition.TabIndex = 3; maskedTextBoxPosition.ValidatingType = typeof(int); // // buttonGoToCheck // - buttonGoToCheck.Location = new Point(6, 195); + buttonGoToCheck.Location = new Point(7, 260); + buttonGoToCheck.Margin = new Padding(3, 4, 3, 4); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(162, 44); + buttonGoToCheck.Size = new Size(185, 59); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тест"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -142,9 +151,10 @@ // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(6, 344); + buttonCreateCompany.Location = new Point(7, 459); + buttonCreateCompany.Margin = new Padding(3, 4, 3, 4); buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(162, 23); + buttonCreateCompany.Size = new Size(185, 31); buttonCreateCompany.TabIndex = 8; buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.UseVisualStyleBackColor = true; @@ -160,16 +170,18 @@ panelStorage.Controls.Add(textBoxCollectionName); panelStorage.Controls.Add(labelCollectionName); panelStorage.Dock = DockStyle.Top; - panelStorage.Location = new Point(3, 19); + panelStorage.Location = new Point(3, 24); + panelStorage.Margin = new Padding(3, 4, 3, 4); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(168, 271); + panelStorage.Size = new Size(193, 361); panelStorage.TabIndex = 7; // // buttonCollectionRemove // - buttonCollectionRemove.Location = new Point(3, 210); + buttonCollectionRemove.Location = new Point(3, 280); + buttonCollectionRemove.Margin = new Padding(3, 4, 3, 4); buttonCollectionRemove.Name = "buttonCollectionRemove"; - buttonCollectionRemove.Size = new Size(162, 23); + buttonCollectionRemove.Size = new Size(185, 31); buttonCollectionRemove.TabIndex = 6; buttonCollectionRemove.Text = "Удалить коллекцию"; buttonCollectionRemove.UseVisualStyleBackColor = true; @@ -178,17 +190,18 @@ // listBoxCollection // listBoxCollection.FormattingEnabled = true; - listBoxCollection.ItemHeight = 15; - listBoxCollection.Location = new Point(3, 110); + listBoxCollection.Location = new Point(3, 147); + listBoxCollection.Margin = new Padding(3, 4, 3, 4); listBoxCollection.Name = "listBoxCollection"; - listBoxCollection.Size = new Size(162, 94); + listBoxCollection.Size = new Size(185, 124); listBoxCollection.TabIndex = 5; // // buttonCollectionAdd // - buttonCollectionAdd.Location = new Point(3, 81); + buttonCollectionAdd.Location = new Point(3, 108); + buttonCollectionAdd.Margin = new Padding(3, 4, 3, 4); buttonCollectionAdd.Name = "buttonCollectionAdd"; - buttonCollectionAdd.Size = new Size(162, 23); + buttonCollectionAdd.Size = new Size(185, 31); buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.UseVisualStyleBackColor = true; @@ -197,9 +210,10 @@ // radioButtonList // radioButtonList.AutoSize = true; - radioButtonList.Location = new Point(92, 56); + radioButtonList.Location = new Point(105, 75); + radioButtonList.Margin = new Padding(3, 4, 3, 4); radioButtonList.Name = "radioButtonList"; - radioButtonList.Size = new Size(66, 19); + radioButtonList.Size = new Size(80, 24); radioButtonList.TabIndex = 3; radioButtonList.TabStop = true; radioButtonList.Text = "Список"; @@ -208,9 +222,10 @@ // radioButtonMassive // radioButtonMassive.AutoSize = true; - radioButtonMassive.Location = new Point(3, 56); + radioButtonMassive.Location = new Point(3, 75); + radioButtonMassive.Margin = new Padding(3, 4, 3, 4); radioButtonMassive.Name = "radioButtonMassive"; - radioButtonMassive.Size = new Size(67, 19); + radioButtonMassive.Size = new Size(82, 24); radioButtonMassive.TabIndex = 2; radioButtonMassive.TabStop = true; radioButtonMassive.Text = "Массив"; @@ -218,17 +233,18 @@ // // textBoxCollectionName // - textBoxCollectionName.Location = new Point(3, 27); + textBoxCollectionName.Location = new Point(3, 36); + textBoxCollectionName.Margin = new Padding(3, 4, 3, 4); textBoxCollectionName.Name = "textBoxCollectionName"; - textBoxCollectionName.Size = new Size(162, 23); + textBoxCollectionName.Size = new Size(185, 27); textBoxCollectionName.TabIndex = 1; // // labelCollectionName // labelCollectionName.AutoSize = true; - labelCollectionName.Location = new Point(21, 9); + labelCollectionName.Location = new Point(24, 12); labelCollectionName.Name = "labelCollectionName"; - labelCollectionName.Size = new Size(125, 15); + labelCollectionName.Size = new Size(158, 20); labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // @@ -238,9 +254,10 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 312); + 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; // @@ -248,18 +265,21 @@ // 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(659, 663); + 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(833, 663); + ClientSize = new Size(952, 884); Controls.Add(pictureBox); Controls.Add(groupBox1); + Margin = new Padding(3, 4, 3, 4); Name = "FormWarPlaneCollection"; Text = "Коллекция военных самолетов"; groupBox1.ResumeLayout(false); diff --git a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs index e442a76..8702bf4 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs @@ -19,7 +19,7 @@ public partial class FormWarPlaneCollection : Form /// Хранилище коолекций /// private readonly StorageCollection _storageCollection; - + /// /// Компания /// @@ -59,8 +59,7 @@ public partial class FormWarPlaneCollection : Form break; case nameof(DrawningAirFighter): drawningWarPlane = new DrawningAirFighter(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + GetColor(random),GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: @@ -171,7 +170,7 @@ public partial class FormWarPlaneCollection : Form /// private void buttonCollectionAdd_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(textBoxCollectionName.Text) ||(!radioButtonList.Checked && !radioButtonMassive.Checked)) + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; @@ -243,7 +242,7 @@ public partial class FormWarPlaneCollection : Form MessageBox.Show("Коллекция не проинициализирована"); return; } - + switch (comboBoxSelectorCompany.Text) { case "Хранилище": @@ -251,11 +250,13 @@ public partial class FormWarPlaneCollection : Form pictureBox.Height, collection); break; } - + panelCompanyTools.Enabled = true; RerfreshListBoxItems(); } + + } -- 2.25.1 From 6dcc2b89b7f83d4953df71cc45b068c1b3ee87e2 Mon Sep 17 00:00:00 2001 From: nezui1 Date: Tue, 9 Apr 2024 09:10:22 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=E2=84=964(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 3 +++ .../MassiveGenericObjects.cs | 19 +++++++++++++++++-- .../StorageCollection.cs | 12 ++++++++++++ .../FormWarPlaneCollection.cs | 2 +- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs index cb362ec..f891363 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/CollectionType.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace ProjectAirFighter.CollectionGenericObjects; +/// +/// Перечисление типов коллекции +/// public enum CollectionType { /// 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 index a8a4bdd..cc7d23f 100644 --- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/StorageCollection.cs @@ -81,4 +81,16 @@ public class StorageCollection 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.cs b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs index 8702bf4..0a9b329 100644 --- a/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs +++ b/ProjectAirFighter/ProjectAirFighter/FormWarPlaneCollection.cs @@ -215,7 +215,7 @@ public partial class FormWarPlaneCollection : Form MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } -- 2.25.1