PIbd-13 Gutorov I. A. LabWork04 Simple #4

Closed
vasmaae wants to merge 1 commits from LabWork04 into LabWork03
5 changed files with 482 additions and 69 deletions

View File

@ -0,0 +1,22 @@
namespace ProjectAirbus.CollectionGenericObjects;
/// <summary>
/// Тип коллекции
/// </summary>
public enum CollectionType
{
/// <summary>
/// Неопределенно
/// </summary>
None = 0,
/// <summary>
/// Массив
/// </summary>
Massive = 1,
/// <summary>
/// Список
/// </summary>
List = 2
}

View File

@ -0,0 +1,84 @@
namespace ProjectAirbus.CollectionGenericObjects;
/// <summary>
/// Параметризованный набор объектов
/// </summary>
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 < 0 || position >= Count)
{
return null;
}
return _collection[position];
}
public int Insert(T obj)
{
if (Count == _maxCount)
{
return -1;
}
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
if (Count == _maxCount)
{
return -1;
}
if (position >= Count || position < 0)
{
return -1;
}
_collection.Insert(position, obj);
return position;
}
public T Remove(int position)
{
if (position >= Count || position < 0)
{
return null;
}
T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
}

View File

@ -0,0 +1,78 @@
namespace ProjectAirbus.CollectionGenericObjects;
/// <summary>
/// Класс-хранилище коллекций
/// </summary>
/// <typeparam name="T"></typeparam>
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)
{
if (_storages.ContainsKey(name) || collectionType == CollectionType.None)
{
return;
}
switch (collectionType)
{
case CollectionType.Massive:
_storages[name] = new MassiveGenericObjects<T>();
break;
case CollectionType.List:
_storages[name] = new ListGenericObjects<T>();
break;
}
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
if (_storages.ContainsKey(name) && name != null)
{
_storages.Remove(name);
}
}
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectionGenericObjects<T>? this[string name]
{
get
{
if (_storages.ContainsKey(name))
{
return _storages[name];
}
return null;
}
}
}

View File

@ -29,26 +29,35 @@
private void InitializeComponent()
{
groupBocTools = new GroupBox();
maskedTextBoxPosition = new MaskedTextBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveAirbus = new Button();
buttonAddBigAirbus = new Button();
panelCompanyTools = new Panel();
buttonAddAirbus = new Button();
buttonAddBigAirbus = new Button();
buttonRemoveAirbus = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button();
buttonRefresh = 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();
groupBocTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBocTools
//
groupBocTools.Controls.Add(maskedTextBoxPosition);
groupBocTools.Controls.Add(buttonRefresh);
groupBocTools.Controls.Add(buttonGoToCheck);
groupBocTools.Controls.Add(buttonRemoveAirbus);
groupBocTools.Controls.Add(buttonAddBigAirbus);
groupBocTools.Controls.Add(buttonAddAirbus);
groupBocTools.Controls.Add(panelCompanyTools);
groupBocTools.Controls.Add(buttonCreateCompany);
groupBocTools.Controls.Add(panelStorage);
groupBocTools.Controls.Add(comboBoxSelectorCompany);
groupBocTools.Dock = DockStyle.Right;
groupBocTools.Location = new Point(867, 0);
@ -58,61 +67,25 @@
groupBocTools.TabStop = false;
groupBocTools.Text = "Инструменты";
//
// maskedTextBoxPosition
// panelCompanyTools
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Location = new Point(6, 205);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(160, 23);
maskedTextBoxPosition.TabIndex = 7;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRefresh
//
buttonRefresh.Location = new Point(6, 413);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(160, 23);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(6, 328);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(160, 23);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
//
// buttonRemoveAirbus
//
buttonRemoveAirbus.Location = new Point(6, 234);
buttonRemoveAirbus.Name = "buttonRemoveAirbus";
buttonRemoveAirbus.Size = new Size(160, 23);
buttonRemoveAirbus.TabIndex = 4;
buttonRemoveAirbus.Text = "Удалить аэробус";
buttonRemoveAirbus.UseVisualStyleBackColor = true;
buttonRemoveAirbus.Click += buttonRemoveAirbus_Click;
//
// buttonAddBigAirbus
//
buttonAddBigAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBigAirbus.Location = new Point(6, 105);
buttonAddBigAirbus.Name = "buttonAddBigAirbus";
buttonAddBigAirbus.Size = new Size(160, 47);
buttonAddBigAirbus.TabIndex = 2;
buttonAddBigAirbus.Text = "Добавление большого аэробуса";
buttonAddBigAirbus.UseVisualStyleBackColor = true;
buttonAddBigAirbus.Click += buttonAddBigAirbus_Click;
panelCompanyTools.Controls.Add(buttonAddAirbus);
panelCompanyTools.Controls.Add(buttonAddBigAirbus);
panelCompanyTools.Controls.Add(buttonRemoveAirbus);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 335);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(166, 198);
panelCompanyTools.TabIndex = 10;
//
// buttonAddAirbus
//
buttonAddAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirbus.Location = new Point(6, 76);
buttonAddAirbus.Location = new Point(3, 3);
buttonAddAirbus.Name = "buttonAddAirbus";
buttonAddAirbus.Size = new Size(160, 23);
buttonAddAirbus.TabIndex = 1;
@ -120,13 +93,158 @@
buttonAddAirbus.UseVisualStyleBackColor = true;
buttonAddAirbus.Click += buttonAddAirbus_Click;
//
// buttonAddBigAirbus
//
buttonAddBigAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBigAirbus.Location = new Point(3, 32);
buttonAddBigAirbus.Name = "buttonAddBigAirbus";
buttonAddBigAirbus.Size = new Size(160, 47);
buttonAddBigAirbus.TabIndex = 2;
buttonAddBigAirbus.Text = "Добавление большого аэробуса";
buttonAddBigAirbus.UseVisualStyleBackColor = true;
buttonAddBigAirbus.Click += buttonAddBigAirbus_Click;
//
// buttonRemoveAirbus
//
buttonRemoveAirbus.Location = new Point(3, 114);
buttonRemoveAirbus.Name = "buttonRemoveAirbus";
buttonRemoveAirbus.Size = new Size(160, 23);
buttonRemoveAirbus.TabIndex = 4;
buttonRemoveAirbus.Text = "Удалить аэробус";
buttonRemoveAirbus.UseVisualStyleBackColor = true;
buttonRemoveAirbus.Click += buttonRemoveAirbus_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.Location = new Point(3, 85);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(160, 23);
maskedTextBoxPosition.TabIndex = 7;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(3, 143);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(160, 23);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
//
// buttonRefresh
//
buttonRefresh.Location = new Point(3, 172);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(160, 23);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
// buttonCreateCompany
//
buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonCreateCompany.Location = new Point(6, 309);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(160, 23);
buttonCreateCompany.TabIndex = 9;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click;
//
// panelStorage
//
panelStorage.Controls.Add(buttonCollectionDel);
panelStorage.Controls.Add(listBoxCollection);
panelStorage.Controls.Add(buttonCollectionAdd);
panelStorage.Controls.Add(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(166, 255);
panelStorage.TabIndex = 8;
//
// buttonCollectionDel
//
buttonCollectionDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonCollectionDel.Location = new Point(3, 229);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(160, 23);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += buttonCollectionDel_Click;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 15;
listBoxCollection.Location = new Point(3, 113);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(160, 109);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 84);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(160, 23);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(97, 59);
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, 59);
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, 30);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(160, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(20, 12);
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, 280);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(160, 23);
comboBoxSelectorCompany.TabIndex = 0;
@ -150,7 +268,10 @@
Name = "FormAirbusCollection";
Text = "Коллекция аэробусов";
groupBocTools.ResumeLayout(false);
groupBocTools.PerformLayout();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@ -166,5 +287,15 @@
private Button buttonRefresh;
private PictureBox pictureBox;
private MaskedTextBox maskedTextBoxPosition;
private Panel panelStorage;
private TextBox textBoxCollectionName;
private Label labelCollectionName;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
}
}

View File

@ -8,6 +8,11 @@ namespace ProjectAirbus;
/// </summary>
public partial class FormAirbusCollection : Form
{
/// <summary>
/// Хранилище коллекций
/// </summary>
private readonly StorageCollection<DrawningAirbus> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -19,6 +24,7 @@ public partial class FormAirbusCollection : Form
public FormAirbusCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -28,12 +34,7 @@ public partial class FormAirbusCollection : Form
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(Object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new AirbusAerodromeService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAirbus>());
break;
}
panelCompanyTools.Enabled = false;
}
/// <summary>
@ -184,4 +185,101 @@ public partial class FormAirbusCollection : 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 < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
RefreshListBoxItems();
}
/// <summary>
/// Обновление списка в ListBoxCollection
/// </summary>
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<DrawningAirbus>? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new AirbusAerodromeService(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
}