Lab04
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
namespace MotorBoat.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Тип коллекции
|
||||
/// </summary>
|
||||
public enum CollectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неопределено
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Массив
|
||||
/// </summary>
|
||||
Massive = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Список
|
||||
/// </summary>
|
||||
List = 2
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
namespace MotorBoat.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();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//---------------TODO ПРОВЕРКА ПО ПОЗИЦИИ----------------------------//
|
||||
//---------------TODO НЕ ВЫХОДИТ ЛИ ЗА ГРАНИЦЫ СПИСКА---------------//
|
||||
/// /////////////////////////////////////////////////////////////////
|
||||
/// <param name="position"></param>
|
||||
/// <returns></returns>
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////
|
||||
//---------------TODO ПРОВЕРКА ВСТАВКИ----------------------//
|
||||
//---------------TODO ВСТАВКА В КОНЕЦ НАБОРА---------------//
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Insert(T obj)
|
||||
{
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_collection.Add(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//---------------TODO ПРОВЕРКА ВСТАВКИ--------------------------------------------------------//
|
||||
//---------------TODO ОТСУТСТВИЕ ПРЕВЫШЕНИЯ МАКСИМАЛЬНОГО КОЛИЧЕСТВА ЭЛЕМЕНТОВ---------------//
|
||||
//---------------TODO ПРОВЕРКА ПОЗИЦИИ------------------------------------------------------//
|
||||
//---------------TODO ВСТАВКА ПО ПОЗИЦИИ---------------------------------------------------//
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
public bool Insert(T obj, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount || Count == _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//---------------TODO ПРОВЕРКА ПОЗИЦИИ--------------------------//
|
||||
//---------------TODO УДАЛЕНИЕ ОБЪЕКТА ИЗ СПИСКА---------------//
|
||||
////////////////////////////////////////////////////////////////
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (_collection.Count == 0 || position < 0 || position >= _collection.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_collection.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
namespace MotorBoat.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>>();
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//---------------TODO ПРОВЕРКА ЧТО NAME НЕ ПУСТОЙ - ОТСУТСТВУЕТ ЗАПИСЬ В СЛОВАРЕ С ТАКИМ КЛЮЧОМ---------------//
|
||||
//---------------TODO ЛОГИКА ДЛЯ ДОБАВЛЕНИЯ ЗАВИСИМОСТИ ОТ collectionType СОЗДАЕМ ОБЪЕКТ ЛИБО----------------//
|
||||
//---------------TODO В MassiveGenericObjects ЛИБО в ListGenericObjects-------------------------------------//
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Добавление коллекции в хранилище
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
if (name == null || Keys.Contains(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
switch (collectionType)
|
||||
{
|
||||
case CollectionType.Massive:
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
break;
|
||||
case CollectionType.List:
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
break;
|
||||
case CollectionType.None:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
//---------------TODO УДАЛЕНИЕ КОЛЛЕКЦИИ С ПРОВЕРКОЙ НАЛИЧИЯ КЛЮЧА---------------//
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (name == null || !Keys.Contains(name))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storages.Remove(name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
//---------------TODO ЛОГИКА ПОЛУЧЕНИЯ ОБЪЕКТА---------------//
|
||||
//////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Доступ к коллекции
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
return _storages.GetValueOrDefault(name, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
169
MotorBoat/MotorBoat/FormBoatCollection.Designer.cs
generated
169
MotorBoat/MotorBoat/FormBoatCollection.Designer.cs
generated
@@ -29,6 +29,15 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
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();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonRemoveBoat = new Button();
|
||||
@@ -37,18 +46,18 @@
|
||||
buttonAddBoat = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
panelCompanyTools = new Panel();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonRemoveBoat);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
||||
groupBoxTools.Controls.Add(buttonAddMotorBoat);
|
||||
groupBoxTools.Controls.Add(buttonAddBoat);
|
||||
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||
groupBoxTools.Controls.Add(buttonCreateCompany);
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(884, 0);
|
||||
@@ -58,12 +67,104 @@
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(15, 303);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(173, 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(194, 249);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(12, 219);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(173, 23);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
buttonCollectionDel.Click += ButtonCollectionDel_Click;
|
||||
//
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(12, 119);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(173, 94);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(12, 86);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(173, 23);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
|
||||
//
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(119, 61);
|
||||
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(16, 61);
|
||||
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(12, 27);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(173, 23);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(35, 9);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(125, 15);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Название коллекции:";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(15, 363);
|
||||
buttonRefresh.Location = new Point(14, 147);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(173, 33);
|
||||
buttonRefresh.Size = new Size(167, 21);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@@ -72,9 +173,9 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(15, 278);
|
||||
buttonGoToCheck.Location = new Point(14, 118);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(173, 33);
|
||||
buttonGoToCheck.Size = new Size(167, 23);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@@ -83,9 +184,9 @@
|
||||
// buttonRemoveBoat
|
||||
//
|
||||
buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveBoat.Location = new Point(15, 196);
|
||||
buttonRemoveBoat.Location = new Point(14, 91);
|
||||
buttonRemoveBoat.Name = "buttonRemoveBoat";
|
||||
buttonRemoveBoat.Size = new Size(173, 33);
|
||||
buttonRemoveBoat.Size = new Size(167, 21);
|
||||
buttonRemoveBoat.TabIndex = 4;
|
||||
buttonRemoveBoat.Text = "Удалить лодку";
|
||||
buttonRemoveBoat.UseVisualStyleBackColor = true;
|
||||
@@ -94,19 +195,19 @@
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxPosition.Location = new Point(15, 167);
|
||||
maskedTextBoxPosition.Location = new Point(14, 62);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(173, 23);
|
||||
maskedTextBoxPosition.Size = new Size(167, 23);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddMotorBoat
|
||||
//
|
||||
buttonAddMotorBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMotorBoat.Location = new Point(15, 88);
|
||||
buttonAddMotorBoat.Location = new Point(14, 33);
|
||||
buttonAddMotorBoat.Name = "buttonAddMotorBoat";
|
||||
buttonAddMotorBoat.Size = new Size(173, 33);
|
||||
buttonAddMotorBoat.Size = new Size(167, 23);
|
||||
buttonAddMotorBoat.TabIndex = 2;
|
||||
buttonAddMotorBoat.Text = "Добавить спортивную лодку";
|
||||
buttonAddMotorBoat.UseVisualStyleBackColor = true;
|
||||
@@ -115,9 +216,9 @@
|
||||
// buttonAddBoat
|
||||
//
|
||||
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddBoat.Location = new Point(15, 51);
|
||||
buttonAddBoat.Location = new Point(14, 3);
|
||||
buttonAddBoat.Name = "buttonAddBoat";
|
||||
buttonAddBoat.Size = new Size(173, 31);
|
||||
buttonAddBoat.Size = new Size(167, 24);
|
||||
buttonAddBoat.TabIndex = 1;
|
||||
buttonAddBoat.Text = "Добавить обычную лодку";
|
||||
buttonAddBoat.UseVisualStyleBackColor = true;
|
||||
@@ -129,7 +230,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(15, 22);
|
||||
comboBoxSelectorCompany.Location = new Point(15, 274);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(173, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
@@ -138,12 +239,27 @@
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Enabled = false;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(884, 561);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonAddBoat);
|
||||
panelCompanyTools.Controls.Add(buttonAddMotorBoat);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveBoat);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Location = new Point(3, 384);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(194, 174);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@@ -154,8 +270,11 @@
|
||||
Name = "FormBoatCollection";
|
||||
Text = "Коллекция лодок";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
panelStorage.ResumeLayout(false);
|
||||
panelStorage.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
@@ -170,5 +289,15 @@
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGoToCheck;
|
||||
private Panel panelStorage;
|
||||
private RadioButton radioButtonList;
|
||||
private RadioButton radioButtonMassive;
|
||||
private TextBox textBoxCollectionName;
|
||||
private Label labelCollectionName;
|
||||
private Button buttonCreateCompany;
|
||||
private Button buttonCollectionDel;
|
||||
private ListBox listBoxCollection;
|
||||
private Button buttonCollectionAdd;
|
||||
private Panel panelCompanyTools;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ namespace MotorBoat
|
||||
/// </summary>
|
||||
public partial class FormBoatCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилише коллекций
|
||||
/// </summary>
|
||||
private readonly StorageCollection<DrawningBoat> _storageCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
@@ -28,6 +33,7 @@ namespace MotorBoat
|
||||
public FormBoatCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -37,13 +43,7 @@ namespace MotorBoat
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new BoatSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningBoat>());
|
||||
break;
|
||||
}
|
||||
|
||||
panelCompanyTools.Enabled = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,9 +76,13 @@ namespace MotorBoat
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBoat):
|
||||
drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000),
|
||||
drawningBoat = new DrawningBoat(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random));
|
||||
break;
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
//---------------TODO ДВОЙНОЙ ВЫБОР ЦВЕТА---------------//
|
||||
/////////////////////////////////////////////////////////
|
||||
case nameof(DrawningMotorBoat):
|
||||
drawningBoat = new DrawningMotorBoat(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random),
|
||||
@@ -149,32 +153,32 @@ namespace MotorBoat
|
||||
private void buttonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningBoat? boat = null;
|
||||
int counter = 100;
|
||||
while (boat == null)
|
||||
{
|
||||
boat = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
DrawningBoat? boat = null;
|
||||
int counter = 100;
|
||||
while (boat == null)
|
||||
{
|
||||
boat = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (boat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (boat == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormMotorBoat form = new()
|
||||
{
|
||||
SetBoat = boat
|
||||
};
|
||||
form.ShowDialog();
|
||||
FormMotorBoat form = new()
|
||||
{
|
||||
SetBoat = boat
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
private void buttonRefresh_Click(object sender, EventArgs e)
|
||||
@@ -186,5 +190,106 @@ namespace MotorBoat
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//---------------TODO УДАЛЕНИЕ ЭЛЕМЕНТА ИЗ КОЛЕКЦИИ----------------------------------------//
|
||||
//---------------TODO ПОДТВЕРДИТЬ НАЛИЧИЕ ВЫБРАННОЙ КОЛЛЕКЦИИ-----------------------------//
|
||||
//---------------TODO ПОДТВЕРДИТЬ ЧЕРЕЗ MessageBox У ПОЛЬЗОВАТЕЛЯ УДАЛЕНИЕ---------------//
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(textBoxCollectionName.Text);
|
||||
MessageBox.Show("Объект удален");
|
||||
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<DrawningBoat>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new BoatSharingService(pictureBox.Width, pictureBox.Height, collection);
|
||||
break;
|
||||
}
|
||||
|
||||
panelCompanyTools.Enabled = true;
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user