Лабораторная №4
This commit is contained in:
parent
c8bb1b3c31
commit
1e6dd7d3a6
@ -0,0 +1,22 @@
|
|||||||
|
namespace ProjectHoistingCrane.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Тип коллекции
|
||||||
|
/// </summary>
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неопределено
|
||||||
|
/// </summary>
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Массив
|
||||||
|
/// </summary>
|
||||||
|
Massive = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Список
|
||||||
|
/// </summary>
|
||||||
|
List = 2
|
||||||
|
}
|
@ -1,6 +1,4 @@
|
|||||||
using ProjectHoistingCrane.Drawnings;
|
using ProjectHoistingCrane.Drawnings;
|
||||||
using static System.Windows.Forms.AxHost;
|
|
||||||
using System.Drawing;
|
|
||||||
|
|
||||||
namespace ProjectHoistingCrane.CollectionGenericObjects;
|
namespace ProjectHoistingCrane.CollectionGenericObjects;
|
||||||
|
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
namespace ProjectHoistingCrane.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)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
|
||||||
|
if (position < Count)
|
||||||
|
{
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public int Insert(T obj)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
if(Count + 1 > _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO вставка в конец набора
|
||||||
|
_collection.Add(obj);
|
||||||
|
|
||||||
|
return _collection.Count-1;
|
||||||
|
}
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
if (Count + 1 > _maxCount)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO вставка по позиции
|
||||||
|
_collection.Insert(position, obj);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO удаление объекта из списка
|
||||||
|
T? temp = _collection[position];
|
||||||
|
_collection.RemoveAt(position);
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
}
|
@ -19,8 +19,23 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public int Count => _collection.Length;
|
public int Count => _collection.Length;
|
||||||
|
|
||||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
public int SetMaxCount
|
||||||
|
{
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
if (_collection.Length > 0)
|
||||||
|
{
|
||||||
|
Array.Resize(ref _collection, value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_collection = new T?[value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -32,7 +47,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
|
|
||||||
if (0 <= position && position <= Count) {
|
if (0 <= position && position < Count) {
|
||||||
|
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -61,7 +77,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
// если нет после, ищем до
|
// если нет после, ищем до
|
||||||
// TODO вставка
|
// TODO вставка
|
||||||
|
|
||||||
if (0 <= position && position <= Count && _collection[position] != null)
|
if (0 <= position && position < Count)
|
||||||
{
|
{
|
||||||
if (_collection[position] == null) {
|
if (_collection[position] == null) {
|
||||||
_collection[position] = obj;
|
_collection[position] = obj;
|
||||||
|
@ -0,0 +1,77 @@
|
|||||||
|
namespace ProjectHoistingCrane.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)
|
||||||
|
{
|
||||||
|
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(name) || _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)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления коллекции
|
||||||
|
if (_storages.ContainsKey(name)) _storages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ICollectionGenericObjects<T>? this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения объекта
|
||||||
|
if (string.IsNullOrEmpty(name) || !_storages.ContainsKey(name))
|
||||||
|
return null;
|
||||||
|
return _storages[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -29,52 +29,107 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
|
panelCompanyTools = new Panel();
|
||||||
|
buttonAddCrane = new Button();
|
||||||
|
buttonAddHoistingCrane = new Button();
|
||||||
buttonRefresh = new Button();
|
buttonRefresh = new Button();
|
||||||
|
maskedTextBoxPosition = new MaskedTextBox();
|
||||||
buttonGoToCheck = new Button();
|
buttonGoToCheck = new Button();
|
||||||
buttonRemoveCrane = new Button();
|
buttonRemoveCrane = new Button();
|
||||||
maskedTextBoxPosition = new MaskedTextBox();
|
buttonCreateCompany = new Button();
|
||||||
buttonAddHoistingCrane = new Button();
|
panelStorage = new Panel();
|
||||||
buttonAddCrane = new Button();
|
buttonCollectionDel = new Button();
|
||||||
|
listBoxCollection = new ListBox();
|
||||||
|
buttonCollectionAdd = new Button();
|
||||||
|
radioButtonList = new RadioButton();
|
||||||
|
radioButtonMassive = new RadioButton();
|
||||||
|
textBoxCollectionName = new TextBox();
|
||||||
|
labelCollectionName = new Label();
|
||||||
comboBoxSelectorCompany = new ComboBox();
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
pictureBox = new PictureBox();
|
pictureBox = new PictureBox();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
|
panelCompanyTools.SuspendLayout();
|
||||||
|
panelStorage.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
//
|
//
|
||||||
groupBoxTools.Controls.Add(buttonRefresh);
|
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||||
groupBoxTools.Controls.Add(buttonRemoveCrane);
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
|
||||||
groupBoxTools.Controls.Add(buttonAddHoistingCrane);
|
|
||||||
groupBoxTools.Controls.Add(buttonAddCrane);
|
|
||||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(738, 0);
|
groupBoxTools.Location = new Point(771, 0);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(222, 618);
|
groupBoxTools.Size = new Size(222, 690);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// panelCompanyTools
|
||||||
|
//
|
||||||
|
panelCompanyTools.Controls.Add(buttonAddCrane);
|
||||||
|
panelCompanyTools.Controls.Add(buttonAddHoistingCrane);
|
||||||
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
|
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||||
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
|
panelCompanyTools.Controls.Add(buttonRemoveCrane);
|
||||||
|
panelCompanyTools.Enabled = false;
|
||||||
|
panelCompanyTools.Location = new Point(6, 395);
|
||||||
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
|
panelCompanyTools.Size = new Size(210, 293);
|
||||||
|
panelCompanyTools.TabIndex = 2;
|
||||||
|
//
|
||||||
|
// buttonAddCrane
|
||||||
|
//
|
||||||
|
buttonAddCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddCrane.Location = new Point(3, 3);
|
||||||
|
buttonAddCrane.Name = "buttonAddCrane";
|
||||||
|
buttonAddCrane.Size = new Size(204, 37);
|
||||||
|
buttonAddCrane.TabIndex = 1;
|
||||||
|
buttonAddCrane.Text = "Добавление крана";
|
||||||
|
buttonAddCrane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddCrane.Click += ButtonAddCrane_Click;
|
||||||
|
//
|
||||||
|
// buttonAddHoistingCrane
|
||||||
|
//
|
||||||
|
buttonAddHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonAddHoistingCrane.Location = new Point(3, 46);
|
||||||
|
buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
|
||||||
|
buttonAddHoistingCrane.Size = new Size(199, 55);
|
||||||
|
buttonAddHoistingCrane.TabIndex = 2;
|
||||||
|
buttonAddHoistingCrane.Text = "Добавление подъёмного крана";
|
||||||
|
buttonAddHoistingCrane.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddHoistingCrane.Click += ButtonAddHoistingCrane_Click;
|
||||||
|
//
|
||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRefresh.Location = new Point(24, 513);
|
buttonRefresh.Location = new Point(3, 229);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
buttonRefresh.Size = new Size(163, 53);
|
buttonRefresh.Size = new Size(199, 53);
|
||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
buttonRefresh.Text = "Обновить";
|
buttonRefresh.Text = "Обновить";
|
||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
buttonRefresh.Click += ButtonRefresh_Click;
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
//
|
//
|
||||||
|
// maskedTextBoxPosition
|
||||||
|
//
|
||||||
|
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
maskedTextBoxPosition.Location = new Point(0, 107);
|
||||||
|
maskedTextBoxPosition.Mask = "00";
|
||||||
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
|
maskedTextBoxPosition.Size = new Size(204, 27);
|
||||||
|
maskedTextBoxPosition.TabIndex = 3;
|
||||||
|
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonGoToCheck.Location = new Point(24, 382);
|
buttonGoToCheck.Location = new Point(3, 182);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(163, 53);
|
buttonGoToCheck.Size = new Size(199, 41);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
buttonGoToCheck.Text = "Передать на тесты";
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
@ -83,44 +138,106 @@
|
|||||||
// buttonRemoveCrane
|
// buttonRemoveCrane
|
||||||
//
|
//
|
||||||
buttonRemoveCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRemoveCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRemoveCrane.Location = new Point(24, 277);
|
buttonRemoveCrane.Location = new Point(3, 140);
|
||||||
buttonRemoveCrane.Name = "buttonRemoveCrane";
|
buttonRemoveCrane.Name = "buttonRemoveCrane";
|
||||||
buttonRemoveCrane.Size = new Size(163, 53);
|
buttonRemoveCrane.Size = new Size(199, 36);
|
||||||
buttonRemoveCrane.TabIndex = 4;
|
buttonRemoveCrane.TabIndex = 4;
|
||||||
buttonRemoveCrane.Text = "Удалить кран";
|
buttonRemoveCrane.Text = "Удалить кран";
|
||||||
buttonRemoveCrane.UseVisualStyleBackColor = true;
|
buttonRemoveCrane.UseVisualStyleBackColor = true;
|
||||||
buttonRemoveCrane.Click += ButtonRemoveCrane_Click;
|
buttonRemoveCrane.Click += ButtonRemoveCrane_Click;
|
||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// buttonCreateCompany
|
||||||
//
|
//
|
||||||
maskedTextBoxPosition.Location = new Point(6, 244);
|
buttonCreateCompany.Location = new Point(6, 349);
|
||||||
maskedTextBoxPosition.Mask = "00";
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
buttonCreateCompany.Size = new Size(216, 29);
|
||||||
maskedTextBoxPosition.Size = new Size(210, 27);
|
buttonCreateCompany.TabIndex = 8;
|
||||||
maskedTextBoxPosition.TabIndex = 3;
|
buttonCreateCompany.Text = "Создать компанию";
|
||||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||||
|
buttonCreateCompany.Click += ButtonCreateCompany_Click;
|
||||||
//
|
//
|
||||||
// buttonAddHoistingCrane
|
// panelStorage
|
||||||
//
|
//
|
||||||
buttonAddHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
panelStorage.Controls.Add(buttonCollectionDel);
|
||||||
buttonAddHoistingCrane.Location = new Point(24, 139);
|
panelStorage.Controls.Add(listBoxCollection);
|
||||||
buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
|
panelStorage.Controls.Add(buttonCollectionAdd);
|
||||||
buttonAddHoistingCrane.Size = new Size(163, 53);
|
panelStorage.Controls.Add(radioButtonList);
|
||||||
buttonAddHoistingCrane.TabIndex = 2;
|
panelStorage.Controls.Add(radioButtonMassive);
|
||||||
buttonAddHoistingCrane.Text = "Добавление подъёмного крана";
|
panelStorage.Controls.Add(textBoxCollectionName);
|
||||||
buttonAddHoistingCrane.UseVisualStyleBackColor = true;
|
panelStorage.Controls.Add(labelCollectionName);
|
||||||
buttonAddHoistingCrane.Click += ButtonAddHoistingCrane_Click;
|
panelStorage.Dock = DockStyle.Top;
|
||||||
|
panelStorage.Location = new Point(3, 23);
|
||||||
|
panelStorage.Name = "panelStorage";
|
||||||
|
panelStorage.Size = new Size(216, 276);
|
||||||
|
panelStorage.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// buttonAddCrane
|
// buttonCollectionDel
|
||||||
//
|
//
|
||||||
buttonAddCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonCollectionDel.Location = new Point(0, 243);
|
||||||
buttonAddCrane.Location = new Point(24, 80);
|
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||||
buttonAddCrane.Name = "buttonAddCrane";
|
buttonCollectionDel.Size = new Size(216, 29);
|
||||||
buttonAddCrane.Size = new Size(163, 53);
|
buttonCollectionDel.TabIndex = 6;
|
||||||
buttonAddCrane.TabIndex = 1;
|
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||||
buttonAddCrane.Text = "Добавление крана";
|
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||||
buttonAddCrane.UseVisualStyleBackColor = true;
|
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||||
buttonAddCrane.Click += ButtonAddCrane_Click;
|
//
|
||||||
|
// listBoxCollection
|
||||||
|
//
|
||||||
|
listBoxCollection.FormattingEnabled = true;
|
||||||
|
listBoxCollection.Location = new Point(3, 133);
|
||||||
|
listBoxCollection.Name = "listBoxCollection";
|
||||||
|
listBoxCollection.Size = new Size(210, 104);
|
||||||
|
listBoxCollection.TabIndex = 5;
|
||||||
|
listBoxCollection.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// buttonCollectionAdd
|
||||||
|
//
|
||||||
|
buttonCollectionAdd.Location = new Point(0, 98);
|
||||||
|
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||||
|
buttonCollectionAdd.Size = new Size(216, 29);
|
||||||
|
buttonCollectionAdd.TabIndex = 4;
|
||||||
|
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||||
|
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||||
|
//
|
||||||
|
// radioButtonList
|
||||||
|
//
|
||||||
|
radioButtonList.AutoSize = true;
|
||||||
|
radioButtonList.Location = new Point(125, 68);
|
||||||
|
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(21, 68);
|
||||||
|
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(0, 35);
|
||||||
|
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||||
|
textBoxCollectionName.Size = new Size(216, 27);
|
||||||
|
textBoxCollectionName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCollectionName
|
||||||
|
//
|
||||||
|
labelCollectionName.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
labelCollectionName.AutoSize = true;
|
||||||
|
labelCollectionName.Location = new Point(26, 12);
|
||||||
|
labelCollectionName.Name = "labelCollectionName";
|
||||||
|
labelCollectionName.Size = new Size(158, 20);
|
||||||
|
labelCollectionName.TabIndex = 0;
|
||||||
|
labelCollectionName.Text = "Название коллекции:";
|
||||||
//
|
//
|
||||||
// comboBoxSelectorCompany
|
// comboBoxSelectorCompany
|
||||||
//
|
//
|
||||||
@ -128,7 +245,7 @@
|
|||||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
comboBoxSelectorCompany.Location = new Point(6, 26);
|
comboBoxSelectorCompany.Location = new Point(6, 315);
|
||||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
comboBoxSelectorCompany.Size = new Size(210, 28);
|
comboBoxSelectorCompany.Size = new Size(210, 28);
|
||||||
comboBoxSelectorCompany.TabIndex = 0;
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
@ -139,7 +256,7 @@
|
|||||||
pictureBox.Dock = DockStyle.Fill;
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
pictureBox.Location = new Point(0, 0);
|
pictureBox.Location = new Point(0, 0);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(738, 618);
|
pictureBox.Size = new Size(771, 690);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -147,13 +264,16 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(960, 618);
|
ClientSize = new Size(993, 690);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Name = "FormCraneCollection";
|
Name = "FormCraneCollection";
|
||||||
Text = "Коллекция кранов";
|
Text = "Коллекция кранов";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
groupBoxTools.PerformLayout();
|
panelCompanyTools.ResumeLayout(false);
|
||||||
|
panelCompanyTools.PerformLayout();
|
||||||
|
panelStorage.ResumeLayout(false);
|
||||||
|
panelStorage.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -169,5 +289,15 @@
|
|||||||
private PictureBox pictureBox;
|
private PictureBox pictureBox;
|
||||||
private Button buttonRefresh;
|
private Button buttonRefresh;
|
||||||
private Button buttonGoToCheck;
|
private Button buttonGoToCheck;
|
||||||
|
private Panel panelStorage;
|
||||||
|
private Label labelCollectionName;
|
||||||
|
private RadioButton radioButtonList;
|
||||||
|
private RadioButton radioButtonMassive;
|
||||||
|
private TextBox textBoxCollectionName;
|
||||||
|
private Button buttonCollectionDel;
|
||||||
|
private ListBox listBoxCollection;
|
||||||
|
private Button buttonCollectionAdd;
|
||||||
|
private Button buttonCreateCompany;
|
||||||
|
private Panel panelCompanyTools;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,6 +17,12 @@ namespace ProjectHoistingCrane;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class FormCraneCollection : Form
|
public partial class FormCraneCollection : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Хранилище компании
|
||||||
|
/// </summary>
|
||||||
|
private readonly StorageCollection<DrawningCrane> _storageCollection;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Компания
|
/// Компания
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,6 +34,7 @@ public partial class FormCraneCollection : Form
|
|||||||
public FormCraneCollection()
|
public FormCraneCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_storageCollection = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -37,12 +44,7 @@ public partial class FormCraneCollection : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
switch (comboBoxSelectorCompany.Text)
|
panelCompanyTools.Enabled = false;
|
||||||
{
|
|
||||||
case "Хранилище":
|
|
||||||
_company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningCrane>());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -195,4 +197,99 @@ public partial class FormCraneCollection : Form
|
|||||||
}
|
}
|
||||||
pictureBox.Image = _company.Show();
|
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)
|
||||||
|
{
|
||||||
|
// TODO прописать логику удаления элемента из коллекции
|
||||||
|
// нужно убедиться, что есть выбранная коллекция
|
||||||
|
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
||||||
|
// удалить и обновить ListBox
|
||||||
|
|
||||||
|
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не выбрана");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Вы действительно хотите удалить коллекцию?", "Да", MessageBoxButtons.YesNo) == 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<DrawningCrane>? 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();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user