Sortirovka
This commit is contained in:
parent
3ac973ae9d
commit
f2c3083491
78
Bus/Bus/BusCompareByColor.cs
Normal file
78
Bus/Bus/BusCompareByColor.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bus
|
||||
{
|
||||
internal class BusCompareByColor : 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 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;
|
||||
}
|
||||
|
||||
if (xBus.GetBus.Bus.BodyColor.R.CompareTo(xBus.GetBus.Bus.BodyColor.R) != 0)
|
||||
{
|
||||
return xBus.GetBus.Bus.BodyColor.R.CompareTo(yBus.GetBus.Bus.BodyColor.R);
|
||||
}
|
||||
if (xBus.GetBus.Bus.BodyColor.G.CompareTo(yBus.GetBus.Bus.BodyColor.G) != 0)
|
||||
{
|
||||
return xBus.GetBus.Bus.BodyColor.G.CompareTo(yBus.GetBus.Bus.BodyColor.G);
|
||||
}
|
||||
if (xBus.GetBus.Bus.BodyColor.B.CompareTo(yBus.GetBus.Bus.BodyColor.B) != 0)
|
||||
{
|
||||
return xBus.GetBus.Bus.BodyColor.B.CompareTo(yBus.GetBus.Bus.BodyColor.B);
|
||||
}
|
||||
|
||||
if (xBus.GetBus.Bus is EntitySportBus xSportEntity && yBus.GetBus.Bus is EntitySportBus ySportEntity)
|
||||
{
|
||||
if (xSportEntity.DopColor.R.CompareTo(ySportEntity.DopColor.R) != 0)
|
||||
{
|
||||
return xSportEntity.DopColor.R.CompareTo(ySportEntity.DopColor.R);
|
||||
}
|
||||
if (xSportEntity.DopColor.G.CompareTo(ySportEntity.DopColor.G) != 0)
|
||||
{
|
||||
return xSportEntity.DopColor.G.CompareTo(ySportEntity.DopColor.G);
|
||||
}
|
||||
if (xSportEntity.DopColor.B.CompareTo(ySportEntity.DopColor.B) != 0)
|
||||
{
|
||||
return xSportEntity.DopColor.B.CompareTo(ySportEntity.DopColor.B);
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = xBus.GetBus.Bus.Speed.CompareTo(yBus.GetBus.Bus.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xBus.GetBus.Bus.Weight.CompareTo(yBus.GetBus.Bus.Weight);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
56
Bus/Bus/BusCompareByType.cs
Normal file
56
Bus/Bus/BusCompareByType.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bus
|
||||
{
|
||||
internal class BusCompareByType : 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 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;
|
||||
}
|
||||
if (xBus.GetBus.GetType().Name != yBus.GetBus.GetType().Name)
|
||||
{
|
||||
if (xBus.GetBus.GetType().Name == "DrawningBus")
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
var speedCompare = xBus.GetBus.Bus.Speed.CompareTo(yBus.GetBus.Bus.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return xBus.GetBus.Bus.Weight.CompareTo(yBus.GetBus.Bus.Weight);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -31,6 +31,8 @@ namespace Bus
|
||||
_bus.SetPosition(x, y, width, height);
|
||||
}
|
||||
|
||||
public DrawingBus GetBus => _bus;
|
||||
|
||||
void IDrawingObject.DrawingObject(Graphics g)
|
||||
{
|
||||
_bus.DrawTransport(g);
|
||||
@ -46,8 +48,8 @@ namespace Bus
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var entity = Bus.Bus;
|
||||
var otherEntity = otherBus.Bus.Bus;
|
||||
var entity = _bus.Bus;
|
||||
var otherEntity = otherBus._bus.Bus;
|
||||
if (entity.GetType() != otherEntity.GetType() ||
|
||||
entity.Speed != otherEntity.Speed ||
|
||||
entity.Weight != otherEntity.Weight ||
|
||||
|
46
Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs
generated
46
Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs
generated
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.buttonRight = new System.Windows.Forms.Button();
|
||||
this.buttonDown = new System.Windows.Forms.Button();
|
||||
this.buttonLeft = new System.Windows.Forms.Button();
|
||||
@ -59,6 +61,8 @@
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
this.groupBox1.Controls.Add(this.buttonSortByType);
|
||||
this.groupBox1.Controls.Add(this.buttonSortByColor);
|
||||
this.groupBox1.Controls.Add(this.buttonRight);
|
||||
this.groupBox1.Controls.Add(this.buttonDown);
|
||||
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||
@ -76,6 +80,26 @@
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(15, 463);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonSortByType.TabIndex = 13;
|
||||
this.buttonSortByType.Text = "Сортировка по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(15, 428);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonSortByColor.TabIndex = 12;
|
||||
this.buttonSortByColor.Text = "Сортировка по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.ButtonSortByColor_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@ -126,7 +150,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(15, 426);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(15, 393);
|
||||
this.buttonShowOnMap.Name = "buttonShowOnMap";
|
||||
this.buttonShowOnMap.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonShowOnMap.TabIndex = 5;
|
||||
@ -136,7 +160,7 @@
|
||||
//
|
||||
// buttonShowStorage
|
||||
//
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(15, 391);
|
||||
this.buttonShowStorage.Location = new System.Drawing.Point(15, 358);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -146,16 +170,16 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(15, 320);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(15, 287);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27);
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(193, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 11;
|
||||
//
|
||||
// buttonRemoveBus
|
||||
//
|
||||
this.buttonRemoveBus.Location = new System.Drawing.Point(15, 353);
|
||||
this.buttonRemoveBus.Location = new System.Drawing.Point(15, 320);
|
||||
this.buttonRemoveBus.Name = "buttonRemoveBus";
|
||||
this.buttonRemoveBus.Size = new System.Drawing.Size(129, 32);
|
||||
this.buttonRemoveBus.Size = new System.Drawing.Size(193, 32);
|
||||
this.buttonRemoveBus.TabIndex = 2;
|
||||
this.buttonRemoveBus.Text = "Удалить автобус";
|
||||
this.buttonRemoveBus.UseVisualStyleBackColor = true;
|
||||
@ -163,9 +187,9 @@
|
||||
//
|
||||
// buttonAddBus
|
||||
//
|
||||
this.buttonAddBus.Location = new System.Drawing.Point(15, 281);
|
||||
this.buttonAddBus.Location = new System.Drawing.Point(15, 248);
|
||||
this.buttonAddBus.Name = "buttonAddBus";
|
||||
this.buttonAddBus.Size = new System.Drawing.Size(129, 33);
|
||||
this.buttonAddBus.Size = new System.Drawing.Size(193, 33);
|
||||
this.buttonAddBus.TabIndex = 1;
|
||||
this.buttonAddBus.Text = "Добавить автобус";
|
||||
this.buttonAddBus.UseVisualStyleBackColor = true;
|
||||
@ -265,14 +289,14 @@
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||
this.SaveToolStripMenuItem.Text = "Сохранение";
|
||||
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||
this.LoadToolStripMenuItem.Text = "Загрузка";
|
||||
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
|
||||
//
|
||||
@ -333,5 +357,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByType;
|
||||
private Button buttonSortByColor;
|
||||
}
|
||||
}
|
@ -276,5 +276,25 @@ namespace Bus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new BusCompareByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new BusCompareByType());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,4 +66,7 @@
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>311, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
@ -158,5 +158,10 @@ namespace Bus
|
||||
_setBus.Insert(DrawingObjectBus.Create(rec) as T);
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setBus.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -93,5 +93,14 @@ namespace Bus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user