PIbd-12 Ulybin A.A. Monorail Lab04 Simple #8

Closed
qkrlnt wants to merge 2 commits from Lab04 into Lab03
8 changed files with 484 additions and 64 deletions

View File

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

View File

@ -0,0 +1,67 @@
using ProjectMonorail.CollectionGenericObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMonorail.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 < 0 || position >= Count) { return null; }
return _collection[position];
}
public int Insert(T obj)
{
if (obj == null || Count + 1 > _maxCount) { return -1; }
_collection.Add(obj);
return Count + 1;
}
public int Insert(T obj, int position)
{
if (obj == null || Count + 1 > _maxCount) { return -1; }
if (position < 0 || position >= Count) { return -1; }
_collection.Insert(position, obj);
return Count + 1;
}
public T Remove(int position)
{
if (position < 0 || position >= Count) { return null; }
T tmp = _collection[position];
_collection.RemoveAt(position);
return tmp;
}
}

View File

@ -20,8 +20,23 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
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>

View File

@ -0,0 +1,79 @@
using ProjectMonorail.CollectionGenericObject;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectMonorail.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:
break;
case CollectionType.Massive:
_storages.Add(name, new MassiveGenericObjects<T>());
break;
case CollectionType.List:
_storages.Add(name, new ListGenericObjects<T>());
break;
}
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(String name)
{
if (name == null || !_storages.ContainsKey(name)) { return; }
_storages.Remove(name);
}
/// <summary>
/// Доступ к коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
/// <returns></returns>
public ICollectionGenericObjects<T>? this[String name]
{
get
{
if (_storages.TryGetValue(name, out ICollectionGenericObjects<T>? value)) { return value; }
return null;
}
}
}

View File

@ -108,7 +108,6 @@ public class DrawingTrain
/// <returns></returns>
public bool SetPictureSize(int width, int height)
{
//TODO!
if (_drawingMonorailWidth <= width && _drawingMonorailHeight <= height)
{
_pictureWidth = width;

View File

@ -42,9 +42,8 @@
//
pictureBoxMonorail.Dock = DockStyle.Fill;
pictureBoxMonorail.Location = new Point(0, 0);
pictureBoxMonorail.Margin = new Padding(3, 4, 3, 4);
pictureBoxMonorail.Name = "pictureBoxMonorail";
pictureBoxMonorail.Size = new Size(1142, 596);
pictureBoxMonorail.Size = new Size(1206, 616);
pictureBoxMonorail.TabIndex = 5;
pictureBoxMonorail.TabStop = false;
//
@ -52,8 +51,7 @@
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonDown.BackgroundImage = Properties.Resources.icons8_стрелка_50вниз;
buttonDown.Location = new Point(1024, 530);
buttonDown.Margin = new Padding(3, 4, 3, 4);
buttonDown.Location = new Point(1088, 554);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(50, 50);
buttonDown.TabIndex = 10;
@ -64,8 +62,7 @@
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonRight.BackgroundImage = Properties.Resources.icons8_стрелка_50__1_;
buttonRight.Location = new Point(1080, 530);
buttonRight.Margin = new Padding(3, 4, 3, 4);
buttonRight.Location = new Point(1144, 554);
buttonRight.Name = "buttonRight";
buttonRight.Size = new Size(50, 50);
buttonRight.TabIndex = 9;
@ -76,8 +73,7 @@
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonLeft.BackgroundImage = Properties.Resources.icons8_стрелка_50влево;
buttonLeft.Location = new Point(968, 530);
buttonLeft.Margin = new Padding(3, 4, 3, 4);
buttonLeft.Location = new Point(1032, 554);
buttonLeft.Name = "buttonLeft";
buttonLeft.Size = new Size(50, 50);
buttonLeft.TabIndex = 8;
@ -88,8 +84,7 @@
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
buttonUp.BackgroundImage = Properties.Resources.icons8_стрелка_50вверх;
buttonUp.Location = new Point(1024, 472);
buttonUp.Margin = new Padding(3, 4, 3, 4);
buttonUp.Location = new Point(1088, 498);
buttonUp.Name = "buttonUp";
buttonUp.Size = new Size(50, 50);
buttonUp.TabIndex = 7;
@ -102,17 +97,19 @@
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxStrategy.FormattingEnabled = true;
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
comboBoxStrategy.Location = new Point(979, 12);
comboBoxStrategy.Location = new Point(1064, 9);
comboBoxStrategy.Margin = new Padding(3, 2, 3, 2);
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.Size = new Size(133, 23);
comboBoxStrategy.TabIndex = 12;
//
// buttonStrategyStep
//
buttonStrategyStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
buttonStrategyStep.Location = new Point(1036, 46);
buttonStrategyStep.Location = new Point(1113, 34);
buttonStrategyStep.Margin = new Padding(3, 2, 3, 2);
buttonStrategyStep.Name = "buttonStrategyStep";
buttonStrategyStep.Size = new Size(94, 29);
buttonStrategyStep.Size = new Size(82, 22);
buttonStrategyStep.TabIndex = 13;
buttonStrategyStep.Text = "Шаг";
buttonStrategyStep.UseVisualStyleBackColor = true;
@ -120,9 +117,9 @@
//
// FormMonorail
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1142, 596);
ClientSize = new Size(1206, 616);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonDown);
@ -130,7 +127,6 @@
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
Controls.Add(pictureBoxMonorail);
Margin = new Padding(3, 4, 3, 4);
Name = "FormMonorail";
Text = "FormMonorail";
((System.ComponentModel.ISupportInitialize)pictureBoxMonorail).EndInit();

View File

@ -29,42 +29,69 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemoveTrain = new Button();
maskedTextBoxPosition = new MaskedTextBox();
buttonAddMonorail = new Button();
buttonAddTrain = new Button();
buttonCreateCompany = new Button();
panelStorage = new Panel();
buttonCollectionDel = new Button();
listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
label1 = new Label();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveTrain);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddMonorail);
groupBoxTools.Controls.Add(buttonAddTrain);
groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(861, 0);
groupBoxTools.Location = new Point(1006, 0);
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(229, 634);
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
groupBoxTools.Size = new Size(200, 616);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRemoveTrain);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonAddMonorail);
panelCompanyTools.Controls.Add(buttonAddTrain);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 383);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(194, 231);
panelCompanyTools.TabIndex = 8;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 577);
buttonRefresh.Location = new Point(5, 188);
buttonRefresh.Margin = new Padding(3, 2, 3, 2);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(211, 45);
buttonRefresh.TabIndex = 6;
buttonRefresh.Size = new Size(185, 34);
buttonRefresh.TabIndex = 12;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
@ -72,10 +99,11 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 396);
buttonGoToCheck.Location = new Point(5, 150);
buttonGoToCheck.Margin = new Padding(3, 2, 3, 2);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(211, 45);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Size = new Size(185, 34);
buttonGoToCheck.TabIndex = 11;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
@ -83,30 +111,33 @@
// buttonRemoveTrain
//
buttonRemoveTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemoveTrain.Location = new Point(6, 292);
buttonRemoveTrain.Location = new Point(5, 112);
buttonRemoveTrain.Margin = new Padding(3, 2, 3, 2);
buttonRemoveTrain.Name = "buttonRemoveTrain";
buttonRemoveTrain.Size = new Size(211, 45);
buttonRemoveTrain.TabIndex = 4;
buttonRemoveTrain.Size = new Size(185, 34);
buttonRemoveTrain.TabIndex = 10;
buttonRemoveTrain.Text = "Удалить объект";
buttonRemoveTrain.UseVisualStyleBackColor = true;
buttonRemoveTrain.Click += ButtonRemoveTrain_Click;
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 259);
maskedTextBoxPosition.Location = new Point(5, 85);
maskedTextBoxPosition.Margin = new Padding(3, 2, 3, 2);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(211, 27);
maskedTextBoxPosition.TabIndex = 3;
maskedTextBoxPosition.Size = new Size(185, 23);
maskedTextBoxPosition.TabIndex = 9;
maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddMonorail
//
buttonAddMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddMonorail.Location = new Point(6, 164);
buttonAddMonorail.Location = new Point(5, 47);
buttonAddMonorail.Margin = new Padding(3, 2, 3, 2);
buttonAddMonorail.Name = "buttonAddMonorail";
buttonAddMonorail.Size = new Size(211, 45);
buttonAddMonorail.TabIndex = 2;
buttonAddMonorail.Size = new Size(185, 34);
buttonAddMonorail.TabIndex = 8;
buttonAddMonorail.Text = "Добавление монорельса";
buttonAddMonorail.UseVisualStyleBackColor = true;
buttonAddMonorail.Click += ButtonAddMonorail_Click;
@ -114,23 +145,119 @@
// buttonAddTrain
//
buttonAddTrain.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddTrain.Location = new Point(6, 113);
buttonAddTrain.Location = new Point(5, 9);
buttonAddTrain.Margin = new Padding(3, 2, 3, 2);
buttonAddTrain.Name = "buttonAddTrain";
buttonAddTrain.Size = new Size(211, 45);
buttonAddTrain.TabIndex = 1;
buttonAddTrain.Size = new Size(185, 34);
buttonAddTrain.TabIndex = 7;
buttonAddTrain.Text = "Добавление поезда";
buttonAddTrain.UseVisualStyleBackColor = true;
buttonAddTrain.Click += ButtonAddTrain_Click;
//
// buttonCreateCompany
//
buttonCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonCreateCompany.Location = new Point(6, 344);
buttonCreateCompany.Margin = new Padding(3, 2, 3, 2);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(185, 34);
buttonCreateCompany.TabIndex = 7;
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(label1);
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 18);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(194, 282);
panelStorage.TabIndex = 2;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 245);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(185, 34);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += ButtonCollectionDel_Click;
//
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 15;
listBoxCollection.Location = new Point(3, 122);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(188, 109);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(3, 82);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(185, 34);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(76, 57);
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(3, 57);
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, 28);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(188, 23);
textBoxCollectionName.TabIndex = 1;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(34, 10);
label1.Name = "label1";
label1.Size = new Size(125, 15);
label1.TabIndex = 0;
label1.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(6, 26);
comboBoxSelectorCompany.Location = new Point(6, 317);
comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(211, 28);
comboBoxSelectorCompany.Size = new Size(185, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
@ -138,22 +265,27 @@
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Margin = new Padding(3, 2, 3, 2);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(861, 634);
pictureBox.Size = new Size(1006, 616);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
// FormTrainCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1090, 634);
ClientSize = new Size(1206, 616);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Margin = new Padding(3, 2, 3, 2);
Name = "FormTrainCollection";
Text = "Коллекция поездов";
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@ -162,12 +294,22 @@
private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany;
private Button buttonAddTrain;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddMonorail;
private PictureBox pictureBox;
private Button buttonRemoveTrain;
private Panel panelStorage;
private Label label1;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
private Button buttonRefresh;
private Button buttonGoToCheck;
private Button buttonRemoveTrain;
private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddMonorail;
private Button buttonAddTrain;
}
}

View File

@ -18,6 +18,11 @@ namespace ProjectMonorail;
/// </summary>
public partial class FormTrainCollection : Form
{
/// <summary>
/// Хранилище коллекций
/// </summary>
private readonly StorageCollection<DrawingTrain> _storageCollection;
/// <summary>
/// Компания
/// </summary>
@ -29,6 +34,7 @@ public partial class FormTrainCollection : Form
public FormTrainCollection()
{
InitializeComponent();
_storageCollection = new();
}
/// <summary>
@ -38,13 +44,7 @@ public partial class FormTrainCollection : Form
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new TrainSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingTrain>());
break;
}
panelCompanyTools.Enabled = false;
}
/// <summary>
@ -80,7 +80,7 @@ public partial class FormTrainCollection : Form
drawingTrain = new DrawingTrain(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawingMonorail):
drawingTrain = new DrawingMonorail(random.Next(100, 300), random.Next(1000, 3000), random.Next(2, 5),
drawingTrain = new DrawingMonorail(random.Next(100, 300), random.Next(1000, 3000), random.Next(2, 5),
GetColor(random), GetColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default: return;
@ -192,4 +192,98 @@ public partial class FormTrainCollection : 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;
}
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)
{
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());
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 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
ICollectionGenericObjects<DrawingTrain>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new TrainSharingService(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RefreshListBoxItems();
}
}