diff --git a/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs b/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
index 8d04bfe..d5bcb9f 100644
--- a/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/AbstractCompany.cs
@@ -63,9 +63,9 @@ public abstract class AbstractCompany
/// Компания
/// Добавляемый объект
///
- public static bool operator +(AbstractCompany company, DrawningB B)
+ public static int operator +(AbstractCompany company, DrawningB B)
{
- return company._collection?.Insert(B) ?? false;
+ return company._collection?.Insert(B) ?? -1;
}
///
@@ -74,9 +74,9 @@ public abstract class AbstractCompany
/// Компания
/// Номер удаляемого объекта
///
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningB? operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection?.Remove(position) ?? null;
}
///
diff --git a/laba 0/laba 0/CollectionGenericObjects/CollectionType.cs b/laba 0/laba 0/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..5019a07
--- /dev/null
+++ b/laba 0/laba 0/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,19 @@
+namespace MotorBoat.CollectionGenericObjects;
+
+public enum CollectionType
+{
+ ///
+ /// Неопределенно
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs
index 5a9ed66..643de81 100644
--- a/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -28,7 +28,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка неудалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -36,14 +36,14 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка неудалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T Remove(int position);
///
/// Получение объекта по позиции
diff --git a/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..9e0ff22
--- /dev/null
+++ b/laba 0/laba 0/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,76 @@
+namespace MotorBoat.CollectionGenericObjects;
+
+///
+/// Параметризованный набор объекта
+///
+/// Параметр: ограничение - ссылочный тип
+public class ListGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Список объектов, которые храним
+ ///
+ private readonly List _collection;
+
+ ///
+ /// Максимально допустимое число объектов в списке
+ ///
+ private int _maxCount;
+
+ public int Count => _collection.Count;
+
+ public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
+
+ ///
+ /// Конструктор
+ ///
+ public ListGenericObjects()
+ {
+ _collection = new();
+ }
+
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if (position >= 0 && position < Count)
+ {
+ return _collection[position];
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public int Insert(T obj)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO вставка в конец набора
+ if (Count == _maxCount) { return -1; }
+ _collection.Add(obj);
+ return Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (position < 0 || position >= Count || Count == _maxCount)
+ {
+ return -1;
+ }
+ _collection.Insert(position, obj);
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из списка
+ if (position >= Count || position < 0) return null;
+ T obj = _collection[position];
+ _collection.RemoveAt(position);
+ return obj;
+ }
+}
diff --git a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
index 3be0baf..44ecb53 100644
--- a/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/laba 0/laba 0/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -32,57 +32,59 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
- for (int i = 0; i < _collection.Length; i++)
+ for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
- return false;
+ return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
-
- if (position < 0 || position >= _collection.Length) { return false; }
-
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
if (_collection[position] == null)
{
_collection[position] = obj;
- return true;
+ return position;
}
- else
- {
- for (int i = position + 1; i < _collection.Length; i++)
- {
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return true;
- }
- }
- for (int i = position - 1; i >= 0; i--)
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_collection[i] == null)
{
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return true;
- }
+ _collection[i] = obj;
+ return i;
}
}
- return false;
+ for (int i = position - 1; i >= 0; i--)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+
+ return -1;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
- if (position < 0 || position >= _collection.Length) { return false; }
-
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ T obj = _collection[position];
_collection[position] = null;
- return true;
+ return obj;
}
}
diff --git a/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..2f6934b
--- /dev/null
+++ b/laba 0/laba 0/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,86 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MotorBoat.CollectionGenericObjects;
+
+public class StorageCollection
+ where T : class
+{
+ ///
+ /// Словарь (хранилище) с коллекциями
+ ///
+ readonly Dictionary> _storages;
+
+ ///
+ /// Возвращение списка названий коллекций
+ ///
+ public List Keys => _storages.Keys.ToList();
+
+ ///
+ /// Конструктор
+ ///
+ public StorageCollection()
+ {
+ _storages = new Dictionary>();
+ }
+
+ ///
+ /// Добавление коллекции в хранилище
+ ///
+ /// Название коллекции
+ /// тип коллекции
+ public void AddCollection(string name, CollectionType collectionType)
+ {
+ // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
+ // TODO Прописать логику для добавления
+ if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
+ {
+ return;
+ }
+ switch (collectionType)
+ {
+ case CollectionType.Massive:
+ _storages[name] = new MassiveGenericObjects();
+ break;
+ case CollectionType.List:
+ _storages[name] = new ListGenericObjects();
+ break;
+ default:
+ return;
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ // TODO Прописать логику для удаления коллекции
+ if (_storages.ContainsKey(name))
+ {
+ _storages.Remove(name);
+ }
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ // TODO Продумать логику получения объекта
+ if (_storages.ContainsKey(name))
+ {
+ return _storages[name];
+ }
+ return null;
+ }
+ }
+}
diff --git a/laba 0/laba 0/FormBoatCollection.Designer.cs b/laba 0/laba 0/FormBoatCollection.Designer.cs
index 4687a51..9360975 100644
--- a/laba 0/laba 0/FormBoatCollection.Designer.cs
+++ b/laba 0/laba 0/FormBoatCollection.Designer.cs
@@ -37,23 +37,35 @@
buttonAddBoat = new Button();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
+ panelStorage = new Panel();
+ labelCollectionName = new Label();
+ textBoxCollectionName = new TextBox();
+ radioButtonMassive = new RadioButton();
+ radioButtonList = new RadioButton();
+ buttonCollectionAdd = new Button();
+ listBoxCollection = new ListBox();
+ buttonCollectionDel = new Button();
+ buttonCreateCompany = new Button();
groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ panelStorage.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
//
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(buttonRefresh);
groupBoxTools.Controls.Add(buttonGoToCheck);
groupBoxTools.Controls.Add(buttonRemoveBoat);
groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddMotorBoat);
- groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Controls.Add(buttonAddBoat);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(489, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(194, 411);
+ groupBoxTools.Size = new Size(194, 497);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@@ -61,7 +73,7 @@
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(3, 320);
+ buttonRefresh.Location = new Point(6, 464);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(185, 27);
buttonRefresh.TabIndex = 6;
@@ -72,7 +84,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(3, 260);
+ buttonGoToCheck.Location = new Point(6, 431);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(185, 27);
buttonGoToCheck.TabIndex = 5;
@@ -83,7 +95,7 @@
// buttonRemoveBoat
//
buttonRemoveBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveBoat.Location = new Point(3, 206);
+ buttonRemoveBoat.Location = new Point(6, 398);
buttonRemoveBoat.Name = "buttonRemoveBoat";
buttonRemoveBoat.Size = new Size(185, 27);
buttonRemoveBoat.TabIndex = 4;
@@ -93,7 +105,7 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(3, 177);
+ maskedTextBox.Location = new Point(6, 369);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(185, 23);
@@ -103,7 +115,7 @@
// buttonAddMotorBoat
//
buttonAddMotorBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddMotorBoat.Location = new Point(3, 113);
+ buttonAddMotorBoat.Location = new Point(6, 325);
buttonAddMotorBoat.Name = "buttonAddMotorBoat";
buttonAddMotorBoat.Size = new Size(185, 38);
buttonAddMotorBoat.TabIndex = 2;
@@ -114,7 +126,7 @@
// buttonAddBoat
//
buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddBoat.Location = new Point(3, 69);
+ buttonAddBoat.Location = new Point(6, 281);
buttonAddBoat.Name = "buttonAddBoat";
buttonAddBoat.Size = new Size(185, 38);
buttonAddBoat.TabIndex = 1;
@@ -128,7 +140,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(3, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 228);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(185, 23);
comboBoxSelectorCompany.TabIndex = 0;
@@ -139,15 +151,104 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(489, 411);
+ pictureBox.Size = new Size(489, 497);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // 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(188, 206);
+ panelStorage.TabIndex = 7;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(29, 9);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(135, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
+ // textBoxCollectionName
+ //
+ textBoxCollectionName.Location = new Point(3, 27);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(182, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // radioButtonMassive
+ //
+ radioButtonMassive.AutoSize = true;
+ radioButtonMassive.Location = new Point(17, 56);
+ radioButtonMassive.Name = "radioButtonMassive";
+ radioButtonMassive.Size = new Size(69, 19);
+ radioButtonMassive.TabIndex = 2;
+ radioButtonMassive.TabStop = true;
+ radioButtonMassive.Text = "Массив";
+ radioButtonMassive.UseVisualStyleBackColor = true;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(97, 56);
+ radioButtonList.Name = "radioButtonList";
+ radioButtonList.Size = new Size(67, 19);
+ radioButtonList.TabIndex = 3;
+ radioButtonList.TabStop = true;
+ radioButtonList.Text = "Список";
+ radioButtonList.UseVisualStyleBackColor = true;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(3, 81);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(182, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(3, 110);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(182, 64);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(3, 180);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(182, 23);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(6, 252);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(185, 23);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ //
// FormBoatCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(683, 411);
+ ClientSize = new Size(683, 497);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormBoatCollection";
@@ -155,6 +256,8 @@
groupBoxTools.ResumeLayout(false);
groupBoxTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
ResumeLayout(false);
}
@@ -169,5 +272,14 @@
private MaskedTextBox maskedTextBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCreateCompany;
+ private Button buttonCollectionDel;
}
}
\ No newline at end of file
diff --git a/laba 0/laba 0/FormBoatCollection.cs b/laba 0/laba 0/FormBoatCollection.cs
index 1974650..90d8ee1 100644
--- a/laba 0/laba 0/FormBoatCollection.cs
+++ b/laba 0/laba 0/FormBoatCollection.cs
@@ -71,7 +71,7 @@ public partial class FormBoatCollection : Form
return;
}
- if (_company + drawningB)
+ if (_company + drawningB != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -110,7 +110,7 @@ public partial class FormBoatCollection : Form
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
int pos = Convert.ToInt32(maskedTextBox.Text);
- if (_company - pos)
+ if (_company - pos != null)
{
MessageBox.Show("Объект удалён");
pictureBox.Image = _company.Show();