diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/CollectionType.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..49abc49
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace ProjectLinkor.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
diff --git a/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..b7623d5
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,76 @@
+namespace ProjectLinkor.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 >= Count || position < 0)
+ return null;
+ return _collection[position];
+ }
+
+ public int Insert(T obj)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (Count == _maxCount) return -1;
+ _collection.Add(obj);
+ return Count;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (position >= Count || position < 0)
+ {
+ return -1;
+ }
+ if (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/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..9a8a910
--- /dev/null
+++ b/ProjectSportCar/ProjectSportCar/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,79 @@
+namespace ProjectLinkor.CollectionGenericObjects;
+
+///
+/// Класс-хранилище коллекций
+///
+///
+public class StorageCollection
+ where T : class
+{
+ ///
+ /// Словарь (хранилище) с коллекциями
+ ///
+ private Dictionary> _storages;
+
+ ///
+ /// Возвращение списка названий коллекции
+ ///
+ public List Keys => _storages.Keys.ToList();
+
+ ///
+ /// Конструктор
+ ///
+ public StorageCollection()
+ {
+ _storages = new Dictionary>();
+ }
+
+ ///
+ /// Добавление коллекции в хранилище
+ ///
+ /// Название коллекции
+ /// Тип коллекции
+ public void AddCollection(string name, CollectionType collectionType)
+ {
+ // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
+ if (_storages.ContainsKey(name))
+ return;
+
+ // TODO Прописать логику для добавления
+ if (collectionType == CollectionType.List)
+ {
+ _storages.Add(name, new ListGenericObjects());
+ }
+ if (collectionType == CollectionType.Massive)
+ {
+ _storages.Add(name, new MassiveGenericObjects());
+ }
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ public void DelCollection(string name)
+ {
+ // TODO Прописать логику для удаления коллекции
+ if (!_storages.ContainsKey(name))
+ return;
+ _storages.Remove(name);
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ ///
+ ///
+ public ICollectionGenericObjects this[string name]
+ {
+ get
+ {
+ // TODO Продумать логику получения объекта
+ if (_storages.ContainsKey((string)name))
+ {
+ return _storages[name];
+ }
+ return null;
+ }
+ }
+}
diff --git a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs
index 489eabc..7698fdb 100644
--- a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.Designer.cs
+++ b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.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();
maskedTextBox1 = new MaskedTextBox();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
@@ -36,43 +45,135 @@
buttonAddBattleship = new Button();
buttonAddWarship = new Button();
comboBoxSelectionCompany = new ComboBox();
+ panelCompanyTools = new Panel();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
+ panelStorage.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(maskedTextBox1);
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonRemoveWarship);
- groupBoxTools.Controls.Add(buttonAddBattleship);
- groupBoxTools.Controls.Add(buttonAddWarship);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectionCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(916, 0);
+ groupBoxTools.Location = new Point(961, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(292, 620);
+ groupBoxTools.Size = new Size(292, 704);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(6, 339);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(268, 29);
+ buttonCreateCompany.TabIndex = 7;
+ 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, 23);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(286, 276);
+ panelStorage.TabIndex = 8;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(9, 241);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(268, 29);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 20;
+ listBoxCollection.Location = new Point(9, 131);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(268, 104);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(9, 96);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(268, 29);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(170, 66);
+ radioButtonList.Name = "radioButtonList";
+ radioButtonList.Size = new Size(80, 24);
+ radioButtonList.TabIndex = 3;
+ radioButtonList.TabStop = true;
+ radioButtonList.Text = "Список";
+ radioButtonList.UseVisualStyleBackColor = true;
+ //
+ // radioButtonMassive
+ //
+ radioButtonMassive.AutoSize = true;
+ radioButtonMassive.Location = new Point(34, 66);
+ radioButtonMassive.Name = "radioButtonMassive";
+ radioButtonMassive.Size = new Size(82, 24);
+ radioButtonMassive.TabIndex = 2;
+ radioButtonMassive.TabStop = true;
+ radioButtonMassive.Text = "Массив";
+ radioButtonMassive.UseVisualStyleBackColor = true;
+ //
+ // textBoxCollectionName
+ //
+ textBoxCollectionName.Location = new Point(9, 33);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(268, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(57, 10);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(158, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
// maskedTextBox1
//
maskedTextBox1.Anchor = AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBox1.Location = new Point(12, 269);
+ maskedTextBox1.Location = new Point(3, 91);
maskedTextBox1.Mask = "00";
maskedTextBox1.Name = "maskedTextBox1";
- maskedTextBox1.Size = new Size(274, 27);
+ maskedTextBox1.Size = new Size(271, 27);
maskedTextBox1.TabIndex = 7;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(12, 477);
+ buttonRefresh.Location = new Point(3, 220);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(274, 42);
+ buttonRefresh.Size = new Size(271, 30);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -81,9 +182,9 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(12, 381);
+ buttonGoToCheck.Location = new Point(3, 172);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(274, 42);
+ buttonGoToCheck.Size = new Size(271, 42);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -92,9 +193,9 @@
// buttonRemoveWarship
//
buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveWarship.Location = new Point(12, 283);
+ buttonRemoveWarship.Location = new Point(3, 124);
buttonRemoveWarship.Name = "buttonRemoveWarship";
- buttonRemoveWarship.Size = new Size(274, 42);
+ buttonRemoveWarship.Size = new Size(271, 42);
buttonRemoveWarship.TabIndex = 4;
buttonRemoveWarship.Text = "Удалить корабль";
buttonRemoveWarship.UseVisualStyleBackColor = true;
@@ -103,9 +204,9 @@
// buttonAddBattleship
//
buttonAddBattleship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddBattleship.Location = new Point(12, 141);
+ buttonAddBattleship.Location = new Point(3, 55);
buttonAddBattleship.Name = "buttonAddBattleship";
- buttonAddBattleship.Size = new Size(274, 42);
+ buttonAddBattleship.Size = new Size(271, 30);
buttonAddBattleship.TabIndex = 2;
buttonAddBattleship.Text = "Добавление линкора";
buttonAddBattleship.UseVisualStyleBackColor = true;
@@ -114,9 +215,9 @@
// buttonAddWarship
//
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddWarship.Location = new Point(12, 95);
+ buttonAddWarship.Location = new Point(3, 16);
buttonAddWarship.Name = "buttonAddWarship";
- buttonAddWarship.Size = new Size(274, 40);
+ buttonAddWarship.Size = new Size(271, 33);
buttonAddWarship.TabIndex = 1;
buttonAddWarship.Text = "Добавление военного корабля";
buttonAddWarship.UseVisualStyleBackColor = true;
@@ -128,18 +229,33 @@
comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectionCompany.FormattingEnabled = true;
comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectionCompany.Location = new Point(12, 26);
+ comboBoxSelectionCompany.Location = new Point(6, 305);
comboBoxSelectionCompany.Name = "comboBoxSelectionCompany";
comboBoxSelectionCompany.Size = new Size(274, 28);
comboBoxSelectionCompany.TabIndex = 0;
comboBoxSelectionCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddWarship);
+ panelCompanyTools.Controls.Add(buttonAddBattleship);
+ panelCompanyTools.Controls.Add(maskedTextBox1);
+ panelCompanyTools.Controls.Add(buttonRemoveWarship);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 390);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(286, 311);
+ panelCompanyTools.TabIndex = 9;
+ //
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(916, 620);
+ pictureBox.Size = new Size(961, 704);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -147,13 +263,16 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1208, 620);
+ ClientSize = new Size(1253, 704);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormWarshipCollection";
Text = "Коллекция кораблей";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -168,5 +287,15 @@
private Button buttonRefresh;
private Button buttonGoToCheck;
private MaskedTextBox maskedTextBox1;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs
index 81ca521..5909ec9 100644
--- a/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs
+++ b/ProjectSportCar/ProjectSportCar/FormWarshipCollection.cs
@@ -8,6 +8,11 @@ namespace ProjectLinkor;
///
public partial class FormWarshipCollection : Form
{
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -19,6 +24,7 @@ public partial class FormWarshipCollection : Form
public FormWarshipCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -28,12 +34,7 @@ public partial class FormWarshipCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectionCompany.Text)
- {
- case "Хранилище":
- _company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
@@ -186,4 +187,101 @@ public partial class FormWarshipCollection : Form
}
pictureBox.Image = _company.Show();
}
+
+ ///
+ /// Добавление коллекции
+ ///
+ ///
+ ///
+ 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();
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ ///
+ ///
+ 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.No)
+ {
+ 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 (comboBoxSelectionCompany.Text)
+ {
+ case "Хранилище":
+ _company = new WarshipSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+ }
}
\ No newline at end of file