Лабораторная работа №4
This commit is contained in:
parent
fa5d91263c
commit
33fe1a4537
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Тип коллекции
|
||||
/// </summary>
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр : ограничение - ссылочный тип</typeparam>
|
||||
public class ListgenericObjects<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(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_collection = new();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта из набора позиции
|
||||
/// </summary>
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? this[int position]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _collection?[position];
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (!(position >= 0 && position < Count && _collection?.Count < _maxCount))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_collection?.Insert(position, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
if (_collection?.Count == _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Insert(obj, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (_collection?.Count == _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Insert(obj, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_collection?.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetTheAirplanes(int? maxTheAirplanes = null)
|
||||
{
|
||||
for (int i = 0; i < _collection?.Count; ++i)
|
||||
{
|
||||
yield return _collection?[i];
|
||||
if (maxTheAirplanes.HasValue && i == maxTheAirplanes.Value)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using ProectMilitaryAircraft.MovementStrategy;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
public class StorageCollection<T>
|
||||
where T : class
|
||||
{
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
public void AddCollection (string name, CollectionType collectionType)
|
||||
{
|
||||
if (name != null && !_storages.ContainsKey(name))
|
||||
{
|
||||
|
||||
if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
}
|
||||
if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void DelCollection (string name)
|
||||
{
|
||||
if (!_storages.ContainsKey(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storages.Remove(name);
|
||||
}
|
||||
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
{
|
||||
return _storages[name];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,26 +29,35 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonAddAircraft = new Button();
|
||||
buttonAddMilitaryAircraft = new Button();
|
||||
buttonRefresh = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveAircraft = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddMilitaryAircraft = new Button();
|
||||
buttonAddAircraft = new Button();
|
||||
buttonCreateCompany = new Button();
|
||||
panelStorage = new Panel();
|
||||
buttonCollectionDel = new Button();
|
||||
listBoxCollection = new ListBox();
|
||||
buttonCollectionAdd = new Button();
|
||||
radioButtonList = new RadioButton();
|
||||
radioButtonMassive = new RadioButton();
|
||||
textBoxCollectionName = new TextBox();
|
||||
labelCollectionName = new Label();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveAircraft);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddMilitaryAircraft);
|
||||
groupBoxTools.Controls.Add(buttonAddAircraft);
|
||||
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(607, 0);
|
||||
@ -58,23 +67,68 @@
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = " Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonAddAircraft);
|
||||
panelCompanyTools.Controls.Add(buttonAddMilitaryAircraft);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveAircraft);
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(6, 280);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(182, 283);
|
||||
panelCompanyTools.TabIndex = 8;
|
||||
//
|
||||
// buttonAddAircraft
|
||||
//
|
||||
buttonAddAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAircraft.Location = new Point(4, 3);
|
||||
buttonAddAircraft.Name = "buttonAddAircraft";
|
||||
buttonAddAircraft.Size = new Size(178, 36);
|
||||
buttonAddAircraft.TabIndex = 1;
|
||||
buttonAddAircraft.Text = "Добавление самолета";
|
||||
buttonAddAircraft.UseVisualStyleBackColor = true;
|
||||
buttonAddAircraft.Click += ButtonAddAircraft_Click;
|
||||
//
|
||||
// buttonAddMilitaryAircraft
|
||||
//
|
||||
buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMilitaryAircraft.Location = new Point(4, 45);
|
||||
buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft";
|
||||
buttonAddMilitaryAircraft.Size = new Size(178, 45);
|
||||
buttonAddMilitaryAircraft.TabIndex = 2;
|
||||
buttonAddMilitaryAircraft.Text = "Добавление военного самолета";
|
||||
buttonAddMilitaryAircraft.UseVisualStyleBackColor = true;
|
||||
buttonAddMilitaryAircraft.Click += ButtonAddMilitaryAircraft_Click;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(6, 450);
|
||||
buttonRefresh.Location = new Point(4, 229);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(182, 45);
|
||||
buttonRefresh.Size = new Size(178, 45);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(4, 98);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(178, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(6, 299);
|
||||
buttonGoToCheck.Location = new Point(4, 178);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(182, 45);
|
||||
buttonGoToCheck.Size = new Size(178, 45);
|
||||
buttonGoToCheck.TabIndex = 4;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -83,44 +137,105 @@
|
||||
// buttonRemoveAircraft
|
||||
//
|
||||
buttonRemoveAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveAircraft.Location = new Point(6, 208);
|
||||
buttonRemoveAircraft.Location = new Point(4, 127);
|
||||
buttonRemoveAircraft.Name = "buttonRemoveAircraft";
|
||||
buttonRemoveAircraft.Size = new Size(182, 45);
|
||||
buttonRemoveAircraft.Size = new Size(178, 45);
|
||||
buttonRemoveAircraft.TabIndex = 3;
|
||||
buttonRemoveAircraft.Text = " Удалить самолет";
|
||||
buttonRemoveAircraft.UseVisualStyleBackColor = true;
|
||||
buttonRemoveAircraft.Click += ButtonRemoveAircraft_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
// buttonCreateCompany
|
||||
//
|
||||
maskedTextBox.Location = new Point(6, 179);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(182, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
buttonCreateCompany.Location = new Point(6, 251);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(182, 23);
|
||||
buttonCreateCompany.TabIndex = 7;
|
||||
buttonCreateCompany.Text = "Создать компанию";
|
||||
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||
buttonCreateCompany.Click += ButtonCreateCompany_Click;
|
||||
//
|
||||
// buttonAddMilitaryAircraft
|
||||
// panelStorage
|
||||
//
|
||||
buttonAddMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMilitaryAircraft.Location = new Point(6, 112);
|
||||
buttonAddMilitaryAircraft.Name = "buttonAddMilitaryAircraft";
|
||||
buttonAddMilitaryAircraft.Size = new Size(182, 45);
|
||||
buttonAddMilitaryAircraft.TabIndex = 2;
|
||||
buttonAddMilitaryAircraft.Text = "Добавление военного самолета";
|
||||
buttonAddMilitaryAircraft.UseVisualStyleBackColor = true;
|
||||
buttonAddMilitaryAircraft.Click += ButtonAddMilitaryAircraft_Click;
|
||||
panelStorage.Controls.Add(buttonCollectionDel);
|
||||
panelStorage.Controls.Add(listBoxCollection);
|
||||
panelStorage.Controls.Add(buttonCollectionAdd);
|
||||
panelStorage.Controls.Add(radioButtonList);
|
||||
panelStorage.Controls.Add(radioButtonMassive);
|
||||
panelStorage.Controls.Add(textBoxCollectionName);
|
||||
panelStorage.Controls.Add(labelCollectionName);
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 19);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(188, 186);
|
||||
panelStorage.TabIndex = 6;
|
||||
//
|
||||
// buttonAddAircraft
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonAddAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAircraft.Location = new Point(6, 70);
|
||||
buttonAddAircraft.Name = "buttonAddAircraft";
|
||||
buttonAddAircraft.Size = new Size(182, 36);
|
||||
buttonAddAircraft.TabIndex = 1;
|
||||
buttonAddAircraft.Text = "Добавление самолета";
|
||||
buttonAddAircraft.UseVisualStyleBackColor = true;
|
||||
buttonAddAircraft.Click += ButtonAddAircraft_Click;
|
||||
buttonCollectionDel.Location = new Point(3, 156);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(182, 21);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||
//
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(3, 101);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(182, 49);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(3, 72);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(182, 23);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||
//
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(119, 47);
|
||||
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, 47);
|
||||
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, 18);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(182, 23);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(29, 0);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(125, 15);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Название коллекции:";
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
@ -128,7 +243,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 22);
|
||||
comboBoxSelectorCompany.Location = new Point(6, 211);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(182, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
@ -153,7 +268,10 @@
|
||||
Name = "FormAircraftCollection";
|
||||
Text = "Коллекция самолетов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -169,5 +287,15 @@
|
||||
private Button buttonRemoveAircraft;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Panel panelStorage;
|
||||
private TextBox textBoxCollectionName;
|
||||
private Label labelCollectionName;
|
||||
private RadioButton radioButtonMassive;
|
||||
private RadioButton radioButtonList;
|
||||
private Button buttonCollectionAdd;
|
||||
private ListBox listBoxCollection;
|
||||
private Button buttonCreateCompany;
|
||||
private Button buttonCollectionDel;
|
||||
private Panel panelCompanyTools;
|
||||
}
|
||||
}
|
@ -18,6 +18,11 @@ namespace ProectMilitaryAircraft;
|
||||
/// </summary>
|
||||
public partial class FormAircraftCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилище коллекций
|
||||
/// </summary>
|
||||
private readonly StorageCollection<DrawningAircraft> _storageCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
@ -30,6 +35,7 @@ public partial class FormAircraftCollection : Form
|
||||
public FormAircraftCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
@ -38,12 +44,7 @@ public partial class FormAircraftCollection : Form
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAircraft>());
|
||||
break;
|
||||
}
|
||||
panelCompanyTools.Enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -77,7 +78,7 @@ public partial class FormAircraftCollection : Form
|
||||
if (_company + drawningAircraft)
|
||||
{
|
||||
MessageBox.Show("Не удалось добаить объект");
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -153,7 +154,7 @@ public partial class FormAircraftCollection : Form
|
||||
}
|
||||
DrawningAircraft? aircraft = null;
|
||||
int counter = 100;
|
||||
while(aircraft == null)
|
||||
while (aircraft == null)
|
||||
{
|
||||
aircraft = _company.GetRandomObject();
|
||||
counter--;
|
||||
@ -186,4 +187,94 @@ public partial class FormAircraftCollection : 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);
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект{listBoxCollection.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem?.ToString()
|
||||
?? string.Empty);
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void RefreshListBoxItems()
|
||||
{
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i =0; i < _storageCollection.Keys?.Count; i++)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateCompany_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItems == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString()?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллкция не проиницилизирована");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new AircraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAircraft>());
|
||||
break;
|
||||
}
|
||||
|
||||
panelCompanyTools.Enabled = true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user