Todo left

This commit is contained in:
Tonb73 2024-03-28 08:57:08 +03:00
parent 14379b9543
commit f4307c9c87
5 changed files with 390 additions and 28 deletions

View File

@ -0,0 +1,24 @@
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,59 @@
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 SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public int Count => _collection.Count;
/// <summary>
/// Конструктор
/// </summary>
public ListGenericObjects()
{
_collection = new();
}
public T? Get(int position)
{
// TODO проверка позиции
return _collection[position];
}
public int Insert(T obj)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO вставка в конец набора
return 1;
}
public int Insert(T obj, int position)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO проверка позиции
// TODO вставка по позиции
return 1;
}
public T Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из списка
return (T)1;
}
}
}

View File

@ -0,0 +1,62 @@
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)
{
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
// TODO Прописать логику для удаления коллекции
}
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectionGenericObjects<T>? this[string name]
{
get
{
// TODO Продумать логику получения объекта
return null;
}
}
}

View File

@ -29,6 +29,15 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
buttonCreateCompany = new Button();
labelCollectionName = new Label();
panelStorage = new Panel();
buttonCollectionDel = new Button();
listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonDelLocomotive = new Button();
@ -37,30 +46,121 @@
buttonAddLocomotive = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
panelCompanyTools = new Panel();
groupBoxTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonDelLocomotive);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddElectricLocomotive);
groupBoxTools.Controls.Add(buttonAddLocomotive);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(labelCollectionName);
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(574, 0);
groupBoxTools.Location = new Point(589, 0);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(226, 450);
groupBoxTools.Size = new Size(503, 450);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(223, 375);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(246, 34);
buttonCreateCompany.TabIndex = 10;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += buttonCreateCompany_Click;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(242, 9);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(182, 25);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции";
//
// 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.Location = new Point(220, 30);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(254, 300);
panelStorage.TabIndex = 8;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 254);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(246, 34);
buttonCollectionDel.TabIndex = 13;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += buttonCollectionDel_Click;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 25;
listBoxCollection.Location = new Point(3, 119);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(246, 129);
listBoxCollection.TabIndex = 12;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 79);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(246, 34);
buttonCollectionAdd.TabIndex = 9;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += buttonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(120, 44);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(96, 29);
radioButtonList.TabIndex = 11;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(3, 44);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(98, 29);
radioButtonMassive.TabIndex = 10;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 7);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(246, 31);
textBoxCollectionName.TabIndex = 9;
//
// buttonRefresh
//
buttonRefresh.Location = new Point(21, 358);
buttonRefresh.Location = new Point(12, 297);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(193, 39);
buttonRefresh.TabIndex = 7;
@ -70,7 +170,7 @@
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(21, 313);
buttonGoToCheck.Location = new Point(12, 252);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(193, 39);
buttonGoToCheck.TabIndex = 6;
@ -80,7 +180,7 @@
//
// buttonDelLocomotive
//
buttonDelLocomotive.Location = new Point(21, 244);
buttonDelLocomotive.Location = new Point(12, 183);
buttonDelLocomotive.Name = "buttonDelLocomotive";
buttonDelLocomotive.Size = new Size(193, 63);
buttonDelLocomotive.TabIndex = 5;
@ -90,7 +190,7 @@
//
// maskedTextBox
//
maskedTextBox.Location = new Point(21, 207);
maskedTextBox.Location = new Point(12, 146);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(193, 31);
@ -99,7 +199,7 @@
//
// buttonAddElectricLocomotive
//
buttonAddElectricLocomotive.Location = new Point(21, 138);
buttonAddElectricLocomotive.Location = new Point(12, 77);
buttonAddElectricLocomotive.Name = "buttonAddElectricLocomotive";
buttonAddElectricLocomotive.Size = new Size(193, 63);
buttonAddElectricLocomotive.TabIndex = 2;
@ -109,7 +209,7 @@
//
// buttonAddLocomotive
//
buttonAddLocomotive.Location = new Point(21, 69);
buttonAddLocomotive.Location = new Point(12, 8);
buttonAddLocomotive.Name = "buttonAddLocomotive";
buttonAddLocomotive.Size = new Size(193, 63);
buttonAddLocomotive.TabIndex = 1;
@ -123,9 +223,9 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Депо" });
comboBoxSelectorCompany.Location = new Point(21, 30);
comboBoxSelectorCompany.Location = new Point(223, 336);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(193, 33);
comboBoxSelectorCompany.Size = new Size(246, 33);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
//
@ -134,22 +234,40 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(574, 450);
pictureBox.Size = new Size(589, 450);
pictureBox.TabIndex = 3;
pictureBox.TabStop = false;
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonAddLocomotive);
panelCompanyTools.Controls.Add(buttonAddElectricLocomotive);
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonDelLocomotive);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(6, 30);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(211, 379);
panelCompanyTools.TabIndex = 4;
//
// FormLocomotiveCollection
//
AutoScaleDimensions = new SizeF(10F, 25F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(1092, 450);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormLocomotiveCollection";
Text = "Коллекция Локомотивов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@ -164,5 +282,15 @@
private Button buttonDelLocomotive;
private Button buttonRefresh;
private Button buttonGoToCheck;
private Panel panelStorage;
private Label labelCollectionName;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
}
}

View File

@ -18,6 +18,12 @@ namespace ProjectElectricLocomotive;
/// </summary>
public partial class FormLocomotiveCollection : Form
{
/// <summary>
/// Хранилище коллекций
/// </summary>
private readonly StorageCollection<DrawningLocomotive> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -28,6 +34,7 @@ public partial class FormLocomotiveCollection : Form
public FormLocomotiveCollection()
{
InitializeComponent();
_storageCollection = new();
}
@ -38,13 +45,7 @@ public partial class FormLocomotiveCollection : Form
/// <param name="e"></param>
private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Депо":
_company = new LocomotiveDepo(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningLocomotive>());
break;
}
panelCompanyTools.Enabled = false;
}
/// <summary>
/// Создание объекта класса-перемещения
@ -59,13 +60,13 @@ public partial class FormLocomotiveCollection : Form
case nameof(DrawningLocomotive):
drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random));
break;
case nameof(DrawningElectricLocomotive):
drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
@ -201,5 +202,93 @@ public partial class FormLocomotiveCollection : Form
pictureBox.Image = _company.Show();
}
}
/// <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<DrawningLocomotive>? collection =
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new LocomotiveDepo(pictureBox.Width,
pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonCollectionDel_Click(object sender, EventArgs e)
{
// TODO прописать логику удаления элемента из коллекции
// нужно убедиться, что есть выбранная коллекция
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
// удалить и обновить ListBox
}
/// <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();
}
}