Добавили сортировку
This commit is contained in:
parent
5c7b6d8bf2
commit
996797c794
@ -130,5 +130,11 @@ namespace ProjectLiner.CollectionGenericObjects
|
|||||||
/// Расстановка объектов
|
/// Расстановка объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void SetObjectsPosition();
|
protected abstract void SetObjectsPosition();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
public void Sort(IComparer<DrawningCommonLiner?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -104,5 +104,10 @@ namespace ProjectLiner.CollectionGenericObjects
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
_collection.Sort(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,5 +147,9 @@ namespace ProjectLiner.CollectionGenericObjects
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
Array.Sort(_collection, comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectLiner.Drawnings;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сравнение по цвету, скорости, весу
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningLinerCompareByColor : IComparer<DrawningCommonLiner?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningCommonLiner? x, DrawningCommonLiner? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCommonLiner == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityCommonLiner == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var bodycolorCompare = x.EntityCommonLiner.BodyColor.Name.CompareTo(y.EntityCommonLiner.BodyColor.Name);
|
||||||
|
if (bodycolorCompare != 0)
|
||||||
|
{
|
||||||
|
return bodycolorCompare;
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityCommonLiner.Speed.CompareTo(y.EntityCommonLiner.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityCommonLiner.Weight.CompareTo(y.EntityCommonLiner.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -52,6 +52,8 @@
|
|||||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
openFileDialog = new OpenFileDialog();
|
openFileDialog = new OpenFileDialog();
|
||||||
saveFileDialog = new SaveFileDialog();
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
|
buttonSortByType = new Button();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
panelStorage.SuspendLayout();
|
panelStorage.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
@ -67,7 +69,7 @@
|
|||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(1052, 49);
|
groupBoxTools.Location = new Point(1052, 49);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(272, 1014);
|
groupBoxTools.Size = new Size(272, 1140);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
@ -190,7 +192,7 @@
|
|||||||
//
|
//
|
||||||
pictureBox.Dock = DockStyle.Bottom;
|
pictureBox.Dock = DockStyle.Bottom;
|
||||||
pictureBox.Enabled = false;
|
pictureBox.Enabled = false;
|
||||||
pictureBox.Location = new Point(0, 51);
|
pictureBox.Location = new Point(0, 177);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(1052, 1012);
|
pictureBox.Size = new Size(1052, 1012);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
@ -199,6 +201,8 @@
|
|||||||
// panelCompanyTools
|
// panelCompanyTools
|
||||||
//
|
//
|
||||||
panelCompanyTools.BackColor = SystemColors.Window;
|
panelCompanyTools.BackColor = SystemColors.Window;
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||||
panelCompanyTools.Controls.Add(buttonAddLiner);
|
panelCompanyTools.Controls.Add(buttonAddLiner);
|
||||||
panelCompanyTools.Controls.Add(maskedTextBox1);
|
panelCompanyTools.Controls.Add(maskedTextBox1);
|
||||||
panelCompanyTools.Controls.Add(button5);
|
panelCompanyTools.Controls.Add(button5);
|
||||||
@ -207,14 +211,14 @@
|
|||||||
panelCompanyTools.Location = new Point(1052, 592);
|
panelCompanyTools.Location = new Point(1052, 592);
|
||||||
panelCompanyTools.Margin = new Padding(5);
|
panelCompanyTools.Margin = new Padding(5);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(272, 470);
|
panelCompanyTools.Size = new Size(272, 589);
|
||||||
panelCompanyTools.TabIndex = 9;
|
panelCompanyTools.TabIndex = 9;
|
||||||
//
|
//
|
||||||
// buttonAddLiner
|
// buttonAddLiner
|
||||||
//
|
//
|
||||||
buttonAddLiner.Location = new Point(6, 54);
|
buttonAddLiner.Location = new Point(6, 54);
|
||||||
buttonAddLiner.Name = "buttonAddLiner";
|
buttonAddLiner.Name = "buttonAddLiner";
|
||||||
buttonAddLiner.Size = new Size(214, 75);
|
buttonAddLiner.Size = new Size(242, 75);
|
||||||
buttonAddLiner.TabIndex = 7;
|
buttonAddLiner.TabIndex = 7;
|
||||||
buttonAddLiner.Text = "Добавить";
|
buttonAddLiner.Text = "Добавить";
|
||||||
buttonAddLiner.UseVisualStyleBackColor = true;
|
buttonAddLiner.UseVisualStyleBackColor = true;
|
||||||
@ -225,7 +229,7 @@
|
|||||||
maskedTextBox1.Location = new Point(3, 167);
|
maskedTextBox1.Location = new Point(3, 167);
|
||||||
maskedTextBox1.Mask = "00";
|
maskedTextBox1.Mask = "00";
|
||||||
maskedTextBox1.Name = "maskedTextBox1";
|
maskedTextBox1.Name = "maskedTextBox1";
|
||||||
maskedTextBox1.Size = new Size(217, 47);
|
maskedTextBox1.Size = new Size(245, 47);
|
||||||
maskedTextBox1.TabIndex = 3;
|
maskedTextBox1.TabIndex = 3;
|
||||||
maskedTextBox1.ValidatingType = typeof(int);
|
maskedTextBox1.ValidatingType = typeof(int);
|
||||||
//
|
//
|
||||||
@ -234,7 +238,7 @@
|
|||||||
button5.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
button5.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
button5.Location = new Point(3, 384);
|
button5.Location = new Point(3, 384);
|
||||||
button5.Name = "button5";
|
button5.Name = "button5";
|
||||||
button5.Size = new Size(216, 75);
|
button5.Size = new Size(245, 75);
|
||||||
button5.TabIndex = 6;
|
button5.TabIndex = 6;
|
||||||
button5.Text = "Обновить";
|
button5.Text = "Обновить";
|
||||||
button5.UseVisualStyleBackColor = true;
|
button5.UseVisualStyleBackColor = true;
|
||||||
@ -245,7 +249,7 @@
|
|||||||
button3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
button3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
button3.Location = new Point(3, 220);
|
button3.Location = new Point(3, 220);
|
||||||
button3.Name = "button3";
|
button3.Name = "button3";
|
||||||
button3.Size = new Size(216, 75);
|
button3.Size = new Size(245, 75);
|
||||||
button3.TabIndex = 4;
|
button3.TabIndex = 4;
|
||||||
button3.Text = "Удаление Лайнера";
|
button3.Text = "Удаление Лайнера";
|
||||||
button3.UseVisualStyleBackColor = true;
|
button3.UseVisualStyleBackColor = true;
|
||||||
@ -256,7 +260,7 @@
|
|||||||
button4.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
button4.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
button4.Location = new Point(3, 302);
|
button4.Location = new Point(3, 302);
|
||||||
button4.Name = "button4";
|
button4.Name = "button4";
|
||||||
button4.Size = new Size(216, 75);
|
button4.Size = new Size(245, 75);
|
||||||
button4.TabIndex = 5;
|
button4.TabIndex = 5;
|
||||||
button4.Text = "Передать на тесты";
|
button4.Text = "Передать на тесты";
|
||||||
button4.UseVisualStyleBackColor = true;
|
button4.UseVisualStyleBackColor = true;
|
||||||
@ -304,11 +308,35 @@
|
|||||||
//
|
//
|
||||||
saveFileDialog.Filter = "txt file | *.txt";
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByColor.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
buttonSortByColor.Location = new Point(3, 526);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(245, 44);
|
||||||
|
buttonSortByColor.TabIndex = 9;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByType.Font = new Font("Segoe UI", 9.818182F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
buttonSortByType.Location = new Point(4, 476);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(244, 44);
|
||||||
|
buttonSortByType.TabIndex = 8;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
// FormLinerCollection
|
// FormLinerCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(17F, 41F);
|
AutoScaleDimensions = new SizeF(17F, 41F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1324, 1063);
|
ClientSize = new Size(1324, 1189);
|
||||||
Controls.Add(panelCompanyTools);
|
Controls.Add(panelCompanyTools);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
@ -358,5 +386,7 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -325,5 +325,32 @@ namespace ProjectLiner
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e) => CompareTrucks(new DrawningLinerCompareByType());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по цвету
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e) => CompareTrucks(new DrawningLinerCompareByColor());
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по сравнителю
|
||||||
|
/// </summary>
|
||||||
|
private void CompareTrucks(IComparer<DrawningCommonLiner?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user