массив
This commit is contained in:
parent
948640a1ea
commit
dd1829520c
@ -15,7 +15,7 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 80;
|
||||
protected readonly int _placeSizeHeight = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
|
@ -0,0 +1,16 @@
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
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)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= Count || position < 0) return null;
|
||||
return _collection[position];
|
||||
}
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (Count == _maxCount) return -1;
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
}
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (Count == _maxCount) return -1;
|
||||
if (position >= Count || position < 0) return -1;
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if (position >= Count || position < 0) return null;
|
||||
T obj = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return obj;
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using ProjectStormtrooper.Drawnings;
|
||||
|
||||
namespace ProjectStormtrooper.CollectionGenericObjects;
|
||||
|
||||
public class StorageCollection<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
if (_storages.ContainsKey(name)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
else if (collectionType == CollectionType.List)
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
|
||||
// TODO Прописать логику для удаления коллекции
|
||||
if (_storages.ContainsKey(name))
|
||||
_storages.Remove(name);
|
||||
}
|
||||
/// <summary>
|
||||
/// Доступ к коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения объекта
|
||||
if (_storages.ContainsKey(name))
|
||||
return _storages[name];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
234
ProjectStormtrooper/FormAirplaneCollection.Designer.cs
generated
234
ProjectStormtrooper/FormAirplaneCollection.Designer.cs
generated
@ -29,56 +29,114 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonAddAirplane = new Button();
|
||||
buttonAddStormtrooper = new Button();
|
||||
buttonRefresh = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveAirplane = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddStormtrooper = new Button();
|
||||
buttonAddAirplane = 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(buttonRemoveAirplane);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddStormtrooper);
|
||||
groupBoxTools.Controls.Add(buttonAddAirplane);
|
||||
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(894, 0);
|
||||
groupBoxTools.Margin = new Padding(3, 4, 3, 4);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Padding = new Padding(3, 4, 3, 4);
|
||||
groupBoxTools.Size = new Size(205, 821);
|
||||
groupBoxTools.Size = new Size(205, 749);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonAddAirplane);
|
||||
panelCompanyTools.Controls.Add(buttonAddStormtrooper);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveAirplane);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Location = new Point(3, 421);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(199, 324);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// buttonAddAirplane
|
||||
//
|
||||
buttonAddAirplane.Dock = DockStyle.Bottom;
|
||||
buttonAddAirplane.Location = new Point(0, 4);
|
||||
buttonAddAirplane.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddAirplane.Name = "buttonAddAirplane";
|
||||
buttonAddAirplane.Size = new Size(199, 60);
|
||||
buttonAddAirplane.TabIndex = 1;
|
||||
buttonAddAirplane.Text = "Добавление самолета";
|
||||
buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||
buttonAddAirplane.Click += buttonAddAirplane_Click;
|
||||
//
|
||||
// buttonAddStormtrooper
|
||||
//
|
||||
buttonAddStormtrooper.Dock = DockStyle.Bottom;
|
||||
buttonAddStormtrooper.Location = new Point(0, 64);
|
||||
buttonAddStormtrooper.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddStormtrooper.Name = "buttonAddStormtrooper";
|
||||
buttonAddStormtrooper.Size = new Size(199, 61);
|
||||
buttonAddStormtrooper.TabIndex = 2;
|
||||
buttonAddStormtrooper.Text = "Добавление штурмовика";
|
||||
buttonAddStormtrooper.UseVisualStyleBackColor = true;
|
||||
buttonAddStormtrooper.Click += buttonAddStormtrooper_Click;
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(7, 665);
|
||||
buttonRefresh.Dock = DockStyle.Bottom;
|
||||
buttonRefresh.Location = new Point(0, 125);
|
||||
buttonRefresh.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(191, 53);
|
||||
buttonRefresh.Size = new Size(199, 54);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += buttonRefresh_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Dock = DockStyle.Bottom;
|
||||
maskedTextBox.Location = new Point(0, 179);
|
||||
maskedTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(199, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(7, 481);
|
||||
buttonGoToCheck.Dock = DockStyle.Bottom;
|
||||
buttonGoToCheck.Location = new Point(0, 206);
|
||||
buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(191, 53);
|
||||
buttonGoToCheck.Size = new Size(199, 56);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -86,49 +144,108 @@
|
||||
//
|
||||
// buttonRemoveAirplane
|
||||
//
|
||||
buttonRemoveAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveAirplane.Location = new Point(7, 335);
|
||||
buttonRemoveAirplane.Dock = DockStyle.Bottom;
|
||||
buttonRemoveAirplane.Location = new Point(0, 262);
|
||||
buttonRemoveAirplane.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRemoveAirplane.Name = "buttonRemoveAirplane";
|
||||
buttonRemoveAirplane.Size = new Size(191, 53);
|
||||
buttonRemoveAirplane.Size = new Size(199, 62);
|
||||
buttonRemoveAirplane.TabIndex = 4;
|
||||
buttonRemoveAirplane.Text = "Удалить автомобиль";
|
||||
buttonRemoveAirplane.Text = "Удалить самолет";
|
||||
buttonRemoveAirplane.UseVisualStyleBackColor = true;
|
||||
buttonRemoveAirplane.Click += buttonRemoveAirplane_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
// buttonCreateCompany
|
||||
//
|
||||
maskedTextBox.Location = new Point(7, 296);
|
||||
maskedTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(190, 27);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
buttonCreateCompany.Location = new Point(8, 364);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(192, 29);
|
||||
buttonCreateCompany.TabIndex = 8;
|
||||
buttonCreateCompany.Text = "Создать компанию";
|
||||
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||
buttonCreateCompany.Click += buttonCreateCompany_Click;
|
||||
//
|
||||
// buttonAddStormtrooper
|
||||
// panelStorage
|
||||
//
|
||||
buttonAddStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddStormtrooper.Location = new Point(7, 183);
|
||||
buttonAddStormtrooper.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddStormtrooper.Name = "buttonAddStormtrooper";
|
||||
buttonAddStormtrooper.Size = new Size(191, 53);
|
||||
buttonAddStormtrooper.TabIndex = 2;
|
||||
buttonAddStormtrooper.Text = "Добавление штурмовика";
|
||||
buttonAddStormtrooper.UseVisualStyleBackColor = true;
|
||||
buttonAddStormtrooper.Click += buttonAddStormtrooper_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.Controls.Add(comboBoxSelectorCompany);
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 24);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(199, 298);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// buttonAddAirplane
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonAddAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddAirplane.Location = new Point(7, 121);
|
||||
buttonAddAirplane.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddAirplane.Name = "buttonAddAirplane";
|
||||
buttonAddAirplane.Size = new Size(191, 53);
|
||||
buttonAddAirplane.TabIndex = 1;
|
||||
buttonAddAirplane.Text = "Добавление самолета";
|
||||
buttonAddAirplane.UseVisualStyleBackColor = true;
|
||||
buttonAddAirplane.Click += buttonAddAirplane_Click;
|
||||
buttonCollectionDel.Location = new Point(4, 262);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(192, 29);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
buttonCollectionDel.Click += buttonCollectionDel_Click;
|
||||
//
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 20;
|
||||
listBoxCollection.Location = new Point(7, 132);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(190, 124);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(7, 97);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(192, 29);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
|
||||
//
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(110, 67);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(80, 24);
|
||||
radioButtonList.TabIndex = 3;
|
||||
radioButtonList.TabStop = true;
|
||||
radioButtonList.Text = "Список";
|
||||
radioButtonList.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// radioButtonMassive
|
||||
//
|
||||
radioButtonMassive.AutoSize = true;
|
||||
radioButtonMassive.Location = new Point(7, 67);
|
||||
radioButtonMassive.Name = "radioButtonMassive";
|
||||
radioButtonMassive.Size = new Size(82, 24);
|
||||
radioButtonMassive.TabIndex = 2;
|
||||
radioButtonMassive.TabStop = true;
|
||||
radioButtonMassive.Text = "Массив";
|
||||
radioButtonMassive.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// textBoxCollectionName
|
||||
//
|
||||
textBoxCollectionName.Location = new Point(5, 34);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(192, 27);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(25, 11);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(150, 20);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Назвние коллекции:";
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
@ -136,7 +253,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(7, 29);
|
||||
comboBoxSelectorCompany.Location = new Point(10, 329);
|
||||
comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(190, 28);
|
||||
@ -149,7 +266,7 @@
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Margin = new Padding(3, 4, 3, 4);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(894, 821);
|
||||
pictureBox.Size = new Size(894, 749);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -157,14 +274,17 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1099, 821);
|
||||
ClientSize = new Size(1099, 749);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormAirplaneCollection";
|
||||
Text = "Коллекция автомобилей";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -180,5 +300,15 @@
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonRefresh;
|
||||
private Panel panelStorage;
|
||||
private Button buttonCollectionAdd;
|
||||
private RadioButton radioButtonList;
|
||||
private RadioButton radioButtonMassive;
|
||||
private TextBox textBoxCollectionName;
|
||||
private Label labelCollectionName;
|
||||
private Button buttonCreateCompany;
|
||||
private Button buttonCollectionDel;
|
||||
private ListBox listBoxCollection;
|
||||
private Panel panelCompanyTools;
|
||||
}
|
||||
}
|
@ -13,12 +13,15 @@ public partial class FormAirplaneCollection : Form
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
private readonly StorageCollection<DrawningAirplane> _storageCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormAirplaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -28,12 +31,7 @@ public partial class FormAirplaneCollection : Form
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new AirplaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAirplane>());
|
||||
break;
|
||||
}
|
||||
panelCompanyTools.Enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -155,4 +153,78 @@ public partial class FormAirplaneCollection : 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 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 buttonCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
// TODO прописать логику удаления элемента из коллекции
|
||||
// нужно убедиться, что есть выбранная коллекция
|
||||
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
||||
// удалить и обновить ListBox
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
private void buttonCreateCompany_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
ICollectionGenericObjects<DrawningAirplane>? collection =
|
||||
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new AirplaneSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||
break;
|
||||
}
|
||||
panelCompanyTools.Enabled = true;
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user