Четвертая лаба
This commit is contained in:
parent
7f2792be67
commit
87c20a4587
@ -0,0 +1,26 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LocomotiveProject.CollectionGenericObjects;
|
||||||
|
/// <summary>
|
||||||
|
/// Тип коллекции
|
||||||
|
/// </summary>
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Неопределено
|
||||||
|
/// </summary>
|
||||||
|
None = 0,
|
||||||
|
/// <summary>
|
||||||
|
/// Массив
|
||||||
|
/// </summary>
|
||||||
|
Massive = 1,
|
||||||
|
/// <summary>
|
||||||
|
/// Список
|
||||||
|
/// </summary>
|
||||||
|
List = 2
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LocomotiveProject.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 int Insert(T obj)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
// TODO вставка в конец набора
|
||||||
|
if (_collection.Count >= _maxCount) return -1;
|
||||||
|
_collection.Add(obj);
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position)
|
||||||
|
{
|
||||||
|
// TODO проверка, что не превышено максимальное количество элементов
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO вставка по позиции
|
||||||
|
if (_collection.Count >= _maxCount || _collection[position] == null || position < 0) { return -1; }
|
||||||
|
_collection.Insert(position, obj);
|
||||||
|
return Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Get(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
if (!_collection.Any()) { return null; }
|
||||||
|
if (_collection.Count <= position || position < 0 || position >= _maxCount) { return null; }
|
||||||
|
return _collection[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? Remove(int position)
|
||||||
|
{
|
||||||
|
// TODO проверка позиции
|
||||||
|
// TODO удаление объекта из списка
|
||||||
|
if (position >= Count || position < 0) return null;
|
||||||
|
T obj = _collection[position];
|
||||||
|
_collection.RemoveAt(position);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
}
|
@ -8,9 +8,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace LocomotiveProject.CollectionGenericObjects;
|
namespace LocomotiveProject.CollectionGenericObjects;
|
||||||
|
|
||||||
public class LocomotiveDock : AbstractCompany
|
public class LocomotiveStation : AbstractCompany
|
||||||
{
|
{
|
||||||
public LocomotiveDock(int picWidth, int pictureHeight, ICollectionGenericObjects<DrawningBaseLocomotive> collection) : base(picWidth, pictureHeight, collection)
|
public LocomotiveStation(int picWidth, int pictureHeight, ICollectionGenericObjects<DrawningBaseLocomotive> collection) : base(picWidth, pictureHeight, collection)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LocomotiveProject.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 (name.Length <= 0 || _storages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
switch (collectionType)
|
||||||
|
{
|
||||||
|
case CollectionType.List:
|
||||||
|
_storages.Add(name, new ListGenericObjects<T>());
|
||||||
|
break;
|
||||||
|
case CollectionType.Massive:
|
||||||
|
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
public void DelCollection(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления коллекции
|
||||||
|
if (!_storages.ContainsKey(name)) { return; }
|
||||||
|
_storages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название коллекции</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ICollectionGenericObjects<T>? this[string name]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения объекта
|
||||||
|
if (!_storages.ContainsKey(name)) { return null; }
|
||||||
|
return _storages[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
using LocomotiveProject.Drawnings;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace LocomotiveProject.CollectionGenericObjects
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Параметризованный класс
|
|
||||||
/// </summary>
|
|
||||||
/// <typeparam name="T"></typeparam>
|
|
||||||
public class parameterizedClass<T> where T : DrawningLocomotive { }
|
|
||||||
}
|
|
@ -1,4 +1,4 @@
|
|||||||
namespace LocomotiveProject
|
namespace LocomativeProject
|
||||||
{
|
{
|
||||||
partial class LocomotiveProjectCollection
|
partial class LocomotiveProjectCollection
|
||||||
{
|
{
|
||||||
@ -29,26 +29,35 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
groupBox1 = new GroupBox();
|
groupBox1 = new GroupBox();
|
||||||
buttonRefresh = new Button();
|
panelCompany = new Panel();
|
||||||
buttonGoToCheck = new Button();
|
|
||||||
buttonRemoveLocomotive = new Button();
|
|
||||||
maskedTextBox = new MaskedTextBox();
|
|
||||||
buttonModifLocomotive = new Button();
|
buttonModifLocomotive = new Button();
|
||||||
buttonAddLocomotive = new Button();
|
buttonAddLocomotive = new Button();
|
||||||
|
maskedTextBox = new MaskedTextBox();
|
||||||
|
buttonRefresh = new Button();
|
||||||
|
buttonRemoveLocomotive = new Button();
|
||||||
|
buttonGoToCheck = 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();
|
||||||
|
labelCollectionName = new Label();
|
||||||
comboBoxSelectorCompany = new ComboBox();
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
pictureBox = new PictureBox();
|
pictureBox = new PictureBox();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
|
panelCompany.SuspendLayout();
|
||||||
|
panelStorage.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBox1
|
// groupBox1
|
||||||
//
|
//
|
||||||
groupBox1.Controls.Add(buttonRefresh);
|
groupBox1.Controls.Add(panelCompany);
|
||||||
groupBox1.Controls.Add(buttonGoToCheck);
|
groupBox1.Controls.Add(buttonCreateCompany);
|
||||||
groupBox1.Controls.Add(buttonRemoveLocomotive);
|
groupBox1.Controls.Add(panelStorage);
|
||||||
groupBox1.Controls.Add(maskedTextBox);
|
|
||||||
groupBox1.Controls.Add(buttonModifLocomotive);
|
|
||||||
groupBox1.Controls.Add(buttonAddLocomotive);
|
|
||||||
groupBox1.Controls.Add(comboBoxSelectorCompany);
|
groupBox1.Controls.Add(comboBoxSelectorCompany);
|
||||||
groupBox1.Dock = DockStyle.Right;
|
groupBox1.Dock = DockStyle.Right;
|
||||||
groupBox1.Location = new Point(912, 0);
|
groupBox1.Location = new Point(912, 0);
|
||||||
@ -58,48 +67,24 @@
|
|||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Инструменты";
|
groupBox1.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// buttonRefresh
|
// panelCompany
|
||||||
//
|
//
|
||||||
buttonRefresh.Location = new Point(32, 530);
|
panelCompany.Controls.Add(buttonModifLocomotive);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
panelCompany.Controls.Add(buttonAddLocomotive);
|
||||||
buttonRefresh.Size = new Size(124, 39);
|
panelCompany.Controls.Add(maskedTextBox);
|
||||||
buttonRefresh.TabIndex = 6;
|
panelCompany.Controls.Add(buttonRefresh);
|
||||||
buttonRefresh.Text = "Обновить";
|
panelCompany.Controls.Add(buttonRemoveLocomotive);
|
||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
panelCompany.Controls.Add(buttonGoToCheck);
|
||||||
buttonRefresh.Click += ButtonRefresh_Click;
|
panelCompany.Dock = DockStyle.Bottom;
|
||||||
//
|
panelCompany.Enabled = false;
|
||||||
// buttonGoToCheck
|
panelCompany.Location = new Point(3, 346);
|
||||||
//
|
panelCompany.Name = "panelCompany";
|
||||||
buttonGoToCheck.Location = new Point(32, 349);
|
panelCompany.Size = new Size(174, 232);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
panelCompany.TabIndex = 9;
|
||||||
buttonGoToCheck.Size = new Size(124, 39);
|
|
||||||
buttonGoToCheck.TabIndex = 5;
|
|
||||||
buttonGoToCheck.Text = "Передать на тесты";
|
|
||||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
|
||||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
|
||||||
//
|
|
||||||
// buttonRemoveLocomotive
|
|
||||||
//
|
|
||||||
buttonRemoveLocomotive.Location = new Point(18, 207);
|
|
||||||
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
|
||||||
buttonRemoveLocomotive.Size = new Size(150, 23);
|
|
||||||
buttonRemoveLocomotive.TabIndex = 4;
|
|
||||||
buttonRemoveLocomotive.Text = "Удалить поезд";
|
|
||||||
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
|
||||||
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
|
|
||||||
//
|
|
||||||
// maskedTextBox
|
|
||||||
//
|
|
||||||
maskedTextBox.Location = new Point(18, 178);
|
|
||||||
maskedTextBox.Mask = "00";
|
|
||||||
maskedTextBox.Name = "maskedTextBox";
|
|
||||||
maskedTextBox.Size = new Size(150, 23);
|
|
||||||
maskedTextBox.TabIndex = 3;
|
|
||||||
maskedTextBox.ValidatingType = typeof(int);
|
|
||||||
//
|
//
|
||||||
// buttonModifLocomotive
|
// buttonModifLocomotive
|
||||||
//
|
//
|
||||||
buttonModifLocomotive.Location = new Point(18, 102);
|
buttonModifLocomotive.Location = new Point(15, 38);
|
||||||
buttonModifLocomotive.Name = "buttonModifLocomotive";
|
buttonModifLocomotive.Name = "buttonModifLocomotive";
|
||||||
buttonModifLocomotive.Size = new Size(150, 43);
|
buttonModifLocomotive.Size = new Size(150, 43);
|
||||||
buttonModifLocomotive.TabIndex = 2;
|
buttonModifLocomotive.TabIndex = 2;
|
||||||
@ -110,21 +95,152 @@
|
|||||||
// buttonAddLocomotive
|
// buttonAddLocomotive
|
||||||
//
|
//
|
||||||
buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonAddLocomotive.Location = new Point(18, 62);
|
buttonAddLocomotive.Location = new Point(15, 6);
|
||||||
buttonAddLocomotive.Name = "buttonAddLocomotive";
|
buttonAddLocomotive.Name = "buttonAddLocomotive";
|
||||||
buttonAddLocomotive.Size = new Size(150, 23);
|
buttonAddLocomotive.Size = new Size(150, 26);
|
||||||
buttonAddLocomotive.TabIndex = 1;
|
buttonAddLocomotive.TabIndex = 1;
|
||||||
buttonAddLocomotive.Text = "Добавление поезда";
|
buttonAddLocomotive.Text = "Добавление поезда";
|
||||||
buttonAddLocomotive.UseVisualStyleBackColor = true;
|
buttonAddLocomotive.UseVisualStyleBackColor = true;
|
||||||
buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
|
buttonAddLocomotive.Click += ButtonAddLocomotive_Click;
|
||||||
//
|
//
|
||||||
|
// maskedTextBox
|
||||||
|
//
|
||||||
|
maskedTextBox.Location = new Point(15, 87);
|
||||||
|
maskedTextBox.Mask = "00";
|
||||||
|
maskedTextBox.Name = "maskedTextBox";
|
||||||
|
maskedTextBox.Size = new Size(150, 23);
|
||||||
|
maskedTextBox.TabIndex = 3;
|
||||||
|
maskedTextBox.ValidatingType = typeof(int);
|
||||||
|
//
|
||||||
|
// buttonRefresh
|
||||||
|
//
|
||||||
|
buttonRefresh.Location = new Point(27, 190);
|
||||||
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
|
buttonRefresh.Size = new Size(124, 39);
|
||||||
|
buttonRefresh.TabIndex = 6;
|
||||||
|
buttonRefresh.Text = "Обновить";
|
||||||
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
|
buttonRefresh.Click += ButtonRefresh_Click;
|
||||||
|
//
|
||||||
|
// buttonRemoveLocomotive
|
||||||
|
//
|
||||||
|
buttonRemoveLocomotive.Location = new Point(15, 116);
|
||||||
|
buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
|
||||||
|
buttonRemoveLocomotive.Size = new Size(150, 23);
|
||||||
|
buttonRemoveLocomotive.TabIndex = 4;
|
||||||
|
buttonRemoveLocomotive.Text = "Удалить поезд";
|
||||||
|
buttonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
|
||||||
|
//
|
||||||
|
// buttonGoToCheck
|
||||||
|
//
|
||||||
|
buttonGoToCheck.Location = new Point(29, 145);
|
||||||
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
|
buttonGoToCheck.Size = new Size(124, 39);
|
||||||
|
buttonGoToCheck.TabIndex = 5;
|
||||||
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
|
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||||
|
//
|
||||||
|
// buttonCreateCompany
|
||||||
|
//
|
||||||
|
buttonCreateCompany.Location = new Point(18, 320);
|
||||||
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
|
buttonCreateCompany.Size = new Size(150, 23);
|
||||||
|
buttonCreateCompany.TabIndex = 8;
|
||||||
|
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(labelCollectionName);
|
||||||
|
panelStorage.Dock = DockStyle.Top;
|
||||||
|
panelStorage.Location = new Point(3, 19);
|
||||||
|
panelStorage.Name = "panelStorage";
|
||||||
|
panelStorage.Size = new Size(174, 266);
|
||||||
|
panelStorage.TabIndex = 7;
|
||||||
|
//
|
||||||
|
// buttonCollectionDel
|
||||||
|
//
|
||||||
|
buttonCollectionDel.Location = new Point(15, 218);
|
||||||
|
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||||
|
buttonCollectionDel.Size = new Size(150, 23);
|
||||||
|
buttonCollectionDel.TabIndex = 6;
|
||||||
|
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||||
|
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||||
|
//
|
||||||
|
// listBoxCollection
|
||||||
|
//
|
||||||
|
listBoxCollection.FormattingEnabled = true;
|
||||||
|
listBoxCollection.ItemHeight = 15;
|
||||||
|
listBoxCollection.Location = new Point(15, 118);
|
||||||
|
listBoxCollection.Name = "listBoxCollection";
|
||||||
|
listBoxCollection.Size = new Size(150, 94);
|
||||||
|
listBoxCollection.TabIndex = 5;
|
||||||
|
//
|
||||||
|
// buttonCollectionAdd
|
||||||
|
//
|
||||||
|
buttonCollectionAdd.Location = new Point(15, 89);
|
||||||
|
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||||
|
buttonCollectionAdd.Size = new Size(150, 23);
|
||||||
|
buttonCollectionAdd.TabIndex = 4;
|
||||||
|
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||||
|
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||||
|
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||||
|
//
|
||||||
|
// radioButtonList
|
||||||
|
//
|
||||||
|
radioButtonList.AutoSize = true;
|
||||||
|
radioButtonList.Location = new Point(99, 64);
|
||||||
|
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, 64);
|
||||||
|
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(15, 35);
|
||||||
|
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||||
|
textBoxCollectionName.Size = new Size(150, 23);
|
||||||
|
textBoxCollectionName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCollectionName
|
||||||
|
//
|
||||||
|
labelCollectionName.AutoSize = true;
|
||||||
|
labelCollectionName.Location = new Point(29, 17);
|
||||||
|
labelCollectionName.Name = "labelCollectionName";
|
||||||
|
labelCollectionName.Size = new Size(122, 15);
|
||||||
|
labelCollectionName.TabIndex = 0;
|
||||||
|
labelCollectionName.Text = "Название коллекции";
|
||||||
|
//
|
||||||
// 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(18, 22);
|
comboBoxSelectorCompany.Location = new Point(18, 291);
|
||||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
comboBoxSelectorCompany.Size = new Size(150, 23);
|
comboBoxSelectorCompany.Size = new Size(150, 23);
|
||||||
comboBoxSelectorCompany.TabIndex = 0;
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
@ -147,9 +263,12 @@
|
|||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBox1);
|
Controls.Add(groupBox1);
|
||||||
Name = "LocomotiveProjectCollection";
|
Name = "LocomotiveProjectCollection";
|
||||||
Text = "Коллекция Тепловозов";
|
Text = "Коллекция Крейсеров";
|
||||||
groupBox1.ResumeLayout(false);
|
groupBox1.ResumeLayout(false);
|
||||||
groupBox1.PerformLayout();
|
panelCompany.ResumeLayout(false);
|
||||||
|
panelCompany.PerformLayout();
|
||||||
|
panelStorage.ResumeLayout(false);
|
||||||
|
panelStorage.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -165,5 +284,15 @@
|
|||||||
private PictureBox pictureBox;
|
private PictureBox pictureBox;
|
||||||
private Button buttonRefresh;
|
private Button buttonRefresh;
|
||||||
private Button buttonGoToCheck;
|
private Button buttonGoToCheck;
|
||||||
|
private Panel panelStorage;
|
||||||
|
private TextBox textBoxCollectionName;
|
||||||
|
private Label labelCollectionName;
|
||||||
|
private RadioButton radioButtonMassive;
|
||||||
|
private Button buttonCollectionDel;
|
||||||
|
private ListBox listBoxCollection;
|
||||||
|
private Button buttonCollectionAdd;
|
||||||
|
private RadioButton radioButtonList;
|
||||||
|
private Button buttonCreateCompany;
|
||||||
|
private Panel panelCompany;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using LocomativeProject.Drawnings;
|
using LocomativeProject.Drawnings;
|
||||||
|
using LocomotiveProject;
|
||||||
using LocomotiveProject.CollectionGenericObjects;
|
using LocomotiveProject.CollectionGenericObjects;
|
||||||
using LocomotiveProject.Drawnings;
|
using LocomotiveProject.Drawnings;
|
||||||
using System;
|
using System;
|
||||||
@ -11,9 +12,14 @@ using System.Text;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace LocomotiveProject;
|
namespace LocomativeProject;
|
||||||
|
|
||||||
public partial class LocomotiveProjectCollection : Form
|
public partial class LocomotiveProjectCollection : Form
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Хранилище коллекций
|
||||||
|
/// </summary>
|
||||||
|
private readonly StorageCollection<DrawningBaseLocomotive> _storageCollection;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Компания
|
/// Компания
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,6 +30,7 @@ public partial class LocomotiveProjectCollection : Form
|
|||||||
public LocomotiveProjectCollection()
|
public LocomotiveProjectCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
_storageCollection = new();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Выбор компании
|
/// Выбор компании
|
||||||
@ -32,12 +39,7 @@ public partial class LocomotiveProjectCollection : 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)
|
panelCompany.Enabled = false;
|
||||||
{
|
|
||||||
case "Хранилище":
|
|
||||||
_company = new LocomotiveDock(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningBaseLocomotive>());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Создание объекта класса-перемещения
|
/// Создание объекта класса-перемещения
|
||||||
@ -50,24 +52,23 @@ public partial class LocomotiveProjectCollection : Form
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Random rnd = new();
|
Random rnd = new();
|
||||||
DrawningBaseLocomotive drawningBaseLocomotive;
|
DrawningBaseLocomotive DrawningBaseLocomotive;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case nameof(DrawningBaseLocomotive):
|
case nameof(DrawningBaseLocomotive):
|
||||||
drawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd));
|
DrawningBaseLocomotive = new DrawningBaseLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd));
|
||||||
break;
|
break;
|
||||||
case nameof(DrawningLocomotive):
|
case nameof(DrawningLocomotive):
|
||||||
drawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd),
|
DrawningBaseLocomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 3000), GetColor(rnd), GetColor(rnd),
|
||||||
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_company + drawningBaseLocomotive != -1)
|
if (_company + DrawningBaseLocomotive != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBox.Image = _company.Show();
|
pictureBox.Image = _company.Show();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -90,19 +91,19 @@ public partial class LocomotiveProjectCollection : Form
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Кнопка создания обычного поезда
|
/// Кнопка создания обычного крейсера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseLocomotive));
|
private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseLocomotive));
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Кнопка создания модиф поезда
|
/// Кнопка создания модиф крейсера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonModifLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
|
private void ButtonModifLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Кнопка удаления поезда
|
/// Кнопка удаления Крейсера
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="sender"></param>
|
/// <param name="sender"></param>
|
||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
@ -142,11 +143,11 @@ public partial class LocomotiveProjectCollection : Form
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DrawningBaseLocomotive BaseLocomotive = null;
|
DrawningBaseLocomotive baseLocomotive = null;
|
||||||
int counter = 100;
|
int counter = 100;
|
||||||
while (BaseLocomotive == null)
|
while (baseLocomotive == null)
|
||||||
{
|
{
|
||||||
BaseLocomotive = _company.GetRandomObject();
|
baseLocomotive = _company.GetRandomObject();
|
||||||
counter--;
|
counter--;
|
||||||
if (counter <= 0)
|
if (counter <= 0)
|
||||||
{
|
{
|
||||||
@ -154,14 +155,14 @@ public partial class LocomotiveProjectCollection : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BaseLocomotive == null)
|
if (baseLocomotive == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
LocomotiveProject form = new() { SetLocomotive = BaseLocomotive };
|
LocomotiveProjectForm form = new() { SetLocomotive = baseLocomotive };
|
||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
|
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Кнопка обновления компании
|
/// Кнопка обновления компании
|
||||||
@ -170,10 +171,98 @@ public partial class LocomotiveProjectCollection : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_company == null)
|
if (_company != null)
|
||||||
|
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;
|
return;
|
||||||
}
|
}
|
||||||
pictureBox.Image = _company.Show();
|
|
||||||
|
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.SelectedItem == null || listBoxCollection.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция для удаления не выбрана");
|
||||||
|
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<DrawningBaseLocomotive>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (collection == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Коллекция не проинициализирована");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (comboBoxSelectorCompany.Text)
|
||||||
|
{
|
||||||
|
case "Хранилище":
|
||||||
|
_company = new LocomotiveStation(pictureBox.Width, pictureBox.Height, collection);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
panelCompany.Enabled = true;
|
||||||
|
RerfreshListBoxItems();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
namespace LocomotiveProject
|
namespace LocomotiveProject
|
||||||
{
|
{
|
||||||
partial class LocomotiveProject
|
partial class LocomotiveProjectForm
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@ -28,7 +28,7 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProject));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LocomotiveProjectForm));
|
||||||
pictureBox1 = new PictureBox();
|
pictureBox1 = new PictureBox();
|
||||||
pictureBoxLocomotive = new PictureBox();
|
pictureBoxLocomotive = new PictureBox();
|
||||||
buttonUp = new Button();
|
buttonUp = new Button();
|
@ -15,7 +15,7 @@ using LocomativeProject.MovementStrategy;
|
|||||||
|
|
||||||
namespace LocomotiveProject
|
namespace LocomotiveProject
|
||||||
{
|
{
|
||||||
public partial class LocomotiveProject : Form
|
public partial class LocomotiveProjectForm : Form
|
||||||
{
|
{
|
||||||
private DrawningBaseLocomotive? _drawningLocomotive;
|
private DrawningBaseLocomotive? _drawningLocomotive;
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ namespace LocomotiveProject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public LocomotiveProject()
|
public LocomotiveProjectForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_strategy = null;
|
_strategy = null;
|
@ -1,3 +1,5 @@
|
|||||||
|
using LocomativeProject;
|
||||||
|
|
||||||
namespace LocomotiveProject
|
namespace LocomotiveProject
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
|
Loading…
Reference in New Issue
Block a user