PIbd22_Kamcharova_K.A._lab7 #15

Closed
MayDayR wants to merge 1 commits from lab7 into lab6
26 changed files with 289 additions and 250 deletions

View File

@ -8,6 +8,18 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
@ -23,4 +35,6 @@
</EmbeddedResource>
</ItemGroup>
<ProjectExtensions><VisualStudio><UserProperties serilog_1json__JsonSchema="https://dstack-runner-downloads.s3.eu-west-1.amazonaws.com/latest/schemas/configuration.json" /></VisualStudio></ProjectExtensions>
</Project>

View File

@ -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)

View File

@ -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);

View File

@ -29,7 +29,6 @@ namespace DoubleDeckerbus.Drawing
}
return null;
}
public static string GetDataForSave(this DrawingBus DrawingBus, char separatorForObject)
{
var truck = DrawingBus.EntityBus;

View File

@ -12,6 +12,5 @@ namespace DoubleDeckerbus.Entities
Down = 2,
Left = 3,
Right = 4
}
}

View File

@ -18,7 +18,6 @@ namespace DoubleDeckerbus.Entities
Weight = weight;
BodyColor = bodyColor;
}
public void ChangeBodyColor(Color color)
{
BodyColor = color;

View File

@ -19,7 +19,6 @@ namespace DoubleDeckerbus.Entities
IsSecondFloor = secondfloor;
IsStairs = stairs;
}
public void ChangeAdditionalColor(Color additionalColor)
{
AddColor = additionalColor;

View File

@ -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) { }
}
}

View File

@ -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) { }
}
}

View File

@ -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);

View File

@ -14,7 +14,6 @@ namespace DoubleDeckerbus
{
public partial class FormBusConfig : Form
{
DrawingBus? _bus = null;
private event Action<DrawingBus>? 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();
}

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">

View File

@ -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<FormDoubleDeckerbusCollection> 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();
}
}
}

View File

@ -17,7 +17,6 @@ namespace DoubleDeckerbus.Generic
private readonly int _placeSizeWidth = 200;
private readonly int _placeSizeHeight = 120;
private readonly SetGeneric<T> _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<T?> 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)

View File

@ -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<DrawingBus, DrawingObjectBus>(_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<string,
BusGenericCollection<DrawingBus, DrawingObjectBus>> 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<DrawingBus, DrawingObjectBus> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
continue;
}
BusGenericCollection<DrawingBus, DrawingObjectBus>
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;
}
}
}

View File

@ -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<T?>(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
}
}
}
}
}

View File

@ -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;
}
}
}
}

View File

@ -8,7 +8,6 @@ using System.Threading.Tasks;
using DoubleDeckerbus.Entities;
using DoubleDeckerbus.Drawing;
namespace DoubleDeckerbus.Move_Strategy
{
public class DrawingObjectBus : IMoveableObject

View File

@ -38,7 +38,6 @@ namespace DoubleDeckerbus.Move_Strategy
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())

View File

@ -38,7 +38,6 @@ namespace DoubleDeckerbus.Move_Strategy
{
MoveRight();
}
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())

View File

@ -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<FormDoubleDeckerbusCollection>());
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddSingleton<FormDoubleDeckerbusCollection>().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);
});
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

View File

@ -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"
}
}
}