From e016dde468d4d4bcbbc09d8552e55a8c2378c1f3 Mon Sep 17 00:00:00 2001 From: Daria Date: Mon, 22 Apr 2024 22:32:27 +0400 Subject: [PATCH] =?UTF-8?q?4=20=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 22 ++ .../ListGenericObjects.cs | 61 ++++++ .../StorageCollection.cs | 74 +++++++ .../FormTrackedVehicleCollection.Designer.cs | 196 +++++++++++++++--- .../Excavator/FormTrackedVehicleCollection.cs | 109 +++++++++- 5 files changed, 420 insertions(+), 42 deletions(-) create mode 100644 Excavator/Excavator/CollectionGenericObjects/CollectionType.cs create mode 100644 Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs diff --git a/Excavator/Excavator/CollectionGenericObjects/CollectionType.cs b/Excavator/Excavator/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..df20777 --- /dev/null +++ b/Excavator/Excavator/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,22 @@ +namespace Excavator.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + + /// + /// Массив + /// + Massive = 1, + + /// + /// Список + /// + List = 2 +} diff --git a/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs b/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..07e7923 --- /dev/null +++ b/Excavator/Excavator/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,61 @@ +namespace Excavator.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 >= Count || position < 0) return null; + return _collection[position]; + } + + public int Insert(T obj) + { + if (Count + 1 > _maxCount) return -1; + _collection.Add(obj); + return Count; + } + + public int Insert(T obj, int position) + { + if (Count + 1 > _maxCount) return -1; + if (position < 0 || position > Count) return -1; + _collection.Insert(position, obj); + return 1; + } + + public bool Remove(int position) + { + if (!(position >= 0 && position < Count)) + return false; + _collection.RemoveAt(position); + return true; + } + + +} \ No newline at end of file diff --git a/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..e856bc1 --- /dev/null +++ b/Excavator/Excavator/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,74 @@ +namespace Excavator.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 (name == null || _storages.ContainsKey(name)) { return; } + switch (collectionType) + + { + case CollectionType.None: + return; + case CollectionType.Massive: + _storages[name] = new MassiveGenericObjects(); + return; + case CollectionType.List: + _storages[name] = new ListGenericObjects(); + return; + } + } + + /// + /// Удаление коллекции + /// + /// Название коллекции + public void DelCollection(string name) + { + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + if (name == null || !_storages.ContainsKey(name)) { return null; } + return _storages[name]; + + } + } +} diff --git a/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs b/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs index 86f7770..7701381 100644 --- a/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs +++ b/Excavator/Excavator/FormTrackedVehicleCollection.Designer.cs @@ -29,26 +29,35 @@ private void InitializeComponent() { groupBox1 = 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(); + comboBoxSelectorCompany = new ComboBox(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); buttonDelExcavator = new Button(); maskedTextBox = new MaskedTextBox(); buttonAddExcavator = new Button(); buttonAddTrackedVehicle = new Button(); - comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); + panelCompanyTools = new Panel(); groupBox1.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBox1 // - groupBox1.Controls.Add(buttonRefresh); - groupBox1.Controls.Add(buttonGoToCheck); - groupBox1.Controls.Add(buttonDelExcavator); - groupBox1.Controls.Add(maskedTextBox); - groupBox1.Controls.Add(buttonAddExcavator); - groupBox1.Controls.Add(buttonAddTrackedVehicle); + groupBox1.Controls.Add(panelCompanyTools); + groupBox1.Controls.Add(buttonCreateCompany); + groupBox1.Controls.Add(panelStorage); groupBox1.Controls.Add(comboBoxSelectorCompany); groupBox1.Dock = DockStyle.Right; groupBox1.Location = new Point(939, 0); @@ -58,12 +67,115 @@ groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(24, 441); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(180, 29); + buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 23); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(215, 362); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(15, 287); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(180, 29); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.Location = new Point(3, 161); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(203, 104); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(16, 116); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(180, 29); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(103, 81); + 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(15, 81); + 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(15, 37); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(191, 27); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(27, 14); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(155, 20); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции"; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(18, 402); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(191, 28); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(18, 487); + buttonRefresh.Location = new Point(18, 273); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(191, 45); + buttonRefresh.Size = new Size(176, 45); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -72,9 +184,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(18, 406); + buttonGoToCheck.Location = new Point(18, 222); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(191, 45); + buttonGoToCheck.Size = new Size(171, 45); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -83,9 +195,9 @@ // buttonDelExcavator // buttonDelExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelExcavator.Location = new Point(18, 327); + buttonDelExcavator.Location = new Point(18, 171); buttonDelExcavator.Name = "buttonDelExcavator"; - buttonDelExcavator.Size = new Size(191, 45); + buttonDelExcavator.Size = new Size(171, 45); buttonDelExcavator.TabIndex = 4; buttonDelExcavator.Text = "Удалить машину"; buttonDelExcavator.UseVisualStyleBackColor = true; @@ -93,7 +205,7 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(18, 257); + maskedTextBox.Location = new Point(13, 125); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(191, 27); @@ -103,9 +215,9 @@ // buttonAddExcavator // buttonAddExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddExcavator.Location = new Point(18, 162); + buttonAddExcavator.Location = new Point(18, 72); buttonAddExcavator.Name = "buttonAddExcavator"; - buttonAddExcavator.Size = new Size(191, 45); + buttonAddExcavator.Size = new Size(166, 35); buttonAddExcavator.TabIndex = 2; buttonAddExcavator.Text = "Добавить экскаватор"; buttonAddExcavator.UseVisualStyleBackColor = true; @@ -114,35 +226,38 @@ // buttonAddTrackedVehicle // buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddTrackedVehicle.Location = new Point(18, 83); + buttonAddTrackedVehicle.Location = new Point(12, 3); buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle"; - buttonAddTrackedVehicle.Size = new Size(191, 60); + buttonAddTrackedVehicle.Size = new Size(177, 52); buttonAddTrackedVehicle.TabIndex = 1; buttonAddTrackedVehicle.Text = "Добавить гусеничную машину"; buttonAddTrackedVehicle.UseVisualStyleBackColor = true; buttonAddTrackedVehicle.Click += ButtonAddCar_Click; // - // comboBoxSelectorCompany - // - comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxSelectorCompany.FormattingEnabled = true; - comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(18, 34); - comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(191, 28); - comboBoxSelectorCompany.TabIndex = 0; - comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; - // // pictureBox // pictureBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(1, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(939, 800); + pictureBox.Size = new Size(938, 800); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddTrackedVehicle); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonAddExcavator); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonDelExcavator); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 473); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(215, 330); + panelCompanyTools.TabIndex = 9; + // // FormTrackedVehicleCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -153,8 +268,11 @@ Name = "FormTrackedVehicleCollection"; Text = "Коллекция экскаваторов"; groupBox1.ResumeLayout(false); - groupBox1.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -166,8 +284,18 @@ private Button buttonDelExcavator; private MaskedTextBox maskedTextBox; private Button buttonAddExcavator; - private PictureBox pictureBox; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Label labelCollectionName; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private Button buttonCreateCompany; + private Panel panelCompanyTools; + private PictureBox pictureBox; } } \ No newline at end of file diff --git a/Excavator/Excavator/FormTrackedVehicleCollection.cs b/Excavator/Excavator/FormTrackedVehicleCollection.cs index 77fa004..a25cc47 100644 --- a/Excavator/Excavator/FormTrackedVehicleCollection.cs +++ b/Excavator/Excavator/FormTrackedVehicleCollection.cs @@ -1,6 +1,5 @@ using Excavator.CollectionGenericObjects; using Excavator.Drawnings; -using System.Windows.Forms; namespace Excavator; @@ -9,6 +8,10 @@ namespace Excavator; /// public partial class FormTrackedVehicleCollection : Form { + /// + /// Хранилише коллекций + /// + private readonly StorageCollection _storageCollection; /// /// Компания /// @@ -20,6 +23,8 @@ public partial class FormTrackedVehicleCollection : Form public FormTrackedVehicleCollection() { InitializeComponent(); + _storageCollection = new(); + } /// @@ -29,12 +34,7 @@ public partial class FormTrackedVehicleCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new Garage(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -181,5 +181,98 @@ public partial class FormTrackedVehicleCollection : 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; + } -} \ No newline at end of file + 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(); + } + /// + /// Обновление списка в listBoxCollection + /// + private void RerfreshListBoxItems() + { + listBoxCollection.Items.Clear(); + for (int i = 0; i < _storageCollection.Keys?.Count; ++i) + { + string? colName = _storageCollection.Keys?[i]; + if (!string.IsNullOrEmpty(colName)) + { + listBoxCollection.Items.Add(colName); + } + } + + } + /// + /// Создание компании + /// + /// + /// + private void 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 Garage(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } + + +}