diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/CollectionType.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..b3d0cc0
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,18 @@
+namespace SelfPropelledArtilleryUnit.CollectionGenericObjects;
+
+
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+ ///
+ /// Список
+ ///
+ List = 2
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..06e23e5
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,56 @@
+namespace SelfPropelledArtilleryUnit.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 вставка в конец набора
+ if (Count == _maxCount) return -1;
+ _collection.Add(obj);
+ return Count;
+ }
+ public int Insert(T obj, int position)
+ {
+ // TODO проверка, что не превышено максимальное количество элементов
+ // TODO проверка позиции
+ // TODO вставка по позиции
+ if (Count == _maxCount) return -1;
+ if (position >= Count || position < 0) 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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..491cfb5
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,64 @@
+using SelfPropelledArtilleryUnit.Drawnings;
+
+namespace SelfPropelledArtilleryUnit.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 (_storages.ContainsKey(name)) return;
+ if (collectionType == CollectionType.None) return;
+ else if (collectionType == CollectionType.Massive)
+ _storages[name] = new MassiveGenericObjects();
+ else if (collectionType == CollectionType.List)
+ _storages[name] = new ListGenericObjects();
+ }
+ ///
+ /// Удаление коллекции
+ ///
+ /// Название коллекции
+ 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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.Designer.cs
index 3311f7c..b80eae7 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.Designer.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.Designer.cs
@@ -29,6 +29,15 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ buttonCreateCompany = new Button();
+ panelStorage = new Panel();
+ buttonCollectionDel = new Button();
+ listBoxCollection = new ListBox();
+ buttonColectionAdd = new Button();
+ radioButtonList = new RadioButton();
+ radioButtonMassive = new RadioButton();
+ textBoxCollectionName = new TextBox();
+ labelCollectionName = new Label();
buttonRefresh = new Button();
buttonGoToCheck = new Button();
buttonRemovePropelledArtillery = new Button();
@@ -37,18 +46,18 @@
buttonAddPropelledArtillery = 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(buttonRemovePropelledArtillery);
- groupBoxTools.Controls.Add(maskedTextBox);
- groupBoxTools.Controls.Add(buttonAddSelfPropelledArtilleryUnit);
- groupBoxTools.Controls.Add(buttonAddPropelledArtillery);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(736, 0);
@@ -58,12 +67,104 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(6, 308);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(188, 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(buttonColectionAdd);
+ 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, 239);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(3, 206);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(188, 23);
+ buttonCollectionDel.TabIndex = 5;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += buttonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(3, 106);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(188, 94);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonColectionAdd
+ //
+ buttonColectionAdd.Location = new Point(3, 77);
+ buttonColectionAdd.Name = "buttonColectionAdd";
+ buttonColectionAdd.Size = new Size(188, 23);
+ buttonColectionAdd.TabIndex = 4;
+ buttonColectionAdd.Text = "Добавить коллекцию";
+ buttonColectionAdd.UseVisualStyleBackColor = true;
+ buttonColectionAdd.Click += buttonColectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(107, 52);
+ 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(19, 52);
+ 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, 15);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(188, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(33, 1);
+ 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(6, 520);
+ buttonRefresh.Location = new Point(0, 185);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(188, 36);
+ buttonRefresh.Size = new Size(188, 22);
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, 362);
+ buttonGoToCheck.Location = new Point(0, 153);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(188, 36);
+ buttonGoToCheck.Size = new Size(188, 26);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -83,9 +184,9 @@
// buttonRemovePropelledArtillery
//
buttonRemovePropelledArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemovePropelledArtillery.Location = new Point(6, 261);
+ buttonRemovePropelledArtillery.Location = new Point(0, 123);
buttonRemovePropelledArtillery.Name = "buttonRemovePropelledArtillery";
- buttonRemovePropelledArtillery.Size = new Size(188, 36);
+ buttonRemovePropelledArtillery.Size = new Size(188, 24);
buttonRemovePropelledArtillery.TabIndex = 4;
buttonRemovePropelledArtillery.Text = "Удаление";
buttonRemovePropelledArtillery.UseVisualStyleBackColor = true;
@@ -94,7 +195,7 @@
// maskedTextBox
//
maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBox.Location = new Point(6, 232);
+ maskedTextBox.Location = new Point(0, 95);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(188, 23);
@@ -105,7 +206,7 @@
// buttonAddSelfPropelledArtilleryUnit
//
buttonAddSelfPropelledArtilleryUnit.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddSelfPropelledArtilleryUnit.Location = new Point(6, 138);
+ buttonAddSelfPropelledArtilleryUnit.Location = new Point(0, 49);
buttonAddSelfPropelledArtilleryUnit.Name = "buttonAddSelfPropelledArtilleryUnit";
buttonAddSelfPropelledArtilleryUnit.Size = new Size(188, 40);
buttonAddSelfPropelledArtilleryUnit.TabIndex = 2;
@@ -116,7 +217,7 @@
// buttonAddPropelledArtillery
//
buttonAddPropelledArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddPropelledArtillery.Location = new Point(6, 92);
+ buttonAddPropelledArtillery.Location = new Point(0, 3);
buttonAddPropelledArtillery.Name = "buttonAddPropelledArtillery";
buttonAddPropelledArtillery.Size = new Size(188, 40);
buttonAddPropelledArtillery.TabIndex = 1;
@@ -130,7 +231,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 279);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(188, 23);
comboBoxSelectorCompany.TabIndex = 0;
@@ -145,6 +246,20 @@
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(maskedTextBox);
+ panelCompanyTools.Controls.Add(buttonAddPropelledArtillery);
+ panelCompanyTools.Controls.Add(buttonAddSelfPropelledArtilleryUnit);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonRemovePropelledArtillery);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(6, 343);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(200, 213);
+ panelCompanyTools.TabIndex = 9;
+ //
// FormPropelledArtilleryCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -155,8 +270,11 @@
Name = "FormPropelledArtilleryCollection";
Text = "Коллекция установок";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@@ -171,5 +289,15 @@
private Button buttonRefresh;
private Button buttonGoToCheck;
private Button buttonRemovePropelledArtillery;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private Button buttonColectionAdd;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private Button buttonCreateCompany;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.cs
index 8fc01bf..1712ce2 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormPropelledArtilleryCollection.cs
@@ -14,6 +14,11 @@ namespace SelfPropelledArtilleryUnit;
public partial class FormPropelledArtilleryCollection : Form
{
+ ///
+ /// Хранилише коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
+
///
/// Компания
///
@@ -25,6 +30,7 @@ public partial class FormPropelledArtilleryCollection : Form
public FormPropelledArtilleryCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -35,31 +41,26 @@ public partial class FormPropelledArtilleryCollection : Form
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new ArtilleryBase(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
private void buttonAddPropelledArtillery_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawningPropelledArtillery));
-
+
private void buttonAddSelfPropelledArtilleryUnit_Click_1(object sender, EventArgs e) => CreateObject(nameof(DrawningSelfPropelledArtilleryUnit));
- // ///
- ///// Добавление Бронированная машина
- /////
- /////
- /////
- //private void ButtonAddPropelledArtillery_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPropelledArtillery));
+ // ///
+ ///// Добавление Бронированная машина
+ /////
+ /////
+ /////
+ //private void ButtonAddPropelledArtillery_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPropelledArtillery));
- // ///
- // /// Добавление Самоходная арт. установка
- // ///
- // ///
- // ///
- // private void ButtonAddSelfPropelledArtilleryUnit_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSelfPropelledArtilleryUnit));
+ // ///
+ // /// Добавление Самоходная арт. установка
+ // ///
+ // ///
+ // ///
+ // private void ButtonAddSelfPropelledArtilleryUnit_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSelfPropelledArtilleryUnit));
///
/// Создание объекта класса-перемещения
@@ -197,7 +198,80 @@ public partial class FormPropelledArtilleryCollection : Form
pictureBox.Image = _company.Show();
}
+ private void buttonColectionAdd_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 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 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();
+ }
+ 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 ArtilleryBase(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
+ }
}