From 51298923d3418561e9e2531601902a9b1c8881aa Mon Sep 17 00:00:00 2001 From: Anastasia Yazykova Date: Sun, 14 Apr 2024 21:49:56 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=205?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TrolleybusProject/BusConfig.Designer.cs | 373 ++++++++++++++++++ .../TrolleybusProject/BusConfig.cs | 153 +++++++ .../TrolleybusProject/BusConfig.resx | 120 ++++++ .../TrolleybusProject/BusDelegate.cs | 11 + .../TrolleybusProject/Entities/EntityBus.cs | 5 +- .../Entities/EntityTrolleybus.cs | 4 + .../FormBusCollection.Designer.cs | 68 ++-- .../TrolleybusProject/FormBusCollection.cs | 52 +-- 8 files changed, 706 insertions(+), 80 deletions(-) create mode 100644 TrolleybusProject/TrolleybusProject/BusConfig.Designer.cs create mode 100644 TrolleybusProject/TrolleybusProject/BusConfig.cs create mode 100644 TrolleybusProject/TrolleybusProject/BusConfig.resx create mode 100644 TrolleybusProject/TrolleybusProject/BusDelegate.cs diff --git a/TrolleybusProject/TrolleybusProject/BusConfig.Designer.cs b/TrolleybusProject/TrolleybusProject/BusConfig.Designer.cs new file mode 100644 index 0000000..44499b4 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/BusConfig.Designer.cs @@ -0,0 +1,373 @@ +namespace TrolleybusProject +{ + partial class BusConfig + { + /// + /// 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(); + checkBoxDoors = new CheckBox(); + checkBoxOtsek = new CheckBox(); + checkBoxRoga = new CheckBox(); + numericUpDownWeight = new NumericUpDown(); + labelWeight = new Label(); + numericUpDownSpeed = new NumericUpDown(); + labelSpeed = new Label(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + pictureBoxObject = new PictureBox(); + buttonCancel = new Button(); + panelObject = new Panel(); + labelAdditionalColor = new Label(); + labelBodyColor = new Label(); + buttonAdd = new Button(); + 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(checkBoxDoors); + groupBoxConfig.Controls.Add(checkBoxOtsek); + groupBoxConfig.Controls.Add(checkBoxRoga); + 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(678, 263); + 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(346, 21); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(296, 162); + groupBoxColors.TabIndex = 1; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Цвета"; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(222, 80); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(41, 37); + panelPurple.TabIndex = 7; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(148, 80); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(41, 37); + panelBlack.TabIndex = 6; + // + // panelGray + // + panelGray.BackColor = Color.Gray; + panelGray.Location = new Point(79, 80); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(41, 37); + panelGray.TabIndex = 5; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(6, 80); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(41, 37); + panelWhite.TabIndex = 4; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(222, 30); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(41, 37); + panelYellow.TabIndex = 3; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(148, 30); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(41, 37); + panelBlue.TabIndex = 2; + // + // panelGreen + // + panelGreen.BackColor = Color.Green; + panelGreen.Location = new Point(79, 30); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(41, 37); + panelGreen.TabIndex = 1; + panelGreen.Paint += panelGreen_Paint; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(6, 30); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(41, 37); + panelRed.TabIndex = 0; + panelRed.Paint += panelRed_Paint; + // + // checkBoxDoors + // + checkBoxDoors.AutoSize = true; + checkBoxDoors.Location = new Point(2, 209); + checkBoxDoors.Name = "checkBoxDoors"; + checkBoxDoors.Size = new Size(240, 29); + checkBoxDoors.TabIndex = 8; + checkBoxDoors.Text = " Признак наличия рогов"; + checkBoxDoors.UseVisualStyleBackColor = true; + // + // checkBoxOtsek + // + checkBoxOtsek.AutoSize = true; + checkBoxOtsek.Location = new Point(4, 175); + checkBoxOtsek.Name = "checkBoxOtsek"; + checkBoxOtsek.Size = new Size(312, 29); + checkBoxOtsek.TabIndex = 7; + checkBoxOtsek.Text = "Признак наличия двойной двери"; + checkBoxOtsek.UseVisualStyleBackColor = true; + // + // checkBoxRoga + // + checkBoxRoga.AutoSize = true; + checkBoxRoga.Location = new Point(5, 142); + checkBoxRoga.Name = "checkBoxRoga"; + checkBoxRoga.Size = new Size(243, 29); + checkBoxRoga.TabIndex = 6; + checkBoxRoga.Text = "Признак наличия отсека"; + checkBoxRoga.UseVisualStyleBackColor = true; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(126, 82); + 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(72, 31); + numericUpDownWeight.TabIndex = 5; + numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelWeight + // + labelWeight.AutoSize = true; + labelWeight.Location = new Point(20, 82); + labelWeight.Name = "labelWeight"; + labelWeight.Size = new Size(39, 25); + labelWeight.TabIndex = 4; + labelWeight.Text = "Вес"; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(126, 32); + 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(72, 31); + numericUpDownSpeed.TabIndex = 3; + numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 }); + // + // labelSpeed + // + labelSpeed.AutoSize = true; + labelSpeed.Location = new Point(20, 32); + labelSpeed.Name = "labelSpeed"; + labelSpeed.Size = new Size(89, 25); + labelSpeed.TabIndex = 2; + labelSpeed.Text = "Скорость"; + // + // labelModifiedObject + // + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(494, 203); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(146, 38); + labelModifiedObject.TabIndex = 1; + labelModifiedObject.Text = "Продвинутый"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += labelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(342, 203); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(146, 38); + labelSimpleObject.TabIndex = 0; + labelSimpleObject.Text = "Простой "; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += labelObject_MouseDown; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(35, 61); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(246, 140); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // buttonCancel + // + buttonCancel.Location = new Point(922, 211); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 34); + 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(712, 0); + panelObject.Name = "panelObject"; + panelObject.Size = new Size(322, 204); + panelObject.TabIndex = 4; + panelObject.DragDrop += panelObject_DragDrop; + panelObject.DragEnter += panelObject_DragEnter; + // + // labelAdditionalColor + // + labelAdditionalColor.AllowDrop = true; + labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle; + labelAdditionalColor.Location = new Point(163, 9); + labelAdditionalColor.Name = "labelAdditionalColor"; + labelAdditionalColor.Size = new Size(146, 38); + labelAdditionalColor.TabIndex = 10; + labelAdditionalColor.Text = "Доп. цвет"; + labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter; + labelAdditionalColor.DragDrop += labelAdditionalColor_DragDrop; + labelAdditionalColor.DragEnter += labelAdditionalColor_DragEnter; + // + // labelBodyColor + // + labelBodyColor.AllowDrop = true; + labelBodyColor.BorderStyle = BorderStyle.FixedSingle; + labelBodyColor.Location = new Point(11, 9); + labelBodyColor.Name = "labelBodyColor"; + labelBodyColor.Size = new Size(146, 38); + labelBodyColor.TabIndex = 9; + labelBodyColor.Text = "Цвет"; + labelBodyColor.TextAlign = ContentAlignment.MiddleCenter; + labelBodyColor.DragDrop += labelBodyColor_DragDrop; + labelBodyColor.DragEnter += labelBodyColor_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(723, 211); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(115, 34); + buttonAdd.TabIndex = 6; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // BusConfig + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1067, 263); + Controls.Add(buttonAdd); + Controls.Add(panelObject); + Controls.Add(buttonCancel); + Controls.Add(groupBoxConfig); + Name = "BusConfig"; + 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 labelModifiedObject; + private Label labelSimpleObject; + private Label labelWeight; + private NumericUpDown numericUpDownSpeed; + private Label labelSpeed; + private NumericUpDown numericUpDownWeight; + private CheckBox checkBoxRoga; + private CheckBox checkBoxOtsek; + private CheckBox checkBoxDoors; + 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; + private Button button1; + } +} \ No newline at end of file diff --git a/TrolleybusProject/TrolleybusProject/BusConfig.cs b/TrolleybusProject/TrolleybusProject/BusConfig.cs new file mode 100644 index 0000000..e861f71 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/BusConfig.cs @@ -0,0 +1,153 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TrolleybusProject.Drawnings; +using TrolleybusProject.Entities; + +namespace TrolleybusProject; + +public partial class BusConfig : Form + +{ + private DrawningBus? _bus; + + private event Action? BusDelegate; + public BusConfig() + { + 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; + // TODO buttonCancel.Click привязать анонимный метод через lambda сзакрытием формы + buttonCancel.Click += (sender, e) => Close(); + + } + private void panel_MouseDown(object? sender, MouseEventArgs e) + { + // TODO отправка цвета в Drag&Drop + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor ?? Color.Black, DragDropEffects.Move | DragDropEffects.Copy); + } + + + + + public void AddEvent(Action busDelegate) + { + BusDelegate += busDelegate; + } + + + private void DrawObject() + { + Bitmap bmp = new(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _bus?.SetPictureSize(pictureBoxObject.Width, + pictureBoxObject.Height); + _bus?.SetPosition(15, 15); + _bus?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + + + 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": + _bus = new DrawningBus((int)numericUpDownSpeed.Value, + (double)numericUpDownWeight.Value, Color.White); + break; + case "labelModifiedObject": + _bus = new + DrawningTrolleybus((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, + Color.White, + Color.Black, checkBoxDoors.Checked, checkBoxRoga.Checked, checkBoxOtsek.Checked); + break; + } + labelBodyColor.BackColor = Color.Empty; + labelAdditionalColor.BackColor = Color.Empty; + DrawObject(); + } + + + + + + + + // TODO Реализовать логику смены цветов: основного и дополнительного (для продвинутого объекта) + + private void labelBodyColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = DragDropEffects.None; + } + } + private void labelBodyColor_DragDrop(object sender, DragEventArgs e) + { + if (_bus != null) + { + _bus.EntityBus?.setBodyColor((Color)e.Data.GetData(typeof(Color))); + DrawObject(); + } + } + private void labelAdditionalColor_DragEnter(object sender, DragEventArgs e) + { + e.Effect = e.Data?.GetDataPresent(typeof(Color)) ?? false ? DragDropEffects.Copy : DragDropEffects.None; + } + private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e) + { + if (_bus?.EntityBus is EntityTrolleybus _trolleybus) + { + _trolleybus.setAdditionalColor((Color)e.Data.GetData(typeof(Color))); + } + DrawObject(); + } + + private void panelGreen_Paint(object sender, PaintEventArgs e) + { + + } + + private void panelRed_Paint(object sender, PaintEventArgs e) + { + + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + if (_bus != null) + { + BusDelegate?.Invoke(_bus); + Close(); + } + + } +} diff --git a/TrolleybusProject/TrolleybusProject/BusConfig.resx b/TrolleybusProject/TrolleybusProject/BusConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/BusConfig.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 diff --git a/TrolleybusProject/TrolleybusProject/BusDelegate.cs b/TrolleybusProject/TrolleybusProject/BusDelegate.cs new file mode 100644 index 0000000..55ced39 --- /dev/null +++ b/TrolleybusProject/TrolleybusProject/BusDelegate.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TrolleybusProject.Drawnings; + +namespace TrolleybusProject; + +public delegate void BusDelegate(DrawningBus bus); + diff --git a/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs b/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs index cb6a2a0..84b2ebe 100644 --- a/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs +++ b/TrolleybusProject/TrolleybusProject/Entities/EntityBus.cs @@ -36,8 +36,11 @@ public class EntityBus /// Шаг перемещения троллейбуса /// public double Step => Speed * 100 / Weight; - + public void setBodyColor(Color color) + { + BodyColor = color; + } ///Конструктор сущности /// Скорость diff --git a/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs b/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs index 060e21b..dd3ef67 100644 --- a/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs +++ b/TrolleybusProject/TrolleybusProject/Entities/EntityTrolleybus.cs @@ -10,6 +10,10 @@ namespace TrolleybusProject.Entities; public class EntityTrolleybus: EntityBus { + public void setAdditionalColor(Color color) + { + AdditionalColor = color; + } public Color AdditionalColor { get; private set; } /// diff --git a/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs b/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs index 5648226..75caab5 100644 --- a/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs +++ b/TrolleybusProject/TrolleybusProject/FormBusCollection.Designer.cs @@ -29,14 +29,12 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - panelCompanyTools = new Panel(); buttonCreateCompany = new Button(); + panelCompanyTools = new Panel(); buttonRefresh = new Button(); - comboBoxSelectionCompany = new ComboBox(); buttonGoToCheck = new Button(); buttonAddBus = new Button(); buttonDelTrolleybus = new Button(); - buttonAddTrolleybus = new Button(); maskedTextBox = new MaskedTextBox(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -46,6 +44,7 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); + comboBoxSelectionCompany = new ComboBox(); pictureBox = new PictureBox(); groupBoxTools.SuspendLayout(); panelCompanyTools.SuspendLayout(); @@ -67,20 +66,6 @@ groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // panelCompanyTools - // - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(buttonGoToCheck); - panelCompanyTools.Controls.Add(buttonAddBus); - panelCompanyTools.Controls.Add(buttonDelTrolleybus); - panelCompanyTools.Controls.Add(buttonAddTrolleybus); - panelCompanyTools.Controls.Add(maskedTextBox); - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(0, 397); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(294, 259); - panelCompanyTools.TabIndex = 9; - // // buttonCreateCompany // buttonCreateCompany.Location = new Point(63, 345); @@ -91,6 +76,19 @@ buttonCreateCompany.UseVisualStyleBackColor = true; buttonCreateCompany.Click += buttonCreateCompany_Click; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonAddBus); + panelCompanyTools.Controls.Add(buttonDelTrolleybus); + panelCompanyTools.Controls.Add(maskedTextBox); + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(0, 397); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(294, 259); + panelCompanyTools.TabIndex = 9; + // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -102,18 +100,6 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += buttonRefresh_Click; // - // comboBoxSelectionCompany - // - comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxSelectionCompany.FormattingEnabled = true; - comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectionCompany.Location = new Point(26, 306); - comboBoxSelectionCompany.Name = "comboBoxSelectionCompany"; - comboBoxSelectionCompany.Size = new Size(244, 33); - comboBoxSelectionCompany.TabIndex = 0; - comboBoxSelectionCompany.SelectedIndexChanged += comboBoxSelectionCompany_SelectedIndexChanged; - // // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -147,17 +133,6 @@ buttonDelTrolleybus.UseVisualStyleBackColor = true; buttonDelTrolleybus.Click += buttonDelTrolleybus_Click; // - // buttonAddTrolleybus - // - buttonAddTrolleybus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddTrolleybus.Location = new Point(24, 58); - buttonAddTrolleybus.Name = "buttonAddTrolleybus"; - buttonAddTrolleybus.Size = new Size(246, 34); - buttonAddTrolleybus.TabIndex = 2; - buttonAddTrolleybus.Text = "Добавление троллейбуса"; - buttonAddTrolleybus.UseVisualStyleBackColor = true; - buttonAddTrolleybus.Click += buttonAddTrolleybus_Click; - // // maskedTextBox // maskedTextBox.Location = new Point(68, 98); @@ -248,6 +223,18 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции"; // + // comboBoxSelectionCompany + // + comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectionCompany.FormattingEnabled = true; + comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectionCompany.Location = new Point(26, 306); + comboBoxSelectionCompany.Name = "comboBoxSelectionCompany"; + comboBoxSelectionCompany.Size = new Size(244, 33); + comboBoxSelectionCompany.TabIndex = 0; + comboBoxSelectionCompany.SelectedIndexChanged += comboBoxSelectionCompany_SelectedIndexChanged; + // // pictureBox // pictureBox.Dock = DockStyle.Fill; @@ -279,7 +266,6 @@ private GroupBox groupBoxTools; private ComboBox comboBoxSelectionCompany; - private Button buttonAddTrolleybus; private Button buttonAddBus; private Button buttonDelTrolleybus; private MaskedTextBox maskedTextBox; diff --git a/TrolleybusProject/TrolleybusProject/FormBusCollection.cs b/TrolleybusProject/TrolleybusProject/FormBusCollection.cs index 33ae42e..5e3cea7 100644 --- a/TrolleybusProject/TrolleybusProject/FormBusCollection.cs +++ b/TrolleybusProject/TrolleybusProject/FormBusCollection.cs @@ -29,33 +29,21 @@ public partial class FormBusCollection : Form _storageCollection = new(); } - private ListBox GetListBoxCollection() + + + private void buttonAddBus_Click(object sender, EventArgs e) { - return listBoxCollection; + BusConfig form= new (); + form.Show(); + form.AddEvent(SetBus); } - private void CreateObject(string type) + private void SetBus(DrawningBus bus) { - if (_company == null) + if (_company == null || bus == null) { return; } - Random random = new(); - DrawningBus drawningBus; - switch (type) - { - case nameof(DrawningBus): - drawningBus = new DrawningBus(random.Next(100, 300), - random.Next(1000, 3000), GetColor(random)); - break; - case nameof(DrawningTrolleybus): - drawningBus = new DrawningTrolleybus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), - GetColor(random), Convert.ToBoolean(random.Next(0, 2)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); - break; - default: - return; - } - if (_company + drawningBus != -1) + if (_company + bus != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -66,28 +54,15 @@ public partial class FormBusCollection : Form } } - private void buttonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); - private void comboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e) { panelCompanyTools.Enabled = false; } - private void buttonAddTrolleybus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrolleybus)); - - 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 buttonDelTrolleybus_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) @@ -188,13 +163,13 @@ public partial class FormBusCollection : Form private void buttonCollectionDel_Click(object sender, EventArgs e) { if (listBoxCollection.SelectedItem == null) return; - if (listBoxCollection.SelectedIndex < 0 ) + if (listBoxCollection.SelectedIndex < 0) { MessageBox.Show("Коллекция не выбрана"); return; } - + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; @@ -228,6 +203,7 @@ public partial class FormBusCollection : Form panelCompanyTools.Enabled = true; RerfreshListBoxItems(); } + }