diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..8dccc3a
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,19 @@
+namespace ProjectSeaplane.CollectionGenericObjects;
+///
+/// тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+ ///
+ /// Список
+ ///
+ List = 2
+}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..5ab70ed
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,56 @@
+namespace ProjectSeaplane.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/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..cd2bc9f
--- /dev/null
+++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,67 @@
+namespace ProjectSeaplane.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/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
index 523d962..5335d2d 100644
--- a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
+++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.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();
buttonDelSeaplane = new Button();
@@ -37,34 +46,126 @@
buttonAddBasicSeaplane = new Button();
СomboBoxSelectorCompany = 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(buttonDelSeaplane);
- groupBoxTools.Controls.Add(maskedTextBox);
- groupBoxTools.Controls.Add(buttonAddSeaplane);
- groupBoxTools.Controls.Add(buttonAddBasicSeaplane);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(СomboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(854, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(180, 398);
+ groupBoxTools.Size = new Size(180, 614);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(3, 334);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(171, 26);
+ 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(174, 280);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(0, 234);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(171, 26);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += buttonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(3, 104);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(168, 124);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(0, 72);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(171, 26);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += buttonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(89, 47);
+ 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(16, 47);
+ 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, 18);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(168, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(16, 0);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(125, 15);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции:";
+ //
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.FlatStyle = FlatStyle.Flat;
- buttonRefresh.Location = new Point(6, 474);
+ buttonRefresh.Location = new Point(0, 197);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(168, 43);
+ buttonRefresh.Size = new Size(174, 31);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -74,9 +175,9 @@
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.FlatStyle = FlatStyle.Flat;
- buttonGoToCheck.Location = new Point(6, 353);
+ buttonGoToCheck.Location = new Point(0, 162);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(168, 43);
+ buttonGoToCheck.Size = new Size(174, 29);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -86,9 +187,9 @@
//
buttonDelSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonDelSeaplane.FlatStyle = FlatStyle.Flat;
- buttonDelSeaplane.Location = new Point(6, 249);
+ buttonDelSeaplane.Location = new Point(0, 126);
buttonDelSeaplane.Name = "buttonDelSeaplane";
- buttonDelSeaplane.Size = new Size(168, 43);
+ buttonDelSeaplane.Size = new Size(174, 30);
buttonDelSeaplane.TabIndex = 4;
buttonDelSeaplane.Text = "Удалить самолет";
buttonDelSeaplane.UseVisualStyleBackColor = true;
@@ -96,10 +197,11 @@
//
// maskedTextBox
//
- maskedTextBox.Location = new Point(6, 220);
+ maskedTextBox.Enabled = false;
+ maskedTextBox.Location = new Point(0, 97);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
- maskedTextBox.Size = new Size(168, 23);
+ maskedTextBox.Size = new Size(174, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
@@ -107,9 +209,9 @@
//
buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddSeaplane.FlatStyle = FlatStyle.Flat;
- buttonAddSeaplane.Location = new Point(6, 135);
+ buttonAddSeaplane.Location = new Point(0, 48);
buttonAddSeaplane.Name = "buttonAddSeaplane";
- buttonAddSeaplane.Size = new Size(168, 43);
+ buttonAddSeaplane.Size = new Size(174, 43);
buttonAddSeaplane.TabIndex = 2;
buttonAddSeaplane.Text = "Добавление гидросамолета";
buttonAddSeaplane.UseVisualStyleBackColor = true;
@@ -119,9 +221,9 @@
//
buttonAddBasicSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddBasicSeaplane.FlatStyle = FlatStyle.Flat;
- buttonAddBasicSeaplane.Location = new Point(6, 86);
+ buttonAddBasicSeaplane.Location = new Point(0, 12);
buttonAddBasicSeaplane.Name = "buttonAddBasicSeaplane";
- buttonAddBasicSeaplane.Size = new Size(168, 43);
+ buttonAddBasicSeaplane.Size = new Size(174, 30);
buttonAddBasicSeaplane.TabIndex = 1;
buttonAddBasicSeaplane.Text = "Добавление самолета";
buttonAddBasicSeaplane.UseVisualStyleBackColor = true;
@@ -132,9 +234,9 @@
СomboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
СomboBoxSelectorCompany.FormattingEnabled = true;
СomboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- СomboBoxSelectorCompany.Location = new Point(6, 22);
+ СomboBoxSelectorCompany.Location = new Point(3, 305);
СomboBoxSelectorCompany.Name = "СomboBoxSelectorCompany";
- СomboBoxSelectorCompany.Size = new Size(168, 23);
+ СomboBoxSelectorCompany.Size = new Size(171, 23);
СomboBoxSelectorCompany.TabIndex = 0;
СomboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged;
//
@@ -143,23 +245,39 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(854, 398);
+ pictureBox.Size = new Size(854, 614);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddBasicSeaplane);
+ panelCompanyTools.Controls.Add(buttonAddSeaplane);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(maskedTextBox);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Controls.Add(buttonDelSeaplane);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Location = new Point(3, 374);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(174, 237);
+ panelCompanyTools.TabIndex = 9;
+ //
// FormPlaneCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1034, 398);
+ ClientSize = new Size(1034, 614);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormPlaneCollection";
Text = "Коллекция самолетов";
- Load += FormPlaneCollection_Load;
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@@ -174,5 +292,15 @@
private MaskedTextBox maskedTextBox;
private PictureBox pictureBox;
private Button buttonRefresh;
+ private Panel panelStorage;
+ private TextBox textBoxCollectionName;
+ private Label labelCollectionName;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCollectionAdd;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
index 8077c5b..c0ab1af 100644
--- a/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
+++ b/ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
@@ -7,6 +7,11 @@ namespace ProjectSeaplane;
///
public partial class FormPlaneCollection : Form
{
+
+ ///
+ /// Хранилище коллекций
+ ///
+ private readonly StorageCollection _storageCollection;
///
/// Компания
///
@@ -18,6 +23,7 @@ public partial class FormPlaneCollection : Form
public FormPlaneCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -27,12 +33,7 @@ public partial class FormPlaneCollection : Form
///
private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (СomboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new PlanePark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
+ panelCompanyTools.Enabled = false;
}
@@ -186,8 +187,95 @@ public partial class FormPlaneCollection : Form
pictureBox.Image = _company.Show();
}
- private void FormPlaneCollection_Load(object sender, EventArgs e)
+
+
+ ///
+ /// добавление коллекции
+ ///
+ ///
+ ///
+ 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();
+ }
+ ///
+ /// Обновление списка в 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 buttonCollectionDel_Click(object sender, EventArgs e)
+ {
+ 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 (СomboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new PlanePark(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+ panelCompanyTools.Enabled = true;
+ RerfreshListBoxItems();
}
}