diff --git a/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/CollectionType.cs b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/CollectionType.cs new file mode 100644 index 0000000..7049f5d --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/CollectionType.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.CollectionGenericObjects; + +/// +/// Тип коллекции +/// +public enum CollectionType +{ + None = 0, + + Massive = 1, + + List = 2 +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/StorageCollection.cs b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/StorageCollection.cs new file mode 100644 index 0000000..1a19758 --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/StorageCollection.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.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 (string.IsNullOrEmpty(name) || _storages.ContainsKey(name)) + { + return; + } + switch (collectionType) + { + case CollectionType.List: + ListGenericObjects _listToAdd = new ListGenericObjects(); + _storages.Add(name, _listToAdd); + return; + case CollectionType.Massive: + MassiveGenericObjects _arrayToAdd = new MassiveGenericObjects(); + _storages.Add(name, _arrayToAdd); + return; + case CollectionType.None: + return; + + } + } + + public void DelCollection(string name) + { + _storages.Remove(name); + } + + public ICollectionGenericObjects? this[string name] + { + get + { + if (_storages.ContainsKey(name)) + { + return _storages[name]; + } + return null; + } + } +} diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs index 0bef3a8..4a635c5 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs @@ -29,105 +29,221 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveBus = new Button(); - maskedTextBox = new MaskedTextBox(); - buttonAddDoublrDeckerBus = new Button(); + panelCompanyTools = new Panel(); buttonAddBus = new Button(); + buttonAddDoublrDeckerBus = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonRemoveBus = new Button(); + buttonGoToCheck = new Button(); + buttonCreateCompany = new Button(); + panelStorage = new Panel(); + buttonRemoveCollection = new Button(); + listBoxCollectionItems = new ListBox(); + buttonCollectionAdd = new Button(); + radioButtonList = new RadioButton(); + radioButtonArray = new RadioButton(); + textBoxCollectionName = new TextBox(); + labelCollectionName = new Label(); comboBoxSelectCompany = 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(buttonRemoveBus); - groupBoxTools.Controls.Add(maskedTextBox); - groupBoxTools.Controls.Add(buttonAddDoublrDeckerBus); - groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(panelCompanyTools); + groupBoxTools.Controls.Add(buttonCreateCompany); + groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectCompany); groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(870, 0); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(200, 450); + groupBoxTools.Size = new Size(200, 626); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Tools"; // - // buttonRefresh + // panelCompanyTools // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(6, 390); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(188, 35); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Refresh"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; + panelCompanyTools.Controls.Add(buttonAddBus); + panelCompanyTools.Controls.Add(buttonAddDoublrDeckerBus); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonRemoveBus); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 358); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(194, 265); + panelCompanyTools.TabIndex = 16; // - // buttonGoToCheck + // buttonAddBus // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(6, 312); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(188, 35); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Send to check"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveBus - // - buttonRemoveBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveBus.Location = new Point(6, 225); - buttonRemoveBus.Name = "buttonRemoveBus"; - buttonRemoveBus.Size = new Size(188, 35); - buttonRemoveBus.TabIndex = 4; - buttonRemoveBus.Text = "Remove bus"; - buttonRemoveBus.UseVisualStyleBackColor = true; - buttonRemoveBus.Click += ButtonRemoveBus_Click; - // - // maskedTextBox - // - maskedTextBox.Location = new Point(6, 196); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(182, 23); - maskedTextBox.TabIndex = 3; - maskedTextBox.ValidatingType = typeof(int); + buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBus.Location = new Point(0, 13); + buttonAddBus.Name = "buttonAddBus"; + buttonAddBus.Size = new Size(191, 35); + buttonAddBus.TabIndex = 1; + buttonAddBus.Text = "Add bus"; + buttonAddBus.UseVisualStyleBackColor = true; + buttonAddBus.Click += ButtonAddBus_Click; // // buttonAddDoublrDeckerBus // buttonAddDoublrDeckerBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddDoublrDeckerBus.Location = new Point(6, 126); + buttonAddDoublrDeckerBus.Location = new Point(0, 54); buttonAddDoublrDeckerBus.Name = "buttonAddDoublrDeckerBus"; - buttonAddDoublrDeckerBus.Size = new Size(188, 35); + buttonAddDoublrDeckerBus.Size = new Size(191, 35); buttonAddDoublrDeckerBus.TabIndex = 2; buttonAddDoublrDeckerBus.Text = "Add double-decker bus"; buttonAddDoublrDeckerBus.UseVisualStyleBackColor = true; buttonAddDoublrDeckerBus.Click += ButtonAddDoublrDeckerBus_Click; // - // buttonAddBus + // maskedTextBox // - buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBus.Location = new Point(6, 85); - buttonAddBus.Name = "buttonAddBus"; - buttonAddBus.Size = new Size(188, 35); - buttonAddBus.TabIndex = 1; - buttonAddBus.Text = "Add bus"; - buttonAddBus.UseVisualStyleBackColor = true; - buttonAddBus.Click += ButtonAddBus_Click; + maskedTextBox.Location = new Point(0, 95); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(188, 23); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(0, 206); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(191, 35); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonRemoveBus + // + buttonRemoveBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveBus.Location = new Point(0, 124); + buttonRemoveBus.Name = "buttonRemoveBus"; + buttonRemoveBus.Size = new Size(191, 35); + buttonRemoveBus.TabIndex = 4; + buttonRemoveBus.Text = "Remove bus"; + buttonRemoveBus.UseVisualStyleBackColor = true; + buttonRemoveBus.Click += ButtonRemoveBus_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(0, 165); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(191, 35); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Send to check"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(6, 296); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(188, 23); + buttonCreateCompany.TabIndex = 15; + buttonCreateCompany.Text = "Create compnay"; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += ButtonCreateCompany_Click; + // + // panelStorage + // + panelStorage.Controls.Add(buttonRemoveCollection); + panelStorage.Controls.Add(listBoxCollectionItems); + panelStorage.Controls.Add(buttonCollectionAdd); + panelStorage.Controls.Add(radioButtonList); + panelStorage.Controls.Add(radioButtonArray); + 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, 242); + panelStorage.TabIndex = 7; + // + // buttonRemoveCollection + // + buttonRemoveCollection.Location = new Point(3, 208); + buttonRemoveCollection.Name = "buttonRemoveCollection"; + buttonRemoveCollection.Size = new Size(188, 23); + buttonRemoveCollection.TabIndex = 14; + buttonRemoveCollection.Text = "Remove Collection"; + buttonRemoveCollection.UseVisualStyleBackColor = true; + buttonRemoveCollection.Click += ButtonRemoveCollection_Click; + // + // listBoxCollectionItems + // + listBoxCollectionItems.FormattingEnabled = true; + listBoxCollectionItems.ItemHeight = 15; + listBoxCollectionItems.Location = new Point(3, 108); + listBoxCollectionItems.Name = "listBoxCollectionItems"; + listBoxCollectionItems.Size = new Size(188, 94); + listBoxCollectionItems.TabIndex = 13; + // + // buttonCollectionAdd + // + buttonCollectionAdd.Location = new Point(3, 79); + buttonCollectionAdd.Name = "buttonCollectionAdd"; + buttonCollectionAdd.Size = new Size(188, 23); + buttonCollectionAdd.TabIndex = 12; + buttonCollectionAdd.Text = "Add Collection"; + buttonCollectionAdd.UseVisualStyleBackColor = true; + buttonCollectionAdd.Click += ButtonCollectionAdd_Click; + // + // radioButtonList + // + radioButtonList.AutoSize = true; + radioButtonList.Location = new Point(126, 47); + radioButtonList.Name = "radioButtonList"; + radioButtonList.Size = new Size(43, 19); + radioButtonList.TabIndex = 11; + radioButtonList.TabStop = true; + radioButtonList.Text = "List"; + radioButtonList.UseVisualStyleBackColor = true; + // + // radioButtonArray + // + radioButtonArray.AutoSize = true; + radioButtonArray.Location = new Point(22, 47); + radioButtonArray.Name = "radioButtonArray"; + radioButtonArray.Size = new Size(53, 19); + radioButtonArray.TabIndex = 10; + radioButtonArray.TabStop = true; + radioButtonArray.Text = "Array"; + radioButtonArray.UseVisualStyleBackColor = true; + // + // textBoxCollectionName + // + textBoxCollectionName.Location = new Point(3, 18); + textBoxCollectionName.Name = "textBoxCollectionName"; + textBoxCollectionName.Size = new Size(188, 23); + textBoxCollectionName.TabIndex = 9; + // + // labelCollectionName + // + labelCollectionName.AutoSize = true; + labelCollectionName.Location = new Point(40, 0); + labelCollectionName.Name = "labelCollectionName"; + labelCollectionName.Size = new Size(108, 15); + labelCollectionName.TabIndex = 8; + labelCollectionName.Text = "Name of collection\r\n"; // // comboBoxSelectCompany // comboBoxSelectCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectCompany.FormattingEnabled = true; comboBoxSelectCompany.Items.AddRange(new object[] { "Storage" }); - comboBoxSelectCompany.Location = new Point(6, 22); + comboBoxSelectCompany.Location = new Point(6, 267); comboBoxSelectCompany.Name = "comboBoxSelectCompany"; comboBoxSelectCompany.Size = new Size(188, 23); comboBoxSelectCompany.TabIndex = 0; @@ -138,7 +254,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(870, 450); + pictureBox.Size = new Size(870, 626); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -146,13 +262,16 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1070, 450); + ClientSize = new Size(1070, 626); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Name = "FormBusCollection"; Text = "Bus collection"; groupBoxTools.ResumeLayout(false); - groupBoxTools.PerformLayout(); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); + panelStorage.ResumeLayout(false); + panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); ResumeLayout(false); } @@ -168,5 +287,15 @@ private PictureBox pictureBox; private Button buttonRefresh; private Button buttonGoToCheck; + private Panel panelStorage; + private Label labelCollectionName; + private TextBox textBoxCollectionName; + private RadioButton radioButtonArray; + private RadioButton radioButtonList; + private Button buttonCollectionAdd; + private ListBox listBoxCollectionItems; + private Button buttonCreateCompany; + private Button buttonRemoveCollection; + private Panel panelCompanyTools; } } \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs index fb2f7aa..99c8d5c 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs @@ -16,22 +16,20 @@ public partial class FormBusCollection : Form { private AbstractCompany? _company = null; + private readonly StorageCollection _storageCollection; + /// /// Конструктор /// public FormBusCollection() { InitializeComponent(); + _storageCollection = new(); } private void comboBoxSelectCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectCompany.Text) - { - case "Storage": - _company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } private void CreateObject(string type) @@ -150,4 +148,86 @@ public partial class FormBusCollection : Form pictureBox.Image = _company.Show(); } + + private void ButtonCollectionAdd_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonArray.Checked && !radioButtonList.Checked)) + { + MessageBox.Show("Not all data is filled in", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + CollectionType collectionType = CollectionType.None; + if (radioButtonArray.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } + + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + RefreshListBoxItems(); + } + + private void RefreshListBoxItems() + { + listBoxCollectionItems.Items.Clear(); + for (int i = 0; i < _storageCollection.Keys?.Count; i++) + { + string? colName = _storageCollection.Keys?[i]; + if (!string.IsNullOrEmpty(colName)) + { + listBoxCollectionItems.Items.Add(colName); + } + } + } + + private void ButtonRemoveCollection_Click(object sender, EventArgs e) + { + if (listBoxCollectionItems.SelectedIndex < 0) + { + MessageBox.Show("No collection selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (listBoxCollectionItems.SelectedItems.Count == 1) + { + DialogResult result = MessageBox.Show("Are you sure you want to delete the selected collection?", "Confirm and remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question); + + if (result == DialogResult.Yes) + { + _storageCollection.DelCollection(listBoxCollectionItems.Text); + RefreshListBoxItems(); + } + else + { + return; + } + } + } + + private void ButtonCreateCompany_Click(object sender, EventArgs e) + { + if (listBoxCollectionItems.SelectedIndex < 0 || listBoxCollectionItems.SelectedItem == null) + { + MessageBox.Show("No collection selected"); + return; + } + ICollectionGenericObjects? collection = _storageCollection[listBoxCollectionItems.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("The collection is not initialized"); + return; + } + switch (comboBoxSelectCompany.Text) + { + case "Storage": + _company = new BusStation(pictureBox.Width, pictureBox.Height, collection); + break; + } + + panelCompanyTools.Enabled = true; + } }