ISEbd-12_Pravednikova_D._O._ LabWork04.Simple #4

Closed
Darya wants to merge 3 commits from LabWork04 into LabWork03
5 changed files with 420 additions and 42 deletions
Showing only changes of commit e016dde468 - Show all commits

View File

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

View File

@ -0,0 +1,61 @@
namespace Excavator.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 bool Remove(int position)
{
if (!(position >= 0 && position < Count))
return false;
_collection.RemoveAt(position);
return true;
}
}

View File

@ -0,0 +1,74 @@
namespace Excavator.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()
{
groupBox1 = 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();
comboBoxSelectorCompany = new ComboBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonDelExcavator = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddExcavator = new Button();
buttonAddTrackedVehicle = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
panelCompanyTools = new Panel();
groupBox1.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout();
//
// groupBox1
//
groupBox1.Controls.Add(buttonRefresh);
groupBox1.Controls.Add(buttonGoToCheck);
groupBox1.Controls.Add(buttonDelExcavator);
groupBox1.Controls.Add(maskedTextBox);
groupBox1.Controls.Add(buttonAddExcavator);
groupBox1.Controls.Add(buttonAddTrackedVehicle);
groupBox1.Controls.Add(panelCompanyTools);
groupBox1.Controls.Add(buttonCreateCompany);
groupBox1.Controls.Add(panelStorage);
groupBox1.Controls.Add(comboBoxSelectorCompany);
groupBox1.Dock = DockStyle.Right;
groupBox1.Location = new Point(939, 0);
@ -58,12 +67,115 @@
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(24, 441);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(180, 29);
buttonCreateCompany.TabIndex = 8;
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, 23);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(215, 362);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(15, 287);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(180, 29);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += buttonCollectionDel_Click;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.Location = new Point(3, 161);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(203, 104);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(16, 116);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(180, 29);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(103, 81);
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(15, 81);
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(15, 37);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(191, 27);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(27, 14);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(155, 20);
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(18, 402);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(191, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(18, 487);
buttonRefresh.Location = new Point(18, 273);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(191, 45);
buttonRefresh.Size = new Size(176, 45);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@ -72,9 +184,9 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(18, 406);
buttonGoToCheck.Location = new Point(18, 222);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(191, 45);
buttonGoToCheck.Size = new Size(171, 45);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@ -83,9 +195,9 @@
// buttonDelExcavator
//
buttonDelExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelExcavator.Location = new Point(18, 327);
buttonDelExcavator.Location = new Point(18, 171);
buttonDelExcavator.Name = "buttonDelExcavator";
buttonDelExcavator.Size = new Size(191, 45);
buttonDelExcavator.Size = new Size(171, 45);
buttonDelExcavator.TabIndex = 4;
buttonDelExcavator.Text = "Удалить машину";
buttonDelExcavator.UseVisualStyleBackColor = true;
@ -93,7 +205,7 @@
//
// maskedTextBox
//
maskedTextBox.Location = new Point(18, 257);
maskedTextBox.Location = new Point(13, 125);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(191, 27);
@ -103,9 +215,9 @@
// buttonAddExcavator
//
buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddExcavator.Location = new Point(18, 162);
buttonAddExcavator.Location = new Point(18, 72);
buttonAddExcavator.Name = "buttonAddExcavator";
buttonAddExcavator.Size = new Size(191, 45);
buttonAddExcavator.Size = new Size(166, 35);
buttonAddExcavator.TabIndex = 2;
buttonAddExcavator.Text = "Добавить экскаватор";
buttonAddExcavator.UseVisualStyleBackColor = true;
@ -114,35 +226,38 @@
// buttonAddTrackedVehicle
//
buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTrackedVehicle.Location = new Point(18, 83);
buttonAddTrackedVehicle.Location = new Point(12, 3);
buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle";
buttonAddTrackedVehicle.Size = new Size(191, 60);
buttonAddTrackedVehicle.Size = new Size(177, 52);
buttonAddTrackedVehicle.TabIndex = 1;
buttonAddTrackedVehicle.Text = "Добавить гусеничную машину";
buttonAddTrackedVehicle.UseVisualStyleBackColor = true;
buttonAddTrackedVehicle.Click += ButtonAddCar_Click;
//
// 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(18, 34);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(191, 28);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// pictureBox
//
pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
pictureBox.Location = new Point(0, 0);
pictureBox.Location = new Point(1, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(939, 800);
pictureBox.Size = new Size(938, 800);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddTrackedVehicle);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonAddExcavator);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonDelExcavator);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 473);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(215, 330);
panelCompanyTools.TabIndex = 9;
//
// FormTrackedVehicleCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
@ -153,8 +268,11 @@
Name = "FormTrackedVehicleCollection";
Text = "Коллекция экскаваторов";
groupBox1.ResumeLayout(false);
groupBox1.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@ -166,8 +284,18 @@
private Button buttonDelExcavator;
private MaskedTextBox maskedTextBox;
private Button buttonAddExcavator;
private PictureBox pictureBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
private Panel panelStorage;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Label labelCollectionName;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
private PictureBox pictureBox;
}
}

View File

@ -1,6 +1,5 @@
using Excavator.CollectionGenericObjects;
using Excavator.Drawnings;
using System.Windows.Forms;
namespace Excavator;
@ -9,6 +8,10 @@ namespace Excavator;
/// </summary>
public partial class FormTrackedVehicleCollection : Form
{
/// <summary>
/// Хранилише коллекций
/// </summary>
private readonly StorageCollection<DrawningTrackedVehicle> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -20,6 +23,8 @@ public partial class FormTrackedVehicleCollection : Form
public FormTrackedVehicleCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -29,12 +34,7 @@ public partial class FormTrackedVehicleCollection : Form
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTrackedVehicle>());
break;
}
panelCompanyTools.Enabled = false;
}
/// <summary>
@ -181,5 +181,98 @@ public partial class FormTrackedVehicleCollection : 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);
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>
/// Обновление списка в 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 buttonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects<DrawningTrackedVehicle>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
}