PIBD-13_Fomichev_V.S._LabWork04_Simple_ #5

Closed
slavaxom9k wants to merge 1 commits from labwork04 into labwork03
5 changed files with 399 additions and 27 deletions

View File

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

View File

@ -0,0 +1,61 @@
using AntiAircraftGun.CollectionGenereticObject;
namespace AntiAircraftGun.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 == _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 >= _collection.Count || position < 0) return null;
T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
}

View File

@ -0,0 +1,70 @@
using AntiAircraftGun.CollectionGenereticObject;
namespace AntiAircraftGun.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)) 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)
{
if (_storages.ContainsKey(name))
_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,6 +29,15 @@
private void InitializeComponent()
{
groupBoxToools = new GroupBox();
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();
buttonRefresh = new Button();
buttonGoToChek = new Button();
buttonRemoveArmoredCar = new Button();
@ -37,18 +46,18 @@
buttonAddArmoredCar = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
panelCompanyTools = new Panel();
groupBoxToools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout();
//
// groupBoxToools
//
groupBoxToools.Controls.Add(buttonRefresh);
groupBoxToools.Controls.Add(buttonGoToChek);
groupBoxToools.Controls.Add(buttonRemoveArmoredCar);
groupBoxToools.Controls.Add(maskedTextBox);
groupBoxToools.Controls.Add(buttonAddAntiAircraftGun);
groupBoxToools.Controls.Add(buttonAddArmoredCar);
groupBoxToools.Controls.Add(panelCompanyTools);
groupBoxToools.Controls.Add(buttonCreateCompany);
groupBoxToools.Controls.Add(panelStorage);
groupBoxToools.Controls.Add(comboBoxSelectorCompany);
groupBoxToools.Dock = DockStyle.Right;
groupBoxToools.Location = new Point(1057, 0);
@ -58,12 +67,104 @@
groupBoxToools.TabStop = false;
groupBoxToools.Text = "Инструменты";
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(6, 290);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(198, 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(204, 258);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 228);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(198, 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(198, 109);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 84);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(198, 23);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(115, 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(15, 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(198, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(39, 12);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(125, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 527);
buttonRefresh.Location = new Point(6, 216);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(198, 39);
buttonRefresh.Size = new Size(191, 39);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@ -72,9 +173,9 @@
// buttonGoToChek
//
buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToChek.Location = new Point(6, 482);
buttonGoToChek.Location = new Point(6, 171);
buttonGoToChek.Name = "buttonGoToChek";
buttonGoToChek.Size = new Size(198, 39);
buttonGoToChek.Size = new Size(191, 39);
buttonGoToChek.TabIndex = 5;
buttonGoToChek.Text = "Передать на тесты";
buttonGoToChek.UseVisualStyleBackColor = true;
@ -83,9 +184,9 @@
// buttonRemoveArmoredCar
//
buttonRemoveArmoredCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveArmoredCar.Location = new Point(6, 302);
buttonRemoveArmoredCar.Location = new Point(6, 123);
buttonRemoveArmoredCar.Name = "buttonRemoveArmoredCar";
buttonRemoveArmoredCar.Size = new Size(198, 60);
buttonRemoveArmoredCar.Size = new Size(191, 44);
buttonRemoveArmoredCar.TabIndex = 4;
buttonRemoveArmoredCar.Text = "Удалить бронемашину";
buttonRemoveArmoredCar.UseVisualStyleBackColor = true;
@ -93,19 +194,19 @@
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 249);
maskedTextBox.Location = new Point(6, 94);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(198, 23);
maskedTextBox.Size = new Size(194, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonAddAntiAircraftGun
//
buttonAddAntiAircraftGun.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAntiAircraftGun.Location = new Point(6, 164);
buttonAddAntiAircraftGun.Location = new Point(6, 42);
buttonAddAntiAircraftGun.Name = "buttonAddAntiAircraftGun";
buttonAddAntiAircraftGun.Size = new Size(198, 60);
buttonAddAntiAircraftGun.Size = new Size(191, 46);
buttonAddAntiAircraftGun.TabIndex = 2;
buttonAddAntiAircraftGun.Text = "Добавление зениитной установки";
buttonAddAntiAircraftGun.UseVisualStyleBackColor = true;
@ -114,9 +215,9 @@
// buttonAddArmoredCar
//
buttonAddArmoredCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddArmoredCar.Location = new Point(6, 86);
buttonAddArmoredCar.Location = new Point(6, 3);
buttonAddArmoredCar.Name = "buttonAddArmoredCar";
buttonAddArmoredCar.Size = new Size(198, 60);
buttonAddArmoredCar.Size = new Size(191, 40);
buttonAddArmoredCar.TabIndex = 1;
buttonAddArmoredCar.Text = "Добавление бронемашины";
buttonAddArmoredCar.UseVisualStyleBackColor = true;
@ -128,7 +229,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(6, 22);
comboBoxSelectorCompany.Location = new Point(6, 319);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(198, 23);
comboBoxSelectorCompany.TabIndex = 0;
@ -143,6 +244,20 @@
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddAntiAircraftGun);
panelCompanyTools.Controls.Add(buttonAddArmoredCar);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonRemoveArmoredCar);
panelCompanyTools.Controls.Add(buttonGoToChek);
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(6, 348);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(200, 261);
panelCompanyTools.TabIndex = 8;
//
// FormArmoredCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
@ -153,8 +268,11 @@
Name = "FormArmoredCarCollection";
Text = "Коллекция бронемашин";
groupBoxToools.ResumeLayout(false);
groupBoxToools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@ -169,5 +287,15 @@
private MaskedTextBox maskedTextBox;
private Button buttonRefresh;
private Button buttonGoToChek;
private Panel panelStorage;
private Label labelCollectionName;
private TextBox textBoxCollectionName;
private RadioButton radioButtonMassive;
private RadioButton radioButtonList;
private Button buttonCollectionAdd;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
}
}

View File

@ -1,5 +1,6 @@
using AntiAircraftGun.CollectionGenereticObject;
using AntiAircraftGun.CollectionGenereticObjects;
using AntiAircraftGun.CollectionGenericObjects;
using AntiAircraftGun.Drawnings;
@ -9,6 +10,10 @@ namespace AntiAircraftGun;
/// </summary>
public partial class FormArmoredCarCollection : Form
{
/// <summary>
/// Хранилише коллекций
/// </summary>
private readonly StorageCollection<DrawningArmoredCar> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -20,6 +25,7 @@ public partial class FormArmoredCarCollection : Form
public FormArmoredCarCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -29,12 +35,7 @@ public partial class FormArmoredCarCollection : Form
/// <param name="e"></param>
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new CarBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningArmoredCar>());
break;
}
panelCompanyTools.Enabled = false;
}
/// <summary>
@ -185,6 +186,97 @@ public partial class FormArmoredCarCollection : Form
form.ShowDialog();
}
/// <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 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>
/// Удаление коллекции
/// </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());
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<DrawningArmoredCar>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new CarBase(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
}