From be244e37364cbc8ad9394099ec6014bd174e9328 Mon Sep 17 00:00:00 2001 From: allllen4a Date: Tue, 7 Nov 2023 13:43:16 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=8F=D1=82=D0=B0=D1=8F=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusesGenericCollection.cs | 15 +- .../projectDoubleDeckerBus/DrawningBus.cs | 5 +- .../DrawningDoubleDeckerBus.cs | 8 + .../projectDoubleDeckerBus/EntityBus.cs | 4 + .../EntityDoubleDeckerBus.cs | 4 + .../FormBusCollection.cs | 165 +++++--- .../FormBusConfig.Designer.cs | 360 ++++++++++++++++++ .../projectDoubleDeckerBus/FormBusConfig.cs | 135 +++++++ .../projectDoubleDeckerBus/FormBusConfig.resx | 120 ++++++ .../projectDoubleDeckerBus/SetGeneric.cs | 36 +- 10 files changed, 774 insertions(+), 78 deletions(-) create mode 100644 projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.Designer.cs create mode 100644 projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.cs create mode 100644 projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.resx diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/BusesGenericCollection.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/BusesGenericCollection.cs index 6908865..36183a7 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/BusesGenericCollection.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/BusesGenericCollection.cs @@ -54,17 +54,18 @@ namespace projectDoubleDeckerBus /// /// //преобразовали bool в int - public static bool operator +(BusesGenericCollection collect, T? - obj) + public static int operator +(BusesGenericCollection collect, T obj) { if (obj == null) { - return false; + return -1; } - return (bool)collect?._collection.Insert(obj); + + return collect?._collection.Insert(obj) ?? -1; } - public static T? operator -(BusesGenericCollection collect, int - pos) + + /// Перегрузка оператора вычитания + public static T? operator -(BusesGenericCollection collect, int pos) { T? obj = collect._collection[pos]; if (obj != null) @@ -73,6 +74,8 @@ namespace projectDoubleDeckerBus } return obj; } + + // получение объекта imoveableObj public U? GetU(int pos) { return (U?)_collection[pos]?.GetMoveableObject; diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningBus.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningBus.cs index 85e5fa4..534fe64 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningBus.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningBus.cs @@ -296,6 +296,9 @@ namespace projectDoubleDeckerBus.Drawings g.FillEllipse(brBlue, _startPosX + 145, _startPosY + 50, windowSize, windowSize); } - + public void setColor(Color color) + { + EntityBus.setColor(color); + } } } diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningDoubleDeckerBus.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningDoubleDeckerBus.cs index 98f7fb3..fcc83f9 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningDoubleDeckerBus.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/DrawningDoubleDeckerBus.cs @@ -79,5 +79,13 @@ namespace projectDoubleDeckerBus.Drawings } base.DrawTransport(g); } + public void setAddColor(Color color) + { + if (EntityBus is EntityDoubleDeckerBus doubledeckerbus) + { + doubledeckerbus.setAddColor(color); + } + + } } } diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityBus.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityBus.cs index 2a955e4..70b8ce2 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityBus.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityBus.cs @@ -38,5 +38,9 @@ namespace projectDoubleDeckerBus.Entity Weight = weight; BodyColor = bodyColor; } + public void setColor(Color color) + { + BodyColor = color; + } } } diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityDoubleDeckerBus.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityDoubleDeckerBus.cs index f4712e7..6e0137b 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityDoubleDeckerBus.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/EntityDoubleDeckerBus.cs @@ -42,5 +42,9 @@ namespace projectDoubleDeckerBus.Entity Floor = floor; Tailpipe = tailpipe; } + public void setAddColor(Color color) + { + AdditionalColor = color; + } } } \ No newline at end of file diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusCollection.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusCollection.cs index d90c6e9..a7c69d0 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusCollection.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusCollection.cs @@ -16,7 +16,13 @@ namespace projectDoubleDeckerBus { public partial class FormBusCollection : Form { + /// + /// Набор объектов + /// private readonly BusesGenericStorage _storage; + /// + /// Конструктор + /// public FormBusCollection() { InitializeComponent(); @@ -24,6 +30,9 @@ namespace projectDoubleDeckerBus listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged; ReloadObjects(); } + /// + /// Заполнение listBoxObjects + /// private void ReloadObjects() { int index = listBoxStorages.SelectedIndex; @@ -32,105 +41,86 @@ namespace projectDoubleDeckerBus { listBoxStorages.Items.Add(_storage.Keys[i]); } - if (listBoxStorages.Items.Count > 0 && (index == -1 || index - >= listBoxStorages.Items.Count)) + 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) + else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count) { listBoxStorages.SelectedIndex = index; } } - 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) + private void AddBus(DrawningBus bus) { if (listBoxStorages.SelectedIndex == -1) { return; } - if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, - MessageBoxIcon.Question) == DialogResult.Yes) - { - _storage.DelSet(listBoxStorages.SelectedItem.ToString() - ?? string.Empty); - ReloadObjects(); - } - } - private void buttonUpdateCollection_Click(object sender, EventArgs e) - { - if (listBoxStorages.SelectedIndex == -1) - { - return; - } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - DrawBus.Image = obj.ShowBuses(); - } - private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) - { - DrawBus.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBuses(); + if ((obj + bus) != -1) + { + MessageBox.Show("Объект добавлен"); + DrawBus.Image = obj.ShowBuses(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } } + /// + /// Добавление объекта в набор + /// + /// + /// private void ButtonAddBus_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (obj == null) { return; } - FormDoubleDeckerBus form = new(); - if (form.ShowDialog() == DialogResult.OK) - { - if (obj + form.SelectedBus) - { - MessageBox.Show("Объект добавлен"); - DrawBus.Image = obj.ShowBuses(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - + FormBusConfig form = new FormBusConfig(); + form.Show(); + form.AddEvent(AddBus); } + /// + /// Удаление объекта из набора + /// + /// + /// private void ButtonRemoveBus_Click(object sender, EventArgs e) { if (listBoxStorages.SelectedIndex == -1) { return; } - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? - string.Empty]; - if (obj == null) - { - return; - } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } + foreach (var it in maskedTextBoxNumber.Text) + if (it < '0' || it > '9') + { + MessageBox.Show("Не удалось удалить объект"); + return; + } + if (maskedTextBoxNumber.Text.Length == 0) + { + MessageBox.Show("Не удалось удалить объект"); + return; + } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); if (obj - pos != null) { @@ -141,6 +131,65 @@ namespace projectDoubleDeckerBus { MessageBox.Show("Не удалось удалить объект"); } + } + /// + /// Обновление рисунка по набору + /// + /// + /// + private void buttonUpdateCollection_Click(object sender, EventArgs e) + { + if (listBoxStorages.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; + DrawBus.Image = obj.ShowBuses(); + } + + /// + /// Добавление набора в коллекцию + /// + /// + /// + 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 listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) + { + DrawBus.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBuses(); + } + + /// + /// Удаление набора + /// + /// + /// + 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(); + } } } diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.Designer.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.Designer.cs new file mode 100644 index 0000000..ca073c8 --- /dev/null +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.Designer.cs @@ -0,0 +1,360 @@ +namespace projectDoubleDeckerBus +{ + partial class FormBusConfig + { + /// + /// 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() + { + groupBoxParametrs = new GroupBox(); + labelModifiedObject = new Label(); + labelSimpleObject = new Label(); + numericUpDownWeight = new NumericUpDown(); + groupBoxColors = new GroupBox(); + panelWhite = new Panel(); + panelGray = new Panel(); + panelBlack = new Panel(); + panelPurple = new Panel(); + panelYellow = new Panel(); + panelBlue = new Panel(); + panelGreen = new Panel(); + panelRed = new Panel(); + numericUpDownSpeed = new NumericUpDown(); + checkBoxTailpipe = new CheckBox(); + checkBoxFloor = new CheckBox(); + label2 = new Label(); + label1 = new Label(); + pictureBoxObject = new PictureBox(); + LabelColor = new Label(); + labelAddColor = new Label(); + buttonCancel = new Button(); + PanelObject = new Panel(); + buttonAdd = new Button(); + groupBoxParametrs.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); + groupBoxColors.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).BeginInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).BeginInit(); + PanelObject.SuspendLayout(); + SuspendLayout(); + // + // groupBoxParametrs + // + groupBoxParametrs.Controls.Add(labelModifiedObject); + groupBoxParametrs.Controls.Add(labelSimpleObject); + groupBoxParametrs.Controls.Add(numericUpDownWeight); + groupBoxParametrs.Controls.Add(groupBoxColors); + groupBoxParametrs.Controls.Add(numericUpDownSpeed); + groupBoxParametrs.Controls.Add(checkBoxTailpipe); + groupBoxParametrs.Controls.Add(checkBoxFloor); + groupBoxParametrs.Controls.Add(label2); + groupBoxParametrs.Controls.Add(label1); + groupBoxParametrs.Location = new Point(12, 12); + groupBoxParametrs.Name = "groupBoxParametrs"; + groupBoxParametrs.Size = new Size(411, 250); + groupBoxParametrs.TabIndex = 0; + groupBoxParametrs.TabStop = false; + groupBoxParametrs.Text = "Parametrs"; + // + // labelModifiedObject + // + labelModifiedObject.AllowDrop = true; + labelModifiedObject.BorderStyle = BorderStyle.FixedSingle; + labelModifiedObject.Location = new Point(312, 202); + labelModifiedObject.Name = "labelModifiedObject"; + labelModifiedObject.Size = new Size(81, 32); + labelModifiedObject.TabIndex = 6; + labelModifiedObject.Text = "Modified"; + labelModifiedObject.TextAlign = ContentAlignment.MiddleCenter; + labelModifiedObject.MouseDown += LabelObject_MouseDown; + // + // labelSimpleObject + // + labelSimpleObject.AllowDrop = true; + labelSimpleObject.BorderStyle = BorderStyle.FixedSingle; + labelSimpleObject.Location = new Point(174, 202); + labelSimpleObject.Name = "labelSimpleObject"; + labelSimpleObject.Size = new Size(81, 32); + labelSimpleObject.TabIndex = 5; + labelSimpleObject.Text = "Simple"; + labelSimpleObject.TextAlign = ContentAlignment.MiddleCenter; + labelSimpleObject.MouseDown += LabelObject_MouseDown; + // + // numericUpDownWeight + // + numericUpDownWeight.Location = new Point(50, 72); + numericUpDownWeight.Name = "numericUpDownWeight"; + numericUpDownWeight.Size = new Size(98, 23); + numericUpDownWeight.TabIndex = 2; + // + // groupBoxColors + // + groupBoxColors.Controls.Add(panelWhite); + groupBoxColors.Controls.Add(panelGray); + groupBoxColors.Controls.Add(panelBlack); + groupBoxColors.Controls.Add(panelPurple); + groupBoxColors.Controls.Add(panelYellow); + groupBoxColors.Controls.Add(panelBlue); + groupBoxColors.Controls.Add(panelGreen); + groupBoxColors.Controls.Add(panelRed); + groupBoxColors.Location = new Point(174, 22); + groupBoxColors.Name = "groupBoxColors"; + groupBoxColors.Size = new Size(219, 159); + groupBoxColors.TabIndex = 4; + groupBoxColors.TabStop = false; + groupBoxColors.Text = "Colors"; + // + // panelWhite + // + panelWhite.BackColor = Color.White; + panelWhite.Location = new Point(6, 87); + panelWhite.Name = "panelWhite"; + panelWhite.Size = new Size(33, 30); + panelWhite.TabIndex = 7; + panelWhite.MouseDown += PanelColor_MouseDown; + // + // panelGray + // + panelGray.BackColor = Color.Silver; + panelGray.Location = new Point(54, 87); + panelGray.Name = "panelGray"; + panelGray.Size = new Size(33, 30); + panelGray.TabIndex = 6; + panelGray.MouseDown += PanelColor_MouseDown; + // + // panelBlack + // + panelBlack.BackColor = Color.Black; + panelBlack.Location = new Point(103, 87); + panelBlack.Name = "panelBlack"; + panelBlack.Size = new Size(33, 30); + panelBlack.TabIndex = 5; + panelBlack.MouseDown += PanelColor_MouseDown; + // + // panelPurple + // + panelPurple.BackColor = Color.Purple; + panelPurple.Location = new Point(162, 87); + panelPurple.Name = "panelPurple"; + panelPurple.Size = new Size(33, 30); + panelPurple.TabIndex = 4; + panelPurple.MouseDown += PanelColor_MouseDown; + // + // panelYellow + // + panelYellow.BackColor = Color.Yellow; + panelYellow.Location = new Point(159, 22); + panelYellow.Name = "panelYellow"; + panelYellow.Size = new Size(33, 30); + panelYellow.TabIndex = 3; + panelYellow.MouseDown += PanelColor_MouseDown; + // + // panelBlue + // + panelBlue.BackColor = Color.Blue; + panelBlue.Location = new Point(103, 22); + panelBlue.Name = "panelBlue"; + panelBlue.Size = new Size(33, 30); + panelBlue.TabIndex = 2; + panelBlue.MouseDown += PanelColor_MouseDown; + // + // panelGreen + // + panelGreen.BackColor = Color.Lime; + panelGreen.Location = new Point(54, 22); + panelGreen.Name = "panelGreen"; + panelGreen.Size = new Size(33, 30); + panelGreen.TabIndex = 1; + panelGreen.MouseDown += PanelColor_MouseDown; + // + // panelRed + // + panelRed.BackColor = Color.Red; + panelRed.Location = new Point(6, 22); + panelRed.Name = "panelRed"; + panelRed.Size = new Size(33, 30); + panelRed.TabIndex = 0; + panelRed.MouseDown += PanelColor_MouseDown; + // + // numericUpDownSpeed + // + numericUpDownSpeed.Location = new Point(50, 28); + numericUpDownSpeed.Name = "numericUpDownSpeed"; + numericUpDownSpeed.Size = new Size(98, 23); + numericUpDownSpeed.TabIndex = 1; + // + // checkBoxTailpipe + // + checkBoxTailpipe.AutoSize = true; + checkBoxTailpipe.Location = new Point(6, 162); + checkBoxTailpipe.Name = "checkBoxTailpipe"; + checkBoxTailpipe.Size = new Size(66, 19); + checkBoxTailpipe.TabIndex = 3; + checkBoxTailpipe.Text = "Tailpipe"; + checkBoxTailpipe.UseVisualStyleBackColor = true; + // + // checkBoxFloor + // + checkBoxFloor.AutoSize = true; + checkBoxFloor.Location = new Point(6, 120); + checkBoxFloor.Name = "checkBoxFloor"; + checkBoxFloor.Size = new Size(53, 19); + checkBoxFloor.TabIndex = 2; + checkBoxFloor.Text = "Floor"; + checkBoxFloor.UseVisualStyleBackColor = true; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(6, 74); + label2.Name = "label2"; + label2.Size = new Size(45, 15); + label2.TabIndex = 1; + label2.Text = "Weight"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(6, 30); + label1.Name = "label1"; + label1.Size = new Size(39, 15); + label1.TabIndex = 0; + label1.Text = "Speed"; + // + // pictureBoxObject + // + pictureBoxObject.Location = new Point(3, 29); + pictureBoxObject.Name = "pictureBoxObject"; + pictureBoxObject.Size = new Size(340, 212); + pictureBoxObject.TabIndex = 1; + pictureBoxObject.TabStop = false; + // + // LabelColor + // + LabelColor.AllowDrop = true; + LabelColor.BorderStyle = BorderStyle.FixedSingle; + LabelColor.Location = new Point(23, 4); + LabelColor.Name = "LabelColor"; + LabelColor.Size = new Size(76, 22); + LabelColor.TabIndex = 2; + LabelColor.Text = "ColorBase"; + LabelColor.TextAlign = ContentAlignment.MiddleCenter; + LabelColor.DragDrop += LabelColor_DragDrop; + LabelColor.DragEnter += LabelColor_DragEnter; + // + // labelAddColor + // + labelAddColor.AllowDrop = true; + labelAddColor.BorderStyle = BorderStyle.FixedSingle; + labelAddColor.Location = new Point(241, 4); + labelAddColor.Name = "labelAddColor"; + labelAddColor.Size = new Size(76, 22); + labelAddColor.TabIndex = 3; + labelAddColor.Text = "AddColor"; + labelAddColor.TextAlign = ContentAlignment.MiddleCenter; + labelAddColor.DragDrop += LabelAddColor_DragDrop; + labelAddColor.DragEnter += LabelColor_DragEnter; + // + // buttonCancel + // + buttonCancel.Location = new Point(659, 268); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(123, 39); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "cancel"; + buttonCancel.UseVisualStyleBackColor = true; + // + // PanelObject + // + PanelObject.AllowDrop = true; + PanelObject.Controls.Add(LabelColor); + PanelObject.Controls.Add(labelAddColor); + PanelObject.Controls.Add(pictureBoxObject); + PanelObject.Location = new Point(434, 18); + PanelObject.Name = "PanelObject"; + PanelObject.Size = new Size(348, 244); + PanelObject.TabIndex = 6; + PanelObject.DragDrop += PanelObject_DragDrop; + PanelObject.DragEnter += PanelObject_DragEnter; + // + // buttonAdd + // + buttonAdd.Location = new Point(434, 268); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(123, 39); + buttonAdd.TabIndex = 7; + buttonAdd.Text = "add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormBusConfig + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(789, 323); + Controls.Add(buttonAdd); + Controls.Add(buttonCancel); + Controls.Add(groupBoxParametrs); + Controls.Add(PanelObject); + Name = "FormBusConfig"; + Text = "FormBusConfig"; + groupBoxParametrs.ResumeLayout(false); + groupBoxParametrs.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit(); + groupBoxColors.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)numericUpDownSpeed).EndInit(); + ((System.ComponentModel.ISupportInitialize)pictureBoxObject).EndInit(); + PanelObject.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxParametrs; + private GroupBox groupBoxColors; + private CheckBox checkBoxTailpipe; + private CheckBox checkBoxFloor; + private Label label2; + private Label label1; + private NumericUpDown numericUpDownSpeed; + private NumericUpDown numericUpDownWeight; + private Panel panelWhite; + private Panel panelGray; + private Panel panelBlack; + private Panel panelPurple; + private Panel panelYellow; + private Panel panelBlue; + private Panel panelGreen; + private Panel panelRed; + private PictureBox pictureBoxObject; + private Label labelModifiedObject; + private Label labelSimpleObject; + private Label LabelColor; + private Label labelAddColor; + private Button buttonCancel; + private Panel PanelObject; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.cs new file mode 100644 index 0000000..afbd460 --- /dev/null +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.cs @@ -0,0 +1,135 @@ +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 projectDoubleDeckerBus.Entity; +using projectDoubleDeckerBus.Drawings; +using projectDouble_Decker_Bus.MovementStrategy; + +namespace projectDoubleDeckerBus +{ + public partial class FormBusConfig : Form + { + DrawningBus? _bus = null; + private event Action EventAddBus; + public FormBusConfig() + { + InitializeComponent(); + panelBlack.MouseDown += PanelColor_MouseDown; + panelPurple.MouseDown += PanelColor_MouseDown; + panelGray.MouseDown += PanelColor_MouseDown; + panelBlue.MouseDown += PanelColor_MouseDown; + panelWhite.MouseDown += PanelColor_MouseDown; + panelYellow.MouseDown += PanelColor_MouseDown; + panelGreen.MouseDown += PanelColor_MouseDown; + panelRed.MouseDown += PanelColor_MouseDown; + buttonCancel.Click += (s, e) => Close(); + } + private void DrawCar() + { + Bitmap bmp = new Bitmap(pictureBoxObject.Width, pictureBoxObject.Height); + Graphics gr = Graphics.FromImage(bmp); + _bus?.SetPosition(5, 5); + if (_bus is DrawningBus) + (_bus as DrawningBus).DrawTransport(gr); + else + _bus?.DrawTransport(gr); + pictureBoxObject.Image = bmp; + } + private void PanelColor_MouseDown(object sender, MouseEventArgs e) + { + (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, + DragDropEffects.Move | DragDropEffects.Copy); + } + private void LabelColor_DragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(typeof(Color))) + e.Effect = DragDropEffects.Copy; + else + { + e.Effect = DragDropEffects.None; + } + } + private void LabelColor_DragDrop(object sender, DragEventArgs e) + { + + if (_bus is DrawningBus bus) + { + LabelColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + _bus.setColor((Color)e.Data.GetData(typeof(Color))); + } + DrawCar(); + } + private void LabelAddColor_DragDrop(object sender, DragEventArgs e) + { + if (_bus is DrawningDoubleDeckerBus bus) + { + labelAddColor.BackColor = (Color)e.Data.GetData(typeof(Color)); + bus.setAddColor((Color)e.Data.GetData(typeof(Color))); + } + DrawCar(); + } + private void LabelObject_MouseDown(object sender, MouseEventArgs e) + { + (sender as Label)?.DoDragDrop((sender as Label)?.Name, + DragDropEffects.Move | DragDropEffects.Copy); + + } + private void PanelObject_DragEnter(object sender, DragEventArgs e) + { + if (e.Data?.GetDataPresent(DataFormats.Text) ?? false) + { + e.Effect = DragDropEffects.Copy; + } + else + { + e.Effect = 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, + (int)numericUpDownWeight.Value, Color.White, 900, + 500); + LabelColor.BackColor = Color.White; + labelAddColor.BackColor = Color.Transparent; + break; + case "labelModifiedObject": + _bus = new DrawningDoubleDeckerBus((int)numericUpDownSpeed.Value, + (int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxFloor.Checked, + checkBoxTailpipe.Checked, 900, + 500); + LabelColor.BackColor = Color.White; + labelAddColor.BackColor = Color.Black; + break; + } + + DrawCar(); + } + public void AddEvent(Action ev) + { + if (EventAddBus == null) + { + EventAddBus = ev; + } + else + { + EventAddBus += ev; + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + EventAddBus?.Invoke(_bus); + Close(); + } + } +} diff --git a/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.resx b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/FormBusConfig.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/projectDoubleDeckerBus/projectDoubleDeckerBus/SetGeneric.cs b/projectDoubleDeckerBus/projectDoubleDeckerBus/SetGeneric.cs index 216c35b..a3b1468 100644 --- a/projectDoubleDeckerBus/projectDoubleDeckerBus/SetGeneric.cs +++ b/projectDoubleDeckerBus/projectDoubleDeckerBus/SetGeneric.cs @@ -35,42 +35,52 @@ namespace projectDoubleDeckerBus.Generics /// /// Добавляемый автобус /// - public bool Insert(T bus) + public int Insert(T bus) { - return Insert(bus, 0); + if (_places.Count >= _maxCount) + return -1; + _places.Insert(0, bus); + return 0; } public bool Insert(T bus, int position) { - if (position < 0 || position >= _maxCount) + if (_places.Count >= _maxCount) return false; - if (Count >= _maxCount) + if (position < 0 || position > _places.Count) return false; - _places.Insert(0, bus); + + if (position == _places.Count) + _places.Add(bus); + else + _places.Insert(position, bus); + return true; } public bool Remove(int position) { - if (position < 0 || position > _maxCount) - return false; - if (position >= Count) + if (position < 0 || position >= _places.Count) return false; _places.RemoveAt(position); return true; } - public T? this[int position] + public T Get(int position) + { + if (position < 0 || position >= _places.Count) + return null; + return _places[position]; + } + public T this[int position] { get { - if (position < 0 || position > _maxCount) + if (position < 0 || position >= _places.Count) return null; return _places[position]; } set { - if (position < 0 || position > _maxCount) - return; - _places[position] = value; + Insert(value, position); } } public IEnumerable GetBuses(int? maxBuses = null)