Добавление новый способ хранения объектов в "Сервисе"
This commit is contained in:
parent
9aec819091
commit
10ce368f63
@ -71,7 +71,7 @@ namespace ProjectLiner.CollectionGenericObjects
|
||||
/// <returns></returns>
|
||||
public static DrawningCommonLiner operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection.Remove(position);
|
||||
return company._collection.Remove(position) ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -0,0 +1,24 @@
|
||||
|
||||
namespace ProjectLiner.CollectionGenericObjects;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Тип коллекции
|
||||
/// </summary>
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2,
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -63,45 +63,33 @@ namespace ProjectLiner.CollectionGenericObjects
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (_collection[position] != null)
|
||||
int temp = position + 1;
|
||||
while (temp < Count)
|
||||
{
|
||||
bool pushed = false;
|
||||
for (int index = position + 1; index < Count; index++)
|
||||
if (_collection[temp] == null)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
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;
|
||||
_collection[temp] = obj;
|
||||
return temp;
|
||||
}
|
||||
++temp;
|
||||
}
|
||||
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
temp = position - 1;
|
||||
while (temp >= 0)
|
||||
{
|
||||
if (_collection[temp] == null)
|
||||
{
|
||||
_collection[temp] = obj;
|
||||
return temp;
|
||||
}
|
||||
--temp;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
@ -111,7 +99,7 @@ namespace ProjectLiner.CollectionGenericObjects
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_collection[position] == null) return null;
|
||||
//if (_collection[position] == null) return null;
|
||||
|
||||
T? temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
}
|
@ -29,98 +29,149 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveLiner = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonAddCommonLiner = new Button();
|
||||
buttonAddLiner = 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();
|
||||
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();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveLiner);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
||||
groupBoxTools.Controls.Add(buttonAddCommonLiner);
|
||||
groupBoxTools.Controls.Add(buttonAddLiner);
|
||||
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
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.Size = new Size(272, 845);
|
||||
groupBoxTools.Padding = new Padding(2);
|
||||
groupBoxTools.Size = new Size(176, 648);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(33, 683);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(217, 76);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
buttonCreateCompany.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonCreateCompany.Location = new Point(5, 317);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(166, 23);
|
||||
buttonCreateCompany.TabIndex = 8;
|
||||
buttonCreateCompany.Text = "Создать компанию";
|
||||
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||
buttonCreateCompany.Click += ButtonCreateCompany_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
// panelStorage
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(33, 562);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(217, 76);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
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(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;
|
||||
buttonRemoveLiner.Location = new Point(33, 416);
|
||||
buttonRemoveLiner.Name = "buttonRemoveLiner";
|
||||
buttonRemoveLiner.Size = new Size(217, 76);
|
||||
buttonRemoveLiner.TabIndex = 4;
|
||||
buttonRemoveLiner.Text = "Удаление Лайнера";
|
||||
buttonRemoveLiner.UseVisualStyleBackColor = true;
|
||||
buttonRemoveLiner.Click += ButtonRemoveLiner_Click;
|
||||
buttonCollectionDel.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonCollectionDel.Location = new Point(3, 212);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(166, 23);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить Коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
// listBoxCollection
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(33, 363);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(217, 47);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
listBoxCollection.Font = new Font("Segoe UI", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 17;
|
||||
listBoxCollection.Location = new Point(3, 110);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(166, 89);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonAddCommonLiner
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonAddCommonLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddCommonLiner.Location = new Point(33, 236);
|
||||
buttonAddCommonLiner.Name = "buttonAddCommonLiner";
|
||||
buttonAddCommonLiner.Size = new Size(217, 76);
|
||||
buttonAddCommonLiner.TabIndex = 2;
|
||||
buttonAddCommonLiner.Text = "Добавление Обычного Лайнера";
|
||||
buttonAddCommonLiner.UseVisualStyleBackColor = true;
|
||||
buttonAddCommonLiner.Click += ButtonAddCommonLiner_Click;
|
||||
buttonCollectionAdd.Font = new Font("Segoe UI", 7.948052F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
buttonCollectionAdd.Location = new Point(2, 82);
|
||||
buttonCollectionAdd.Margin = new Padding(2);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(170, 23);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||
//
|
||||
// buttonAddLiner
|
||||
// radioButtonList
|
||||
//
|
||||
buttonAddLiner.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddLiner.Location = new Point(33, 126);
|
||||
buttonAddLiner.Name = "buttonAddLiner";
|
||||
buttonAddLiner.Size = new Size(217, 76);
|
||||
buttonAddLiner.TabIndex = 1;
|
||||
buttonAddLiner.Text = "Добавление Лайнера";
|
||||
buttonAddLiner.UseVisualStyleBackColor = true;
|
||||
buttonAddLiner.Click += ButtonAddLiner_Click;
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
radioButtonList.Location = new Point(89, 58);
|
||||
radioButtonList.Margin = new Padding(2);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(73, 23);
|
||||
radioButtonList.TabIndex = 3;
|
||||
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
|
||||
//
|
||||
@ -128,33 +179,125 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
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.Size = new Size(242, 49);
|
||||
comboBoxSelectorCompany.Size = new Size(158, 33);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Dock = DockStyle.Bottom;
|
||||
pictureBox.Enabled = false;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Margin = new Padding(2);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(1053, 845);
|
||||
pictureBox.Size = new Size(681, 648);
|
||||
pictureBox.TabIndex = 1;
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(17F, 41F);
|
||||
AutoScaleDimensions = new SizeF(11F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1325, 845);
|
||||
ClientSize = new Size(857, 648);
|
||||
Controls.Add(panelCompanyTools);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Margin = new Padding(2);
|
||||
Name = "FormLinerCollection";
|
||||
Text = "Коллекция автомобилей";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@ -169,5 +312,21 @@
|
||||
private Button buttonRemoveLiner;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,188 +1,256 @@
|
||||
using ProjectLiner.CollectionGenericObjects;
|
||||
|
||||
using ProjectLiner.CollectionGenericObjects;
|
||||
using ProjectLiner.Drawnings;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ProjectLiner
|
||||
namespace ProjectLiner;
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormLinerCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// Хранилише коллекций
|
||||
/// </summary>
|
||||
public partial class FormLinerCollection : Form
|
||||
private readonly StorageCollection<DrawningCommonLiner> _storageCollection;
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormLinerCollection()
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormLinerCollection()
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
Random random = new();
|
||||
DrawningCommonLiner drawningCommonLiner;
|
||||
switch (type)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new LinerSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningCommonLiner>());
|
||||
break;
|
||||
}
|
||||
case nameof(DrawningCommonLiner):
|
||||
drawningCommonLiner = new DrawningCommonLiner(random.Next(100, 300),
|
||||
random.Next(1000, 3000), GetColor(random));
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
if (_company + drawningCommonLiner != -1)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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 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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user