From 4fd89af30ed1c120327e5b2344c64d4a13892869 Mon Sep 17 00:00:00 2001 From: shadowik Date: Sun, 11 Dec 2022 23:17:18 +0400 Subject: [PATCH] All without change Insert --- .../DoubleDeckerBus/BusCompareByColor.cs | 45 ++++++++++++++++++- .../DoubleDeckerBus/DrawingObjectBus.cs | 21 ++++++++- .../DoubleDeckerBus/FormMapWithSetBuses.cs | 7 ++- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs index ed65f61..166b266 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/BusCompareByColor.cs @@ -10,8 +10,49 @@ namespace DoubleDeckerBus { public int Compare(IDrawingObject? x, IDrawingObject? y) { - // TODO реализовать - throw new NotImplementedException(); + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xBus = x as DrawingObjectBus; + var yBus = y as DrawingObjectBus; + if (xBus == null && yBus == null) + { + return 0; + } + if (xBus == null && yBus != null) + { + return 1; + } + if (xBus != null && yBus == null) + { + return -1; + } + + var baseColorCompare = xBus.GetBus.Bus.BodyColor.ToString().CompareTo(yBus.GetBus.Bus.BodyColor.ToString()); + if (baseColorCompare != 0) + { + return baseColorCompare; + } + + if (xBus.GetBus.Bus is EntityDDB xDDB && yBus.GetBus.Bus is EntityDDB yDDB) { + var extraColorCompare = xDDB.BodyColor.ToString().CompareTo(yDDB.BodyColor.ToString()); + if (extraColorCompare != 0) + { + return extraColorCompare; + } + } + + return 0; } } + } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs index b1deb0d..b845317 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/DrawingObjectBus.cs @@ -87,7 +87,26 @@ namespace DoubleDeckerBus { return false; } - // TODO доделать проверки в случае продвинутого объекта + + if (bus is EntityDDB DDB) { + if (other is not EntityDDB otherDDB) { + return false; + } + + if (DDB.Ledder != otherDDB.Ledder) { + return false; + } + + if (DDB.SecondStage != otherDDB.SecondStage) { + return false; + } + + if (DDB.ExtraColor != otherDDB.ExtraColor) + { + return false; + } + } + return true; } diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs index 67c7551..a5458cb 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/FormMapWithSetBuses.cs @@ -260,7 +260,12 @@ namespace DoubleDeckerBus private void ButtonSortByColor_Click(object sender, EventArgs e) { - // TODO прописать логику + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? String.Empty].Sort(new BusCompareByColor()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } } }