diff --git a/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs index b7a3f8e..2dd3a42 100644 --- a/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs +++ b/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs @@ -11,6 +11,11 @@ /// public Color AdditionalColor { get; private set; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } + /// /// (опция) наличие дополнительных двигателей /// diff --git a/ProjectAirbus/ProjectAirbus/Entities/EntityPlane.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityPlane.cs index f2a0607..37d8c64 100644 --- a/ProjectAirbus/ProjectAirbus/Entities/EntityPlane.cs +++ b/ProjectAirbus/ProjectAirbus/Entities/EntityPlane.cs @@ -21,6 +21,11 @@ public class EntityPlane /// public Color BodyColor { get; private set; } + public void SetBodyColor(Color bodyColor) + { + BodyColor = bodyColor; + } + /// /// шаг перемещения самолёта /// diff --git a/ProjectAirbus/ProjectAirbus/FormPlaneCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormPlaneCollection.Designer.cs index 4b8214b..69d6654 100644 --- a/ProjectAirbus/ProjectAirbus/FormPlaneCollection.Designer.cs +++ b/ProjectAirbus/ProjectAirbus/FormPlaneCollection.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelCompanyTools = new Panel(); + buttonAddPlane = new Button(); + buttonGoToCheck = new Button(); + buttonDelPlane = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonRefresh = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -38,19 +44,12 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonDelPlane = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddAirbus = new Button(); - buttonAddPlane = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -60,18 +59,89 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(940, 0); + groupBoxTools.Location = new Point(1075, 0); + groupBoxTools.Margin = new Padding(3, 4, 3, 4); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(198, 668); + groupBoxTools.Padding = new Padding(3, 4, 3, 4); + groupBoxTools.Size = new Size(226, 891); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddPlane); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonDelPlane); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(15, 493); + panelCompanyTools.Margin = new Padding(3, 4, 3, 4); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(203, 381); + panelCompanyTools.TabIndex = 9; + // + // buttonAddPlane + // + buttonAddPlane.Location = new Point(0, 19); + buttonAddPlane.Margin = new Padding(3, 4, 3, 4); + buttonAddPlane.Name = "buttonAddPlane"; + buttonAddPlane.Size = new Size(189, 64); + buttonAddPlane.TabIndex = 1; + buttonAddPlane.Text = "Добавить самолёт"; + buttonAddPlane.UseVisualStyleBackColor = true; + buttonAddPlane.Click += ButtonAddPlane_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Location = new Point(0, 257); + buttonGoToCheck.Margin = new Padding(3, 4, 3, 4); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(189, 64); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += buttonGoToCheck_Click; + // + // buttonDelPlane + // + buttonDelPlane.Location = new Point(0, 201); + buttonDelPlane.Margin = new Padding(3, 4, 3, 4); + buttonDelPlane.Name = "buttonDelPlane"; + buttonDelPlane.Size = new Size(189, 43); + buttonDelPlane.TabIndex = 4; + buttonDelPlane.Text = "Удалить самолёт"; + buttonDelPlane.UseVisualStyleBackColor = true; + buttonDelPlane.Click += buttonDelPlane_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(0, 163); + maskedTextBoxPosition.Margin = new Padding(3, 4, 3, 4); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(188, 27); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonRefresh + // + buttonRefresh.Location = new Point(0, 329); + buttonRefresh.Margin = new Padding(3, 4, 3, 4); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(189, 33); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(13, 341); + buttonCreateCompany.Location = new Point(15, 455); + buttonCreateCompany.Margin = new Padding(3, 4, 3, 4); buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(165, 23); + buttonCreateCompany.Size = new Size(189, 31); buttonCreateCompany.TabIndex = 8; buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.UseVisualStyleBackColor = true; @@ -87,16 +157,18 @@ panelStorage.Controls.Add(textBoxCollectionName); panelStorage.Controls.Add(labelCollectionName); panelStorage.Dock = DockStyle.Top; - panelStorage.Location = new Point(3, 19); + panelStorage.Location = new Point(3, 24); + panelStorage.Margin = new Padding(3, 4, 3, 4); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(192, 278); + panelStorage.Size = new Size(220, 371); panelStorage.TabIndex = 7; // // buttonCollectionDel // - buttonCollectionDel.Location = new Point(10, 248); + buttonCollectionDel.Location = new Point(11, 331); + buttonCollectionDel.Margin = new Padding(3, 4, 3, 4); buttonCollectionDel.Name = "buttonCollectionDel"; - buttonCollectionDel.Size = new Size(174, 23); + buttonCollectionDel.Size = new Size(199, 31); buttonCollectionDel.TabIndex = 6; buttonCollectionDel.Text = "Удалить коллекцию"; buttonCollectionDel.UseVisualStyleBackColor = true; @@ -105,17 +177,19 @@ // listBoxCollection // listBoxCollection.FormattingEnabled = true; - listBoxCollection.ItemHeight = 15; - listBoxCollection.Location = new Point(10, 133); + listBoxCollection.ItemHeight = 20; + listBoxCollection.Location = new Point(11, 177); + listBoxCollection.Margin = new Padding(3, 4, 3, 4); listBoxCollection.Name = "listBoxCollection"; - listBoxCollection.Size = new Size(174, 109); + listBoxCollection.Size = new Size(198, 144); listBoxCollection.TabIndex = 5; // // buttonCollectionAdd // - buttonCollectionAdd.Location = new Point(10, 104); + buttonCollectionAdd.Location = new Point(11, 139); + buttonCollectionAdd.Margin = new Padding(3, 4, 3, 4); buttonCollectionAdd.Name = "buttonCollectionAdd"; - buttonCollectionAdd.Size = new Size(174, 23); + buttonCollectionAdd.Size = new Size(199, 31); buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.UseVisualStyleBackColor = true; @@ -124,9 +198,10 @@ // radioButtonList // radioButtonList.AutoSize = true; - radioButtonList.Location = new Point(117, 69); + radioButtonList.Location = new Point(134, 92); + radioButtonList.Margin = new Padding(3, 4, 3, 4); radioButtonList.Name = "radioButtonList"; - radioButtonList.Size = new Size(66, 19); + radioButtonList.Size = new Size(80, 24); radioButtonList.TabIndex = 3; radioButtonList.TabStop = true; radioButtonList.Text = "Список"; @@ -135,9 +210,10 @@ // radioButtonMassive // radioButtonMassive.AutoSize = true; - radioButtonMassive.Location = new Point(12, 69); + radioButtonMassive.Location = new Point(14, 92); + radioButtonMassive.Margin = new Padding(3, 4, 3, 4); radioButtonMassive.Name = "radioButtonMassive"; - radioButtonMassive.Size = new Size(67, 19); + radioButtonMassive.Size = new Size(82, 24); radioButtonMassive.TabIndex = 2; radioButtonMassive.TabStop = true; radioButtonMassive.Text = "Массив"; @@ -145,88 +221,31 @@ // // textBoxCollectionName // - textBoxCollectionName.Location = new Point(12, 28); + textBoxCollectionName.Location = new Point(14, 37); + textBoxCollectionName.Margin = new Padding(3, 4, 3, 4); textBoxCollectionName.Name = "textBoxCollectionName"; - textBoxCollectionName.Size = new Size(171, 23); + textBoxCollectionName.Size = new Size(195, 27); textBoxCollectionName.TabIndex = 1; // // labelCollectionName // labelCollectionName.AutoSize = true; - labelCollectionName.Location = new Point(35, 10); + labelCollectionName.Location = new Point(40, 13); labelCollectionName.Name = "labelCollectionName"; - labelCollectionName.Size = new Size(122, 15); + labelCollectionName.Size = new Size(155, 20); labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции"; // - // buttonRefresh - // - buttonRefresh.Location = new Point(0, 247); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(165, 25); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += buttonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Location = new Point(0, 193); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(165, 48); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += buttonGoToCheck_Click; - // - // buttonDelPlane - // - buttonDelPlane.Location = new Point(0, 151); - buttonDelPlane.Name = "buttonDelPlane"; - buttonDelPlane.Size = new Size(165, 32); - buttonDelPlane.TabIndex = 4; - buttonDelPlane.Text = "Удалить самолёт"; - buttonDelPlane.UseVisualStyleBackColor = true; - buttonDelPlane.Click += buttonDelPlane_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Location = new Point(0, 122); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(165, 23); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddAirbus - // - buttonAddAirbus.Location = new Point(0, 68); - buttonAddAirbus.Name = "buttonAddAirbus"; - buttonAddAirbus.Size = new Size(165, 48); - buttonAddAirbus.TabIndex = 2; - buttonAddAirbus.Text = "Добавить аэробус"; - buttonAddAirbus.UseVisualStyleBackColor = true; - buttonAddAirbus.Click += ButtonAddAirbus_Click; - // - // buttonAddPlane - // - buttonAddPlane.Location = new Point(0, 14); - buttonAddPlane.Name = "buttonAddPlane"; - buttonAddPlane.Size = new Size(165, 48); - buttonAddPlane.TabIndex = 1; - buttonAddPlane.Text = "Добавить самолёт"; - buttonAddPlane.UseVisualStyleBackColor = true; - buttonAddPlane.Click += ButtonAddPlane_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(13, 312); + comboBoxSelectorCompany.Location = new Point(15, 416); + comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(165, 23); + comboBoxSelectorCompany.Size = new Size(188, 28); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // @@ -234,40 +253,28 @@ // pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 0); + pictureBox.Margin = new Padding(3, 4, 3, 4); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(940, 668); + pictureBox.Size = new Size(1075, 891); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // - // panelCompanyTools - // - panelCompanyTools.Controls.Add(buttonAddPlane); - panelCompanyTools.Controls.Add(buttonAddAirbus); - panelCompanyTools.Controls.Add(buttonGoToCheck); - panelCompanyTools.Controls.Add(buttonDelPlane); - panelCompanyTools.Controls.Add(maskedTextBoxPosition); - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(13, 370); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(178, 286); - panelCompanyTools.TabIndex = 9; - // // FormPlaneCollection // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1138, 668); + ClientSize = new Size(1301, 891); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Margin = new Padding(3, 4, 3, 4); Name = "FormPlaneCollection"; Text = "Коллекция самолётов"; groupBoxTools.ResumeLayout(false); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTools.ResumeLayout(false); - panelCompanyTools.PerformLayout(); ResumeLayout(false); } @@ -276,7 +283,6 @@ private GroupBox groupBoxTools; private Button buttonAddPlane; private ComboBox comboBoxSelectorCompany; - private Button buttonAddAirbus; private PictureBox pictureBox; private Button buttonDelPlane; private MaskedTextBox maskedTextBoxPosition; diff --git a/ProjectAirbus/ProjectAirbus/FormPlaneCollection.cs b/ProjectAirbus/ProjectAirbus/FormPlaneCollection.cs index e7435e6..f1aa10b 100644 --- a/ProjectAirbus/ProjectAirbus/FormPlaneCollection.cs +++ b/ProjectAirbus/ProjectAirbus/FormPlaneCollection.cs @@ -1,276 +1,239 @@ using ProjectAirbus.CollectionGenericObjects; using ProjectAirbus.Drawnings; -namespace ProjectAirbus +namespace ProjectAirbus; + + +/// +/// Форма работы с компанией +/// +public partial class FormPlaneCollection : Form { + /// + /// Хранилище коллекций + /// + private readonly StorageCollection _storageCollection; /// - /// Форма работы с компанией + /// Компания /// - public partial class FormPlaneCollection : Form + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormPlaneCollection() { - /// - /// Хранилище коллекций - /// - private readonly StorageCollection _storageCollection; + InitializeComponent(); + _storageCollection = new(); + } - /// - /// Компания - /// - private AbstractCompany? _company = null; + /// + /// Выбор компании + /// + /// + /// + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + panelCompanyTools.Enabled = false; + } - /// - /// Конструктор - /// - public FormPlaneCollection() + /// + /// добавить самолет + /// + /// + /// + private void ButtonAddPlane_Click(object sender, EventArgs e) + { + FormPlaneConfig form = new(); + form.Show(); + form.AddEvent(SetPlane); + } + + /// + /// добавление самолета в коллекцию + /// + /// + private void SetPlane(DrawningPlane plane) + { + if (_company == null || plane == null) { - InitializeComponent(); - _storageCollection = new(); + return; } - - /// - /// Выбор компании - /// - /// - /// - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + if (_company + plane != -1) { - panelCompanyTools.Enabled = false; - } - - /// - /// Получение цвета - /// - /// Генератор случайных чисел - /// - private static Color GetColor(Random random) - { - Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); - ColorDialog dialog = new(); - if (dialog.ShowDialog() == DialogResult.OK) - { - color = dialog.Color; - } - - return color; - } - - /// - /// Создание объекта класса-перемещения - /// - /// Тип создаваемого объекта - private void CreateObject(string type) - { - if (_company == null) - { - return; - } - DrawningPlane _drawningShip; - Random random = new(); - switch (type) - { - case nameof(DrawningPlane): - _drawningShip = new DrawningPlane(random.Next(30, 70), random.Next(100, 500), - GetColor(random)); - break; - case nameof(DrawningAirbus): - _drawningShip = new DrawningAirbus(random.Next(30, 70), random.Next(100, 500), - GetColor(random), GetColor(random), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - - } - if (_company + _drawningShip != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - - /// - /// добавить самолет - /// - /// - /// - private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); - - /// - /// добавить аэробус - /// - /// - /// - private void ButtonAddAirbus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirbus)); - - /// - /// Удаление объекта - /// - /// - /// - private void buttonDelPlane_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) - { - return; - } - - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - - int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось удалить объект"); - } - } - - /// - /// Передача объекта в другую форму - /// - /// - /// - private void buttonGoToCheck_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - - DrawningPlane? plane = null; - int counter = 100; - while (plane == null) - { - plane = _company.GetRandomObject(); - counter--; - if (counter <= 0) - { - break; - } - } - - if (plane == null) - { - return; - } - - FormAirbus form = new FormAirbus(); - form.SetPlane = plane; - form.ShowDialog(); - } - - /// - /// Перерисовка коллекции - /// - /// - /// - private void buttonRefresh_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - + MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); } - - /// - /// Добавление коллекции - /// - /// - /// - private void buttonCollectionAdd_Click(object sender, EventArgs e) + else { - 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); - RefreshListBoxItems(); - } - - private void RefreshListBoxItems() - { - 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 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() ?? string.Empty); - RefreshListBoxItems(); - } - - /// - /// - /// - /// - /// - 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 AirbusSharingService(pictureBox.Width, pictureBox.Height, collection); - break; - } - panelCompanyTools.Enabled = true; - RefreshListBoxItems(); + MessageBox.Show("Не удалось добавить объект"); } } -} + + /// + /// Удаление объекта + /// + /// + /// + private void buttonDelPlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void buttonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningPlane? plane = null; + int counter = 100; + while (plane == null) + { + plane = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (plane == null) + { + return; + } + + FormAirbus form = new FormAirbus(); + form.SetPlane = plane; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + 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); + RefreshListBoxItems(); + } + + private void RefreshListBoxItems() + { + 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 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() ?? string.Empty); + RefreshListBoxItems(); + } + + /// + /// + /// + /// + /// + 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 AirbusSharingService(pictureBox.Width, pictureBox.Height, collection); + break; + } + panelCompanyTools.Enabled = true; + RefreshListBoxItems(); + } +} \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormPlaneConfig.Designer.cs b/ProjectAirbus/ProjectAirbus/FormPlaneConfig.Designer.cs new file mode 100644 index 0000000..2745549 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/FormPlaneConfig.Designer.cs @@ -0,0 +1,358 @@ +namespace ProjectAirbus +{ + partial class FormPlaneConfig + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + groupBoxConfig = new GroupBox(); + groupBoxColors = new GroupBox(); + panelPurple = new Panel(); + panelBlack = new Panel(); + panelGray = new Panel(); + panelWhite = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + checkBoxOtsek = new CheckBox(); + checkBoxMotor = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + labelWeight = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + pictureBoxObject = new PictureBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelBodyColor = new Label(); + groupBoxConfig.SuspendLayout(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + panelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxConfig + // + groupBoxConfig.Controls.Add(groupBoxColors); + groupBoxConfig.Controls.Add(checkBoxOtsek); + groupBoxConfig.Controls.Add(checkBoxMotor); + groupBoxConfig.Controls.Add(numericUpDownWeight); + groupBoxConfig.Controls.Add(labelWeight); + groupBoxConfig.Controls.Add(numericUpDownSpeed); + groupBoxConfig.Controls.Add(labelSpeed); + groupBoxConfig.Controls.Add(labelModifiedObject); + groupBoxConfig.Controls.Add(labelSimpleObject); + groupBoxConfig.Dock = DockStyle.Left; + groupBoxConfig.Location = new Point(0, 0); + groupBoxConfig.Name = "groupBoxConfig"; + groupBoxConfig.Size = new Size(775, 277); + groupBoxConfig.TabIndex = 0; + groupBoxConfig.TabStop = false; + groupBoxConfig.Text = "Параметры"; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(377, 12); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(381, 177); + groupBoxColors.TabIndex = 8; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(305, 105); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(58, 57); + panelPurple.TabIndex = 1; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(219, 105); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(58, 57); + panelBlack.TabIndex = 1; + // + // panelGray + // + panelGray.BackColor = Color.DarkGray; + panelGray.Location = new Point(122, 105); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(58, 57); + panelGray.TabIndex = 1; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(22, 105); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(58, 57); + panelWhite.TabIndex = 1; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(305, 26); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(58, 57); + panelYellow.TabIndex = 1; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(219, 26); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(58, 57); + panelBlue.TabIndex = 1; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(122, 26); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(58, 57); + panelGreen.TabIndex = 1; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(22, 26); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(58, 57); + panelRed.TabIndex = 0; + // + // checkBoxOtsek + // + checkBoxOtsek.AutoSize = true; + checkBoxOtsek.Location = new Point(12, 204); + checkBoxOtsek.Name = "checkBoxOtsek"; + checkBoxOtsek.Size = new Size(141, 24); + checkBoxOtsek.TabIndex = 7; + checkBoxOtsek.Text = "Наличие отсека"; + checkBoxOtsek.UseVisualStyleBackColor = true; + // + // checkBoxMotor + // + checkBoxMotor.AutoSize = true; + checkBoxMotor.Location = new Point(12, 166); + checkBoxMotor.Name = "checkBoxMotor"; + checkBoxMotor.Size = new Size(157, 24); + checkBoxMotor.TabIndex = 6; + checkBoxMotor.Text = "Наличие моторов"; + checkBoxMotor.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(101, 87); + numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(187, 27); + numericUpDownWeight.TabIndex = 5; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(12, 94); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(33, 20); + labelWeight.TabIndex = 4; + labelWeight.Text = "Вес"; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(101, 44); + numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 }); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(187, 27); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(12, 51); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(73, 20); + labelSpeed.TabIndex = 2; + labelSpeed.Text = "Скорость"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(596, 204); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(162, 57); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += labelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(377, 204); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(162, 57); + labelSimpleObject.TabIndex = 0; + labelSimpleObject.Text = "Простой"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(3, 44); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(233, 163); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonAdd + // + buttonAdd.Location = new Point(781, 223); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(111, 36); + buttonAdd.TabIndex = 2; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(912, 223); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(111, 35); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // panelObject + // + panelObject.AllowDrop = true; + panelObject.Controls.Add(labelAdditionalColor); + panelObject.Controls.Add(labelBodyColor); + panelObject.Controls.Add(pictureBoxObject); + panelObject.Location = new Point(780, 7); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(250, 210); + panelObject.TabIndex = 4; + panelObject.DragDrop += PanelObject_DragDrop; + panelObject.DragEnter += PanelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(146, 5); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.RightToLeft = RightToLeft.No; + labelAdditionalColor.Size = new Size(90, 36); + labelAdditionalColor.TabIndex = 10; + labelAdditionalColor.Text = "Доп. Цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += LabelColors_DragDrop; + labelAdditionalColor.DragEnter += LabelColors_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(3, 5); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(90, 36); + labelBodyColor.TabIndex = 9; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += LabelColors_DragDrop; + labelBodyColor.DragEnter += LabelColors_DragEnter; + // + // FormPlaneConfig + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1028, 277); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(groupBoxConfig); + Name = "FormPlaneConfig"; + Text = "Создание объекта"; + groupBoxConfig.ResumeLayout(false); + groupBoxConfig.PerformLayout(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + panelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxConfig; + private Label labelSimpleObject; + private NumericUpDown numericUpDownWeight; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private Label labelModifiedObject; + private CheckBox checkBoxMotor; + private CheckBox checkBoxOtsek; + private GroupBox groupBoxColors; + private Panel panelPurple; + private Panel panelBlack; + private Panel panelGray; + private Panel panelWhite; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Button buttonAdd; + private Button buttonCancel; + private Panel panelObject; + private Label labelAdditionalColor; + private Label labelBodyColor; + } +} \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormPlaneConfig.cs b/ProjectAirbus/ProjectAirbus/FormPlaneConfig.cs new file mode 100644 index 0000000..4ffcbd9 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/FormPlaneConfig.cs @@ -0,0 +1,163 @@ +using ProjectAirbus.Drawnings; +using ProjectAirbus.Entities; + +namespace ProjectAirbus; + +/// +/// Форма конфигурации объекта +/// +public partial class FormPlaneConfig : Form +{ + /// + /// Объект - прорисовка корабля + /// + private DrawningPlane? _plane = null; + + /// + /// Событие для передачи объекта + /// + private event Action? _planeDelegate; + + /// + /// Конструктор + /// + public FormPlaneConfig() + { + InitializeComponent(); + + panelRed.MouseDown += Panel_MouseDown; + panelGreen.MouseDown += Panel_MouseDown; + panelBlue.MouseDown += Panel_MouseDown; + panelYellow.MouseDown += Panel_MouseDown; + panelWhite.MouseDown += Panel_MouseDown; + panelGray.MouseDown += Panel_MouseDown; + panelBlack.MouseDown += Panel_MouseDown; + panelPurple.MouseDown += Panel_MouseDown; + + buttonCancel.Click += (sender, e) => Close(); + } + + /// + /// Привязка внешнего метода к событию + /// + /// + public void AddEvent(Action planeDelegate) + { + _planeDelegate += planeDelegate; + } + + + /// + /// Прорисовка объекта + /// + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _plane?.SetPictureSize(pictureBoxObject.Width, pictureBoxObject.Height); + _plane?.SetPosition(5, 5); + _plane?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + /// + /// Передаем информацию при нажатии на Label + /// + /// + /// + private void labelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name ?? + string.Empty, DragDropEffects.Move | DragDropEffects.Copy); + } + + /// + /// Проверка получаемой информации + /// + /// + /// + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None; + } + + + /// + /// Действия при приеме перетаскиваемой информации + /// + /// + /// + private void PanelObject_DragDrop(object sender, DragEventArgs e) + { + switch (e.Data?.GetData(DataFormats.Text)?.ToString()) + { + case "labelSimpleObject": + _plane = new DrawningPlane((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _plane = new DrawningAirbus((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, + Color.White, Color.Black, checkBoxMotor.Checked, checkBoxOtsek.Checked); + break; + } + DrawObject(); + } + + + + /// + /// Передаем информацию при нажатии на Panel + /// + /// + /// + private void Panel_MouseDown(object? sender, MouseEventArgs e) + { + + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.White, DragDropEffects.Move | DragDropEffects.Copy); + + } + + private void LabelColors_DragEnter(object? sender, DragEventArgs e) + { + e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; + } + + private void LabelColors_DragDrop(object? sender, DragEventArgs e) + { + if (_plane == null || sender == null || _plane.EntityPlane == null) + { + return; + } + + Label label = (Label)sender; + Color newColor = (Color)e.Data?.GetData(typeof(Color)); + + switch (label.Name) + { + case "labelBodyColor": + _plane.EntityPlane.SetBodyColor(newColor); + DrawObject(); + break; + case "labelAdditionalColor": + if (_plane is DrawningAirbus) + { + (_plane.EntityPlane as EntityAirbus)?.SetAdditionalColor(newColor); + DrawObject(); + } + break; + } + } + + /// + /// Передача объекта + /// + /// + /// + private void ButtonAdd_Click(object sender, EventArgs e) + { + if (_plane != null) + { + _planeDelegate?.Invoke(_plane); + Close(); + } + } +} \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormPlaneConfig.resx b/ProjectAirbus/ProjectAirbus/FormPlaneConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/FormPlaneConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file