From 1d9936c8803f845b632cfad9fbc8909f9d041a55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=A8=D0=B8=D0=BF?= =?UTF-8?q?=D0=B8=D0=BB=D0=BE=D0=B2?= <116575516+LAYT73@users.noreply.github.com> Date: Mon, 15 Apr 2024 00:56:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionType.cs | 17 ++ .../ListGenericObjects.cs | 45 +++++ .../StorageCollection.cs | 63 +++++++ .../FormSeaplaneCollection.Designer.cs | 164 ++++++++++++++++-- .../ProjectSeaplane/FormSeaplaneCollection.cs | 89 +++++++++- 5 files changed, 353 insertions(+), 25 deletions(-) create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs create mode 100644 ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..b8b5c7a --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,17 @@ +namespace ProjectSeaplane.CollectionGenericObjects; + +public enum CollectionType +{ + /// + /// Неопределено + /// + None = 0, + /// + /// Массив + /// + Massive = 1, + /// + /// Список + /// + List = 2 +} diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs new file mode 100644 index 0000000..f1cdedb --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/ListGenericObjects.cs @@ -0,0 +1,45 @@ +namespace ProjectSeaplane.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 == _maxCount) return -1; + _collection.Add(obj); + return Count; + } + public int Insert(T obj, int position) + { + if (Count == _maxCount) return -1; + if (position >= Count || position < 0) return -1; + _collection.Insert(position, obj); + return position; + } + public T Remove(int position) + { + if (position >= Count || position < 0) return null; + T obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } +} diff --git a/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..1feafd5 --- /dev/null +++ b/ProjectSeaplane/ProjectSeaplane/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,63 @@ +namespace ProjectSeaplane.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) + { + // TODO проверка, что name не пустой и нет в словаре записи с таким ключом + // TODO Прописать логику для добавления + 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) + { + + // TODO Прописать логику для удаления коллекции + if (_storages.ContainsKey(name)) + _storages.Remove(name); + } + /// + /// Доступ к коллекции + /// + /// Название коллекции + /// + public ICollectionGenericObjects? this[string name] + { + get + { + // TODO Продумать логику получения объекта + if (_storages.ContainsKey(name)) + return _storages[name]; + return null; + } + } +} diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.Designer.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.Designer.cs index e527e20..1c80c37 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.Designer.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.Designer.cs @@ -29,6 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonCollectionDel = new Button(); + listBoxCollection = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonMassive = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); buttonRefresh = new Button(); buttonGoToCheck = new Button(); buttonDelPlane = new Button(); @@ -37,30 +46,122 @@ buttonAddPlane = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); + panelCompanyTools = new Panel(); groupBoxTools.SuspendLayout(); + panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); + panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonRefresh); - groupBoxTools.Controls.Add(buttonGoToCheck); - groupBoxTools.Controls.Add(buttonDelPlane); - groupBoxTools.Controls.Add(maskedTextBoxPosition); - groupBoxTools.Controls.Add(buttonAddSeaplane); - groupBoxTools.Controls.Add(buttonAddPlane); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(655, 0); + groupBoxTools.Location = new Point(764, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(200, 565); + groupBoxTools.Size = new Size(200, 627); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 300); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(182, 23); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonCollectionDel); + panelStorage.Controls.Add(listBoxCollection); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonMassive); + panelStorage.Controls.Add(textBoxCollectionName); + panelStorage.Controls.Add(labelCollectionName); + panelStorage.Dock = DockStyle.Top; + panelStorage.Location = new Point(3, 19); + panelStorage.Name = "panelStorage"; + panelStorage.Size = new Size(194, 246); + panelStorage.TabIndex = 7; + // + // buttonCollectionDel + // + buttonCollectionDel.Location = new Point(3, 212); + buttonCollectionDel.Name = "buttonCollectionDel"; + buttonCollectionDel.Size = new Size(188, 23); + buttonCollectionDel.TabIndex = 6; + buttonCollectionDel.Text = "Удалить коллекцию"; + buttonCollectionDel.UseVisualStyleBackColor = true; + buttonCollectionDel.Click += buttonCollectionDel_Click; + // + // listBoxCollection + // + listBoxCollection.FormattingEnabled = true; + listBoxCollection.ItemHeight = 15; + listBoxCollection.Location = new Point(3, 112); + listBoxCollection.Name = "listBoxCollection"; + listBoxCollection.Size = new Size(188, 94); + listBoxCollection.TabIndex = 5; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 83); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(188, 23); + buttonCollectionAdd.TabIndex = 4; + buttonCollectionAdd.Text = "Добавить коллекцию"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += buttonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(90, 58); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(66, 19); + radioButtonList.TabIndex = 3; + radioButtonList.TabStop = true; + radioButtonList.Text = "Список"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonMassive + // + radioButtonMassive.AutoSize = true; + radioButtonMassive.Location = new Point(17, 58); + radioButtonMassive.Name = "radioButtonMassive"; + radioButtonMassive.Size = new Size(67, 19); + radioButtonMassive.TabIndex = 2; + radioButtonMassive.TabStop = true; + radioButtonMassive.Text = "Массив"; + radioButtonMassive.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 29); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(188, 23); + textBoxCollectionName.TabIndex = 1; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(38, 11); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(125, 15); + labelCollectionName.TabIndex = 0; + labelCollectionName.Text = "Название коллекции:"; + // // buttonRefresh // - buttonRefresh.Location = new Point(6, 469); + buttonRefresh.Location = new Point(3, 216); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(182, 41); buttonRefresh.TabIndex = 6; @@ -70,7 +171,7 @@ // // buttonGoToCheck // - buttonGoToCheck.Location = new Point(6, 322); + buttonGoToCheck.Location = new Point(3, 173); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(182, 41); buttonGoToCheck.TabIndex = 5; @@ -80,7 +181,7 @@ // // buttonDelPlane // - buttonDelPlane.Location = new Point(6, 235); + buttonDelPlane.Location = new Point(3, 126); buttonDelPlane.Name = "buttonDelPlane"; buttonDelPlane.Size = new Size(182, 41); buttonDelPlane.TabIndex = 4; @@ -90,7 +191,7 @@ // // maskedTextBoxPosition // - maskedTextBoxPosition.Location = new Point(6, 206); + maskedTextBoxPosition.Location = new Point(3, 97); maskedTextBoxPosition.Mask = "00"; maskedTextBoxPosition.Name = "maskedTextBoxPosition"; maskedTextBoxPosition.Size = new Size(182, 23); @@ -99,7 +200,7 @@ // // buttonAddSeaplane // - buttonAddSeaplane.Location = new Point(6, 123); + buttonAddSeaplane.Location = new Point(3, 50); buttonAddSeaplane.Name = "buttonAddSeaplane"; buttonAddSeaplane.Size = new Size(182, 41); buttonAddSeaplane.TabIndex = 2; @@ -109,7 +210,7 @@ // // buttonAddPlane // - buttonAddPlane.Location = new Point(6, 76); + buttonAddPlane.Location = new Point(3, 3); buttonAddPlane.Name = "buttonAddPlane"; buttonAddPlane.Size = new Size(182, 41); buttonAddPlane.TabIndex = 1; @@ -123,7 +224,7 @@ comboBoxSelectorCompany.AutoCompleteCustomSource.AddRange(new string[] { "Хранилище" }); comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 22); + comboBoxSelectorCompany.Location = new Point(6, 271); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(182, 23); comboBoxSelectorCompany.TabIndex = 0; @@ -134,22 +235,39 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(655, 565); + pictureBox.Size = new Size(764, 627); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddPlane); + panelCompanyTools.Controls.Add(buttonAddSeaplane); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonDelPlane); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(6, 346); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(188, 269); + panelCompanyTools.TabIndex = 8; + // // FormSeaplaneCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(855, 565); + ClientSize = new Size(964, 627); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormSeaplaneCollection"; Text = "FormSeaplaneCollection"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -164,5 +282,15 @@ private MaskedTextBox maskedTextBoxPosition; private Button buttonAddSeaplane; private PictureBox pictureBox; + private Panel panelStorage; + private Label labelCollectionName; + private Button buttonCollectionDel; + private ListBox listBoxCollection; + private Button buttonCollectionAdd; + private RadioButton radioButtonList; + private RadioButton radioButtonMassive; + private TextBox textBoxCollectionName; + private Button buttonCreateCompany; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.cs b/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.cs index ce60ae6..60eeb7c 100644 --- a/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.cs +++ b/ProjectSeaplane/ProjectSeaplane/FormSeaplaneCollection.cs @@ -6,21 +6,19 @@ namespace ProjectSeaplane; public partial class FormSeaplaneCollection : Form { + private readonly StorageCollection _storageCollection; + private AbstractCompany? _company = null; public FormSeaplaneCollection() { InitializeComponent(); + _storageCollection = new(); } private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingPlane)); @@ -42,7 +40,7 @@ public partial class FormSeaplaneCollection : Form drawningPlane = new DrawingPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); break; case nameof(DrawingSeaplane): - drawningPlane = new DrawingSeaplane(random.Next(100, 300), random.Next(1000, 3000), + drawningPlane = new DrawingSeaplane(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; @@ -137,4 +135,81 @@ public partial class FormSeaplaneCollection : Form pictureBox.Image = _company.Show(); } + + private void buttonCollectionAdd_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } + + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + RerfreshListBoxItems(); + } + + private void buttonCollectionDel_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + + private void 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 PlaneSharingService(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + RerfreshListBoxItems(); + } } -- 2.25.1