лаба4

This commit is contained in:
Anya 2024-05-20 14:22:37 +04:00
parent aae38b1efd
commit 2206e25233
6 changed files with 528 additions and 104 deletions

View File

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

View File

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

View File

@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectBus.CollectionGenericObject;
/// <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:
return;
case CollectionType.Massive:
_storages.Add(name, new MassiveGenericObjects<T> { });
return;
case CollectionType.List:
_storages.Add(name, new ListGenericObjects<T> { });
return;
}
}
/// <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 (name == null || !_storages.ContainsKey(name)) { return null; }
return _storages[name];
}
}
}

View File

@ -29,83 +29,62 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
buttonRefresh = new Button(); panelCompanyTools = new Panel();
buttonGoToCheck = new Button();
buttonDelBus = new Button();
maskedTextBox = new MaskedTextBox();
buttonAddBus = new Button(); buttonAddBus = new Button();
buttonAddSimpleBus = new Button(); buttonAddSimpleBus = new Button();
maskedTextBox = new MaskedTextBox();
buttonRefresh = new Button();
buttonDelBus = new Button();
buttonGoToCheck = new Button();
panelStorage = new Panel();
buttonCollectionDel = new Button();
buttonCreateCompany = new Button();
listBoxCollection = new ListBox();
buttonCollectionAdd = new Button();
comboBoxSelectorCompany = new ComboBox(); comboBoxSelectorCompany = new ComboBox();
radioButtonList = new RadioButton();
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
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(panelStorage);
groupBoxTools.Controls.Add(buttonDelBus);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddBus);
groupBoxTools.Controls.Add(buttonAddSimpleBus);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(1063, 0); groupBoxTools.Location = new Point(1018, 0);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(333, 962); groupBoxTools.Size = new Size(356, 1058);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// buttonRefresh // panelCompanyTools
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelCompanyTools.Controls.Add(buttonAddBus);
buttonRefresh.Location = new Point(6, 731); panelCompanyTools.Controls.Add(buttonAddSimpleBus);
buttonRefresh.Name = "buttonRefresh"; panelCompanyTools.Controls.Add(maskedTextBox);
buttonRefresh.Size = new Size(315, 84); panelCompanyTools.Controls.Add(buttonRefresh);
buttonRefresh.TabIndex = 7; panelCompanyTools.Controls.Add(buttonDelBus);
buttonRefresh.Text = "Обновить"; panelCompanyTools.Controls.Add(buttonGoToCheck);
buttonRefresh.UseVisualStyleBackColor = true; panelCompanyTools.Dock = DockStyle.Bottom;
buttonRefresh.Click += ButtonRefresh_Click_1; panelCompanyTools.Enabled = false;
// panelCompanyTools.Location = new Point(3, 543);
// buttonGoToCheck panelCompanyTools.Name = "panelCompanyTools";
// panelCompanyTools.Size = new Size(350, 512);
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelCompanyTools.TabIndex = 8;
buttonGoToCheck.Location = new Point(6, 565);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(315, 84);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click_1;
//
// buttonDelBus
//
buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBus.Location = new Point(6, 416);
buttonDelBus.Name = "buttonDelBus";
buttonDelBus.Size = new Size(315, 84);
buttonDelBus.TabIndex = 5;
buttonDelBus.Text = "Удалить автобус";
buttonDelBus.UseVisualStyleBackColor = true;
//
// maskedTextBox
//
maskedTextBox.Location = new Point(6, 355);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(315, 39);
maskedTextBox.TabIndex = 4;
maskedTextBox.ValidatingType = typeof(int);
// //
// buttonAddBus // buttonAddBus
// //
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddBus.Location = new Point(6, 77);
buttonAddBus.Location = new Point(6, 225);
buttonAddBus.Name = "buttonAddBus"; buttonAddBus.Name = "buttonAddBus";
buttonAddBus.Size = new Size(315, 84); buttonAddBus.Size = new Size(321, 76);
buttonAddBus.TabIndex = 2; buttonAddBus.TabIndex = 2;
buttonAddBus.Text = "Добавление автобуса с доп. отсеком"; buttonAddBus.Text = "Добавление автобуса с доп. отсеком";
buttonAddBus.UseVisualStyleBackColor = true; buttonAddBus.UseVisualStyleBackColor = true;
@ -113,51 +92,190 @@
// //
// buttonAddSimpleBus // buttonAddSimpleBus
// //
buttonAddSimpleBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddSimpleBus.Location = new Point(9, 3);
buttonAddSimpleBus.Location = new Point(6, 118);
buttonAddSimpleBus.Name = "buttonAddSimpleBus"; buttonAddSimpleBus.Name = "buttonAddSimpleBus";
buttonAddSimpleBus.Size = new Size(315, 84); buttonAddSimpleBus.Size = new Size(318, 59);
buttonAddSimpleBus.TabIndex = 1; buttonAddSimpleBus.TabIndex = 1;
buttonAddSimpleBus.Text = "Добавление автобуса"; buttonAddSimpleBus.Text = "Добавление автобуса";
buttonAddSimpleBus.UseVisualStyleBackColor = true; buttonAddSimpleBus.UseVisualStyleBackColor = true;
buttonAddSimpleBus.Click += ButtonAddSimpleBus_Click; buttonAddSimpleBus.Click += ButtonAddSimpleBus_Click;
// //
// maskedTextBox
//
maskedTextBox.Location = new Point(15, 173);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(306, 39);
maskedTextBox.TabIndex = 0;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 366);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(328, 49);
buttonRefresh.TabIndex = 7;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click;
//
// buttonDelBus
//
buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelBus.Location = new Point(6, 231);
buttonDelBus.Name = "buttonDelBus";
buttonDelBus.Size = new Size(321, 46);
buttonDelBus.TabIndex = 5;
buttonDelBus.Text = "Удалить автобус";
buttonDelBus.UseVisualStyleBackColor = true;
buttonDelBus.Click += buttonDelBus_Click;
//
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 293);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(328, 58);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click;
//
// panelStorage
//
panelStorage.Controls.Add(buttonCollectionDel);
panelStorage.Controls.Add(buttonCreateCompany);
panelStorage.Controls.Add(listBoxCollection);
panelStorage.Controls.Add(buttonCollectionAdd);
panelStorage.Controls.Add(comboBoxSelectorCompany);
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, 35);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(350, 518);
panelStorage.TabIndex = 8;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(3, 348);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(324, 46);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
buttonCollectionDel.Click += ButtonCollectionDel_Click;
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(6, 456);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(324, 46);
buttonCreateCompany.TabIndex = 9;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
buttonCreateCompany.Click += ButtonCreateCompany_Click;
//
// listBoxCollection
//
listBoxCollection.ItemHeight = 32;
listBoxCollection.Location = new Point(0, 231);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(324, 100);
listBoxCollection.TabIndex = 7;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(0, 166);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(324, 46);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
//
// comboBoxSelectorCompany // comboBoxSelectorCompany
// //
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
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, 47); comboBoxSelectorCompany.Location = new Point(0, 400);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(315, 40); comboBoxSelectorCompany.Size = new Size(344, 40);
comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(181, 114);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(125, 36);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(13, 114);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(128, 36);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(3, 60);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(318, 39);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(34, 25);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(251, 32);
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(1063, 962); pictureBox.Size = new Size(1018, 1058);
pictureBox.TabIndex = 3; pictureBox.TabIndex = 0;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
// FormSimpleBusCollection // FormSimpleBusCollection
// //
AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleDimensions = new SizeF(13F, 32F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1396, 962); ClientSize = new Size(1374, 1058);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Name = "FormSimpleBusCollection"; Name = "FormSimpleBusCollection";
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);
} }
#endregion #endregion
@ -170,5 +288,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 TextBox textBoxCollectionName;
private RadioButton radioButtonList;
private RadioButton radioButtonMassive;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
} }
} }

View File

@ -6,12 +6,30 @@ namespace ProjectBus;
public partial class FormSimpleBusCollection : Form public partial class FormSimpleBusCollection : Form
{ {
/// <summary>
/// Хранилише коллекций
/// </summary>
private readonly StorageCollection<DrawningSimpleBus> _storageCollection;
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormSimpleBusCollection() public FormSimpleBusCollection()
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new();
} }
/// <summary>
/// Выбор компании
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
switch (comboBoxSelectorCompany.Text) switch (comboBoxSelectorCompany.Text)
@ -22,6 +40,11 @@ public partial class FormSimpleBusCollection : Form
} }
} }
/// <summary>
/// Добавление обычного автомобиля
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus)); private void ButtonAddSimpleBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSimpleBus));
/// <summary> /// <summary>
@ -35,35 +58,6 @@ public partial class FormSimpleBusCollection : Form
/// Создание объекта класса-перемещения /// Создание объекта класса-перемещения
/// </summary> /// </summary>
/// <param name="type">Тип создаваемого объекта</param> /// <param name="type">Тип создаваемого объекта</param>
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CreateObject(string type) private void CreateObject(string type)
{ {
if (_company == null) if (_company == null)
@ -98,6 +92,12 @@ public partial class FormSimpleBusCollection : Form
_ = MessageBox.Show(drawningSimpleBus.ToString()); _ = MessageBox.Show(drawningSimpleBus.ToString());
} }
} }
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
private static Color GetColor(Random random) private static Color GetColor(Random random)
{ {
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
@ -110,8 +110,12 @@ public partial class FormSimpleBusCollection : Form
return color; return color;
} }
/// <summary>
private void ButtonDelBus_Click_1(object sender, EventArgs e) /// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonDelBus_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{ {
@ -136,7 +140,12 @@ public partial class FormSimpleBusCollection : Form
} }
private void ButtonRefresh_Click_1(object sender, EventArgs e) /// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)
{ {
@ -147,7 +156,12 @@ public partial class FormSimpleBusCollection : Form
} }
private void ButtonGoToCheck_Click_1(object sender, EventArgs e) /// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)
{ {
@ -178,5 +192,109 @@ public partial class FormSimpleBusCollection : 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);
RerfreshListBoxItems();
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonCollectionDel_Click(object sender, EventArgs e)
{
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
{
MessageBox.Show("Коллекция не выбрана");
return;
}
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
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);
}
}
}
/// <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<DrawningSimpleBus>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "хранилище":
_company = new BusStation(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
} }

View File

@ -7,8 +7,6 @@ using System.Threading.Tasks;
namespace ProjectBus.MovementStrategy; namespace ProjectBus.MovementStrategy;
public class MoveToBorder : AbstractStrategy public class MoveToBorder : AbstractStrategy
{ {
protected override bool IsTargetDestinaion() protected override bool IsTargetDestinaion()
{ {
ObjectParameters? objParams = GetObjectParameters; ObjectParameters? objParams = GetObjectParameters;
@ -16,11 +14,12 @@ public class MoveToBorder : AbstractStrategy
{ {
return false; return false;
} }
return objParams.RightBorder - GetStep() <= FieldWidth return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
&& objParams.RightBorder + GetStep() >= FieldWidth && && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth &&
objParams.DownBorder - GetStep() <= FieldHeight objParams.ObjectMiddleVertical - GetStep() <= FieldHeight
&& objParams.DownBorder + GetStep() >= FieldHeight; && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
} }
protected override void MoveToTarget() protected override void MoveToTarget()
{ {
ObjectParameters? objParams = GetObjectParameters; ObjectParameters? objParams = GetObjectParameters;