Лабораторная работа №4
This commit is contained in:
parent
f74d8a8bd3
commit
dd60ab3219
@ -50,7 +50,7 @@ public abstract class AbstractCompany
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount - 4;
|
||||
_collection.SetMaxCount = GetMaxCount - 3;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
|
||||
}
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр ограничение - ссылочный тип</typeparam>
|
||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T> _collection;
|
||||
|
||||
/// <summary>
|
||||
/// Максимально допустимое число объектов в списке
|
||||
/// </summary>
|
||||
private int _maxCount;
|
||||
|
||||
public int Count => _collection.Count;
|
||||
|
||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-хранилище коллекций
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public class StorageCollection<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление коллекций в хранилище
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="collectionType"></param>
|
||||
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<T>();
|
||||
return;
|
||||
case CollectionType.List:
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
{
|
||||
_storages.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Доступ к коллекции
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T> this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
//логика получения объекта
|
||||
if(name == null || !_storages.ContainsKey(name))
|
||||
return null;
|
||||
|
||||
return _storages[name];
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилище коолекций
|
||||
/// </summary>
|
||||
private readonly StorageCollection<DrawningWarPlane> _storageCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormWarPlaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new WarPlaneBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningWarPlane>());
|
||||
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;
|
||||
}
|
||||
@ -128,7 +143,8 @@ public partial class FormWarPlaneCollection : Form
|
||||
}
|
||||
}
|
||||
|
||||
if (warPlane == null) {
|
||||
if (warPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@ -148,6 +164,98 @@ public partial class FormWarPlaneCollection : Form
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обновление списка в listBoxCollection
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удалиние коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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();
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Создать компанию
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningWarPlane>? 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();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user