Добавление новый способ хранения объектов в "Сервисе"

This commit is contained in:
gettterot 2024-04-03 08:28:54 +04:00
parent 9aec819091
commit 10ce368f63
7 changed files with 641 additions and 282 deletions

View File

@ -71,7 +71,7 @@ namespace ProjectLiner.CollectionGenericObjects
/// <returns></returns> /// <returns></returns>
public static DrawningCommonLiner operator -(AbstractCompany company, int position) public static DrawningCommonLiner operator -(AbstractCompany company, int position)
{ {
return company._collection.Remove(position); return company._collection.Remove(position) ;
} }
/// <summary> /// <summary>

View File

@ -0,0 +1,24 @@

namespace ProjectLiner.CollectionGenericObjects;
/// <summary>
/// Тип коллекции
/// </summary>
public enum CollectionType
{
/// <summary>
/// Неопределено
/// </summary>
None = 0,
/// <summary>
/// Массив
/// </summary>
Massive = 1,
/// <summary>
/// Список
/// </summary>
List = 2,
}

View File

@ -0,0 +1,52 @@
using ProjectLiner.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 >= Count || position < 0) return null;
return _collection[position];
}
public int Insert(T obj)
{
if (Count + 1 > _maxCount) return -1;
_collection.Add(obj);
return Count;
}
public int Insert(T obj, int position)
{
if (Count + 1 > _maxCount) return -1;
if (position < 0 || position > Count) return -1;
_collection.Insert(position, obj);
return 1;
}
public T? Remove(int position)
{
if (position < 0 || position > Count) return null;
T? temp = _collection[position];
_collection.RemoveAt(position);
return temp;
}
}

View File

@ -63,45 +63,33 @@ namespace ProjectLiner.CollectionGenericObjects
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if (position < 0 || position >= Count) if (position >= Count || position < 0) return -1;
if (_collection[position] == null)
{ {
return -1; _collection[position] = obj;
return position;
} }
int temp = position + 1;
if (_collection[position] != null) while (temp < Count)
{ {
bool pushed = false; if (_collection[temp] == null)
for (int index = position + 1; index < Count; index++)
{ {
if (_collection[index] == null) _collection[temp] = obj;
{ return temp;
position = index;
pushed = true;
break;
}
}
if (!pushed)
{
for (int index = position - 1; index >= 0; index--)
{
if (_collection[index] == null)
{
position = index;
pushed = true;
break;
}
}
}
if (!pushed)
{
return position;
} }
++temp;
} }
temp = position - 1;
_collection[position] = obj; while (temp >= 0)
return position; {
if (_collection[temp] == null)
{
_collection[temp] = obj;
return temp;
}
--temp;
}
return -1;
} }
public T? Remove(int position) public T? Remove(int position)
@ -111,7 +99,7 @@ namespace ProjectLiner.CollectionGenericObjects
return null; return null;
} }
if (_collection[position] == null) return null; //if (_collection[position] == null) return null;
T? temp = _collection[position]; T? temp = _collection[position];
_collection[position] = null; _collection[position] = null;

View File

@ -0,0 +1,68 @@
using ProjectLiner.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:
return;
case CollectionType.Massive:
_storages[name] = new MassiveGenericObjects<T>();
return;
case CollectionType.List:
_storages[name] = new ListGenericObjects<T>();
return;
}
}
/// <summary>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
{
if (_storages.ContainsKey(name))
_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,98 +29,149 @@
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
buttonRefresh = new Button(); buttonCreateCompany = new Button();
buttonGoToCheck = new Button(); panelStorage = new Panel();
buttonRemoveLiner = new Button(); buttonCollectionDel = new Button();
maskedTextBoxPosition = new MaskedTextBox(); listBoxCollection = new ListBox();
buttonAddCommonLiner = new Button(); buttonCollectionAdd = new Button();
buttonAddLiner = 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();
panelCompanyTools = new Panel();
button1 = new Button();
button2 = new Button();
maskedTextBox1 = new MaskedTextBox();
button3 = new Button();
button4 = new Button();
button5 = new Button();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
panelCompanyTools.SuspendLayout();
SuspendLayout(); SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
groupBoxTools.Controls.Add(buttonRefresh); groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(buttonGoToCheck); groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(buttonRemoveLiner);
groupBoxTools.Controls.Add(maskedTextBoxPosition);
groupBoxTools.Controls.Add(buttonAddCommonLiner);
groupBoxTools.Controls.Add(buttonAddLiner);
groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(1053, 0); groupBoxTools.Location = new Point(681, 0);
groupBoxTools.Margin = new Padding(2);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(272, 845); groupBoxTools.Padding = new Padding(2);
groupBoxTools.Size = new Size(176, 648);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
// //
// buttonRefresh // buttonCreateCompany
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonCreateCompany.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
buttonRefresh.Location = new Point(33, 683); buttonCreateCompany.Location = new Point(5, 317);
buttonRefresh.Name = "buttonRefresh"; buttonCreateCompany.Name = "buttonCreateCompany";
buttonRefresh.Size = new Size(217, 76); buttonCreateCompany.Size = new Size(166, 23);
buttonRefresh.TabIndex = 6; buttonCreateCompany.TabIndex = 8;
buttonRefresh.Text = "Обновить"; buttonCreateCompany.Text = "Создать компанию";
buttonRefresh.UseVisualStyleBackColor = true; buttonCreateCompany.UseVisualStyleBackColor = true;
buttonRefresh.Click += ButtonRefresh_Click; buttonCreateCompany.Click += ButtonCreateCompany_Click;
// //
// buttonGoToCheck // panelStorage
// //
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelStorage.Controls.Add(buttonCollectionDel);
buttonGoToCheck.Location = new Point(33, 562); panelStorage.Controls.Add(listBoxCollection);
buttonGoToCheck.Name = "buttonGoToCheck"; panelStorage.Controls.Add(buttonCollectionAdd);
buttonGoToCheck.Size = new Size(217, 76); panelStorage.Controls.Add(radioButtonList);
buttonGoToCheck.TabIndex = 5; panelStorage.Controls.Add(radioButtonMassive);
buttonGoToCheck.Text = "Передать на тесты"; panelStorage.Controls.Add(textBoxCollectionName);
buttonGoToCheck.UseVisualStyleBackColor = true; panelStorage.Controls.Add(labelCollectionName);
buttonGoToCheck.Click += ButtonGoToCheck_Click; panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(2, 28);
panelStorage.Margin = new Padding(2);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(172, 247);
panelStorage.TabIndex = 7;
// //
// buttonRemoveLiner // buttonCollectionDel
// //
buttonRemoveLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonCollectionDel.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
buttonRemoveLiner.Location = new Point(33, 416); buttonCollectionDel.Location = new Point(3, 212);
buttonRemoveLiner.Name = "buttonRemoveLiner"; buttonCollectionDel.Name = "buttonCollectionDel";
buttonRemoveLiner.Size = new Size(217, 76); buttonCollectionDel.Size = new Size(166, 23);
buttonRemoveLiner.TabIndex = 4; buttonCollectionDel.TabIndex = 6;
buttonRemoveLiner.Text = "Удаление Лайнера"; buttonCollectionDel.Text = "Удалить Коллекцию";
buttonRemoveLiner.UseVisualStyleBackColor = true; buttonCollectionDel.UseVisualStyleBackColor = true;
buttonRemoveLiner.Click += ButtonRemoveLiner_Click; buttonCollectionDel.Click += ButtonCollectionDel_Click;
// //
// maskedTextBoxPosition // listBoxCollection
// //
maskedTextBoxPosition.Location = new Point(33, 363); listBoxCollection.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
maskedTextBoxPosition.Mask = "00"; listBoxCollection.FormattingEnabled = true;
maskedTextBoxPosition.Name = "maskedTextBoxPosition"; listBoxCollection.ItemHeight = 17;
maskedTextBoxPosition.Size = new Size(217, 47); listBoxCollection.Location = new Point(3, 110);
maskedTextBoxPosition.TabIndex = 3; listBoxCollection.Name = "listBoxCollection";
maskedTextBoxPosition.ValidatingType = typeof(int); listBoxCollection.Size = new Size(166, 89);
listBoxCollection.TabIndex = 5;
// //
// buttonAddCommonLiner // buttonCollectionAdd
// //
buttonAddCommonLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonCollectionAdd.Font = new Font("Segoe UI", 7.948052F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddCommonLiner.Location = new Point(33, 236); buttonCollectionAdd.Location = new Point(2, 82);
buttonAddCommonLiner.Name = "buttonAddCommonLiner"; buttonCollectionAdd.Margin = new Padding(2);
buttonAddCommonLiner.Size = new Size(217, 76); buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonAddCommonLiner.TabIndex = 2; buttonCollectionAdd.Size = new Size(170, 23);
buttonAddCommonLiner.Text = "Добавление Обычного Лайнера"; buttonCollectionAdd.TabIndex = 4;
buttonAddCommonLiner.UseVisualStyleBackColor = true; buttonCollectionAdd.Text = "Добавить коллекцию";
buttonAddCommonLiner.Click += ButtonAddCommonLiner_Click; buttonCollectionAdd.UseVisualStyleBackColor = true;
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
// //
// buttonAddLiner // radioButtonList
// //
buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; radioButtonList.AutoSize = true;
buttonAddLiner.Location = new Point(33, 126); radioButtonList.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
buttonAddLiner.Name = "buttonAddLiner"; radioButtonList.Location = new Point(89, 58);
buttonAddLiner.Size = new Size(217, 76); radioButtonList.Margin = new Padding(2);
buttonAddLiner.TabIndex = 1; radioButtonList.Name = "radioButtonList";
buttonAddLiner.Text = "Добавление Лайнера"; radioButtonList.Size = new Size(73, 23);
buttonAddLiner.UseVisualStyleBackColor = true; radioButtonList.TabIndex = 3;
buttonAddLiner.Click += ButtonAddLiner_Click; radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
radioButtonList.UseVisualStyleBackColor = true;
//
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
radioButtonMassive.Location = new Point(2, 58);
radioButtonMassive.Margin = new Padding(2);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(71, 23);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "массив";
radioButtonMassive.UseVisualStyleBackColor = true;
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(0, 26);
textBoxCollectionName.Margin = new Padding(2);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(172, 33);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
labelCollectionName.Location = new Point(14, 5);
labelCollectionName.Margin = new Padding(2, 0, 2, 0);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(140, 19);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции";
// //
// comboBoxSelectorCompany // comboBoxSelectorCompany
// //
@ -128,33 +179,125 @@
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, 46); comboBoxSelectorCompany.Location = new Point(13, 279);
comboBoxSelectorCompany.Margin = new Padding(2);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(242, 49); comboBoxSelectorCompany.Size = new Size(158, 33);
comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// pictureBox // pictureBox
// //
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Bottom;
pictureBox.Enabled = false;
pictureBox.Location = new Point(0, 0); pictureBox.Location = new Point(0, 0);
pictureBox.Margin = new Padding(2);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(1053, 845); pictureBox.Size = new Size(681, 648);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
// panelCompanyTools
//
panelCompanyTools.BackColor = SystemColors.Window;
panelCompanyTools.Controls.Add(button1);
panelCompanyTools.Controls.Add(button2);
panelCompanyTools.Controls.Add(maskedTextBox1);
panelCompanyTools.Controls.Add(button5);
panelCompanyTools.Controls.Add(button3);
panelCompanyTools.Controls.Add(button4);
panelCompanyTools.Location = new Point(681, 346);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(176, 302);
panelCompanyTools.TabIndex = 9;
//
// button1
//
button1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
button1.Location = new Point(4, 2);
button1.Margin = new Padding(2);
button1.Name = "button1";
button1.Size = new Size(140, 46);
button1.TabIndex = 1;
button1.Text = "Добавление Лайнера";
button1.UseVisualStyleBackColor = true;
button1.Click += ButtonAddLiner_Click;
//
// button2
//
button2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
button2.Location = new Point(2, 52);
button2.Margin = new Padding(2);
button2.Name = "button2";
button2.Size = new Size(140, 46);
button2.TabIndex = 2;
button2.Text = "Добавление Обычного Лайнера";
button2.UseVisualStyleBackColor = true;
button2.Click += ButtonAddCommonLiner_Click;
//
// maskedTextBox1
//
maskedTextBox1.Location = new Point(2, 102);
maskedTextBox1.Margin = new Padding(2);
maskedTextBox1.Mask = "00";
maskedTextBox1.Name = "maskedTextBox1";
maskedTextBox1.Size = new Size(142, 33);
maskedTextBox1.TabIndex = 3;
maskedTextBox1.ValidatingType = typeof(int);
//
// button3
//
button3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
button3.Location = new Point(2, 134);
button3.Margin = new Padding(2);
button3.Name = "button3";
button3.Size = new Size(140, 46);
button3.TabIndex = 4;
button3.Text = "Удаление Лайнера";
button3.UseVisualStyleBackColor = true;
button3.Click += ButtonRemoveLiner_Click;
//
// button4
//
button4.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
button4.Location = new Point(2, 184);
button4.Margin = new Padding(2);
button4.Name = "button4";
button4.Size = new Size(140, 46);
button4.TabIndex = 5;
button4.Text = "Передать на тесты";
button4.UseVisualStyleBackColor = true;
button4.Click += ButtonGoToCheck_Click;
//
// button5
//
button5.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
button5.Location = new Point(2, 234);
button5.Margin = new Padding(2);
button5.Name = "button5";
button5.Size = new Size(140, 46);
button5.TabIndex = 6;
button5.Text = "Обновить";
button5.UseVisualStyleBackColor = true;
button5.Click += ButtonRefresh_Click;
//
// FormLinerCollection // FormLinerCollection
// //
AutoScaleDimensions = new SizeF(17F, 41F); AutoScaleDimensions = new SizeF(11F, 25F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1325, 845); ClientSize = new Size(857, 648);
Controls.Add(panelCompanyTools);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Margin = new Padding(2);
Name = "FormLinerCollection"; Name = "FormLinerCollection";
Text = "Коллекция автомобилей"; Text = "Коллекция автомобилей";
groupBoxTools.ResumeLayout(false); groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout(); panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
ResumeLayout(false); ResumeLayout(false);
} }
@ -169,5 +312,21 @@
private Button buttonRemoveLiner; private Button buttonRemoveLiner;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private Button buttonRefresh; private Button buttonRefresh;
private Panel panelStorage;
private Label labelCollectionName;
private RadioButton radioButtonMassive;
private TextBox textBoxCollectionName;
private Button buttonCollectionAdd;
private RadioButton radioButtonList;
private Button buttonCollectionDel;
private ListBox listBoxCollection;
private Button buttonCreateCompany;
private Panel panelCompanyTools;
private Button button1;
private Button button2;
private MaskedTextBox maskedTextBox1;
private Button button5;
private Button button3;
private Button button4;
} }
} }

View File

@ -1,188 +1,256 @@
using ProjectLiner.CollectionGenericObjects; 
using ProjectLiner.CollectionGenericObjects;
using ProjectLiner.Drawnings; using ProjectLiner.Drawnings;
using System.Windows.Forms;
namespace ProjectLiner namespace ProjectLiner;
/// <summary>
/// Форма работы с компанией и ее коллекцией
/// </summary>
public partial class FormLinerCollection : Form
{ {
/// <summary> /// <summary>
/// Форма работы с компанией и ее коллекцией /// Хранилише коллекций
/// </summary> /// </summary>
public partial class FormLinerCollection : Form private readonly StorageCollection<DrawningCommonLiner> _storageCollection;
/// <summary>
/// Компания
/// </summary>
private AbstractCompany? _company = null;
/// <summary>
/// Конструктор
/// </summary>
public FormLinerCollection()
{ {
/// <summary> InitializeComponent();
/// Компания _storageCollection = new();
/// </summary> }
private AbstractCompany? _company = null; /// <summary>
/// Выбор компании
/// <summary> /// </summary>
/// Конструктор /// <param name="sender"></param>
/// </summary> /// <param name="e"></param>
public FormLinerCollection() private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
panelCompanyTools.Enabled = false;
}
/// <summary>
/// Добавление грузовика
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner));
/// <summary>
/// Добавление подметательно-уборочной машины
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
/// <summary>
/// Создание объекта класса-перемещенияв
/// </summary>
/// <param name="type"></param>
private void CreateObject(string type)
{
if (_company == null)
{ {
InitializeComponent(); return;
} }
Random random = new();
/// <summary> DrawningCommonLiner drawningCommonLiner;
/// Выбор компании switch (type)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
switch (comboBoxSelectorCompany.Text) case nameof(DrawningCommonLiner):
{ drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300),
case "Хранилище": random.Next(1000, 3000), GetColor(random));
_company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningCommonLiner>()); break;
break; case nameof(DrawningLiner):
} drawningCommonLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000),
GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break;
default:
return;
} }
if (_company + drawningCommonLiner != -1)
/// <summary>
/// Создание объекта класса-перемещения
/// </summary>
/// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type)
{ {
if (_company == null) MessageBox.Show("Объект добавлен");
{
return;
}
Random random = new();
DrawningCommonLiner drawingLiner;
switch (type)
{
case nameof(DrawningCommonLiner):
drawingLiner = new DrawningCommonLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break;
case nameof(DrawningLiner):
drawingLiner = new DrawningLiner(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)), Convert.ToBoolean(random.Next(1, 2)));
break;
default:
return;
}
if (_company + drawingLiner != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
private static Color GetColor(Random random)
{
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
/// <summary>
/// Добавление обычного лайнер
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddCommonLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningCommonLiner));
/// <summary>
/// Добавление лайнера
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonAddLiner_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLiner));
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveLiner_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningCommonLiner? liner = null;
int counter = 100;
while (liner == null)
{
liner = _company.GetRandomObject();
counter--;
if (counter <= 0)
{
break;
}
}
if (liner == null)
{
return;
}
FormLiner form = new()
{
SetLiner = liner
};
form.ShowDialog();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
} }
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
/// <summary>
/// Получение цвета
/// </summary>
/// <param name="random">Генератор случайных чисел</param>
/// <returns></returns>
private static Color GetColor(Random random)
{
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0,
256), random.Next(0, 256));
ColorDialog dialog = new();
if (dialog.ShowDialog() == DialogResult.OK)
{
color = dialog.Color;
}
return color;
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemoveLiner_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{
return;
}
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
DrawningCommonLiner? liner = null;
int counter = 100;
while (liner == null)
{
liner = _company.GetRandomObject();
counter--;
if (counter <= 0) break;
}
if (liner == null)
{
return;
}
FormLiner form = new FormLiner();
form.SetLiner = liner;
form.ShowDialog();
}
/// <summary>
/// Перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
{
return;
}
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;
}
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.No)
{
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<DrawningCommonLiner>? collection =
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
return;
}
switch (comboBoxSelectorCompany.Text)
{
case "Хранилище":
_company = new LinerSharingService(pictureBox.Width, pictureBox.Height, collection);
break;
}
panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
} }
} }