Сортировка
This commit is contained in:
parent
e3ab4bf429
commit
75aeb9e0ec
78
Bus/Bus/BusComperyByColor.cs
Normal file
78
Bus/Bus/BusComperyByColor.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 BusComperyByColor : 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;
|
||||
}
|
||||
|
||||
var xEntity = xBus.GetBus.Bus;
|
||||
var yEntity = yBus.GetBus.Bus;
|
||||
//var colorCompare = xEntity.DopColor.ToArgb().CompareTo(yEntity.DopColor.ToArgb());
|
||||
|
||||
//int i = xEntity.DopColor.ToArgb();
|
||||
//int j = yEntity.DopColor.ToArgb();
|
||||
|
||||
/*if (colorCompare != 0)
|
||||
{
|
||||
return colorCompare;
|
||||
}*/
|
||||
|
||||
if (xEntity is EntitySportBus xEntityAirbus && yEntity is EntitySportBus yEntityAirbus)
|
||||
{
|
||||
var addColorCompare = xEntityAirbus.DopColor.ToArgb().CompareTo(yEntityAirbus.DopColor.ToArgb());
|
||||
|
||||
if (addColorCompare != 0)
|
||||
{
|
||||
return addColorCompare;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
63
Bus/Bus/BusComperyByType.cs
Normal file
63
Bus/Bus/BusComperyByType.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bus
|
||||
{
|
||||
internal class BusComperyByType : 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 == "DrawningAirbus")
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,8 @@ namespace Bus
|
||||
private DrawingBus _bus = null;
|
||||
public float Step => _bus?.Bus?.Step ?? 0;
|
||||
|
||||
public DrawingBus GetBus => _bus;
|
||||
|
||||
public DrawingObjectBus(DrawingBus bus)
|
||||
{
|
||||
_bus = bus;
|
||||
|
54
Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs
generated
54
Bus/Bus/FormMapWithSetDoubleDeckerBus.Designer.cs
generated
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.buttonSortByType = 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.buttonSortByColor);
|
||||
this.groupBox1.Controls.Add(this.buttonSortByType);
|
||||
this.groupBox1.Controls.Add(this.buttonRight);
|
||||
this.groupBox1.Controls.Add(this.buttonDown);
|
||||
this.groupBox1.Controls.Add(this.buttonLeft);
|
||||
@ -71,17 +75,37 @@
|
||||
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBox1.Location = new System.Drawing.Point(598, 28);
|
||||
this.groupBox1.Name = "groupBox1";
|
||||
this.groupBox1.Size = new System.Drawing.Size(250, 590);
|
||||
this.groupBox1.Size = new System.Drawing.Size(250, 650);
|
||||
this.groupBox1.TabIndex = 0;
|
||||
this.groupBox1.TabStop = false;
|
||||
this.groupBox1.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
this.buttonSortByColor.Location = new System.Drawing.Point(17, 299);
|
||||
this.buttonSortByColor.Name = "buttonSortByColor";
|
||||
this.buttonSortByColor.Size = new System.Drawing.Size(173, 29);
|
||||
this.buttonSortByColor.TabIndex = 13;
|
||||
this.buttonSortByColor.Text = "Сохранить по цвету";
|
||||
this.buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
this.buttonSortByType.Location = new System.Drawing.Point(16, 260);
|
||||
this.buttonSortByType.Name = "buttonSortByType";
|
||||
this.buttonSortByType.Size = new System.Drawing.Size(174, 29);
|
||||
this.buttonSortByType.TabIndex = 12;
|
||||
this.buttonSortByType.Text = "Сохранить по типу";
|
||||
this.buttonSortByType.UseVisualStyleBackColor = true;
|
||||
this.buttonSortByType.Click += new System.EventHandler(this.ButtonSortByType_Click);
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::Bus.Properties.Resources.Frame_4;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(95, 538);
|
||||
this.buttonRight.Location = new System.Drawing.Point(95, 598);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonRight.TabIndex = 10;
|
||||
@ -93,7 +117,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::Bus.Properties.Resources.Frame_5;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(55, 538);
|
||||
this.buttonDown.Location = new System.Drawing.Point(55, 598);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonDown.TabIndex = 9;
|
||||
@ -105,7 +129,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::Bus.Properties.Resources.Frame_6;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(15, 538);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(15, 598);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonLeft.TabIndex = 8;
|
||||
@ -117,7 +141,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::Bus.Properties.Resources.Frame_3;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(55, 498);
|
||||
this.buttonUp.Location = new System.Drawing.Point(55, 558);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(40, 40);
|
||||
this.buttonUp.TabIndex = 7;
|
||||
@ -126,7 +150,7 @@
|
||||
//
|
||||
// buttonShowOnMap
|
||||
//
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(15, 426);
|
||||
this.buttonShowOnMap.Location = new System.Drawing.Point(15, 523);
|
||||
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, 488);
|
||||
this.buttonShowStorage.Name = "buttonShowStorage";
|
||||
this.buttonShowStorage.Size = new System.Drawing.Size(193, 29);
|
||||
this.buttonShowStorage.TabIndex = 4;
|
||||
@ -146,14 +170,14 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(15, 320);
|
||||
this.maskedTextBoxPosition.Location = new System.Drawing.Point(15, 417);
|
||||
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
this.maskedTextBoxPosition.Size = new System.Drawing.Size(100, 27);
|
||||
this.maskedTextBoxPosition.TabIndex = 11;
|
||||
//
|
||||
// buttonRemoveBus
|
||||
//
|
||||
this.buttonRemoveBus.Location = new System.Drawing.Point(15, 353);
|
||||
this.buttonRemoveBus.Location = new System.Drawing.Point(15, 450);
|
||||
this.buttonRemoveBus.Name = "buttonRemoveBus";
|
||||
this.buttonRemoveBus.Size = new System.Drawing.Size(129, 32);
|
||||
this.buttonRemoveBus.TabIndex = 2;
|
||||
@ -163,7 +187,7 @@
|
||||
//
|
||||
// buttonAddBus
|
||||
//
|
||||
this.buttonAddBus.Location = new System.Drawing.Point(15, 281);
|
||||
this.buttonAddBus.Location = new System.Drawing.Point(15, 378);
|
||||
this.buttonAddBus.Name = "buttonAddBus";
|
||||
this.buttonAddBus.Size = new System.Drawing.Size(129, 33);
|
||||
this.buttonAddBus.TabIndex = 1;
|
||||
@ -188,7 +212,7 @@
|
||||
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.pictureBox.Location = new System.Drawing.Point(0, 28);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(598, 590);
|
||||
this.pictureBox.Size = new System.Drawing.Size(598, 650);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
@ -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);
|
||||
//
|
||||
@ -288,7 +312,7 @@
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(848, 618);
|
||||
this.ClientSize = new System.Drawing.Size(848, 678);
|
||||
this.Controls.Add(this.groupBox2);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBox1);
|
||||
@ -333,5 +357,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -66,7 +66,7 @@ namespace Bus
|
||||
map = new MyMap();
|
||||
break;
|
||||
}
|
||||
if(map != null)
|
||||
if (map != null)
|
||||
{
|
||||
_mapBusCollectionGeneric = new MapWithSetDoubleDeckerBusGeneric<DrawingObjectBus, AbstractMap>(pictureBox.Width, pictureBox.Height, map);
|
||||
}
|
||||
@ -272,5 +272,27 @@ namespace Bus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxMaps.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new BusComperyByType());
|
||||
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 BusComperyByColor());
|
||||
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,6 +92,11 @@ namespace Bus
|
||||
}
|
||||
}
|
||||
|
||||
public void Sort(IComparer<T> comparer)
|
||||
{
|
||||
_setBus.SortSet(comparer);
|
||||
}
|
||||
|
||||
private void DrawBackground(Graphics g)
|
||||
{
|
||||
Pen pen = new(Color.Black, 3);
|
||||
|
@ -94,5 +94,15 @@ namespace Bus
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user