diff --git a/solution/lab1/CollectionGenericObjects/ClassForDop.cs b/solution/lab1/CollectionGenericObjects/ClassForDop.cs new file mode 100644 index 0000000..45751db --- /dev/null +++ b/solution/lab1/CollectionGenericObjects/ClassForDop.cs @@ -0,0 +1,15 @@ +using lab1.Drawnings; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace lab1.CollectionGenericObjects +{ + internal class ClassForDoppublic + where T : DrawningTrackedVehicle + { + + } +} diff --git a/solution/lab1/CollectionGenericObjects/CollectionType.cs b/solution/lab1/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..d040d21 --- /dev/null +++ b/solution/lab1/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace lab1.CollectionGenericObjects; + +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 +} diff --git a/solution/lab1/CollectionGenericObjects/ListGenericObjects.cs b/solution/lab1/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..ebaf977 --- /dev/null +++ b/solution/lab1/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,79 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace lab1.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 < _collection.Count) + { + return _collection[position]; + } + return null; + } + + public int Insert(T obj) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO вставка в конец набора + if (_collection.Count <= _maxCount) + { + _collection.Add(obj); + return _collection.Count; + } + return -1; + } + + public int Insert(T obj, int position) + { + // TODO проверка, что не превышено максимальное количество элементов + // TODO проверка позиции + // TODO вставка по позиции + if (position >= 0 && position < _maxCount && _collection.Count <= _maxCount) + { + _collection.Insert(position, obj); + return position; + } + return -1; + } + + public T? Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + if (position < 0 || position > _maxCount) + { + return null; + } + T temp = _collection[position]; + _collection.RemoveAt(position); + return temp; + } +} diff --git a/solution/lab1/CollectionGenericObjects/MassiveGenericObjects.cs b/solution/lab1/CollectionGenericObjects/MassiveGenericObjects.cs index 8353bdf..280370a 100644 --- a/solution/lab1/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/solution/lab1/CollectionGenericObjects/MassiveGenericObjects.cs @@ -15,10 +15,25 @@ public class MassiveGenericObjects : ICollectionGenericObjects private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } } - /// - /// Конструктор - /// + public int SetMaxCount + { + set + { + if (value > 0) + { + if (_collection.Length > 0) + { + Array.Resize(ref _collection, value); + } + else + { + _collection = new T?[value]; + } + } + } + } /// + /// Конструктор + /// public MassiveGenericObjects() { _collection = Array.Empty(); diff --git a/solution/lab1/CollectionGenericObjects/StorageCollection.cs b/solution/lab1/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..e5bd5c6 --- /dev/null +++ b/solution/lab1/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace lab1.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) + { + + 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) + { + 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/solution/lab1/Drawnings/DrawningEntityFighter.cs b/solution/lab1/Drawnings/DrawningEntityFighter.cs index 56e5816..1cf9a10 100644 --- a/solution/lab1/Drawnings/DrawningEntityFighter.cs +++ b/solution/lab1/Drawnings/DrawningEntityFighter.cs @@ -31,24 +31,24 @@ public class DrawningEntityFighter : DrawningTrackedVehicle Brush CraneBrush = new SolidBrush(fighter.AdditionalColor); - + base.DrawTransport(g); if (fighter.Kovsh) { - //ковш - g.DrawRectangle(pen, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15); - g.FillRectangle(CraneBrush, _startPosX.Value - 2, _startPosY.Value + 37, 8, 15); - g.DrawRectangle(pen, _startPosX.Value - -6, _startPosY.Value + 37, 4, 1); + ///ковш + g.DrawRectangle(pen, _startPosX.Value - 17, _startPosY.Value + 12, 8, 15); + g.FillRectangle(CraneBrush, _startPosX.Value - 17, _startPosY.Value + 12, 8, 15); + g.DrawRectangle(pen, _startPosX.Value - 8, _startPosY.Value + 17, 5, 1); } - //противовес + ///противовес if (fighter.Otval) { - g.DrawRectangle(pen, _startPosX.Value + 73, _startPosY.Value + 37, 17, 1); - g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 37, 1, 17); + g.DrawRectangle(pen, _startPosX.Value + 63, _startPosY.Value + 17, 17, 1); + g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 17, 1, 16); } diff --git a/solution/lab1/FormTrackedVehicleCollection.Designer.cs b/solution/lab1/FormTrackedVehicleCollection.Designer.cs index a1ab031..037a526 100644 --- a/solution/lab1/FormTrackedVehicleCollection.Designer.cs +++ b/solution/lab1/FormTrackedVehicleCollection.Designer.cs @@ -29,52 +29,117 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonCollectionDel = new Button(); + panelCompanyTools = new Panel(); + buttonAddFighter = new Button(); + buttonAddTrackedVehicle = new Button(); buttonRefresh = new Button(); + maskedTextBox = new MaskedTextBox(); buttonGoToCheck = new Button(); buttonRemoveTrackedVehicle = new Button(); - maskedTextBox = new MaskedTextBox(); - buttonAddTrackedVehicle = new Button(); - buttonAddFighter = new Button(); + button1CreateCompany = new Button(); + panelStorage = new Panel(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonRemoveTrackedVehicle); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddTrackedVehicle); - groupBoxTools.Controls.Add(buttonAddFighter); + groupBoxTools.Controls.Add(buttonCollectionDel); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(button1CreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(886, 0); + groupBoxTools.Location = new Point(677, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(297, 617); + groupBoxTools.Size = new Size(297, 710); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 284); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(276, 34); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; + // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddFighter); + panelCompanyTools.Controls.Add(buttonAddTrackedVehicle); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRemoveTrackedVehicle); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 431); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(282, 273); + panelCompanyTools.TabIndex = 10; + // + // buttonAddFighter + // + buttonAddFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddFighter.Location = new Point(6, 59); + buttonAddFighter.Name = "buttonAddFighter"; + buttonAddFighter.Size = new Size(273, 59); + buttonAddFighter.TabIndex = 2; + buttonAddFighter.Text = "Добавление гусеничной машины с оборудованием"; + buttonAddFighter.UseVisualStyleBackColor = true; + buttonAddFighter.Click += ButtonAddFighter_Click; + // + // buttonAddTrackedVehicle + // + buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTrackedVehicle.Location = new Point(6, 0); + buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle"; + buttonAddTrackedVehicle.Size = new Size(273, 63); + buttonAddTrackedVehicle.TabIndex = 3; + buttonAddTrackedVehicle.Text = "Добавление гусеничной машины"; + buttonAddTrackedVehicle.UseVisualStyleBackColor = true; + buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(7, 516); + buttonRefresh.Location = new Point(7, 239); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(284, 53); + buttonRefresh.Size = new Size(272, 31); buttonRefresh.TabIndex = 7; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += ButtonRefresh_Click_1; // + // maskedTextBox + // + maskedTextBox.Location = new Point(3, 124); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(284, 31); + maskedTextBox.TabIndex = 4; + maskedTextBox.ValidatingType = typeof(int); + // // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(5, 457); + buttonGoToCheck.Location = new Point(7, 205); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(286, 53); + buttonGoToCheck.Size = new Size(274, 33); buttonGoToCheck.TabIndex = 6; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,45 +148,94 @@ // buttonRemoveTrackedVehicle // buttonRemoveTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveTrackedVehicle.Location = new Point(5, 342); + buttonRemoveTrackedVehicle.Location = new Point(7, 161); buttonRemoveTrackedVehicle.Name = "buttonRemoveTrackedVehicle"; - buttonRemoveTrackedVehicle.Size = new Size(286, 82); + buttonRemoveTrackedVehicle.Size = new Size(274, 38); buttonRemoveTrackedVehicle.TabIndex = 5; buttonRemoveTrackedVehicle.Text = "Удаление гусеничной машины"; buttonRemoveTrackedVehicle.UseVisualStyleBackColor = true; buttonRemoveTrackedVehicle.Click += ButtonRemoveTrackedVehicle_Click; // - // maskedTextBox + // button1CreateCompany // - maskedTextBox.Location = new Point(7, 305); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(284, 31); - maskedTextBox.TabIndex = 4; - maskedTextBox.ValidatingType = typeof(int); - maskedTextBox.MaskInputRejected += maskedTextBox1_MaskInputRejected; + button1CreateCompany.Location = new Point(6, 376); + button1CreateCompany.Name = "button1CreateCompany"; + button1CreateCompany.Size = new Size(276, 34); + button1CreateCompany.TabIndex = 9; + button1CreateCompany.Text = "Создать компанию"; + button1CreateCompany.UseVisualStyleBackColor = true; + button1CreateCompany.Click += button1CreateCompany_Click; // - // buttonAddTrackedVehicle + // panelStorage // - buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddTrackedVehicle.Location = new Point(12, 181); - buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle"; - buttonAddTrackedVehicle.Size = new Size(279, 82); - buttonAddTrackedVehicle.TabIndex = 3; - buttonAddTrackedVehicle.Text = "Добавление гусеничной машины"; - buttonAddTrackedVehicle.UseVisualStyleBackColor = true; - buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click; + 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, 27); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(291, 226); + panelStorage.TabIndex = 8; // - // buttonAddFighter + // listBoxCollection // - buttonAddFighter.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddFighter.Location = new Point(0, 98); - buttonAddFighter.Name = "buttonAddFighter"; - buttonAddFighter.Size = new Size(291, 77); - buttonAddFighter.TabIndex = 2; - buttonAddFighter.Text = "Добавление истребителя"; - buttonAddFighter.UseVisualStyleBackColor = true; - buttonAddFighter.Click += ButtonAddTrackedVehicle_Click; + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 25; + listBoxCollection.Location = new Point(6, 154); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(276, 104); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(6, 114); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(276, 34); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(153, 79); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(96, 29); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(41, 79); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(98, 29); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(4, 42); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(278, 31); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(41, 14); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(186, 25); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; // // comboBoxSelectorCompany // @@ -129,34 +243,34 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(7, 30); + comboBoxSelectorCompany.Location = new Point(1, 324); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(284, 33); comboBoxSelectorCompany.TabIndex = 1; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(886, 617); + pictureBox.Size = new Size(677, 710); pictureBox.TabIndex = 1; pictureBox.TabStop = false; - pictureBox.Click += pictureBox1_Click; // // FormTrackedVehicleCollection // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1183, 617); + ClientSize = new Size(974, 710); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormTrackedVehicleCollection"; Text = "Коллекция гусеничных машин"; - Load += FormTrackedVehicleCollection_Load; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -172,5 +286,15 @@ private MaskedTextBox maskedTextBox; private Button buttonGoToCheck; private Button buttonRefresh; + private Panel panelStorage; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private Button button1CreateCompany; + private Button buttonCollectionDel; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/solution/lab1/FormTrackedVehicleCollection.cs b/solution/lab1/FormTrackedVehicleCollection.cs index cfa1c2a..e33a787 100644 --- a/solution/lab1/FormTrackedVehicleCollection.cs +++ b/solution/lab1/FormTrackedVehicleCollection.cs @@ -1,12 +1,18 @@ using lab1.CollectionGenericObjects; using lab1.Drawnings; +using System.Windows.Forms; namespace lab1; + /// -///Форма работы с компанией и её коллекцией +/// Форма работы с компанией и ее коллекцией /// public partial class FormTrackedVehicleCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; /// /// Компания /// @@ -18,14 +24,15 @@ public partial class FormTrackedVehicleCollection : Form public FormTrackedVehicleCollection() { InitializeComponent(); + _storageCollection = new(); } + /// /// Выбор компании /// /// /// - - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { switch (comboBoxSelectorCompany.Text) { @@ -36,63 +43,64 @@ public partial class FormTrackedVehicleCollection : Form } /// - /// Добавление гусеничной машины + /// Добавление обычного автомобиля /// /// /// private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle)); + /// - /// Добавление истребителя + /// Добавление спортивного автомобиля /// /// /// - private void ButtonAddEntityFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter)); + private void ButtonAddFighter_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningEntityFighter)); /// /// Создание объекта класса-перемещения /// - /// + /// Тип создаваемого объекта private void CreateObject(string type) { if (_company == null) { return; } + Random random = new(); - DrawningTrackedVehicle drawningTrackedVehicle; + DrawningTrackedVehicle drawingTrans; switch (type) { case nameof(DrawningTrackedVehicle): - drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + drawingTrans = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawningEntityFighter): - drawningTrackedVehicle = new DrawningEntityFighter(random.Next(100, 300), random.Next(1000, 3000), - GetColor(random), - GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + // вызов диалогового окна для выбора цвета + drawingTrans = new DrawningEntityFighter(random.Next(100, 300), random.Next(1000, 3000), + GetColor(random), + GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); break; default: return; - } - if (_company + drawningTrackedVehicle != -1) + + if (_company + drawingTrans != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); } else { - MessageBox.Show("Не удалось добавить объект"); + _ = MessageBox.Show(drawingTrans.ToString()); } - - - } + /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// private static Color GetColor(Random random) { Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); @@ -101,28 +109,27 @@ public partial class FormTrackedVehicleCollection : Form { color = dialog.Color; } + return color; } - + /// /// Удаление объекта /// /// /// - private void ButtonRemoveTrackedVehicle_Click(object sender, EventArgs e) + private void buttonCollectionDel_Click(object sender, EventArgs e) { - if (_company == null) - { - return; - } if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } + int pos = Convert.ToInt32(maskedTextBox.Text); if (_company - pos != null) { @@ -134,42 +141,43 @@ public partial class FormTrackedVehicleCollection : Form MessageBox.Show("Не удалось удалить объект"); } } + /// /// Передача объекта в другую форму /// /// /// - private void button1_Click(object sender, EventArgs e) { if (_company == null) { return; } - DrawningTrackedVehicle? fighter = null; + + DrawningTrackedVehicle? car = null; int counter = 100; - while (fighter == null) + while (car == null) { - fighter = _company.GetRandomObject(); + car = _company.GetRandomObject(); counter--; if (counter <= 0) { break; } } - if (fighter == null) + + if (car == null) { return; } + FormFighter form = new() { - SetTrackedVehicle = fighter + SetTrackedVehicle = car }; form.ShowDialog(); - } - /// /// Перерисовка коллекции /// @@ -181,24 +189,103 @@ public partial class FormTrackedVehicleCollection : Form { return; } + pictureBox.Image = _company.Show(); } - private void pictureBox1_Click(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(); } - private void maskedTextBox1_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) + /// + /// Удаление коллекции + /// + /// + /// + private void ButtonRemoveTrackedVehicle_Click(object sender, EventArgs e) { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + /// + /// Обновление списка в listBoxCollection + /// + private void RerfreshListBoxItems() + { + listBoxCollection.Items.Clear(); + foreach (var key in _storageCollection.Keys ?? Enumerable.Empty()) + { + if (!string.IsNullOrEmpty(key)) + { + listBoxCollection.Items.Add(key); + } + } + + } + + /// + /// Создание компании + /// + /// + /// + private void button1CreateCompany_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 TrackedVehicleSharingService(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); } - - private void FormTrackedVehicleCollection_Load(object sender, EventArgs e) - { - - } - -} - +} \ No newline at end of file