PIbd_13 Klykov_N.V. LabWork04 Simple #6

Closed
nikos77781 wants to merge 1 commits from Lab04 into Lab03
6 changed files with 462 additions and 77 deletions
Showing only changes of commit 6cd1804e9a - Show all commits

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Excavator.CollectionGenericObjects;
public enum CollectionType
{
/// <summary>
/// Неопределено
/// </summary>
None = 0,
/// <summary>
/// Массив
/// </summary>
Massive = 1,
/// <summary>
/// Список
/// </summary>
List = 2
}

View File

@ -7,6 +7,7 @@ namespace Excavator.CollectionGenericObjects;
/// </summary>
public class Garage : AbstractCompany
{
/// <summary>
/// Конструктор
/// </summary>

View File

@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Excavator.CollectionGenericObjects;
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
where T : class
{
/// <summary>
/// Список объектов, которые храним
/// </summary>
private readonly List<T?> _collection;
/// <summary>
/// Максимально допустимое число объектов в списке
/// </summary>
public 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 >= Count || position < 0) return null;
T temp = _collection[position];
_collection.RemoveAt(position);
return temp;
}
}

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Excavator.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)
{
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;
default: break;
}
}
/// <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,28 +29,37 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveExcavator = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddExcavator = new Button();
buttonAddSimpleExcavator = new Button();
buttonCreateCompany = new Button();
panelStorage = new Panel();
buttonCollectionDel = new Button();
listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
labelCollectionName = new Label();
textBoxCollectionName = new TextBox();
comboBoxSelectorCompany = new ComboBox();
panelCompanyTools = new Panel();
buttonGoToCheck = new Button();
buttonAddSimpleExcavator = new Button();
buttonAddExcavator = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonRemoveExcavator = new Button();
buttonRefresh = new Button();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
panelStorage.SuspendLayout();
panelCompanyTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Anchor = AnchorStyles.Right;
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveExcavator);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddExcavator);
groupBoxTools.Controls.Add(buttonAddSimpleExcavator);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Font = new Font("Microsoft Sans Serif", 8.25F, FontStyle.Regular, GraphicsUnit.Point);
groupBoxTools.Location = new Point(855, 1);
groupBoxTools.Name = "groupBoxTools";
@ -59,64 +68,97 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonRefresh
// buttonCreateCompany
//
buttonRefresh.Location = new Point(6, 473);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(200, 49);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
buttonCreateCompany.Location = new Point(9, 325);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(191, 34);
buttonCreateCompany.TabIndex = 7;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click;
//
// buttonGoToCheck
// panelStorage
//
buttonGoToCheck.Location = new Point(6, 379);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(200, 49);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
panelStorage.Controls.Add(buttonCollectionDel);
panelStorage.Controls.Add(listBoxCollection);
panelStorage.Controls.Add(buttonCollectionAdd);
panelStorage.Controls.Add(radioButtonList);
panelStorage.Controls.Add(radioButtonMassive);
panelStorage.Controls.Add(labelCollectionName);
panelStorage.Controls.Add(textBoxCollectionName);
panelStorage.Location = new Point(6, 23);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(200, 269);
panelStorage.TabIndex = 8;
//
// buttonRemoveExcavator
// buttonCollectionDel
//
buttonRemoveExcavator.Location = new Point(6, 273);
buttonRemoveExcavator.Name = "buttonRemoveExcavator";
buttonRemoveExcavator.Size = new Size(200, 49);
buttonRemoveExcavator.TabIndex = 4;
buttonRemoveExcavator.Text = "Удалить экскаватор";
buttonRemoveExcavator.UseVisualStyleBackColor = true;
buttonRemoveExcavator.Click += ButtonRemoveExcavator_Click;
buttonCollectionDel.Location = new Point(6, 231);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(191, 38);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += buttonCollectionDel_Click;
//
// maskedTextBoxPosition
// listBoxCollection
//
maskedTextBoxPosition.Location = new Point(12, 244);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(194, 20);
maskedTextBoxPosition.TabIndex = 3;
listBoxCollection.FormattingEnabled = true;
listBoxCollection.Location = new Point(6, 121);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(191, 108);
listBoxCollection.TabIndex = 5;
//
// buttonAddExcavator
// buttonCollectionAdd
//
buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddExcavator.Location = new Point(6, 145);
buttonAddExcavator.Name = "buttonAddExcavator";
buttonAddExcavator.Size = new Size(200, 52);
buttonAddExcavator.TabIndex = 2;
buttonAddExcavator.Text = "Добавить экскаватор с обвесами";
buttonAddExcavator.UseVisualStyleBackColor = true;
buttonAddExcavator.Click += ButtonAddExcavator_Click;
buttonCollectionAdd.Location = new Point(6, 72);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(191, 38);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
//
// buttonAddSimpleExcavator
// radioButtonList
//
buttonAddSimpleExcavator.Location = new Point(6, 87);
buttonAddSimpleExcavator.Name = "buttonAddSimpleExcavator";
buttonAddSimpleExcavator.Size = new Size(200, 52);
buttonAddSimpleExcavator.TabIndex = 1;
buttonAddSimpleExcavator.Text = "Добавить экскаватор";
buttonAddSimpleExcavator.UseVisualStyleBackColor = true;
buttonAddSimpleExcavator.Click += ButtonAddSimleExcavator_Click;
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(117, 49);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(62, 17);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(19, 49);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(64, 17);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(46, 7);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(117, 13);
labelCollectionName.TabIndex = 1;
labelCollectionName.Text = "Название коллекции:";
labelCollectionName.Click += labelCollectionName_Click;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(6, 23);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(191, 20);
textBoxCollectionName.TabIndex = 0;
textBoxCollectionName.TextChanged += textBoxCollectionName_TextChanged;
//
// comboBoxSelectorCompany
//
@ -124,12 +166,84 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(12, 22);
comboBoxSelectorCompany.Location = new Point(9, 298);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(194, 21);
comboBoxSelectorCompany.Size = new Size(191, 21);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonAddSimpleExcavator);
panelCompanyTools.Controls.Add(buttonAddExcavator);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonRemoveExcavator);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Location = new Point(6, 365);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(200, 263);
panelCompanyTools.TabIndex = 7;
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(6, 164);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(191, 42);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonAddSimpleExcavator
//
buttonAddSimpleExcavator.Location = new Point(3, 3);
buttonAddSimpleExcavator.Name = "buttonAddSimpleExcavator";
buttonAddSimpleExcavator.Size = new Size(191, 35);
buttonAddSimpleExcavator.TabIndex = 1;
buttonAddSimpleExcavator.Text = "Добавить экскаватор";
buttonAddSimpleExcavator.UseVisualStyleBackColor = true;
buttonAddSimpleExcavator.Click += ButtonAddSimleExcavator_Click;
//
// buttonAddExcavator
//
buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddExcavator.Location = new Point(3, 44);
buttonAddExcavator.Name = "buttonAddExcavator";
buttonAddExcavator.Size = new Size(191, 41);
buttonAddExcavator.TabIndex = 2;
buttonAddExcavator.Text = "Добавить экскаватор с обвесами";
buttonAddExcavator.UseVisualStyleBackColor = true;
buttonAddExcavator.Click += ButtonAddExcavator_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(3, 91);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(191, 20);
maskedTextBoxPosition.TabIndex = 3;
//
// buttonRemoveExcavator
//
buttonRemoveExcavator.Location = new Point(6, 117);
buttonRemoveExcavator.Name = "buttonRemoveExcavator";
buttonRemoveExcavator.Size = new Size(191, 41);
buttonRemoveExcavator.TabIndex = 4;
buttonRemoveExcavator.Text = "Удалить экскаватор";
buttonRemoveExcavator.UseVisualStyleBackColor = true;
buttonRemoveExcavator.Click += ButtonRemoveExcavator_Click;
//
// buttonRefresh
//
buttonRefresh.Location = new Point(6, 212);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(191, 41);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// pictureBox
//
pictureBox.AccessibleRole = AccessibleRole.None;
@ -152,7 +266,10 @@
Name = "FormExcavatorCollection";
Text = "Коллекция экскаваторов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@ -168,5 +285,15 @@
private Button buttonRemoveExcavator;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRefresh;
private Panel panelStorage;
private Panel panelCompanyTools;
private TextBox textBoxCollectionName;
private Label labelCollectionName;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private ListBox listBoxCollection;
private Button buttonCollectionDel;
private Button buttonCreateCompany;
}
}

View File

@ -1,25 +1,22 @@
using Excavator.CollectionGenericObjects;
using Excavator.Drawnings;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Excavator;
public partial class FormExcavatorCollection : Form
{
/// <summary>
/// Хранилище коллекций
/// </summary>
private readonly StorageCollection<DrawningSimpleExcavator> _storageCollection;
private AbstractCompany? _company = null;
public FormExcavatorCollection()
{
InitializeComponent();
_storageCollection = new();
}
private void pictureBox_Click(object sender, EventArgs e)
@ -28,12 +25,7 @@ public partial class FormExcavatorCollection : Form
}
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningSimpleExcavator>());
break;
}
panelCompanyTools.Enabled = false;
}
private void CreateObject(string type)
{
@ -155,4 +147,99 @@ public partial class FormExcavatorCollection : Form
pictureBox.Image = _company.Show();
}
private void textBoxCollectionName_TextChanged(object sender, EventArgs e)
Review

Пустых методов быть не должно

Пустых методов быть не должно
{
}
private void labelCollectionName_Click(object sender, EventArgs e)
{
}
/// <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);
}
}
}
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();
}
private void buttonCreateCompany_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects<DrawningSimpleExcavator>? 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();
}
}