Romanov E.V. LabWork8 #10

Closed
RomanovEgor wants to merge 2 commits from 8LAB into 7LAB
12 changed files with 255 additions and 50 deletions

View File

@ -1,65 +1,65 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup> </startup>
<runtime> <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral" /> <assemblyIdentity name="Microsoft.Extensions.Primitives" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" /> <assemblyIdentity name="Microsoft.Extensions.Logging.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral" /> <assemblyIdentity name="Microsoft.Extensions.Logging" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" /> <assemblyIdentity name="Microsoft.Extensions.DependencyInjection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2" /> <bindingRedirect oldVersion="0.0.0.0-4.0.1.2" newVersion="4.0.1.2"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1" /> <bindingRedirect oldVersion="0.0.0.0-4.0.5.1" newVersion="4.0.5.1"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.ValueTuple" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" /> <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" /> <assemblyIdentity name="Microsoft.Extensions.Configuration.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" /> <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>

View File

@ -21,7 +21,7 @@ namespace HoistingCrane
} }
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 3);
Brush dopBrush = new SolidBrush(advancedHoistingCrane.DopColor); Brush dopBrush = new SolidBrush(advancedHoistingCrane.DopColor);
if (advancedHoistingCrane.Сounterweight) if (advancedHoistingCrane.Counterweight)
{ {
g.DrawLine(pen, _startPosX + 15, _startPosY + 60, _startPosX + 40, _startPosY + 75); g.DrawLine(pen, _startPosX + 15, _startPosY + 60, _startPosX + 40, _startPosY + 75);
g.DrawLine(pen, _startPosX + 15, _startPosY + 45, _startPosX + 45, _startPosY + 65); g.DrawLine(pen, _startPosX + 15, _startPosY + 45, _startPosX + 45, _startPosY + 65);

View File

@ -8,11 +8,46 @@ namespace HoistingCrane
{ {
_hoistingCrane = hoistingCrane; _hoistingCrane = hoistingCrane;
} }
public DrawingHoistingCrane GetHoistingCrane => _hoistingCrane;
public float Step => _hoistingCrane?.HoistingCrane?.Step ?? 0; public float Step => _hoistingCrane?.HoistingCrane?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{ {
return _hoistingCrane?.GetCurrentPosition() ?? default; return _hoistingCrane?.GetCurrentPosition() ?? default;
} }
public bool Equals(IDrawingObject? other)
{
if (other == null)
{
return false;
}
var otherHoistingCrane = other as DrawingObjectHoistingCrane;
if (otherHoistingCrane == null)
{
return false;
}
var hoistingCrane = _hoistingCrane.HoistingCrane;
var otherHoistingCraneHoistingCrane = otherHoistingCrane._hoistingCrane.HoistingCrane;
if (hoistingCrane.Speed != otherHoistingCraneHoistingCrane.Speed)
{
return false;
}
if (hoistingCrane.Weight != otherHoistingCraneHoistingCrane.Weight)
{
return false;
}
if (hoistingCrane.BodyColor != otherHoistingCraneHoistingCrane.BodyColor)
{
return false;
}
var hoistingcrane = hoistingCrane as EntityAdvancedHoistingCrane;
var otherhoistingcrane = otherHoistingCraneHoistingCrane as EntityAdvancedHoistingCrane;
if (hoistingcrane == null && otherhoistingcrane == null) return true;
if (hoistingcrane == null || otherhoistingcrane == null) return false;
if (hoistingcrane.DopColor != otherhoistingcrane.DopColor) return false;
if (hoistingcrane.Counterweight != otherhoistingcrane.Counterweight) return false;
if (hoistingcrane.Crane != otherhoistingcrane.Crane) return false;
return true;
}
public void MoveObject(Direction direction) public void MoveObject(Direction direction)
{ {
_hoistingCrane?.MoveTransport(direction); _hoistingCrane?.MoveTransport(direction);

View File

@ -11,14 +11,14 @@ namespace HoistingCrane
// наличие крана // наличие крана
public bool Crane { get; private set; } public bool Crane { get; private set; }
// наличие противовеса // наличие противовеса
public bool Сounterweight { get; private set; } public bool Counterweight { get; private set; }
public Color DopColor { get; set; } public Color DopColor { get; set; }
public EntityAdvancedHoistingCrane(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool counterWeight) : public EntityAdvancedHoistingCrane(int speed, float weight, Color bodyColor, Color dopColor, bool crane, bool counterWeight) :
base(speed, weight, bodyColor) base(speed, weight, bodyColor)
{ {
Crane = crane; Crane = crane;
Сounterweight = counterWeight; Counterweight = counterWeight;
DopColor = dopColor; DopColor = dopColor;
} }
} }

View File

@ -47,7 +47,7 @@ namespace HoistingCrane
{ {
return str; return str;
} }
return $"{str}{_separatorForObject}{HoistingCrane.DopColor.Name}{_separatorForObject}{HoistingCrane.Crane}{_separatorForObject}{HoistingCrane.Сounterweight}"; return $"{str}{_separatorForObject}{HoistingCrane.DopColor.Name}{_separatorForObject}{HoistingCrane.Crane}{_separatorForObject}{HoistingCrane.Counterweight}";
} }
} }
} }

View File

@ -37,6 +37,8 @@
this.buttonAddMap = new System.Windows.Forms.Button(); this.buttonAddMap = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.textBoxNewMapName = new System.Windows.Forms.TextBox(); this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.ButtonSortByColor = new System.Windows.Forms.Button();
this.ButtonSortByType = new System.Windows.Forms.Button();
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveHoistingCrane = new System.Windows.Forms.Button(); this.buttonRemoveHoistingCrane = new System.Windows.Forms.Button();
@ -67,11 +69,11 @@
this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.groupBoxMaps.Location = new System.Drawing.Point(13, 28); this.groupBoxMaps.Location = new System.Drawing.Point(0, 0);
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Name = "groupBoxMaps"; this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Size = new System.Drawing.Size(229, 326); this.groupBoxMaps.Size = new System.Drawing.Size(213, 267);
this.groupBoxMaps.TabIndex = 11; this.groupBoxMaps.TabIndex = 11;
this.groupBoxMaps.TabStop = false; this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты"; this.groupBoxMaps.Text = "Карты";
@ -130,8 +132,30 @@
this.textBoxNewMapName.Size = new System.Drawing.Size(200, 27); this.textBoxNewMapName.Size = new System.Drawing.Size(200, 27);
this.textBoxNewMapName.TabIndex = 0; this.textBoxNewMapName.TabIndex = 0;
// //
// ButtonSortByColor
//
this.ButtonSortByColor.Location = new System.Drawing.Point(7, 316);
this.ButtonSortByColor.Name = "ButtonSortByColor";
this.ButtonSortByColor.Size = new System.Drawing.Size(206, 26);
this.ButtonSortByColor.TabIndex = 7;
this.ButtonSortByColor.Text = "SortByColor";
this.ButtonSortByColor.UseVisualStyleBackColor = true;
this.ButtonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
//
// ButtonSortByType
//
this.ButtonSortByType.Location = new System.Drawing.Point(7, 279);
this.ButtonSortByType.Name = "ButtonSortByType";
this.ButtonSortByType.Size = new System.Drawing.Size(206, 31);
this.ButtonSortByType.TabIndex = 6;
this.ButtonSortByType.Text = "SortByType";
this.ButtonSortByType.UseVisualStyleBackColor = true;
this.ButtonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
//
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.ButtonSortByColor);
this.groupBoxTools.Controls.Add(this.ButtonSortByType);
this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonRemoveHoistingCrane); this.groupBoxTools.Controls.Add(this.buttonRemoveHoistingCrane);
@ -154,20 +178,20 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(21, 436); this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 424);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27); this.maskedTextBoxPosition.Size = new System.Drawing.Size(206, 27);
this.maskedTextBoxPosition.TabIndex = 2; this.maskedTextBoxPosition.TabIndex = 2;
this.maskedTextBoxPosition.ValidatingType = typeof(int); this.maskedTextBoxPosition.ValidatingType = typeof(int);
// //
// buttonRemoveHoistingCrane // buttonRemoveHoistingCrane
// //
this.buttonRemoveHoistingCrane.Location = new System.Drawing.Point(20, 471); this.buttonRemoveHoistingCrane.Location = new System.Drawing.Point(7, 471);
this.buttonRemoveHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemoveHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonRemoveHoistingCrane.Name = "buttonRemoveHoistingCrane"; this.buttonRemoveHoistingCrane.Name = "buttonRemoveHoistingCrane";
this.buttonRemoveHoistingCrane.Size = new System.Drawing.Size(199, 47); this.buttonRemoveHoistingCrane.Size = new System.Drawing.Size(206, 47);
this.buttonRemoveHoistingCrane.TabIndex = 3; this.buttonRemoveHoistingCrane.TabIndex = 3;
this.buttonRemoveHoistingCrane.Text = "Удалить подъёмный кран"; this.buttonRemoveHoistingCrane.Text = "Удалить подъёмный кран";
this.buttonRemoveHoistingCrane.UseVisualStyleBackColor = true; this.buttonRemoveHoistingCrane.UseVisualStyleBackColor = true;
@ -175,10 +199,10 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(20, 526); this.buttonShowStorage.Location = new System.Drawing.Point(7, 526);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(199, 47); this.buttonShowStorage.Size = new System.Drawing.Size(206, 47);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -238,10 +262,10 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(21, 584); this.buttonShowOnMap.Location = new System.Drawing.Point(7, 584);
this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(198, 47); this.buttonShowOnMap.Size = new System.Drawing.Size(206, 47);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -249,10 +273,10 @@
// //
// buttonAddHoistingCrane // buttonAddHoistingCrane
// //
this.buttonAddHoistingCrane.Location = new System.Drawing.Point(20, 381); this.buttonAddHoistingCrane.Location = new System.Drawing.Point(7, 349);
this.buttonAddHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddHoistingCrane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddHoistingCrane.Name = "buttonAddHoistingCrane"; this.buttonAddHoistingCrane.Name = "buttonAddHoistingCrane";
this.buttonAddHoistingCrane.Size = new System.Drawing.Size(199, 47); this.buttonAddHoistingCrane.Size = new System.Drawing.Size(206, 67);
this.buttonAddHoistingCrane.TabIndex = 1; this.buttonAddHoistingCrane.TabIndex = 1;
this.buttonAddHoistingCrane.Text = "Добавить подъёмный кран"; this.buttonAddHoistingCrane.Text = "Добавить подъёмный кран";
this.buttonAddHoistingCrane.UseVisualStyleBackColor = true; this.buttonAddHoistingCrane.UseVisualStyleBackColor = true;
@ -355,5 +379,7 @@
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
private System.Windows.Forms.OpenFileDialog openFileDialog; private System.Windows.Forms.OpenFileDialog openFileDialog;
private System.Windows.Forms.SaveFileDialog saveFileDialog; private System.Windows.Forms.SaveFileDialog saveFileDialog;
private System.Windows.Forms.Button ButtonSortByColor;
private System.Windows.Forms.Button ButtonSortByType;
} }
} }

View File

@ -263,5 +263,24 @@ namespace HoistingCrane
} }
} }
} }
private void ButtonSortByType_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new HoistingCraneCompareByType());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
private void ButtonSortByColor_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new HoistingCraneCompareByColor());
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
} }
} }

View File

@ -0,0 +1,56 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class HoistingCraneCompareByType : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject x, IDrawingObject y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xHoistingCrane = x as DrawingObjectHoistingCrane;
var yHoistingCrane = y as DrawingObjectHoistingCrane;
if (xHoistingCrane == null && yHoistingCrane == null)
{
return 0;
}
if (xHoistingCrane == null && yHoistingCrane != null)
{
return 1;
}
if (xHoistingCrane != null && yHoistingCrane == null)
{
return -1;
}
if (xHoistingCrane.GetHoistingCrane.GetType().Name != yHoistingCrane.GetHoistingCrane.GetType().Name)
{
if (xHoistingCrane.GetHoistingCrane.GetType().Name == "DrawingHoistingCrane")
{
return -1;
}
return 1;
}
var speedCompare =
xHoistingCrane.GetHoistingCrane.HoistingCrane.Speed.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xHoistingCrane.GetHoistingCrane.HoistingCrane.Weight.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Weight);
}
}
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HoistingCrane
{
internal class HoistingCraneCompareByColor : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject x, IDrawingObject y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xHoistingCrane = x as DrawingObjectHoistingCrane;
var yHoistingCrane = y as DrawingObjectHoistingCrane;
if (xHoistingCrane == null && yHoistingCrane == null)
{
return 0;
}
if (xHoistingCrane == null && yHoistingCrane != null)
{
return 1;
}
if (xHoistingCrane != null && yHoistingCrane == null)
{
return -1;
}
int colorCompare = string.Compare(xHoistingCrane.GetHoistingCrane.HoistingCrane.BodyColor.Name, yHoistingCrane.GetHoistingCrane.HoistingCrane.BodyColor.Name);
if (colorCompare != 0)
{
return colorCompare;
}
var speedCompare = xHoistingCrane.GetHoistingCrane.HoistingCrane.Speed.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xHoistingCrane.GetHoistingCrane.HoistingCrane.Weight.CompareTo(yHoistingCrane.GetHoistingCrane.HoistingCrane.Weight);
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace HoistingCrane namespace HoistingCrane
{ {
internal interface IDrawingObject internal interface IDrawingObject : IEquatable<IDrawingObject>
{ {
public float Step { get; } public float Step { get; }
void SetObject(int x, int y, int width, int height); void SetObject(int x, int y, int width, int height);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace HoistingCrane namespace HoistingCrane
{ {
internal class MapWithSetHoistingCraneGeneric<T, U> internal class MapWithSetHoistingCraneGeneric<T, U>
where T : class, IDrawingObject where T : class, IDrawingObject, IEquatable<T>
where U : AbstractMap where U : AbstractMap
{ {
private readonly int _pictureWidth; private readonly int _pictureWidth;
@ -140,5 +140,13 @@ namespace HoistingCrane
_setHoistingCranes.Insert(DrawingObjectHoistingCrane.Create(rec) as T); _setHoistingCranes.Insert(DrawingObjectHoistingCrane.Create(rec) as T);
} }
} }
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T> comparer)
{
_setHoistingCranes.SortSet(comparer);
}
} }
} }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace HoistingCrane namespace HoistingCrane
{ {
internal class SetHoistingCraneGeneric<T> internal class SetHoistingCraneGeneric<T>
where T : class where T : class, IEquatable<T>
{ {
private readonly List<T> _places; private readonly List<T> _places;
public int Count => _places.Count; public int Count => _places.Count;
@ -19,6 +19,7 @@ namespace HoistingCrane
} }
public int Insert(T hoistingCrane) public int Insert(T hoistingCrane)
{ {
if (_places.Contains(hoistingCrane)) return -1;
for (int i = 0; i < _maxCount; i++) for (int i = 0; i < _maxCount; i++)
{ {
if (i == Count) if (i == Count)
@ -95,5 +96,13 @@ namespace HoistingCrane
} }
} }
} }
public void SortSet(IComparer<T> comparer)
{
if (comparer == null)
{
return;
}
_places.Sort(comparer);
}
} }
} }