PIbd-13_Ladyagin_P.D. LabWork04 Simple #6

Closed
F1rsTTeaM wants to merge 1 commits from LabWork04.1 into LabWork03.1
5 changed files with 449 additions and 65 deletions

View File

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

View File

@ -0,0 +1,68 @@
namespace ProjectAirplaneWithRadar.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 (Count + 1 > _maxCount)
return -1;
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;
}
}
}

View File

@ -0,0 +1,77 @@
namespace ProjectAirplaneWithRadar.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 (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];
}
}
}
}

View File

@ -29,26 +29,35 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveAirplane = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddAirplaneWithRadar = new Button();
panelCompanyTools = new Panel();
buttonAddAirplane = new Button();
buttonAddAirplaneWithRadar = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonRefresh = new Button();
buttonRemoveAirplane = new Button();
buttonGoToCheck = 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(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddAirplaneWithRadar);
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(883, 0);
@ -58,69 +67,176 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
// panelCompanyTools
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(109, 513);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(91, 56);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
panelCompanyTools.Controls.Add(buttonAddAirplane);
panelCompanyTools.Controls.Add(buttonAddAirplaneWithRadar);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemoveAirplane);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 417);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(200, 187);
panelCompanyTools.TabIndex = 8;
//
// buttonGoToCheck
// buttonAddAirplane
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 513);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(91, 56);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
buttonAddAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirplane.Location = new Point(0, 3);
buttonAddAirplane.Name = "buttonAddAirplane";
buttonAddAirplane.Size = new Size(97, 56);
buttonAddAirplane.TabIndex = 1;
buttonAddAirplane.Text = "Добавить самолет";
buttonAddAirplane.UseVisualStyleBackColor = true;
buttonAddAirplane.Click += ButtonAddAirplane_Click;
//
// buttonRemoveAirplane
// buttonAddAirplaneWithRadar
//
buttonRemoveAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveAirplane.Location = new Point(109, 204);
buttonRemoveAirplane.Name = "buttonRemoveAirplane";
buttonRemoveAirplane.Size = new Size(91, 43);
buttonRemoveAirplane.TabIndex = 4;
buttonRemoveAirplane.Text = "Удалить самолет";
buttonRemoveAirplane.UseVisualStyleBackColor = true;
buttonRemoveAirplane.Click += ButtonRemoveAirplane_Click;
buttonAddAirplaneWithRadar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirplaneWithRadar.Location = new Point(103, 3);
buttonAddAirplaneWithRadar.Name = "buttonAddAirplaneWithRadar";
buttonAddAirplaneWithRadar.Size = new Size(97, 56);
buttonAddAirplaneWithRadar.TabIndex = 2;
buttonAddAirplaneWithRadar.Text = "Добавить самолет с радаром";
buttonAddAirplaneWithRadar.UseVisualStyleBackColor = true;
buttonAddAirplaneWithRadar.Click += ButtonAddAirplaneWithRadar_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 215);
maskedTextBoxPosition.Location = new Point(0, 81);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(78, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddAirplaneWithRadar
// buttonRefresh
//
buttonAddAirplaneWithRadar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirplaneWithRadar.Location = new Point(109, 98);
buttonAddAirplaneWithRadar.Name = "buttonAddAirplaneWithRadar";
buttonAddAirplaneWithRadar.Size = new Size(91, 56);
buttonAddAirplaneWithRadar.TabIndex = 2;
buttonAddAirplaneWithRadar.Text = "Добавить самолет с радаром";
buttonAddAirplaneWithRadar.UseVisualStyleBackColor = true;
buttonAddAirplaneWithRadar.Click += ButtonAddAirplaneWithRadar_Click;
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(103, 123);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(97, 56);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonAddAirplane
// buttonRemoveAirplane
//
buttonAddAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirplane.Location = new Point(6, 98);
buttonAddAirplane.Name = "buttonAddAirplane";
buttonAddAirplane.Size = new Size(91, 56);
buttonAddAirplane.TabIndex = 1;
buttonAddAirplane.Text = "Добавить самолет";
buttonAddAirplane.UseVisualStyleBackColor = true;
buttonAddAirplane.Click += ButtonAddAirplane_Click;
buttonRemoveAirplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveAirplane.Location = new Point(103, 70);
buttonRemoveAirplane.Name = "buttonRemoveAirplane";
buttonRemoveAirplane.Size = new Size(97, 43);
buttonRemoveAirplane.TabIndex = 4;
buttonRemoveAirplane.Text = "Удалить самолет";
buttonRemoveAirplane.UseVisualStyleBackColor = true;
buttonRemoveAirplane.Click += ButtonRemoveAirplane_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(0, 123);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(97, 56);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += buttonGoToCheck_Click;
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(6, 305);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(194, 23);
buttonCreateCompany.TabIndex = 7;
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(200, 251);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 221);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(194, 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, 121);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(194, 94);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 82);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(194, 23);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(106, 57);
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(27, 57);
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, 28);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(194, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(38, 10);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// comboBoxSelectorCompany
//
@ -128,7 +244,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 22);
comboBoxSelectorCompany.Location = new Point(6, 276);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(194, 23);
comboBoxSelectorCompany.TabIndex = 0;
@ -153,7 +269,10 @@
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);
}
@ -169,5 +288,15 @@
private Button buttonRefresh;
private Button buttonGoToCheck;
private Button buttonRemoveAirplane;
private Panel panelStorage;
private TextBox textBoxCollectionName;
private Label labelCollectionName;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private Button buttonCreateCompany;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Panel panelCompanyTools;
}
}

View File

@ -8,6 +8,11 @@ namespace ProjectAirplaneWithRadar
/// </summary>
public partial class FormAirplaneCollection : Form
{
/// <summary>
/// Хранилише коллекций
/// </summary>
private readonly StorageCollection<DrawningAirplane> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -19,6 +24,7 @@ namespace ProjectAirplaneWithRadar
public FormAirplaneCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -28,12 +34,7 @@ namespace ProjectAirplaneWithRadar
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningAirplane>());
break;
}
panelCompanyTools.Enabled = false;
}
/// <summary>
@ -185,5 +186,94 @@ namespace ProjectAirplaneWithRadar
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.SelectedItems == null || listBoxCollection.SelectedIndex < 0)
{
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.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 PlaneSharingService(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
}
}