diff --git a/ProjectStormtrooper/CollectionGenericObjects/CollectionType.cs b/ProjectStormtrooper/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..7b1f089
--- /dev/null
+++ b/ProjectStormtrooper/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics.Tracing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectStormtrooper.CollectionGenericObjects;
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+ ///
+ /// Список
+ ///
+ List = 2
+
+
+}
diff --git a/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs b/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..8887373
--- /dev/null
+++ b/ProjectStormtrooper/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectStormtrooper.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)
+ {
+ if (position>=0 && position < _collection.Count)
+ {
+ return _collection[position];
+ }
+ return null;
+ }
+
+ public int Insert(T obj)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO вставка в конец набора
+ if (_collection.Count <= _maxCount)
+ {
+ _collection.Add(obj);
+ return _collection.Count;
+ }
+ return -1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (position >= 0 && position < _maxCount && _collection.Count <= _maxCount)
+ {
+ _collection.Insert(position, obj);
+ return position;
+ }
+ return -1;
+ }
+
+ public T? Remove(int position)
+ {
+ // TODO проверка позиции
+ // TODO удаление объекта из списка
+ if (position < 0 || position > _maxCount)
+ {
+ return null;
+ }
+ T temp = _collection[position];
+ _collection.RemoveAt(position);
+ return temp;
+ }
+}
diff --git a/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs
index 21093ee..ab0a3d4 100644
--- a/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectStormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -15,10 +15,26 @@ public class MassiveGenericObjects : ICollectionGenericObjects
///
/// Массив объекта, которые храним
///
- private T[] _collection;
+ private T?[] _collection;
public int Count => _collection.Length;
- public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (_collection.Length > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
///
/// Конструктор
///
diff --git a/ProjectStormtrooper/CollectionGenericObjects/StorageCollection.cs b/ProjectStormtrooper/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..302a14e
--- /dev/null
+++ b/ProjectStormtrooper/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectStormtrooper.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 (!(collectionType == CollectionType.None) && !_storages.ContainsKey(name))
+ {
+ if (collectionType == CollectionType.List)
+ {
+ _storages.Add(name, new ListGenericObjects());
+ }
+ else if (collectionType == CollectionType.Massive)
+ {
+ _storages.Add(name, new MassiveGenericObjects());
+ }
+ }
+ }
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ 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/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs b/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs
index 3a733a3..8537139 100644
--- a/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs
+++ b/ProjectStormtrooper/FormStormtrooperCollection.Designer.cs
@@ -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();
buttonRemoveStormtrooper = new Button();
@@ -37,33 +46,125 @@
buttonAddStormtrooperBase = 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(buttonRemoveStormtrooper);
- groupBoxTools.Controls.Add(maskedTextBox);
- groupBoxTools.Controls.Add(buttonAddStormtrooper);
- groupBoxTools.Controls.Add(buttonAddStormtrooperBase);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(919, 0);
+ groupBoxTools.Location = new Point(911, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(165, 861);
+ groupBoxTools.Size = new Size(173, 628);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(14, 332);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(150, 23);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
+ //
+ // panelStorage
+ //
+ panelStorage.Controls.Add(buttonCollectionDel);
+ panelStorage.Controls.Add(listBoxCollection);
+ panelStorage.Controls.Add(buttonCollectionAdd);
+ panelStorage.Controls.Add(radioButtonList);
+ panelStorage.Controls.Add(radioButtonMassive);
+ panelStorage.Controls.Add(textBoxCollectionName);
+ panelStorage.Controls.Add(labelCollectionName);
+ panelStorage.Dock = DockStyle.Top;
+ panelStorage.Location = new Point(3, 19);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(167, 278);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(0, 247);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(150, 23);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(6, 117);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(144, 124);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(6, 88);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(150, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(90, 63);
+ 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(3, 63);
+ 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(3, 34);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(153, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(18, 16);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(122, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции";
+ //
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(6, 381);
+ buttonRefresh.Location = new Point(7, 209);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(153, 32);
+ buttonRefresh.Size = new Size(155, 32);
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(6, 309);
+ buttonGoToCheck.Location = new Point(7, 167);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(153, 36);
+ buttonGoToCheck.Size = new Size(166, 36);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -83,9 +184,9 @@
// buttonRemoveStormtrooper
//
buttonRemoveStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveStormtrooper.Location = new Point(6, 248);
+ buttonRemoveStormtrooper.Location = new Point(6, 128);
buttonRemoveStormtrooper.Name = "buttonRemoveStormtrooper";
- buttonRemoveStormtrooper.Size = new Size(153, 33);
+ buttonRemoveStormtrooper.Size = new Size(166, 33);
buttonRemoveStormtrooper.TabIndex = 4;
buttonRemoveStormtrooper.Text = "Удалить Штурмовик";
buttonRemoveStormtrooper.UseVisualStyleBackColor = true;
@@ -93,19 +194,20 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(6, 208);
+ maskedTextBox.Location = new Point(8, 99);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(153, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
+
//
// buttonAddStormtrooper
//
buttonAddStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddStormtrooper.Location = new Point(6, 139);
+ buttonAddStormtrooper.Location = new Point(7, 48);
buttonAddStormtrooper.Name = "buttonAddStormtrooper";
- buttonAddStormtrooper.Size = new Size(153, 45);
+ buttonAddStormtrooper.Size = new Size(155, 45);
buttonAddStormtrooper.TabIndex = 2;
buttonAddStormtrooper.Text = "Добавление Штурмовика";
buttonAddStormtrooper.UseVisualStyleBackColor = true;
@@ -114,9 +216,9 @@
// buttonAddStormtrooperBase
//
buttonAddStormtrooperBase.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddStormtrooperBase.Location = new Point(6, 78);
+ buttonAddStormtrooperBase.Location = new Point(6, 3);
buttonAddStormtrooperBase.Name = "buttonAddStormtrooperBase";
- buttonAddStormtrooperBase.Size = new Size(153, 39);
+ buttonAddStormtrooperBase.Size = new Size(154, 39);
buttonAddStormtrooperBase.TabIndex = 1;
buttonAddStormtrooperBase.Text = "Добавление базового Штурмовика";
buttonAddStormtrooperBase.UseVisualStyleBackColor = true;
@@ -128,9 +230,9 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 303);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
- comboBoxSelectorCompany.Size = new Size(159, 23);
+ comboBoxSelectorCompany.Size = new Size(161, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged;
//
@@ -139,22 +241,39 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(919, 861);
+ pictureBox.Size = new Size(911, 628);
pictureBox.TabIndex = 3;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddStormtrooperBase);
+ panelCompanyTools.Controls.Add(buttonAddStormtrooper);
+ panelCompanyTools.Controls.Add(maskedTextBox);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonRemoveStormtrooper);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(6, 361);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(161, 261);
+ panelCompanyTools.TabIndex = 7;
+ //
// FormStormtrooperCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1084, 861);
+ ClientSize = new Size(1084, 628);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormStormtrooperCollection";
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 +288,15 @@
private MaskedTextBox maskedTextBox;
private Button buttonGoToCheck;
private Button buttonRefresh;
+ private Panel panelStorage;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Button buttonCreateCompany;
+ private Button buttonCollectionDel;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectStormtrooper/FormStormtrooperCollection.cs b/ProjectStormtrooper/FormStormtrooperCollection.cs
index 5d99278..cea0b4c 100644
--- a/ProjectStormtrooper/FormStormtrooperCollection.cs
+++ b/ProjectStormtrooper/FormStormtrooperCollection.cs
@@ -17,16 +17,21 @@ namespace ProjectStormtrooper;
public partial class FormStormtrooperCollection : Form
{
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
///
/// Компания
///
- private AbstractCompany? _company;
+ private AbstractCompany? _company = null;
///
/// Конструктор
///
public FormStormtrooperCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
@@ -37,12 +42,7 @@ public partial class FormStormtrooperCollection : Form
///
private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new StormtrooperSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = true;
}
///
/// Создание объекта класса-перемещения
@@ -186,4 +186,97 @@ public partial class FormStormtrooperCollection : Form
}
pictureBox.Image = _company.Show();
}
+ ///
+ /// Добавление коллекции
+ ///
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ ///
+ private void ButtonCollectionDel_Click(object sender, EventArgs e)
+ {
+ // TODO прописать логику удаления элемента из коллекции
+ // нужно убедиться, что есть выбранная коллекция
+ // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
+ // удалить и обновить ListBox
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RerfreshListBoxItems();
+ }
+ ///
+ /// Добавление списка в listBoxCollection
+ ///
+ 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);
+ }
+ }
+ }
+ ///
+ /// Создание компании
+ ///
+ ///
+ ///
+ private void ButtonCreateCompany_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
+ {
+ MessageBox.Show("Коллекция не выбрана");
+ return;
+ }
+ ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
+ if (collection == null)
+ {
+ MessageBox.Show("Коллекция не проинициализирована");
+ return;
+ }
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new StormtrooperSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+
+ }
+
+
}