diff --git a/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/CollectionType.cs b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..b5507f8
--- /dev/null
+++ b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace ProjectStormTrooper.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2
+}
\ No newline at end of file
diff --git a/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/Hangar.cs b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/Hangar.cs
index 40f69a6..b6b9cbe 100644
--- a/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/Hangar.cs
+++ b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/Hangar.cs
@@ -25,7 +25,7 @@ public class Hangar : AbstractCompany
for (int i = 0; i < _pictureWidth/_placeSizeWidth; i++)
{
int posY = 0;
- g.DrawLine(pen, posX, posY, posX, posY + _placeSizeHeight*(_pictureHeight/_placeSizeHeight));
+ g.DrawLine(pen, posX, posY, posX, posY + _placeSizeHeight*(_pictureHeight/ _placeSizeHeight));
for(int j = 0; j <= _pictureHeight/_placeSizeHeight; j++)
{
g.DrawLine(pen, posX, posY, posX + _placeSizeWidth-30, posY);
diff --git a/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/ListGenericObjects.cs b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..3bf8826
--- /dev/null
+++ b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,75 @@
+using 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 > _collection.Count || position < 0)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+
+ public bool Insert(T obj)
+ {
+ if(_collection.Count+1 > _maxCount) { return false;}
+ _collection.Add(obj);
+
+ return true;
+ }
+
+ public bool Insert(T obj, int position)
+ {
+ if (_collection.Count + 1 < _maxCount) { return false; }
+ if (position > _collection.Count || position < 0)
+ {
+ return false;
+ }
+ _collection.Insert(position, obj);
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ return true;
+ }
+
+ public T Remove(int position)
+ {
+ if (position > _collection.Count || position < 0)
+ {
+ return null;
+ }
+ T temp = _collection[position];
+ _collection.RemoveAt(position);
+ // TODO проверка позиции
+ // TODO удаление объекта из списка
+ return temp;
+ }
+}
\ No newline at end of file
diff --git a/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/StorageCollection.cs b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..f95d5e6
--- /dev/null
+++ b/ProjectStormTrooper/ProjectStormTrooper/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,77 @@
+using 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)
+ {
+ if(name == null || _storages.ContainsKey(name)) { return; }
+ switch(collectionType)
+
+ {
+ case CollectionType.None:
+ return;
+ case CollectionType.Massive:
+ _storages.Add(name, new MassiveGenericObjects { });
+ return;
+ case CollectionType.List:
+ _storages.Add(name, new ListGenericObjects { });
+ return;
+ }
+ // TODO проверка, что name не пустой и нет в словаре записи с таким ключом
+ // TODO Прописать логику для добавления
+ }
+
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ public void DelCollection(string name)
+ {
+ if (name == null || !_storages.ContainsKey(name)) { return; }
+ _storages.Remove(name);
+ }
+
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ if (name == null || !_storages.ContainsKey(name)) { return null; }
+
+ // TODO Продумать логику получения объекта
+ return _storages[name];
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.Designer.cs b/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.Designer.cs
index ab12e46..075bd6d 100644
--- a/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.Designer.cs
+++ b/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.Designer.cs
@@ -29,6 +29,16 @@
private void InitializeComponent()
{
groupBox1 = new GroupBox();
+ panelStorage = new Panel();
+ buttonCollectionDel = new Button();
+ listBoxCollection = new ListBox();
+ buttonCollectionAdd = new Button();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
+ buttonCreateCompany = new Button();
+ panelCompanyTools = new Panel();
buttonGoToCheck = new Button();
buttonRefresh = new Button();
buttonRemoveWarPlane = new Button();
@@ -38,31 +48,137 @@
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
groupBox1.SuspendLayout();
+ panelStorage.SuspendLayout();
+ panelCompanyTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBox1
//
- groupBox1.Controls.Add(buttonGoToCheck);
- groupBox1.Controls.Add(buttonRefresh);
- groupBox1.Controls.Add(buttonRemoveWarPlane);
- groupBox1.Controls.Add(maskedTextBoxPosition);
- groupBox1.Controls.Add(buttonAddStormTrooper);
- groupBox1.Controls.Add(buttonAddWarPlane);
+ groupBox1.Controls.Add(panelStorage);
+ groupBox1.Controls.Add(buttonCreateCompany);
+ groupBox1.Controls.Add(panelCompanyTools);
groupBox1.Controls.Add(comboBoxSelectorCompany);
groupBox1.Dock = DockStyle.Right;
groupBox1.Location = new Point(616, 0);
groupBox1.Name = "groupBox1";
- groupBox1.Size = new Size(197, 566);
+ groupBox1.Size = new Size(197, 754);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
+ // 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(191, 336);
+ panelStorage.TabIndex = 9;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(5, 294);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(172, 29);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 20;
+ listBoxCollection.Location = new Point(5, 163);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(170, 104);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(5, 116);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(172, 29);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(93, 84);
+ 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(5, 84);
+ 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(5, 40);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(172, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(24, 11);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(158, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(8, 441);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(172, 29);
+ buttonCreateCompany.TabIndex = 8;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += ButtonCreateCompany_Click;
+ //
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonRemoveWarPlane);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonAddStormTrooper);
+ panelCompanyTools.Controls.Add(buttonAddWarPlane);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 493);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(191, 258);
+ panelCompanyTools.TabIndex = 7;
+ //
// buttonGoToCheck
//
- buttonGoToCheck.Location = new Point(19, 391);
+ buttonGoToCheck.Location = new Point(5, 185);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(172, 29);
+ buttonGoToCheck.Size = new Size(172, 27);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -70,7 +186,7 @@
//
// buttonRefresh
//
- buttonRefresh.Location = new Point(19, 456);
+ buttonRefresh.Location = new Point(5, 218);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(172, 29);
buttonRefresh.TabIndex = 5;
@@ -80,7 +196,7 @@
//
// buttonRemoveWarPlane
//
- buttonRemoveWarPlane.Location = new Point(19, 311);
+ buttonRemoveWarPlane.Location = new Point(5, 128);
buttonRemoveWarPlane.Name = "buttonRemoveWarPlane";
buttonRemoveWarPlane.Size = new Size(172, 51);
buttonRemoveWarPlane.TabIndex = 4;
@@ -90,7 +206,7 @@
//
// maskedTextBoxPosition
//
- maskedTextBoxPosition.Location = new Point(19, 236);
+ maskedTextBoxPosition.Location = new Point(5, 95);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(172, 27);
@@ -98,7 +214,7 @@
//
// buttonAddStormTrooper
//
- buttonAddStormTrooper.Location = new Point(19, 182);
+ buttonAddStormTrooper.Location = new Point(5, 60);
buttonAddStormTrooper.Name = "buttonAddStormTrooper";
buttonAddStormTrooper.Size = new Size(172, 29);
buttonAddStormTrooper.TabIndex = 2;
@@ -108,7 +224,7 @@
//
// buttonAddWarPlane
//
- buttonAddWarPlane.Location = new Point(19, 102);
+ buttonAddWarPlane.Location = new Point(5, 4);
buttonAddWarPlane.Name = "buttonAddWarPlane";
buttonAddWarPlane.Size = new Size(172, 50);
buttonAddWarPlane.TabIndex = 1;
@@ -121,7 +237,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Ангар" });
- comboBoxSelectorCompany.Location = new Point(19, 44);
+ comboBoxSelectorCompany.Location = new Point(8, 396);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(172, 28);
comboBoxSelectorCompany.TabIndex = 0;
@@ -132,7 +248,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(616, 566);
+ pictureBox.Size = new Size(616, 754);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -140,13 +256,16 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(813, 566);
+ ClientSize = new Size(813, 754);
Controls.Add(pictureBox);
Controls.Add(groupBox1);
Name = "FormWarPlaneCollection";
Text = "Коллекция военных самолетов";
groupBox1.ResumeLayout(false);
- groupBox1.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -162,5 +281,15 @@
private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox;
private Button buttonGoToCheck;
+ private Panel panelStorage;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private RadioButton radioButtonList;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
}
}
\ No newline at end of file
diff --git a/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.cs b/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.cs
index 86a43f1..7d503c4 100644
--- a/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.cs
+++ b/ProjectStormTrooper/ProjectStormTrooper/FormWarPlaneCollection.cs
@@ -7,10 +7,12 @@ namespace ProjectStormTrooper
public partial class FormWarPlaneCollection : Form
{
private AbstractCompany? _company = null;
-
+ private readonly StorageCollection _storageCollection;
public FormWarPlaneCollection()
{
InitializeComponent();
+ _storageCollection = new();
+
}
///
/// Выбор компании
@@ -19,12 +21,7 @@ namespace ProjectStormTrooper
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Ангар":
- _company = new Hangar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
///
/// Добавление обычного автомобиля
@@ -173,5 +170,105 @@ namespace ProjectStormTrooper
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)
+ {
+ 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();
+ // TODO прописать логику удаления элемента из коллекции
+ // нужно убедиться, что есть выбранная коллекция
+ // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
+ // удалить и обновить ListBox
+ }
+
+ ///
+ /// Обновление списка в 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 Hangar(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+
+ panelCompanyTools.Enabled = true;
+
+ RerfreshListBoxItems();
+ }
+
}
}