diff --git a/DoubleDeckerBus/DoubleDeckerBus.csproj b/DoubleDeckerBus/DoubleDeckerBus.csproj index 13ee123..3b9e809 100644 --- a/DoubleDeckerBus/DoubleDeckerBus.csproj +++ b/DoubleDeckerBus/DoubleDeckerBus.csproj @@ -8,6 +8,18 @@ enable + + + + + + + + + + + + True @@ -23,4 +35,6 @@ + + \ No newline at end of file diff --git a/DoubleDeckerBus/Drawing/DrawingBus.cs b/DoubleDeckerBus/Drawing/DrawingBus.cs index e70186f..1d1d530 100644 --- a/DoubleDeckerBus/Drawing/DrawingBus.cs +++ b/DoubleDeckerBus/Drawing/DrawingBus.cs @@ -90,7 +90,6 @@ namespace DoubleDeckerbus.Drawing } public virtual void DrawTransport(Graphics g) { - // Pen pen = new(Color.Black); @@ -101,6 +100,7 @@ namespace DoubleDeckerbus.Drawing g.FillRectangle(additionalBrush, _startPosX + 147, _startPosY + 71, 30, 27); g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 52, 137, 46); + Brush brBlue = new SolidBrush(Color.LightBlue); g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 55, 15, 15); @@ -122,7 +122,6 @@ namespace DoubleDeckerbus.Drawing g.FillEllipse(gr, _startPosX + 25, _startPosY + 90, 21, 21); g.FillEllipse(gr, _startPosX + 125, _startPosY + 90, 21, 21); } - public bool CanMove(DirectionType direction) { if (EntityBus == null) diff --git a/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs b/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs index 2513eba..4022bcf 100644 --- a/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs +++ b/DoubleDeckerBus/Drawing/DrawingDoubleDeckerbus.cs @@ -16,7 +16,6 @@ namespace DoubleDeckerbus.Drawing { EntityBus = new EntityDoubleDeckerbus(speed, weight, bodyColor, additionalColor, secondfloor, stairs); } - } public override void DrawTransport(Graphics g) { @@ -24,7 +23,7 @@ namespace DoubleDeckerbus.Drawing { return; } - Pen pen = new(Color.Black); + Pen pen = new(Color.Black); Pen additionalPen = new(doubleDeckerBus.AddColor); Brush additionalBrush = new SolidBrush(doubleDeckerBus.AddColor); base.DrawTransport(g); @@ -45,7 +44,6 @@ namespace DoubleDeckerbus.Drawing g.FillRectangle(brBlue, _startPosX + 123, _startPosY + 15, 15, 15); g.FillRectangle(brBlue, _startPosX + 150, _startPosY + 15, 15, 15); } - if (doubleDeckerBus.IsStairs) { g.DrawLine(pen, _startPosX + 10, _startPosY + 55, _startPosX + 34, _startPosY + 55); diff --git a/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs b/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs index e0ee0c7..a30d045 100644 --- a/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs +++ b/DoubleDeckerBus/Drawing/ExtentionDrawingBus.cs @@ -29,7 +29,6 @@ namespace DoubleDeckerbus.Drawing } return null; } - public static string GetDataForSave(this DrawingBus DrawingBus, char separatorForObject) { var truck = DrawingBus.EntityBus; diff --git a/DoubleDeckerBus/Entities/DirectionType.cs b/DoubleDeckerBus/Entities/DirectionType.cs index ae174c9..e635c45 100644 --- a/DoubleDeckerBus/Entities/DirectionType.cs +++ b/DoubleDeckerBus/Entities/DirectionType.cs @@ -12,6 +12,5 @@ namespace DoubleDeckerbus.Entities Down = 2, Left = 3, Right = 4 - } } \ No newline at end of file diff --git a/DoubleDeckerBus/Entities/EntityBus.cs b/DoubleDeckerBus/Entities/EntityBus.cs index bcb71c4..977fd31 100644 --- a/DoubleDeckerBus/Entities/EntityBus.cs +++ b/DoubleDeckerBus/Entities/EntityBus.cs @@ -18,7 +18,6 @@ namespace DoubleDeckerbus.Entities Weight = weight; BodyColor = bodyColor; } - public void ChangeBodyColor(Color color) { BodyColor = color; diff --git a/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs b/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs index 76b2e96..c36669c 100644 --- a/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs +++ b/DoubleDeckerBus/Entities/EntityDoubleDeckerbus.cs @@ -19,7 +19,6 @@ namespace DoubleDeckerbus.Entities IsSecondFloor = secondfloor; IsStairs = stairs; } - public void ChangeAdditionalColor(Color additionalColor) { AddColor = additionalColor; diff --git a/DoubleDeckerBus/Exceptions/BusNotFoundException.cs b/DoubleDeckerBus/Exceptions/BusNotFoundException.cs new file mode 100644 index 0000000..3aeddd4 --- /dev/null +++ b/DoubleDeckerBus/Exceptions/BusNotFoundException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + +namespace DoubleDeckerbus.Exceptions +{ + [Serializable] + internal class BusNotFoundException : ApplicationException + { + public BusNotFoundException(int i) : base($"Не найден объект по позиции {i}") { } + public BusNotFoundException() : base() { } + public BusNotFoundException(string message) : base(message) { } + public BusNotFoundException(string message, Exception exception) : base(message, exception) { } + protected BusNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { } + } +} diff --git a/DoubleDeckerBus/Exceptions/StorageOverflowException.cs b/DoubleDeckerBus/Exceptions/StorageOverflowException.cs new file mode 100644 index 0000000..324c31b --- /dev/null +++ b/DoubleDeckerBus/Exceptions/StorageOverflowException.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + +namespace DoubleDeckerbus.Exceptions +{ + [Serializable] + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: {count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException (string message) : base(message) { } + public StorageOverflowException (string message, Exception exception) : base(message, exception) { } + protected StorageOverflowException(SerializationInfo info, StreamingContext context) : base(info, context) { } + } +} diff --git a/DoubleDeckerBus/FormBusConfig.Designer.cs b/DoubleDeckerBus/FormBusConfig.Designer.cs index a3df69e..6b07eab 100644 --- a/DoubleDeckerBus/FormBusConfig.Designer.cs +++ b/DoubleDeckerBus/FormBusConfig.Designer.cs @@ -71,11 +71,9 @@ this.groupBoxConfig.Controls.Add(this.numericUpDownWeight); this.groupBoxConfig.Controls.Add(this.labelWeight); this.groupBoxConfig.Controls.Add(this.labelSpeed); - this.groupBoxConfig.Location = new System.Drawing.Point(12, 36); - this.groupBoxConfig.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxConfig.Location = new System.Drawing.Point(14, 48); this.groupBoxConfig.Name = "groupBoxConfig"; - this.groupBoxConfig.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.groupBoxConfig.Size = new System.Drawing.Size(499, 188); + this.groupBoxConfig.Size = new System.Drawing.Size(570, 251); this.groupBoxConfig.TabIndex = 0; this.groupBoxConfig.TabStop = false; this.groupBoxConfig.Text = "Параметры"; @@ -83,9 +81,9 @@ // labelAdvancedObject // this.labelAdvancedObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelAdvancedObject.Location = new System.Drawing.Point(385, 141); + this.labelAdvancedObject.Location = new System.Drawing.Point(440, 188); this.labelAdvancedObject.Name = "labelAdvancedObject"; - this.labelAdvancedObject.Size = new System.Drawing.Size(105, 23); + this.labelAdvancedObject.Size = new System.Drawing.Size(120, 30); this.labelAdvancedObject.TabIndex = 8; this.labelAdvancedObject.Text = "Продвинутый"; this.labelAdvancedObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -94,9 +92,9 @@ // labelSimpleObject // this.labelSimpleObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelSimpleObject.Location = new System.Drawing.Point(248, 141); + this.labelSimpleObject.Location = new System.Drawing.Point(283, 188); this.labelSimpleObject.Name = "labelSimpleObject"; - this.labelSimpleObject.Size = new System.Drawing.Size(105, 23); + this.labelSimpleObject.Size = new System.Drawing.Size(120, 30); this.labelSimpleObject.TabIndex = 7; this.labelSimpleObject.Text = "Простой"; this.labelSimpleObject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -112,11 +110,9 @@ this.groupBoxColor.Controls.Add(this.panelYellow); this.groupBoxColor.Controls.Add(this.panelRoyalBlue); this.groupBoxColor.Controls.Add(this.panelFirebrick); - this.groupBoxColor.Location = new System.Drawing.Point(248, 24); - this.groupBoxColor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.groupBoxColor.Location = new System.Drawing.Point(283, 32); this.groupBoxColor.Name = "groupBoxColor"; - this.groupBoxColor.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2); - this.groupBoxColor.Size = new System.Drawing.Size(242, 109); + this.groupBoxColor.Size = new System.Drawing.Size(277, 145); this.groupBoxColor.TabIndex = 6; this.groupBoxColor.TabStop = false; this.groupBoxColor.Text = "Цвета"; @@ -124,82 +120,73 @@ // panelBlue // this.panelBlue.BackColor = System.Drawing.Color.Blue; - this.panelBlue.Location = new System.Drawing.Point(4, 64); - this.panelBlue.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelBlue.Location = new System.Drawing.Point(5, 85); this.panelBlue.Name = "panelBlue"; - this.panelBlue.Size = new System.Drawing.Size(44, 30); + this.panelBlue.Size = new System.Drawing.Size(50, 40); this.panelBlue.TabIndex = 0; // // panelBlack // this.panelBlack.BackColor = System.Drawing.Color.Black; - this.panelBlack.Location = new System.Drawing.Point(66, 64); - this.panelBlack.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelBlack.Location = new System.Drawing.Point(75, 85); this.panelBlack.Name = "panelBlack"; - this.panelBlack.Size = new System.Drawing.Size(44, 30); + this.panelBlack.Size = new System.Drawing.Size(50, 40); this.panelBlack.TabIndex = 0; // // panelPink // this.panelPink.BackColor = System.Drawing.Color.DeepPink; - this.panelPink.Location = new System.Drawing.Point(127, 64); - this.panelPink.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelPink.Location = new System.Drawing.Point(145, 85); this.panelPink.Name = "panelPink"; - this.panelPink.Size = new System.Drawing.Size(44, 30); + this.panelPink.Size = new System.Drawing.Size(50, 40); this.panelPink.TabIndex = 0; // // panelGray // this.panelGray.BackColor = System.Drawing.Color.Gray; - this.panelGray.Location = new System.Drawing.Point(188, 64); - this.panelGray.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelGray.Location = new System.Drawing.Point(215, 85); this.panelGray.Name = "panelGray"; - this.panelGray.Size = new System.Drawing.Size(44, 30); + this.panelGray.Size = new System.Drawing.Size(50, 40); this.panelGray.TabIndex = 0; // // panelGreen // - this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); - this.panelGreen.Location = new System.Drawing.Point(188, 19); - this.panelGreen.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelGreen.BackColor = System.Drawing.Color.Green; + this.panelGreen.Location = new System.Drawing.Point(215, 25); this.panelGreen.Name = "panelGreen"; - this.panelGreen.Size = new System.Drawing.Size(44, 30); + this.panelGreen.Size = new System.Drawing.Size(50, 40); this.panelGreen.TabIndex = 0; // // panelYellow // this.panelYellow.BackColor = System.Drawing.Color.Yellow; - this.panelYellow.Location = new System.Drawing.Point(127, 19); - this.panelYellow.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelYellow.Location = new System.Drawing.Point(145, 25); this.panelYellow.Name = "panelYellow"; - this.panelYellow.Size = new System.Drawing.Size(44, 30); + this.panelYellow.Size = new System.Drawing.Size(50, 40); this.panelYellow.TabIndex = 0; // // panelRoyalBlue // this.panelRoyalBlue.BackColor = System.Drawing.Color.RoyalBlue; - this.panelRoyalBlue.Location = new System.Drawing.Point(66, 19); - this.panelRoyalBlue.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelRoyalBlue.Location = new System.Drawing.Point(75, 25); this.panelRoyalBlue.Name = "panelRoyalBlue"; - this.panelRoyalBlue.Size = new System.Drawing.Size(44, 30); + this.panelRoyalBlue.Size = new System.Drawing.Size(50, 40); this.panelRoyalBlue.TabIndex = 0; // // panelFirebrick // this.panelFirebrick.BackColor = System.Drawing.Color.Firebrick; - this.panelFirebrick.Location = new System.Drawing.Point(4, 19); - this.panelFirebrick.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelFirebrick.Location = new System.Drawing.Point(5, 25); this.panelFirebrick.Name = "panelFirebrick"; - this.panelFirebrick.Size = new System.Drawing.Size(44, 30); + this.panelFirebrick.Size = new System.Drawing.Size(50, 40); this.panelFirebrick.TabIndex = 0; // // checkBoxLadder // this.checkBoxLadder.AutoSize = true; - this.checkBoxLadder.Location = new System.Drawing.Point(11, 112); - this.checkBoxLadder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.checkBoxLadder.Location = new System.Drawing.Point(13, 149); this.checkBoxLadder.Name = "checkBoxLadder"; - this.checkBoxLadder.Size = new System.Drawing.Size(129, 19); + this.checkBoxLadder.Size = new System.Drawing.Size(160, 24); this.checkBoxLadder.TabIndex = 5; this.checkBoxLadder.Text = "Наличие лестница"; this.checkBoxLadder.UseVisualStyleBackColor = true; @@ -207,18 +194,16 @@ // checkBoxSecondFloor // this.checkBoxSecondFloor.AutoSize = true; - this.checkBoxSecondFloor.Location = new System.Drawing.Point(11, 89); - this.checkBoxSecondFloor.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.checkBoxSecondFloor.Location = new System.Drawing.Point(13, 119); this.checkBoxSecondFloor.Name = "checkBoxSecondFloor"; - this.checkBoxSecondFloor.Size = new System.Drawing.Size(157, 19); + this.checkBoxSecondFloor.Size = new System.Drawing.Size(196, 24); this.checkBoxSecondFloor.TabIndex = 4; this.checkBoxSecondFloor.Text = "Наличие второго этажа"; this.checkBoxSecondFloor.UseVisualStyleBackColor = true; // // numericUpDownSpeed // - this.numericUpDownSpeed.Location = new System.Drawing.Point(82, 24); - this.numericUpDownSpeed.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.numericUpDownSpeed.Location = new System.Drawing.Point(94, 32); this.numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, @@ -230,7 +215,7 @@ 0, 0}); this.numericUpDownSpeed.Name = "numericUpDownSpeed"; - this.numericUpDownSpeed.Size = new System.Drawing.Size(131, 23); + this.numericUpDownSpeed.Size = new System.Drawing.Size(150, 27); this.numericUpDownSpeed.TabIndex = 3; this.numericUpDownSpeed.Value = new decimal(new int[] { 100, @@ -240,8 +225,7 @@ // // numericUpDownWeight // - this.numericUpDownWeight.Location = new System.Drawing.Point(82, 62); - this.numericUpDownWeight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.numericUpDownWeight.Location = new System.Drawing.Point(94, 83); this.numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, @@ -253,7 +237,7 @@ 0, 0}); this.numericUpDownWeight.Name = "numericUpDownWeight"; - this.numericUpDownWeight.Size = new System.Drawing.Size(131, 23); + this.numericUpDownWeight.Size = new System.Drawing.Size(150, 27); this.numericUpDownWeight.TabIndex = 2; this.numericUpDownWeight.Value = new decimal(new int[] { 100, @@ -264,28 +248,27 @@ // labelWeight // this.labelWeight.AutoSize = true; - this.labelWeight.Location = new System.Drawing.Point(5, 64); + this.labelWeight.Location = new System.Drawing.Point(6, 85); this.labelWeight.Name = "labelWeight"; - this.labelWeight.Size = new System.Drawing.Size(29, 15); + this.labelWeight.Size = new System.Drawing.Size(36, 20); this.labelWeight.TabIndex = 1; this.labelWeight.Text = "Вес:"; // // labelSpeed // this.labelSpeed.AutoSize = true; - this.labelSpeed.Location = new System.Drawing.Point(5, 24); + this.labelSpeed.Location = new System.Drawing.Point(6, 32); this.labelSpeed.Name = "labelSpeed"; - this.labelSpeed.Size = new System.Drawing.Size(62, 15); + this.labelSpeed.Size = new System.Drawing.Size(76, 20); this.labelSpeed.TabIndex = 0; this.labelSpeed.Text = "Скорость:"; // // pictureBoxObject // this.pictureBoxObject.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.pictureBoxObject.Location = new System.Drawing.Point(31, 63); - this.pictureBoxObject.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.pictureBoxObject.Location = new System.Drawing.Point(35, 84); this.pictureBoxObject.Name = "pictureBoxObject"; - this.pictureBoxObject.Size = new System.Drawing.Size(286, 154); + this.pictureBoxObject.Size = new System.Drawing.Size(327, 205); this.pictureBoxObject.TabIndex = 1; this.pictureBoxObject.TabStop = false; // @@ -295,10 +278,9 @@ this.panelObject.Controls.Add(this.labelAdditionalColor); this.panelObject.Controls.Add(this.labelMainColor); this.panelObject.Controls.Add(this.pictureBoxObject); - this.panelObject.Location = new System.Drawing.Point(536, 22); - this.panelObject.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.panelObject.Location = new System.Drawing.Point(613, 29); this.panelObject.Name = "panelObject"; - this.panelObject.Size = new System.Drawing.Size(351, 226); + this.panelObject.Size = new System.Drawing.Size(401, 301); this.panelObject.TabIndex = 2; this.panelObject.DragDrop += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragDrop); this.panelObject.DragEnter += new System.Windows.Forms.DragEventHandler(this.PanelObject_DragEnter); @@ -307,9 +289,9 @@ // this.labelAdditionalColor.AllowDrop = true; this.labelAdditionalColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelAdditionalColor.Location = new System.Drawing.Point(204, 14); + this.labelAdditionalColor.Location = new System.Drawing.Point(233, 19); this.labelAdditionalColor.Name = "labelAdditionalColor"; - this.labelAdditionalColor.Size = new System.Drawing.Size(79, 38); + this.labelAdditionalColor.Size = new System.Drawing.Size(90, 50); this.labelAdditionalColor.TabIndex = 3; this.labelAdditionalColor.Text = "Доп. цвет"; this.labelAdditionalColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -320,9 +302,9 @@ // this.labelMainColor.AllowDrop = true; this.labelMainColor.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.labelMainColor.Location = new System.Drawing.Point(67, 14); + this.labelMainColor.Location = new System.Drawing.Point(77, 19); this.labelMainColor.Name = "labelMainColor"; - this.labelMainColor.Size = new System.Drawing.Size(79, 38); + this.labelMainColor.Size = new System.Drawing.Size(90, 50); this.labelMainColor.TabIndex = 2; this.labelMainColor.Text = "Цвет"; this.labelMainColor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -331,10 +313,9 @@ // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(603, 253); - this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Location = new System.Drawing.Point(689, 337); this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(82, 22); + this.buttonAdd.Size = new System.Drawing.Size(94, 29); this.buttonAdd.TabIndex = 3; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; @@ -342,24 +323,22 @@ // // buttonCancel // - this.buttonCancel.Location = new System.Drawing.Point(740, 254); - this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonCancel.Location = new System.Drawing.Point(846, 339); this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(82, 22); + this.buttonCancel.Size = new System.Drawing.Size(94, 29); this.buttonCancel.TabIndex = 4; this.buttonCancel.Text = "Отмена"; this.buttonCancel.UseVisualStyleBackColor = true; // // FormBusConfig // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(903, 287); + this.ClientSize = new System.Drawing.Size(1032, 383); this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonAdd); this.Controls.Add(this.panelObject); this.Controls.Add(this.groupBoxConfig); - this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.Name = "FormBusConfig"; this.Text = "FormBusConfig"; this.groupBoxConfig.ResumeLayout(false); diff --git a/DoubleDeckerBus/FormBusConfig.cs b/DoubleDeckerBus/FormBusConfig.cs index d1ed09d..21faed7 100644 --- a/DoubleDeckerBus/FormBusConfig.cs +++ b/DoubleDeckerBus/FormBusConfig.cs @@ -14,7 +14,6 @@ namespace DoubleDeckerbus { public partial class FormBusConfig : Form { - DrawingBus? _bus = null; private event Action? EventAddBus; public FormBusConfig() @@ -49,13 +48,11 @@ namespace DoubleDeckerbus EventAddBus += ev; } } - 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) @@ -90,7 +87,6 @@ namespace DoubleDeckerbus } DrawBus(); } - private void PanelColor_MouseDown(object sender, MouseEventArgs e) { (sender as Panel)?.DoDragDrop((sender as Panel)?.BackColor, @@ -108,14 +104,12 @@ namespace DoubleDeckerbus e.Effect = DragDropEffects.None; } } - private void LabelMainColor_DragDrop(object sender, DragEventArgs e) { var color = (Color)e.Data.GetData(typeof(Color)); _bus.EntityBus.ChangeBodyColor(color); DrawBus(); } - private void LabelAdditionalColor_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(Color)) && _bus != null && _bus is DrawingDoubleDeckerbus) @@ -135,9 +129,11 @@ namespace DoubleDeckerbus _doubledeckerbus.ChangeAdditionalColor(color); DrawBus(); } - private void ButtonAdd_Click(object sender, EventArgs e) { + if (_bus == null) + return; + EventAddBus?.Invoke(_bus); Close(); } diff --git a/DoubleDeckerBus/FormBusConfig.resx b/DoubleDeckerBus/FormBusConfig.resx index af32865..f298a7b 100644 --- a/DoubleDeckerBus/FormBusConfig.resx +++ b/DoubleDeckerBus/FormBusConfig.resx @@ -1,64 +1,4 @@ - - - + diff --git a/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs b/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs index 2b22de3..ed2b001 100644 --- a/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs +++ b/DoubleDeckerBus/FormDoubleDeckerbusCollection.cs @@ -10,6 +10,9 @@ using System.Windows.Forms; using DoubleDeckerbus.Generic; using DoubleDeckerbus.Drawing; using DoubleDeckerbus.Move_Strategy; +using Microsoft.Extensions.Logging; +using DoubleDeckerbus.Exceptions; + namespace DoubleDeckerbus @@ -17,11 +20,12 @@ namespace DoubleDeckerbus public partial class FormDoubleDeckerbusCollection : Form { private readonly BusesGenericStorage _storage; - - public FormDoubleDeckerbusCollection() + private readonly ILogger _logger; + public FormDoubleDeckerbusCollection(ILogger logger) { InitializeComponent(); _storage = new BusesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height); + _logger = logger; } private void ReloadObjects() { @@ -50,6 +54,7 @@ namespace DoubleDeckerbus } _storage.AddSet(textBoxStorageName.Text); ReloadObjects(); + _logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}"); } private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e) { @@ -61,13 +66,16 @@ namespace DoubleDeckerbus { return; } + string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty; if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty); + _storage.DelSet(name); ReloadObjects(); + _logger.LogInformation($"Удалён набор: {name}"); } } + private void buttonAddBus_Click(object sender, EventArgs e) { @@ -88,16 +96,25 @@ namespace DoubleDeckerbus { return; } - selectedBus.ChangeBordersPicture(pictureBoxCollection.Width, pictureBoxCollection.Height); - if (obj + selectedBus != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = obj.ShowBus(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } + selectedBus.ChangeBordersPicture(Width, Height); + try + { + if (obj + selectedBus != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = obj.ShowBus(); + _logger.LogInformation($"Добавлен объект: {selectedBus.EntityBus.BodyColor}"); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + catch (StorageOverflowException ex) + { + MessageBox.Show(ex.Message); + _logger.LogWarning(ex.Message); + } } private void buttonDeleteBus_Click(object sender, EventArgs e) @@ -115,24 +132,29 @@ namespace DoubleDeckerbus { return; } - int pos = 0; try { - pos = Convert.ToInt32(maskedTextBoxNumber.Text); + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (obj - pos) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = obj.ShowBus(); + _logger.LogInformation($"Удалён объект по позиции : {pos}"); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } } - catch + catch (FormatException ex) { - MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; + MessageBox.Show("Неверный формат ввода"); + _logger.LogWarning("Неверный формат ввода"); } - if (obj - pos) + catch (Exception ex) { - MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = obj.ShowBus(); - } - else - { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show(ex.Message); + _logger.LogWarning(ex.Message); } } private void buttonUpdate_Click(object sender, EventArgs e) @@ -149,17 +171,21 @@ namespace DoubleDeckerbus } pictureBoxCollection.Image = obj.ShowBus(); } + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storage.SaveData(saveFileDialog.FileName)) + try { + _storage.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Файл сохранён по пути: {saveFileDialog.FileName}"); } - else + catch (InvalidOperationException ex) { - MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning(ex.Message); } } } @@ -167,18 +193,19 @@ namespace DoubleDeckerbus { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_storage.LoadData(openFileDialog.FileName)) + try { - ReloadObjects(); - var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - pictureBoxCollection.Image = obj.ShowBus(); + _storage.LoadData(openFileDialog.FileName); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + _logger.LogInformation($"Файл загружен по пути: {openFileDialog.FileName}"); } - else + catch (Exception ex) { - MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogWarning(ex.Message); } } + ReloadObjects(); } } } diff --git a/DoubleDeckerBus/Generic/BusGenericCollection.cs b/DoubleDeckerBus/Generic/BusGenericCollection.cs index ca4eef3..1cde817 100644 --- a/DoubleDeckerBus/Generic/BusGenericCollection.cs +++ b/DoubleDeckerBus/Generic/BusGenericCollection.cs @@ -17,7 +17,6 @@ namespace DoubleDeckerbus.Generic private readonly int _placeSizeWidth = 200; private readonly int _placeSizeHeight = 120; private readonly SetGeneric _collection; - public BusGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; @@ -43,13 +42,11 @@ namespace DoubleDeckerbus.Generic } return collect?._collection.Remove(pos) ?? false; } - public IEnumerable GetBus => _collection.GetBus(); public U? GetU(int pos) { return (U?)_collection[pos]?.GetMoveableObject; } - public Bitmap ShowBus() { Bitmap bmp = new(_pictureWidth, _pictureHeight); @@ -58,7 +55,6 @@ namespace DoubleDeckerbus.Generic DrawObjects(gr); return bmp; } - private void DrawBackground(Graphics gr) { Pen pen = new(Color.Black, 3); @@ -71,12 +67,10 @@ namespace DoubleDeckerbus.Generic } } } - private void DrawObjects(Graphics g) { int x = _pictureWidth / _placeSizeWidth - 1; int y = 0; - foreach (var bus in _collection.GetBus()) { if (bus != null) diff --git a/DoubleDeckerBus/Generic/BusesGenericStorage.cs b/DoubleDeckerBus/Generic/BusesGenericStorage.cs index 9b542a2..4b2deeb 100644 --- a/DoubleDeckerBus/Generic/BusesGenericStorage.cs +++ b/DoubleDeckerBus/Generic/BusesGenericStorage.cs @@ -24,20 +24,17 @@ namespace DoubleDeckerbus.Generic _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } - public void AddSet(string name) { foreach (string nameStorage in Keys) { if (nameStorage == name) { - MessageBox.Show("Набор с заданным именем уже есть", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } _busStorages.Add(name, new BusGenericCollection(_pictureWidth, _pictureHeight)); } - public void DelSet(string name) { if (_busStorages.ContainsKey(name)) @@ -57,69 +54,86 @@ namespace DoubleDeckerbus.Generic return null; } } - - public bool SaveData(string filename) + public void SaveData(string filename) { if (File.Exists(filename)) { File.Delete(filename); } - - using (StreamWriter sw = File.CreateText(filename)) + StringBuilder data = new(); + foreach (KeyValuePair> record in _busStorages) { - sw.WriteLine($"DoubleDeckerBusStorage"); - foreach (var record in _busStorages) + StringBuilder records = new(); + foreach (DrawingBus? elem in record.Value.GetBus) { - StringBuilder records = new(); - foreach (DrawingBus? elem in record.Value.GetBus) - { - records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); - } - sw.WriteLine($"{record.Key}{_separatorForKeyValue}{records}"); + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); } - - return true; + if (data.Length == 0) + { + throw new Exception("Невалиданя операция, нет данных для сохранения"); + } + using FileStream fs = new(filename, FileMode.Create); + byte[] info = new + UTF8Encoding(true).GetBytes($"BusStorage{Environment.NewLine}{data}"); + fs.Write(info, 0, info.Length); + return; } - - public bool LoadData(string filename) + public void LoadData(string filename) { if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не найден"); } - - using (StreamReader sr = File.OpenText(filename)) + string bufferTextFromFile = ""; + using (FileStream fs = new(filename, FileMode.Open)) { - string? curLine = sr.ReadLine(); - if (curLine == null || !curLine.Contains("AirbusStorage")) + byte[] b = new byte[fs.Length]; + UTF8Encoding temp = new(true); + while (fs.Read(b, 0, b.Length) > 0) { - return false; + bufferTextFromFile += temp.GetString(b); } - _busStorages.Clear(); - curLine = sr.ReadLine(); - while (curLine != null) + } + var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, + StringSplitOptions.RemoveEmptyEntries); + if (strs == null || strs.Length == 0) + { + throw new Exception("Нет данных для загрузки"); + } + if (!strs[0].StartsWith("BusStorage")) + { + throw new Exception("Неверный формат данных"); + } + _busStorages.Clear(); + foreach (string data in strs) + { + string[] record = data.Split(_separatorForKeyValue, + StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) { - string[] record = curLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - BusGenericCollection collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - - foreach (string elem in set) + continue; + } + BusGenericCollection + collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, + StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawingBus? Bus = + elem?.CreateDrawingBus(_separatorForObject, _pictureWidth, _pictureHeight); + if (Bus != null) { - DrawingBus? Bus = elem?.CreateDrawingBus(_separatorForObject, _pictureWidth, _pictureHeight); - if (Bus != null) + if ((collection + Bus) == -1) { - if (collection + Bus == -1) - { - return false; - } + throw new Exception("Ошибка добавления в коллекцию"); } } - _busStorages.Add(record[0], collection); - curLine = sr.ReadLine(); } + _busStorages.Add(record[0], collection); } - return true; } } } diff --git a/DoubleDeckerBus/Generic/SetGeneric.cs b/DoubleDeckerBus/Generic/SetGeneric.cs index 9823d3a..79ee0ba 100644 --- a/DoubleDeckerBus/Generic/SetGeneric.cs +++ b/DoubleDeckerBus/Generic/SetGeneric.cs @@ -1,4 +1,5 @@ -using System; +using DoubleDeckerbus.Exceptions; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -17,30 +18,30 @@ namespace DoubleDeckerbus.Generic _maxCount = count; _places = new List(count); } - public int Insert(T bus) { - _places.Insert(0, bus); - return 0; + return Insert(bus, 0); } - - public bool Insert(T bus, int position) + public int Insert(T bus, int position) { - if (position < 0 || position >= Count || Count >= _maxCount) + if (Count >= _maxCount) { - return false; + throw new StorageOverflowException(_maxCount); + } + if (position < 0 || position >= _maxCount) + { + throw new IndexOutOfRangeException("Индекс вне границ коллекции"); } _places.Insert(position, bus); - return true; + return 0; } public bool Remove(int position) { if (position < 0 || position >= Count) { - return false; + throw new BusNotFoundException(position); } _places.RemoveAt(position); - return true; } public T? this[int position] @@ -74,4 +75,4 @@ namespace DoubleDeckerbus.Generic } } } -} +} \ No newline at end of file diff --git a/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs b/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs index 1a739b1..2cc7507 100644 --- a/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs +++ b/DoubleDeckerBus/Move_Strategy/AbstractStrategy.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using DoubleDeckerbus.Entities; using static System.Windows.Forms.VisualStyles.VisualStyleElement; - namespace DoubleDeckerbus.Move_Strategy { public abstract class AbstractStrategy @@ -70,5 +69,4 @@ namespace DoubleDeckerbus.Move_Strategy return false; } } -} - +} \ No newline at end of file diff --git a/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs b/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs index 99528c0..067f6c9 100644 --- a/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs +++ b/DoubleDeckerBus/Move_Strategy/DrawingObjectBus.cs @@ -8,7 +8,6 @@ using System.Threading.Tasks; using DoubleDeckerbus.Entities; using DoubleDeckerbus.Drawing; - namespace DoubleDeckerbus.Move_Strategy { public class DrawingObjectBus : IMoveableObject diff --git a/DoubleDeckerBus/Move_Strategy/MoveToBorder.cs b/DoubleDeckerBus/Move_Strategy/MoveToBorder.cs index a519580..51fdcd9 100644 --- a/DoubleDeckerBus/Move_Strategy/MoveToBorder.cs +++ b/DoubleDeckerBus/Move_Strategy/MoveToBorder.cs @@ -38,7 +38,6 @@ namespace DoubleDeckerbus.Move_Strategy { MoveRight(); } - } var diffY = objParams.ObjectMiddleVertical - FieldHeight; if (Math.Abs(diffY) > GetStep()) diff --git a/DoubleDeckerBus/Move_Strategy/MoveToCenter.cs b/DoubleDeckerBus/Move_Strategy/MoveToCenter.cs index b3b0363..482a12d 100644 --- a/DoubleDeckerBus/Move_Strategy/MoveToCenter.cs +++ b/DoubleDeckerBus/Move_Strategy/MoveToCenter.cs @@ -38,7 +38,6 @@ namespace DoubleDeckerbus.Move_Strategy { MoveRight(); } - } var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; if (Math.Abs(diffY) > GetStep()) diff --git a/DoubleDeckerBus/Program.cs b/DoubleDeckerBus/Program.cs index 598623f..ec6b9b4 100644 --- a/DoubleDeckerBus/Program.cs +++ b/DoubleDeckerBus/Program.cs @@ -1,3 +1,8 @@ +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; + namespace DoubleDeckerbus { internal static class Program @@ -11,7 +16,30 @@ namespace DoubleDeckerbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormDoubleDeckerbusCollection()); + var services = new ServiceCollection(); + ConfigureServices(services); + using (ServiceProvider serviceProvider = services.BuildServiceProvider()) + { + Application.Run(serviceProvider.GetRequiredService()); + } + } + + private static void ConfigureServices(ServiceCollection services) + { + services.AddSingleton().AddLogging(option => + { + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}serilog.json", optional: false, reloadOnChange: true).Build(); + var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger(); + + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(logger); + }); } } } \ No newline at end of file diff --git a/DoubleDeckerBus/Resources/стрелка вверх.png b/DoubleDeckerBus/Resources/стрелка вверх.png new file mode 100644 index 0000000..1ec8215 Binary files /dev/null and b/DoubleDeckerBus/Resources/стрелка вверх.png differ diff --git a/DoubleDeckerBus/Resources/стрелка влево.png b/DoubleDeckerBus/Resources/стрелка влево.png new file mode 100644 index 0000000..9b18542 Binary files /dev/null and b/DoubleDeckerBus/Resources/стрелка влево.png differ diff --git a/DoubleDeckerBus/Resources/стрелка вниз.png b/DoubleDeckerBus/Resources/стрелка вниз.png new file mode 100644 index 0000000..1ef3ae9 Binary files /dev/null and b/DoubleDeckerBus/Resources/стрелка вниз.png differ diff --git a/DoubleDeckerBus/Resources/стрелка вправо.png b/DoubleDeckerBus/Resources/стрелка вправо.png new file mode 100644 index 0000000..27c5130 Binary files /dev/null and b/DoubleDeckerBus/Resources/стрелка вправо.png differ diff --git a/DoubleDeckerBus/serilog.json b/DoubleDeckerBus/serilog.json new file mode 100644 index 0000000..d83ac59 --- /dev/null +++ b/DoubleDeckerBus/serilog.json @@ -0,0 +1,20 @@ +{ + "Serilog": { + "Using": [ "Serilog.Sinks.File" ], + "MinimumLevel": "Information", + "WriteTo": [ + { + "Name": "File", + "Args": { + "path": "Logs/buslog.log", + "rollingInterval": "Day", + "outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}" + } + } + ], + "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ], + "Properties": { + "Application": "ProjectAirbus" + } + } +} \ No newline at end of file