diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs
index 23479f1..3fdad4e 100644
--- a/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs
+++ b/AccordionBus/AccordionBus/CollectionGenericObjects/AbstractCompany.cs
@@ -29,14 +29,14 @@ namespace AccordionBus.CollectionGenericObjects
_collection.SetMaxCount = GetMaxCount;
}
- public static bool operator +(AbstractCompany company, DrawningBus bus)
+ public static int operator +(AbstractCompany company, DrawningBus bus)
{
- return company._collection?.Insert(bus) ?? false;
+ return company._collection.Insert(bus);
}
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningBus? operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection.Remove(position);
}
public DrawningBus? GetRandomObject()
@@ -52,10 +52,10 @@ namespace AccordionBus.CollectionGenericObjects
DrawBackground(graphics);
- for (int i = 0; i < (_collection?.Count ?? 0); i++)
+ for (int i = 0; i < (_collection?.MaxCount ?? 0); i++)
{
DrawningBus? obj = _collection?.Get(i);
- SetObjectPosition(i, _collection?.Count ?? 0, obj);
+ SetObjectPosition(i, _collection?.MaxCount ?? 0, obj);
obj?.DrawTransport(graphics);
}
diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/CollectionType.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/CollectionType.cs
new file mode 100644
index 0000000..29d3720
--- /dev/null
+++ b/AccordionBus/AccordionBus/CollectionGenericObjects/CollectionType.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AccordionBus.CollectionGenericObjects
+{
+ public enum CollectionType
+ {
+ None = 0,
+
+ Massive = 1,
+
+ List = 2
+ }
+}
diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs
index 10b3762..c602250 100644
--- a/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/AccordionBus/AccordionBus/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -12,7 +12,7 @@ namespace AccordionBus.CollectionGenericObjects
///
/// кол-во элем
///
- int Count { get; }
+ int MaxCount { get; }
///
/// установить макс элем
///
@@ -22,20 +22,20 @@ namespace AccordionBus.CollectionGenericObjects
///
/// добавляемый объект
///
- bool Insert(T obj);
+ int Insert(T obj);
///
/// вставить по позиции
///
/// добавляемый объект
/// индекс
///
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// удаление
///
/// индекс
///
- bool Remove(int position);
+ T? Remove(int position);
///
/// получение объекта по позиции
///
diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/ListGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/ListGenericObjects.cs
new file mode 100644
index 0000000..32c5207
--- /dev/null
+++ b/AccordionBus/AccordionBus/CollectionGenericObjects/ListGenericObjects.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AccordionBus.CollectionGenericObjects
+{
+ public class ListGenericObjects : ICollectionGenericObjects
+ where T : class
+ {
+
+ private readonly List _collection;
+
+ private int _maxCount;
+ public int MaxCount => _maxCount;
+
+ public int SetMaxCount { set { if (value > 0) _maxCount = value; } }
+
+ public ListGenericObjects()
+ {
+ _collection = new();
+ }
+
+ public T? Get(int position)
+ {
+ if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) return null;
+
+ return _collection[position];
+ }
+
+ public int Insert(T obj)
+ {
+ if (_collection == null || _collection.Count == _maxCount) return -1;
+
+ _collection.Add(obj);
+ return _collection.Count - 1;
+ }
+
+ public int Insert(T obj, int position)
+ {
+ if (_collection == null || position < 0 || position > _maxCount) return -1;
+
+ _collection.Insert(position, obj);
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ if (_collection == null || position < 0 || position >= _collection.Count) return null;
+
+ T? obj = _collection[position];
+ _collection[position] = null;
+ return obj;
+ }
+ }
+}
diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs
index 4caf5c1..9ecc1ee 100644
--- a/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/AccordionBus/AccordionBus/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -11,9 +11,9 @@ namespace AccordionBus.CollectionGenericObjects
{
private T?[] _collection;
- public int Count => _collection.Length;
+ public int MaxCount => _collection.Length;
- public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
+ public int SetMaxCount { set { if (value > 0 && MaxCount == 0) { _collection = new T?[value]; } } }
public MassiveGenericObjects()
{
@@ -26,27 +26,27 @@ namespace AccordionBus.CollectionGenericObjects
return _collection[position];
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
for (int i = 0; i < _collection.Length; i++)
{
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
- return false;
+ return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
- if (position < 0 || position >= _collection.Length) { return false; }
+ if (position < 0 || position >= _collection.Length) { return -1; }
if (_collection[position] == null)
{
_collection[position] = obj;
- return true;
+ return position;
}
else
{
@@ -55,7 +55,7 @@ namespace AccordionBus.CollectionGenericObjects
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
@@ -64,19 +64,20 @@ namespace AccordionBus.CollectionGenericObjects
if (_collection[i] == null)
{
_collection[i] = obj;
- return true;
+ return i;
}
}
}
- return false;
+ return -1;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
- if (position < 0 || position >= _collection.Length) { return false;}
+ if (position < 0 || position >= _collection.Length) { return null;}
+ T? obj = _collection[position];
_collection[position] = null;
- return true;
+ return obj;
}
}
}
diff --git a/AccordionBus/AccordionBus/CollectionGenericObjects/StorageCollection.cs b/AccordionBus/AccordionBus/CollectionGenericObjects/StorageCollection.cs
new file mode 100644
index 0000000..2c23907
--- /dev/null
+++ b/AccordionBus/AccordionBus/CollectionGenericObjects/StorageCollection.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AccordionBus.CollectionGenericObjects
+{
+ public class StorageCollection
+ where T: class
+ {
+ private Dictionary> _storage;
+
+ public List Keys => _storage.Keys.ToList();
+
+ public StorageCollection()
+ {
+ _storage = new Dictionary>();
+ }
+
+ public void AddCollection(string name, CollectionType collectionType)
+ {
+ if (_storage.ContainsKey(name) || name == "") return;
+
+ if (collectionType == CollectionType.Massive)
+ {
+ _storage[name] = new MassiveGenericObjects();
+ }
+ else
+ {
+ _storage[name] = new ListGenericObjects();
+ }
+ }
+
+ public void DelCollection(string name)
+ {
+ _storage.Remove(name);
+ }
+
+ public ICollectionGenericObjects? this[string name]
+ {
+ get
+ {
+ if (!_storage.ContainsKey(name)) return null;
+ return _storage[name];
+ }
+ }
+ }
+}
diff --git a/AccordionBus/AccordionBus/FormBusCollection.Designer.cs b/AccordionBus/AccordionBus/FormBusCollection.Designer.cs
index a7e37de..b74fb90 100644
--- a/AccordionBus/AccordionBus/FormBusCollection.Designer.cs
+++ b/AccordionBus/AccordionBus/FormBusCollection.Designer.cs
@@ -29,38 +29,185 @@
private void InitializeComponent()
{
groupBoxTools = 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();
+ panelTools = new Panel();
+ buttonCreateCompany = new Button();
+ comboBoxSelectedCompany = new ComboBox();
+ buttonAddBus = new Button();
+ buttonAddAccordionBus = new Button();
buttonRefresh = new Button();
+ maskedTextBox = new MaskedTextBox();
buttonGoToCheck = new Button();
buttonRemoveBus = new Button();
- maskedTextBox = new MaskedTextBox();
- buttonAddAccordionBus = new Button();
- buttonAddBus = new Button();
- comboBoxSelectedCompany = new ComboBox();
pictureBox = new PictureBox();
groupBoxTools.SuspendLayout();
+ panelStorage.SuspendLayout();
+ panelTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
SuspendLayout();
//
// groupBoxTools
//
- groupBoxTools.Controls.Add(buttonRefresh);
- groupBoxTools.Controls.Add(buttonGoToCheck);
- groupBoxTools.Controls.Add(buttonRemoveBus);
- groupBoxTools.Controls.Add(maskedTextBox);
- groupBoxTools.Controls.Add(buttonAddAccordionBus);
- groupBoxTools.Controls.Add(buttonAddBus);
+ groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Controls.Add(comboBoxSelectedCompany);
+ groupBoxTools.Controls.Add(panelStorage);
+ groupBoxTools.Controls.Add(panelTools);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(948, 0);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(234, 653);
+ groupBoxTools.Size = new Size(234, 753);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.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(228, 291);
+ panelStorage.TabIndex = 8;
+ //
+ // buttonCollectionDel
+ //
+ buttonCollectionDel.Location = new Point(9, 241);
+ buttonCollectionDel.Name = "buttonCollectionDel";
+ buttonCollectionDel.Size = new Size(207, 29);
+ buttonCollectionDel.TabIndex = 6;
+ buttonCollectionDel.Text = "Удалить коллекцию";
+ buttonCollectionDel.UseVisualStyleBackColor = true;
+ buttonCollectionDel.Click += buttonCollectionDel_Click;
+ //
+ // listBoxCollection
+ //
+ listBoxCollection.FormattingEnabled = true;
+ listBoxCollection.Location = new Point(9, 131);
+ listBoxCollection.Name = "listBoxCollection";
+ listBoxCollection.Size = new Size(207, 104);
+ listBoxCollection.TabIndex = 5;
+ //
+ // buttonCollectionAdd
+ //
+ buttonCollectionAdd.Location = new Point(9, 96);
+ buttonCollectionAdd.Name = "buttonCollectionAdd";
+ buttonCollectionAdd.Size = new Size(207, 29);
+ buttonCollectionAdd.TabIndex = 4;
+ buttonCollectionAdd.Text = "Добавить коллекцию";
+ buttonCollectionAdd.UseVisualStyleBackColor = true;
+ buttonCollectionAdd.Click += buttonCollectionAdd_Click;
+ //
+ // radioButtonList
+ //
+ radioButtonList.AutoSize = true;
+ radioButtonList.Location = new Point(125, 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(22, 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(207, 27);
+ textBoxCollectionName.TabIndex = 1;
+ //
+ // labelCollectionName
+ //
+ labelCollectionName.AutoSize = true;
+ labelCollectionName.Location = new Point(40, 10);
+ labelCollectionName.Name = "labelCollectionName";
+ labelCollectionName.Size = new Size(155, 20);
+ labelCollectionName.TabIndex = 0;
+ labelCollectionName.Text = "Название коллекции";
+ //
+ // panelTools
+ //
+ panelTools.Controls.Add(buttonAddBus);
+ panelTools.Controls.Add(buttonAddAccordionBus);
+ panelTools.Controls.Add(buttonRefresh);
+ panelTools.Controls.Add(maskedTextBox);
+ panelTools.Controls.Add(buttonGoToCheck);
+ panelTools.Controls.Add(buttonRemoveBus);
+ panelTools.Dock = DockStyle.Bottom;
+ panelTools.Enabled = false;
+ panelTools.Location = new Point(3, 396);
+ panelTools.Name = "panelTools";
+ panelTools.Size = new Size(228, 354);
+ panelTools.TabIndex = 7;
+ //
+ // buttonCreateCompany
+ //
+ buttonCreateCompany.Location = new Point(12, 361);
+ buttonCreateCompany.Name = "buttonCreateCompany";
+ buttonCreateCompany.Size = new Size(207, 29);
+ buttonCreateCompany.TabIndex = 7;
+ buttonCreateCompany.Text = "Создать компанию";
+ buttonCreateCompany.UseVisualStyleBackColor = true;
+ buttonCreateCompany.Click += buttonCreateCompany_Click;
+ //
+ // comboBoxSelectedCompany
+ //
+ comboBoxSelectedCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ comboBoxSelectedCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectedCompany.FormattingEnabled = true;
+ comboBoxSelectedCompany.Items.AddRange(new object[] { "Станция" });
+ comboBoxSelectedCompany.Location = new Point(12, 327);
+ comboBoxSelectedCompany.Name = "comboBoxSelectedCompany";
+ comboBoxSelectedCompany.Size = new Size(207, 28);
+ comboBoxSelectedCompany.TabIndex = 0;
+ comboBoxSelectedCompany.SelectedIndexChanged += comboBoxSelectedCompany_SelectedIndexChanged;
+ //
+ // buttonAddBus
+ //
+ buttonAddBus.Location = new Point(9, 13);
+ buttonAddBus.Name = "buttonAddBus";
+ buttonAddBus.Size = new Size(207, 54);
+ buttonAddBus.TabIndex = 1;
+ buttonAddBus.Text = "Добавить автобус";
+ buttonAddBus.UseVisualStyleBackColor = true;
+ buttonAddBus.Click += buttonAddBus_Click;
+ //
+ // buttonAddAccordionBus
+ //
+ buttonAddAccordionBus.Location = new Point(9, 73);
+ buttonAddAccordionBus.Name = "buttonAddAccordionBus";
+ buttonAddAccordionBus.Size = new Size(207, 54);
+ buttonAddAccordionBus.TabIndex = 2;
+ buttonAddAccordionBus.Text = "Добавить автобус с гормошкой";
+ buttonAddAccordionBus.UseVisualStyleBackColor = true;
+ buttonAddAccordionBus.Click += buttonAddAccordionBus_Click;
+ //
// buttonRefresh
//
- buttonRefresh.Location = new Point(15, 554);
+ buttonRefresh.Location = new Point(9, 286);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(207, 54);
buttonRefresh.TabIndex = 6;
@@ -68,9 +215,18 @@
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(9, 133);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(207, 27);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
// buttonGoToCheck
//
- buttonGoToCheck.Location = new Point(15, 443);
+ buttonGoToCheck.Location = new Point(9, 226);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(207, 54);
buttonGoToCheck.TabIndex = 5;
@@ -80,7 +236,7 @@
//
// buttonRemoveBus
//
- buttonRemoveBus.Location = new Point(15, 310);
+ buttonRemoveBus.Location = new Point(9, 166);
buttonRemoveBus.Name = "buttonRemoveBus";
buttonRemoveBus.Size = new Size(207, 54);
buttonRemoveBus.TabIndex = 4;
@@ -88,53 +244,12 @@
buttonRemoveBus.UseVisualStyleBackColor = true;
buttonRemoveBus.Click += buttonRemoveBus_Click;
//
- // maskedTextBox
- //
- maskedTextBox.Location = new Point(15, 277);
- maskedTextBox.Mask = "00";
- maskedTextBox.Name = "maskedTextBox";
- maskedTextBox.Size = new Size(207, 27);
- maskedTextBox.TabIndex = 3;
- maskedTextBox.ValidatingType = typeof(int);
- //
- // buttonAddAccordionBus
- //
- buttonAddAccordionBus.Location = new Point(15, 155);
- buttonAddAccordionBus.Name = "buttonAddAccordionBus";
- buttonAddAccordionBus.Size = new Size(207, 54);
- buttonAddAccordionBus.TabIndex = 2;
- buttonAddAccordionBus.Text = "Добавить автобус с гормошкой";
- buttonAddAccordionBus.UseVisualStyleBackColor = true;
- buttonAddAccordionBus.Click += buttonAddAccordionBus_Click;
- //
- // buttonAddBus
- //
- buttonAddBus.Location = new Point(15, 95);
- buttonAddBus.Name = "buttonAddBus";
- buttonAddBus.Size = new Size(207, 54);
- buttonAddBus.TabIndex = 1;
- buttonAddBus.Text = "Добавить автобус";
- buttonAddBus.UseVisualStyleBackColor = true;
- buttonAddBus.Click += buttonAddBus_Click;
- //
- // comboBoxSelectedCompany
- //
- comboBoxSelectedCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- comboBoxSelectedCompany.DropDownStyle = ComboBoxStyle.DropDownList;
- comboBoxSelectedCompany.FormattingEnabled = true;
- comboBoxSelectedCompany.Items.AddRange(new object[] { "Станция" });
- comboBoxSelectedCompany.Location = new Point(15, 40);
- comboBoxSelectedCompany.Name = "comboBoxSelectedCompany";
- comboBoxSelectedCompany.Size = new Size(207, 28);
- comboBoxSelectedCompany.TabIndex = 0;
- comboBoxSelectedCompany.SelectedIndexChanged += comboBoxSelectedCompany_SelectedIndexChanged;
- //
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(948, 653);
+ pictureBox.Size = new Size(948, 753);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -142,14 +257,17 @@
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(1182, 653);
+ ClientSize = new Size(1182, 753);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Name = "FormBusCollection";
StartPosition = FormStartPosition.CenterScreen;
Text = "Коллекция автобусов";
groupBoxTools.ResumeLayout(false);
- groupBoxTools.PerformLayout();
+ panelStorage.ResumeLayout(false);
+ panelStorage.PerformLayout();
+ panelTools.ResumeLayout(false);
+ panelTools.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
ResumeLayout(false);
}
@@ -165,5 +283,15 @@
private MaskedTextBox maskedTextBox;
private Button buttonRefresh;
private Button buttonGoToCheck;
+ private Panel panelTools;
+ private Panel panelStorage;
+ private Label labelCollectionName;
+ private RadioButton radioButtonMassive;
+ private TextBox textBoxCollectionName;
+ private RadioButton radioButtonList;
+ private Button buttonCollectionAdd;
+ private Button buttonCollectionDel;
+ private ListBox listBoxCollection;
+ private Button buttonCreateCompany;
}
}
\ No newline at end of file
diff --git a/AccordionBus/AccordionBus/FormBusCollection.cs b/AccordionBus/AccordionBus/FormBusCollection.cs
index 4873e21..a18139c 100644
--- a/AccordionBus/AccordionBus/FormBusCollection.cs
+++ b/AccordionBus/AccordionBus/FormBusCollection.cs
@@ -15,22 +15,19 @@ namespace AccordionBus
{
public partial class FormBusCollection : Form
{
- private AbstractCompany? _company;
+ private StorageCollection _storageCollection;
+
+ private AbstractCompany? _company = null;
public FormBusCollection()
{
InitializeComponent();
+ _storageCollection = new StorageCollection();
}
private void comboBoxSelectedCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- switch (comboBoxSelectedCompany.Text)
- {
- case "Станция":
- _company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
- pictureBox.Image = _company.Show();
- break;
- }
+ panelTools.Enabled = false;
}
private void CreateObject(string type)
@@ -47,7 +44,7 @@ namespace AccordionBus
break;
case nameof(DrawningAccordionBus):
_drawningBus = new DrawningAccordionBus(random.Next(100, 300), random.Next(1000, 3000),
- GetColor(random), GetColor(random),
+ GetColor(random), GetColor(random),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
_drawningBus.SetPictureSize(pictureBox.Width, pictureBox.Height);
break;
@@ -55,7 +52,7 @@ namespace AccordionBus
return;
}
- if (_company + _drawningBus)
+ if (_company + _drawningBus != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
@@ -86,10 +83,11 @@ namespace AccordionBus
{
if (_company == null || string.IsNullOrEmpty(maskedTextBox.Text)) return;
- if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
int pos = Convert.ToInt32(maskedTextBox.Text);
- if (_company - pos)
+ if (_company - pos is DrawningBus)
{
MessageBox.Show("Объект удалён");
pictureBox.Image = _company.Show();
@@ -106,7 +104,7 @@ namespace AccordionBus
DrawningBus? bus = null;
int counter = 100;
- while (bus == null || counter > 0)
+ while (bus == null && counter > 0)
{
bus = _company.GetRandomObject();
counter--;
@@ -127,5 +125,79 @@ namespace AccordionBus
pictureBox.Image = _company.Show();
}
+
+ private void buttonCollectionAdd_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonMassive.Checked && !radioButtonList.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);
+ textBoxCollectionName.Text = "";
+ RefreshListBoxItems();
+ }
+
+ private void buttonCollectionDel_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedItem == null) return;
+
+ if (MessageBox.Show("Вы действительно хотите удалить выбранный элемент?",
+ "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
+ RefreshListBoxItems();
+ MessageBox.Show("Компания удалена");
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить компанию");
+ }
+
+ }
+
+ private void buttonCreateCompany_Click(object sender, EventArgs e)
+ {
+ if (listBoxCollection.SelectedIndex < 0)
+ {
+ MessageBox.Show("Компания не выбрана");
+ return;
+ }
+
+ ICollectionGenericObjects collection = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
+ if (collection == null)
+ {
+ MessageBox.Show("Компания не инициализирована");
+ return;
+ }
+
+ switch (comboBoxSelectedCompany.Text)
+ {
+ case "Станция":
+ _company = new BusStation(pictureBox.Width, pictureBox.Height, collection);
+ pictureBox.Image = _company.Show();
+ break;
+ }
+
+ panelTools.Enabled = true;
+ }
+
+ private void RefreshListBoxItems()
+ {
+ 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);
+ }
+ }
+ }
}
}