diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs index 302c514..eec22a2 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/AbstractCompany.cs @@ -63,9 +63,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static bool operator +(AbstractCompany company, DrawningDozer dozer) + public static int operator +(AbstractCompany company, DrawningDozer dozer) { - return company._collection?.Insert(dozer) ?? false; + return company._collection.Insert(dozer); } /// @@ -74,9 +74,9 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static bool operator -(AbstractCompany company, int position) + public static DrawningDozer? operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position) ?? false; + return company._collection.Remove(position); } /// @@ -100,7 +100,8 @@ public abstract class AbstractCompany DrawBackground(graphics); SetObjectsPosition(); - for (int i = 0; i < (_collection?.Count ?? 0); i++) { + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { DrawningDozer? obj = _collection?.Get(i); obj?.DrawTransport(graphics); } diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..0e85ab4 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs index 1e25e8d..c1131d7 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/Garage.cs @@ -31,8 +31,10 @@ public class Garage : AbstractCompany { int cntVertically = _pictureHeight / _placeSizeHeight; //Колличество мест по вертикали int cntHorizontally = _pictureWidth / _placeSizeWidth; //Колличество мест по горизонтали - Pen pen = new Pen(Color.FromArgb(185, 140, 0)); - pen.Width = 3; + Pen pen = new(Color.FromArgb(185, 140, 0)) + { + Width = 3 + }; for (int i = 0; i < cntHorizontally; i++) { @@ -78,7 +80,5 @@ public class Garage : AbstractCompany placeVertically--; } } - - //throw new NotImplementedException(); } } diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs index be6c0e0..ef584bc 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ICollectoinGenericObjects.cs @@ -28,7 +28,7 @@ public interface ICollectoinGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj); + int Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -36,14 +36,14 @@ public interface ICollectoinGenericObjects /// Добавляемый объект /// Позиция /// true - вставка прошла удачно, false - вставка не удалась - bool Insert(T obj, int position); + int Insert(T obj, int position); /// /// Удаление объекта из коллекции на конкретной позиции /// /// Позиция /// - bool Remove(int position); + T? Remove(int position); /// /// Получение объекта по позиции diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..3b24d65 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.CollectionGenericObjects; + +/// +/// Параметрезированный набор объектов +/// +/// Параметр: ограничение - ссылочный тип +public class ListGenericObjects : ICollectoinGenericObjects + 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 >= _collection.Count || _collection == null || _collection.Count == 0) + { + return null; + } + return _collection[position]; + } + public int Insert(T obj) + { + // Проверка, что не привышено максимальное колличество элементов. + if (Count == _maxCount) + { + return -1; + } + + // Вставка в конец набора. + _collection.Add(obj); + return _collection.Count; + } + + public int Insert(T obj, int position) + { + // Проверка, что не превышено максимальное колличество элементов. + if (Count == _maxCount) + { + return -1; + } + + // Проверка позиции. + if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) //TODO проверить, что если заменить _Collection.Count на Count + { + return -1; + } + + // Вставка по позиции. + _collection.Insert(position, obj); + return position; + } + + + public T? Remove(int position) + { + // Проверка позиции. + if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) + { + return null; + } + + // Удаление объекта из списка. + T? obj = _collection[position]; + _collection[position] = null; + return obj; + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs index 22bf179..10ade07 100644 --- a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/MassiveGenericObject.cs @@ -22,11 +22,14 @@ public class MassiveGenericObject : ICollectoinGenericObjects { if (value > 0) { - Array.Resize(ref _collection, value); - } - else - { - _collection =new T?[value]; + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T[value]; + } } } } @@ -52,7 +55,7 @@ public class MassiveGenericObject : ICollectoinGenericObjects } } - public bool Insert(T obj) + public int Insert(T obj) { //Вставка в свободное место набора for (int i = 0; i < Count; i++) @@ -60,19 +63,19 @@ public class MassiveGenericObject : ICollectoinGenericObjects 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 >= Count)) { - return false; + return -1; } //Проверка, что элемент массива по этой позиции пустой, если нет, то ищется свободное место после этой @@ -105,25 +108,26 @@ public class MassiveGenericObject : ICollectoinGenericObjects if (placed == false) { - return false; + return -1; } } //Вставка _collection[position] = obj; - return true; + return position; } - public bool Remove(int position) + public T? Remove(int position) { //Проверка позиции if ((position < 0) || (position >= Count) || (_collection[position] == null)) { - return false; + return null; } //Удаление объекта из массива, присвоив элементу массива значение null + T? elem = _collection[position]; _collection[position] = null; - return true; + return elem; } } diff --git a/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..6537f15 --- /dev/null +++ b/ProjectBulldozer/ProjectBulldozer/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectBulldozer.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) + { + // Проверка, что name не пустой и нет в словаре записи с таким ключом. + if (_storages.ContainsKey(name) && name == "") + { + return; + } + // Логика для добавления. + if (collectionType == CollectionType.Massive) + { + _storages[name] = new MassiveGenericObject(); + } + else + { + _storages[name] = new ListGenericObjects(); + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + // Логика для удаления коллекции. + if (_storages.ContainsKey(name)) + { + _storages.Remove(name); + } + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectoinGenericObjects? this[string name] + { + get + { + // Логика получения объекта. + if (_storages.ContainsKey(name)) + { + return _storages[name]; + } + return null; + } + } +} diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs index a9ff02a..a3d7ad0 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.Designer.cs @@ -29,96 +29,64 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - maskedTextBox = new MaskedTextBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonDelBulldozer = new Button(); - buttonAddBulldozer = new Button(); + panelCompanyTools = new Panel(); buttonAddDozer = new Button(); + buttonAddBulldozer = new Button(); + buttonDelBulldozer = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonGoToCheck = new Button(); + buttonRefresh = new Button(); + panelStorage = new Panel(); + listBoxCollection = new ListBox(); + buttonCollectionDel = new Button(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); + buttonCreateCompany = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonDelBulldozer); - groupBoxTools.Controls.Add(buttonAddBulldozer); - groupBoxTools.Controls.Add(buttonAddDozer); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(panelStorage); + groupBoxTools.Controls.Add(buttonCreateCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); groupBoxTools.Location = new Point(1290, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(358, 914); + groupBoxTools.Size = new Size(358, 1051); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // maskedTextBox + // panelCompanyTools // - maskedTextBox.Location = new Point(14, 340); - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(332, 39); - maskedTextBox.TabIndex = 5; - maskedTextBox.ValidatingType = typeof(int); - // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonRefresh.Location = new Point(14, 719); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(332, 63); - buttonRefresh.TabIndex = 3; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonGoToCheck.Location = new Point(14, 520); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(332, 63); - buttonGoToCheck.TabIndex = 3; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonDelBulldozer - // - buttonDelBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonDelBulldozer.Location = new Point(14, 385); - buttonDelBulldozer.Name = "buttonDelBulldozer"; - buttonDelBulldozer.Size = new Size(332, 63); - buttonDelBulldozer.TabIndex = 3; - buttonDelBulldozer.Text = "Удаленить бульдозер"; - buttonDelBulldozer.UseVisualStyleBackColor = true; - buttonDelBulldozer.Click += ButtonDelBulldozer_Click; - // - // buttonAddBulldozer - // - buttonAddBulldozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonAddBulldozer.Location = new Point(14, 210); - buttonAddBulldozer.Name = "buttonAddBulldozer"; - buttonAddBulldozer.Size = new Size(332, 79); - buttonAddBulldozer.TabIndex = 3; - buttonAddBulldozer.Text = "Добавление крутого бульдозера"; - buttonAddBulldozer.UseVisualStyleBackColor = true; - buttonAddBulldozer.Click += ButtonAddBulldozer_Click; + panelCompanyTools.Controls.Add(buttonAddDozer); + panelCompanyTools.Controls.Add(buttonAddBulldozer); + panelCompanyTools.Controls.Add(buttonDelBulldozer); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 624); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(400, 449); + panelCompanyTools.TabIndex = 7; // // buttonAddDozer // - buttonAddDozer.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddDozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; buttonAddDozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); - buttonAddDozer.Location = new Point(14, 140); + buttonAddDozer.Location = new Point(11, 14); buttonAddDozer.Name = "buttonAddDozer"; buttonAddDozer.Size = new Size(332, 64); buttonAddDozer.TabIndex = 2; @@ -126,24 +94,174 @@ buttonAddDozer.UseVisualStyleBackColor = true; buttonAddDozer.Click += ButtonAddDozer_Click; // + // buttonAddBulldozer + // + buttonAddBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonAddBulldozer.Location = new Point(11, 84); + buttonAddBulldozer.Name = "buttonAddBulldozer"; + buttonAddBulldozer.Size = new Size(332, 79); + buttonAddBulldozer.TabIndex = 3; + buttonAddBulldozer.Text = "Добавление крутого бульдозера"; + buttonAddBulldozer.UseVisualStyleBackColor = true; + buttonAddBulldozer.Click += ButtonAddBulldozer_Click; + // + // buttonDelBulldozer + // + buttonDelBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBulldozer.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonDelBulldozer.Location = new Point(11, 216); + buttonDelBulldozer.Name = "buttonDelBulldozer"; + buttonDelBulldozer.Size = new Size(332, 63); + buttonDelBulldozer.TabIndex = 3; + buttonDelBulldozer.Text = "Удаленить бульдозер"; + buttonDelBulldozer.UseVisualStyleBackColor = true; + buttonDelBulldozer.Click += ButtonDelBulldozer_Click; + // + // maskedTextBox + // + maskedTextBox.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(11, 169); + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(332, 41); + maskedTextBox.TabIndex = 5; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonGoToCheck.Location = new Point(11, 285); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(332, 63); + buttonGoToCheck.TabIndex = 3; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonRefresh.Location = new Point(11, 354); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(332, 63); + buttonRefresh.TabIndex = 3; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // panelStorage + // + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionDel); + 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, 37); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(352, 465); + panelStorage.TabIndex = 6; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 33; + listBoxCollection.Location = new Point(11, 219); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(332, 169); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(11, 407); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(332, 46); + buttonCollectionDel.TabIndex = 4; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += ButtonCollectionDel_Click; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(11, 157); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(332, 46); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(183, 115); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(129, 37); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(38, 115); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(130, 37); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(11, 59); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(332, 41); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(57, 13); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(263, 33); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(14, 572); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(332, 46); + buttonCreateCompany.TabIndex = 4; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // // comboBoxSelectorCompany // - comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.Font = new Font("Comic Sans MS", 9F, FontStyle.Regular, GraphicsUnit.Point); comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(14, 52); + comboBoxSelectorCompany.Location = new Point(14, 525); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(332, 41); comboBoxSelectorCompany.TabIndex = 1; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // - pictureBox.Location = new Point(12, 12); + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1272, 890); + pictureBox.Size = new Size(1290, 1051); pictureBox.TabIndex = 4; pictureBox.TabStop = false; // @@ -151,13 +269,16 @@ // AutoScaleDimensions = new SizeF(13F, 32F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1648, 914); + ClientSize = new Size(1648, 1051); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormBulldozerCollection"; Text = "Коллекция бульдозеров"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -173,5 +294,15 @@ private Button buttonDelBulldozer; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private Label labelCollectionName; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCollectionAdd; + private ListBox listBoxCollection; + private Button buttonCollectionDel; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs index 6e42ba8..0f24c1a 100644 --- a/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs +++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozerCollection.cs @@ -18,6 +18,11 @@ namespace ProjectBulldozer; /// public partial class FormBulldozerCollection : Form { + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; + /// /// Компания /// @@ -29,6 +34,7 @@ public partial class FormBulldozerCollection : Form public FormBulldozerCollection() { InitializeComponent(); + _storageCollection = new(); } /// @@ -36,25 +42,11 @@ public partial class FormBulldozerCollection : Form /// /// /// - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); - break; - } + panelCompanyTools.Enabled = false; } -/* private void ComboBoxSelectorCompany_SelectedIndexChanget(object sender, EventArgs e) - { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new CarSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObject()); - break; - } - }*/ /// /// Добавление обычного бульдозера @@ -94,14 +86,14 @@ public partial class FormBulldozerCollection : Form case nameof(DrawningBulldozer): //Вызов диалогового окна для выбора цвета drawningDozer = new DrawningBulldozer(random.Next(100, 300), random.Next(1000, 3000), - GetBodyColor(random), GetWheelsColor(random), + GetBodyColor(random), GetWheelsColor(random), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; } - if (_company + drawningDozer) + if (_company + drawningDozer != -1) { MessageBox.Show("Объект добавлен."); pictureBox.Image = _company.Show(); @@ -162,7 +154,7 @@ public partial class FormBulldozerCollection : Form } int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos) + if (_company - pos != null) { MessageBox.Show("Объект удалён."); pictureBox.Image = _company.Show(); @@ -223,4 +215,117 @@ public partial class FormBulldozerCollection : 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); + RefreshListBoxItems(); + } + + /*private ListBox GetListBoxCollection() + { + return listBoxCollection; + }*/ + + /// + /// Удаление коллекции + /// + /// + /// + private void ButtonCollectionDel_Click(object sender, EventArgs e) + { + // Прописать логику удаления элемента из коллекции. + // Нужно убедиться, что есть выбранная коллекция + if (listBoxCollection.SelectedItem == null || listBoxCollection.SelectedIndex < 0) + { + MessageBox.Show("Коллекция не выбрана!"); + return; + } + else + { + // Спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + if (MessageBox.Show("Удалить коллекцию?", "Удаление...", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + MessageBox.Show("Коллекция не выбрана!"); + return; + } + else + { + // Удалить и обновить ListBox + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RefreshListBoxItems(); + } + } + + + + } + + /// + /// Обновление списка в ListBoxCollection + /// + 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); + } + } + } + + /// + /// Создание компании + /// + /// + /// + private void ButtonCreateCompany_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана!"); + return; + } + + ICollectoinGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("Коллекция не проинициализирована!"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new Garage(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RefreshListBoxItems(); + } }