This commit is contained in:
BoiledMilk123 2024-04-09 09:51:13 +04:00
parent 3dd21881b4
commit 7881a9852a
8 changed files with 493 additions and 87 deletions

View File

@ -17,7 +17,7 @@ public abstract class AbstractCompany
/// <summary> /// <summary>
/// Размер места (высота) /// Размер места (высота)
/// </summary> /// </summary>
protected readonly int _placeSizeHeight = 64; protected readonly int _placeSizeHeight = 60;
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна

View File

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

View File

@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.CollectionGenericObjects;
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 (position >= Count || position < 0)
{
return -1;
}
if (Count == _maxCount)
{
return -1;
}
_collection.Insert(position, obj);
return position;
}
public T Remove(int position)
{
// проверка позиции
// удаление объекта из списка
if (position >= Count || position < 0) return null;
T obj = _collection[position];
_collection.RemoveAt(position);
return obj;
}
}

View File

@ -29,8 +29,8 @@ public class LocomotiveDepot : AbstractCompany
{ {
for (int j = 0; j < count_height + 1; ++j) for (int j = 0; j < count_height + 1; ++j)
{ {
g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 1, i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight+1); g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight + 5 , i * _placeSizeWidth + _placeSizeWidth - 50, j * _placeSizeHeight + 5);
g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight, i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight); g.DrawLine(pen, i * _placeSizeWidth + 10, j * _placeSizeHeight , i * _placeSizeWidth + 10, j * _placeSizeHeight + _placeSizeHeight );
} }
} }
} }

View File

@ -20,7 +20,7 @@ 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 (Count > 0) { Array.Resize(ref _collection, value); } else { _collection = new T?[value]; } } }
/// <summary> /// <summary>
/// Конструктор /// Конструктор

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectElectricLocomotive.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)
{
// проверка что name не пустой и нет в словаре записи с таким ключом
// логика добавления
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name) || collectionType == CollectionType.None) return;
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);
}
}
public ICollectionGenericObjects<T>? this[string name]
{
get
{
// логика получения объекта (если есть запись с ключом мы должны вернуть объект иначе значение словаря по ключу)
if (_storages.ContainsKey(name))
{
return _storages[name];
}
else
{
return null;
}
}
}
}

View File

@ -29,95 +29,54 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
buttonCreateCompany = new Button();
comboBoxSelectorCompany = new ComboBox();
panelCompanyTools = new Panel();
buttonAddLocomotive = new Button();
buttonAddElectricLocomotiv = new Button();
buttonRefresh = new Button(); buttonRefresh = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button(); buttonGoToCheck = new Button();
buttonRemoveLocomotive = new Button(); buttonRemoveLocomotive = new Button();
maskedTextBoxPosition = new MaskedTextBox(); panelStorage = new Panel();
buttonAddElectricLocomotiv = new Button(); buttonCollectionDel = new Button();
buttonAddLocomotive = new Button(); listBoxCollection = new ListBox();
comboBoxSelectorCompany = new ComboBox(); buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
colorDialog1 = new ColorDialog(); colorDialog1 = new ColorDialog();
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(buttonCreateCompany);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveLocomotive);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddElectricLocomotiv);
groupBoxTools.Controls.Add(buttonAddLocomotive);
groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(600, 0); groupBoxTools.Location = new Point(640, 0);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(200, 450); groupBoxTools.Size = new Size(200, 593);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// buttonRefresh // buttonCreateCompany
// //
buttonRefresh.Location = new Point(6, 336); buttonCreateCompany.Location = new Point(6, 336);
buttonRefresh.Name = "buttonRefresh"; buttonCreateCompany.Name = "buttonCreateCompany";
buttonRefresh.Size = new Size(188, 32); buttonCreateCompany.Size = new Size(188, 22);
buttonRefresh.TabIndex = 6; buttonCreateCompany.TabIndex = 7;
buttonRefresh.Text = "Обновить"; buttonCreateCompany.Text = "Создать компанию";
buttonRefresh.UseVisualStyleBackColor = true; buttonCreateCompany.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click; buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(6, 265);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(188, 32);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Поставить на пути";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveLocomotive
//
buttonRemoveLocomotive.Location = new Point(6, 193);
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
buttonRemoveLocomotive.Size = new Size(188, 32);
buttonRemoveLocomotive.TabIndex = 4;
buttonRemoveLocomotive.Text = "Удалить локомотив";
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 164);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(188, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddElectricLocomotiv
//
buttonAddElectricLocomotiv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddElectricLocomotiv.Location = new Point(6, 104);
buttonAddElectricLocomotiv.Name = "buttonAddElectricLocomotiv";
buttonAddElectricLocomotiv.Size = new Size(188, 32);
buttonAddElectricLocomotiv.TabIndex = 2;
buttonAddElectricLocomotiv.Text = "Добавить электровоз";
buttonAddElectricLocomotiv.UseVisualStyleBackColor = true;
buttonAddElectricLocomotiv.Click += ButtonAddElectricLocomotive_Click;
//
// buttonAddLocomotive
//
buttonAddLocomotive.Location = new Point(6, 66);
buttonAddLocomotive.Name = "buttonAddLocomotive";
buttonAddLocomotive.Size = new Size(188, 32);
buttonAddLocomotive.TabIndex = 1;
buttonAddLocomotive.Text = "Добавить локомотив";
buttonAddLocomotive.UseVisualStyleBackColor = true;
buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
// //
// comboBoxSelectorCompany // comboBoxSelectorCompany
// //
@ -125,18 +84,175 @@
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, 22); comboBoxSelectorCompany.Location = new Point(6, 307);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(188, 23); comboBoxSelectorCompany.Size = new Size(182, 23);
comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddLocomotive);
panelCompanyTools.Controls.Add(buttonAddElectricLocomotiv);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRemoveLocomotive);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 364);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(194, 226);
panelCompanyTools.TabIndex = 8;
//
// buttonAddLocomotive
//
buttonAddLocomotive.Location = new Point(3, 3);
buttonAddLocomotive.Name = "buttonAddLocomotive";
buttonAddLocomotive.Size = new Size(188, 31);
buttonAddLocomotive.TabIndex = 1;
buttonAddLocomotive.Text = "Добавить локомотив";
buttonAddLocomotive.UseVisualStyleBackColor = true;
buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
//
// buttonAddElectricLocomotiv
//
buttonAddElectricLocomotiv.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddElectricLocomotiv.Location = new Point(3, 40);
buttonAddElectricLocomotiv.Name = "buttonAddElectricLocomotiv";
buttonAddElectricLocomotiv.Size = new Size(188, 31);
buttonAddElectricLocomotiv.TabIndex = 2;
buttonAddElectricLocomotiv.Text = "Добавить электровоз";
buttonAddElectricLocomotiv.UseVisualStyleBackColor = true;
buttonAddElectricLocomotiv.Click += ButtonAddElectricLocomotive_Click;
//
// buttonRefresh
//
buttonRefresh.Location = new Point(3, 180);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(188, 37);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(3, 77);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(188, 23);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(3, 143);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(188, 31);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Поставить на пути";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// buttonRemoveLocomotive
//
buttonRemoveLocomotive.Location = new Point(3, 106);
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
buttonRemoveLocomotive.Size = new Size(188, 31);
buttonRemoveLocomotive.TabIndex = 4;
buttonRemoveLocomotive.Text = "Удалить локомотив";
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_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(194, 282);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 245);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(188, 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, 130);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(188, 109);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 101);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(188, 23);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(97, 76);
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, 76);
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, 47);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(188, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(27, 15);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(122, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции";
//
// pictureBox // pictureBox
// //
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(600, 450); pictureBox.Size = new Size(640, 593);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
@ -144,13 +260,16 @@
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450); ClientSize = new Size(840, 593);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Name = "FormLocomotiveCollection"; Name = "FormLocomotiveCollection";
Text = "FormLocomotiveCollection"; Text = "FormLocomotiveCollection";
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);
} }
@ -167,5 +286,15 @@
private Button buttonGoToCheck; private Button buttonGoToCheck;
private Button buttonRefresh; private Button buttonRefresh;
private ColorDialog colorDialog1; private ColorDialog colorDialog1;
private Panel panelStorage;
private TextBox textBoxCollectionName;
private Label labelCollectionName;
private Button buttonCreateCompany;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private Panel panelCompanyTools;
} }
} }

View File

@ -15,6 +15,11 @@ namespace ProjectElectricLocomotive;
public partial class FormLocomotiveCollection : Form public partial class FormLocomotiveCollection : Form
{ {
/// <summary>
/// Хранилище коллекций
/// </summary>
private readonly StorageCollection<DrawningLocomotive> _storageCollection;
/// <summary> /// <summary>
/// Компания /// Компания
/// </summary> /// </summary>
@ -26,6 +31,7 @@ public partial class FormLocomotiveCollection : Form
public FormLocomotiveCollection() public FormLocomotiveCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new();
} }
/// <summary> /// <summary>
@ -35,12 +41,7 @@ public partial class FormLocomotiveCollection : 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 LocomotiveDepot(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningLocomotive>());
break;
}
} }
/// <summary> /// <summary>
/// Добавление грузовика /// Добавление грузовика
@ -151,7 +152,6 @@ public partial class FormLocomotiveCollection : Form
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e) private void ButtonGoToCheck_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)
@ -180,5 +180,96 @@ public partial class FormLocomotiveCollection : Form
form.ShowDialog(); form.ShowDialog();
} }
/// <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)
{
//TODO логика удаления элемента из коллекции
//убедиться что есть выбранная коллекция
//спросить через месседжбокс что он пождтверждает что хочет удалить запись
//удалить и обновить ListBox
if (listBoxCollection.SelectedIndex < 0)
{
MessageBox.Show("Коллекция не существует");
return;
}
if (MessageBox.Show("Вы хотите удалить коллекцию?", "Коллекция удалена", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
_storageCollection.DelCollection(listBoxCollection.SelectedItem?.ToString() ?? string.Empty);
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)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects<DrawningLocomotive>? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проиннициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new LocomotiveDepot(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
} }