diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/CollectionType.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..85631dd
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,22 @@
+namespace ProjectTrolleybus.CollectionGenericObjects;
+
+///
+/// Тип коллекции
+///
+public enum CollectionType
+{
+ ///
+ /// Неопределено
+ ///
+ None = 0,
+
+ ///
+ /// Массив
+ ///
+ Massive = 1,
+
+ ///
+ /// Список
+ ///
+ List = 2,
+}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..e9fec46
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,71 @@
+namespace ProjectTrolleybus.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 < Count)
+ {
+ return _collection[position];
+ }
+ return null;
+ }
+
+ public int Insert(T obj)
+ {
+ if (Count <= _maxCount)
+ {
+ _collection.Add(obj);
+ return Count;
+ }
+ return -1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ if (Count < _maxCount && position >= 0 && position < _maxCount)
+ {
+ _collection.Insert(position, obj);
+ return position;
+ }
+ return -1;
+ }
+
+ public T Remove(int position)
+ {
+ T temp = _collection[position];
+ if (position >= 0 && position < _maxCount)
+ {
+ _collection.RemoveAt(position);
+ return temp;
+ }
+ return null;
+ }
+}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/StorageCollection.cs b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..f8d9499
--- /dev/null
+++ b/ProjectTrolleybus/ProjectTrolleybus/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,72 @@
+namespace ProjectTrolleybus.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)
+ {
+ 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)
+ {
+ if (_storages.ContainsKey(name)) { _storages.Remove(name); }
+ }
+ ///
+ /// Доступ к коллекции
+ ///
+ /// Название коллекции
+ ///
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ if (_storages.ContainsKey(name))
+ {
+ return _storages[name];
+ }
+ return null;
+ }
+ }
+}
diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.Designer.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.Designer.cs
index 06c0de7..bcceda7 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.Designer.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.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();
buttonRemoveTrolleyB = new Button();
@@ -37,18 +46,18 @@
buttonAddTrolleyB = 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(buttonRemoveTrolleyB);
- groupBoxTools.Controls.Add(maskedTextBoxPosition);
- groupBoxTools.Controls.Add(buttonAddTrolleybus);
- groupBoxTools.Controls.Add(buttonAddTrolleyB);
+ groupBoxTools.Controls.Add(panelCompanyTools);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
+ groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(861, 0);
@@ -58,10 +67,102 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(12, 335);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(177, 23);
+ 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, 19);
+ panelStorage.Name = "panelStorage";
+ panelStorage.Size = new Size(195, 270);
+ panelStorage.TabIndex = 7;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(9, 240);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(177, 23);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += ButtonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.ItemHeight = 15;
+ listBoxCollection.Location = new Point(9, 110);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(177, 124);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(9, 81);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(177, 23);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(106, 56);
+ 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, 56);
+ 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, 27);
+ textBoxCollectionName.Name = "textBoxCollectionName";
+ textBoxCollectionName.Size = new Size(189, 23);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(33, 9);
+ 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, 544);
+ buttonRefresh.Location = new Point(3, 229);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(189, 41);
buttonRefresh.TabIndex = 6;
@@ -72,7 +173,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(6, 362);
+ buttonGoToCheck.Location = new Point(3, 182);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(189, 41);
buttonGoToCheck.TabIndex = 5;
@@ -83,7 +184,7 @@
// buttonRemoveTrolleyB
//
buttonRemoveTrolleyB.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveTrolleyB.Location = new Point(6, 257);
+ buttonRemoveTrolleyB.Location = new Point(3, 135);
buttonRemoveTrolleyB.Name = "buttonRemoveTrolleyB";
buttonRemoveTrolleyB.Size = new Size(189, 41);
buttonRemoveTrolleyB.TabIndex = 4;
@@ -94,7 +195,7 @@
// maskedTextBoxPosition
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBoxPosition.Location = new Point(6, 228);
+ maskedTextBoxPosition.Location = new Point(3, 106);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(189, 23);
@@ -104,7 +205,7 @@
// buttonAddTrolleybus
//
buttonAddTrolleybus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddTrolleybus.Location = new Point(6, 153);
+ buttonAddTrolleybus.Location = new Point(3, 59);
buttonAddTrolleybus.Name = "buttonAddTrolleybus";
buttonAddTrolleybus.Size = new Size(189, 41);
buttonAddTrolleybus.TabIndex = 2;
@@ -115,7 +216,7 @@
// buttonAddTrolleyB
//
buttonAddTrolleyB.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddTrolleyB.Location = new Point(6, 106);
+ buttonAddTrolleyB.Location = new Point(3, 12);
buttonAddTrolleyB.Name = "buttonAddTrolleyB";
buttonAddTrolleyB.Size = new Size(189, 41);
buttonAddTrolleyB.TabIndex = 1;
@@ -129,7 +230,7 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
- comboBoxSelectorCompany.Location = new Point(6, 22);
+ comboBoxSelectorCompany.Location = new Point(6, 295);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(189, 23);
comboBoxSelectorCompany.TabIndex = 0;
@@ -144,6 +245,21 @@
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonAddTrolleyB);
+ panelCompanyTools.Controls.Add(buttonAddTrolleybus);
+ panelCompanyTools.Controls.Add(maskedTextBoxPosition);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(buttonRemoveTrolleyB);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 364);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(195, 278);
+ panelCompanyTools.TabIndex = 8;
+ //
// FormTrolleyBCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
@@ -154,8 +270,11 @@
Name = "FormTrolleyBCollection";
Text = "Коллекция троллейбусов";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ panelCompanyTools.ResumeLayout(false);
+ panelCompanyTools.PerformLayout();
ResumeLayout(false);
}
@@ -170,5 +289,15 @@
private MaskedTextBox maskedTextBoxPosition;
private Button buttonRefresh;
private Button buttonGoToCheck;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private TextBox textBoxCollectionName;
+ private RadioButton radioButtonList;
+ private RadioButton radioButtonMassive;
+ private Button buttonCollectionAdd;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCreateCompany;
+ private Panel panelCompanyTools;
}
}
\ No newline at end of file
diff --git a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs
index 2086e70..9088e7a 100644
--- a/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs
+++ b/ProjectTrolleybus/ProjectTrolleybus/FormTrolleyBCollection.cs
@@ -4,12 +4,14 @@ using ProjectTrolleybus.Drawnings;
namespace ProjectTrolleybus;
///
-///
+/// Форма работы с компанией и её коллекцией
///
public partial class FormTrolleyBCollection : Form
{
+ private readonly StorageCollection _storageCollection;
+
///
- ///
+ /// Компания
///
private AbstractCompany? _company = null;
@@ -19,6 +21,7 @@ public partial class FormTrolleyBCollection : Form
public FormTrolleyBCollection()
{
InitializeComponent();
+ _storageCollection = new();
}
///
@@ -28,13 +31,7 @@ public partial class FormTrolleyBCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectorCompany.Text)
- {
- case "Хранилище":
- _company = new TrolleyBCarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- break;
- }
-
+ panelCompanyTools.Enabled = false;
}
///
@@ -81,8 +78,8 @@ public partial class FormTrolleyBCollection : Form
if (_company + drawningTrolleyB != -1)
{
- MessageBox.Show("Объект добавлен");
- pictureBox.Image = _company.Show();
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
}
else
@@ -190,4 +187,98 @@ public partial class FormTrolleyBCollection : 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)
+ {
+ 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 TrolleyBCarSharingService(pictureBox.Width, pictureBox.Height, collection);
+ break;
+ }
+
+ panelCompanyTools.Enabled = true;
+ 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);
+ }
+ }
+ }
}