diff --git a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs index f762bda..9f69ef5 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.Designer.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.Designer.cs @@ -29,13 +29,19 @@ private void InitializeComponent() { pictureBoxCollection = new PictureBox(); - panelTools = new Panel(); - maskedTextBoxNumber = new MaskedTextBox(); - buttonRefreshCollection = new Button(); - buttonRemovePlane = new Button(); buttonAddPlane = new Button(); + buttonRemovePlane = new Button(); + buttonRefreshCollection = new Button(); + maskedTextBoxNumber = new MaskedTextBox(); + groupBoxTools = new GroupBox(); + groupBoxStorages = new GroupBox(); + textBoxStorageName = new TextBox(); + buttonDelObject = new Button(); + buttonAddObject = new Button(); + listBoxStorages = new ListBox(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); - panelTools.SuspendLayout(); + groupBoxTools.SuspendLayout(); + groupBoxStorages.SuspendLayout(); SuspendLayout(); // // pictureBoxCollection @@ -44,54 +50,13 @@ pictureBoxCollection.Dock = DockStyle.Left; pictureBoxCollection.Location = new Point(0, 0); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(708, 548); + pictureBoxCollection.Size = new Size(708, 746); pictureBoxCollection.TabIndex = 0; pictureBoxCollection.TabStop = false; // - // panelTools - // - panelTools.Controls.Add(maskedTextBoxNumber); - panelTools.Controls.Add(buttonRefreshCollection); - panelTools.Controls.Add(buttonRemovePlane); - panelTools.Controls.Add(buttonAddPlane); - panelTools.Dock = DockStyle.Right; - panelTools.Location = new Point(719, 0); - panelTools.Name = "panelTools"; - panelTools.Size = new Size(237, 548); - panelTools.TabIndex = 1; - // - // maskedTextBoxNumber - // - maskedTextBoxNumber.Location = new Point(37, 218); - maskedTextBoxNumber.Mask = "00"; - maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(160, 31); - maskedTextBoxNumber.TabIndex = 3; - maskedTextBoxNumber.ValidatingType = typeof(int); - // - // buttonRefreshCollection - // - buttonRefreshCollection.Location = new Point(37, 394); - buttonRefreshCollection.Name = "buttonRefreshCollection"; - buttonRefreshCollection.Size = new Size(160, 86); - buttonRefreshCollection.TabIndex = 2; - buttonRefreshCollection.Text = "Обновить коллекцию"; - buttonRefreshCollection.UseVisualStyleBackColor = true; - buttonRefreshCollection.Click += buttonRefreshCollection_Click; - // - // buttonRemovePlane - // - buttonRemovePlane.Location = new Point(37, 266); - buttonRemovePlane.Name = "buttonRemovePlane"; - buttonRemovePlane.Size = new Size(160, 60); - buttonRemovePlane.TabIndex = 1; - buttonRemovePlane.Text = "Удалить самолет"; - buttonRemovePlane.UseVisualStyleBackColor = true; - buttonRemovePlane.Click += buttonRemovePlane_Click; - // // buttonAddPlane // - buttonAddPlane.Location = new Point(37, 94); + buttonAddPlane.Location = new Point(76, 417); buttonAddPlane.Name = "buttonAddPlane"; buttonAddPlane.Size = new Size(160, 64); buttonAddPlane.TabIndex = 0; @@ -99,28 +64,127 @@ buttonAddPlane.UseVisualStyleBackColor = true; buttonAddPlane.Click += buttonAddPlane_Click; // + // buttonRemovePlane + // + buttonRemovePlane.Location = new Point(76, 549); + buttonRemovePlane.Name = "buttonRemovePlane"; + buttonRemovePlane.Size = new Size(160, 60); + buttonRemovePlane.TabIndex = 1; + buttonRemovePlane.Text = "Удалить самолет"; + buttonRemovePlane.UseVisualStyleBackColor = true; + buttonRemovePlane.Click += buttonRemovePlane_Click; + // + // buttonRefreshCollection + // + buttonRefreshCollection.Location = new Point(76, 648); + buttonRefreshCollection.Name = "buttonRefreshCollection"; + buttonRefreshCollection.Size = new Size(160, 86); + buttonRefreshCollection.TabIndex = 2; + buttonRefreshCollection.Text = "Обновить коллекцию"; + buttonRefreshCollection.UseVisualStyleBackColor = true; + buttonRefreshCollection.Click += buttonRefreshCollection_Click; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(76, 501); + maskedTextBoxNumber.Mask = "00"; + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(160, 31); + maskedTextBoxNumber.TabIndex = 3; + maskedTextBoxNumber.ValidatingType = typeof(int); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(groupBoxStorages); + groupBoxTools.Controls.Add(buttonAddPlane); + groupBoxTools.Controls.Add(buttonRefreshCollection); + groupBoxTools.Controls.Add(buttonRemovePlane); + groupBoxTools.Controls.Add(maskedTextBoxNumber); + groupBoxTools.Location = new Point(714, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(305, 746); + groupBoxTools.TabIndex = 4; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // groupBoxStorages + // + groupBoxStorages.Controls.Add(textBoxStorageName); + groupBoxStorages.Controls.Add(buttonDelObject); + groupBoxStorages.Controls.Add(buttonAddObject); + groupBoxStorages.Controls.Add(listBoxStorages); + groupBoxStorages.Location = new Point(5, 30); + groupBoxStorages.Name = "groupBoxStorages"; + groupBoxStorages.Size = new Size(294, 368); + groupBoxStorages.TabIndex = 4; + groupBoxStorages.TabStop = false; + groupBoxStorages.Text = "Наборы"; + // + // textBoxStorageName + // + textBoxStorageName.Location = new Point(6, 54); + textBoxStorageName.Name = "textBoxStorageName"; + textBoxStorageName.Size = new Size(281, 31); + textBoxStorageName.TabIndex = 3; + // + // buttonDelObject + // + buttonDelObject.Location = new Point(44, 305); + buttonDelObject.Name = "buttonDelObject"; + buttonDelObject.Size = new Size(209, 34); + buttonDelObject.TabIndex = 2; + buttonDelObject.Text = "Удалить набор"; + buttonDelObject.UseVisualStyleBackColor = true; + buttonDelObject.Click += buttonDelObject_Click; + // + // buttonAddObject + // + buttonAddObject.Location = new Point(44, 106); + buttonAddObject.Name = "buttonAddObject"; + buttonAddObject.Size = new Size(209, 34); + buttonAddObject.TabIndex = 1; + buttonAddObject.Text = "Добавить набор"; + buttonAddObject.UseVisualStyleBackColor = true; + buttonAddObject.Click += buttonAddObject_Click; + // + // listBoxStorages + // + listBoxStorages.FormattingEnabled = true; + listBoxStorages.ItemHeight = 25; + listBoxStorages.Location = new Point(6, 160); + listBoxStorages.Name = "listBoxStorages"; + listBoxStorages.Size = new Size(281, 129); + listBoxStorages.TabIndex = 0; + // // FormPlaneCollection // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(956, 548); - Controls.Add(panelTools); + ClientSize = new Size(1030, 746); + Controls.Add(groupBoxTools); Controls.Add(pictureBoxCollection); Name = "FormPlaneCollection"; Text = "Набор самолетов"; ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); - panelTools.ResumeLayout(false); - panelTools.PerformLayout(); + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + groupBoxStorages.ResumeLayout(false); + groupBoxStorages.PerformLayout(); ResumeLayout(false); } #endregion private PictureBox pictureBoxCollection; - private Panel panelTools; - private MaskedTextBox maskedTextBoxNumber; - private Button buttonRefreshCollection; - private Button buttonRemovePlane; private Button buttonAddPlane; + private Button buttonRemovePlane; + private Button buttonRefreshCollection; + private MaskedTextBox maskedTextBoxNumber; + private GroupBox groupBoxTools; + private GroupBox groupBoxStorages; + private TextBox textBoxStorageName; + private Button buttonDelObject; + private Button buttonAddObject; + private ListBox listBoxStorages; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormPlaneCollection.cs b/AirBomber/AirBomber/FormPlaneCollection.cs index eba8446..9754cce 100644 --- a/AirBomber/AirBomber/FormPlaneCollection.cs +++ b/AirBomber/AirBomber/FormPlaneCollection.cs @@ -15,14 +15,42 @@ namespace AirBomber /// /// Набор объектов /// - private readonly PlanesGenericCollection _planes; - + private readonly PlanesGenericStorage _storage; public FormPlaneCollection() { InitializeComponent(); - _planes = new PlanesGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height); - + _storage = new PlanesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); } + /// + /// Заполнение listBoxObjects + /// + private void ReloadObjects() + { + int index = listBoxStorages.SelectedIndex; listBoxStorages.Items.Clear(); + for (int i = 0; i < _storage.Keys.Count; i++) + { + listBoxStorages.Items.Add(_storage.Keys[i]); + } + if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count)) + { + listBoxStorages.SelectedIndex = 0; + } + else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count) + { + listBoxStorages.SelectedIndex = index; + } + } + /// + /// Выбор набора + /// + /// + /// + private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBoxCollection.Image = + _storage[listBoxStorages.SelectedItem?.ToString()?? string.Empty]?.ShowPlanes(); + } + /// /// Добавление объекта в набор /// @@ -30,13 +58,22 @@ namespace AirBomber /// private void buttonAddPlane_Click(object sender, EventArgs e) { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString()?? string.Empty]; + if (obj == null) + { + return; + } FormAirBomber form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_planes + form.SelectedPlane != -1) + if (obj + form.SelectedPlane != -1) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _planes.ShowPlanes(); + pictureBoxCollection.Image = obj.ShowPlanes(); } else { @@ -51,15 +88,24 @@ namespace AirBomber /// private void buttonRemovePlane_Click(object sender, EventArgs e) { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_planes - pos != null) + if (obj - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _planes.ShowPlanes(); + pictureBoxCollection.Image = obj.ShowPlanes(); } else { @@ -73,7 +119,44 @@ namespace AirBomber /// private void buttonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _planes.ShowPlanes(); + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + if (obj == null) + { + return; + } + pictureBoxCollection.Image = obj.ShowPlanes(); + } + /// + /// Добавление набора в коллекцию + /// + /// + /// + private void buttonAddObject_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxStorageName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _storage.AddSet(textBoxStorageName.Text); + ReloadObjects(); + } + private void buttonDelObject_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Удалить объект{listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) +{ + _storage.DelSet(listBoxStorages.SelectedItem.ToString()?? string.Empty); + ReloadObjects(); + } } } }