PIbd-22. Stroev V.M. Lab Work 08 #10
50
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
50
Monorail/Monorail/FormMonorailCollection.Designer.cs
generated
@ -30,6 +30,8 @@
|
|||||||
{
|
{
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
panel1 = new Panel();
|
panel1 = new Panel();
|
||||||
|
ButtonSortByColor = new Button();
|
||||||
|
ButtonSortByType = new Button();
|
||||||
panel2 = new Panel();
|
panel2 = new Panel();
|
||||||
label2 = new Label();
|
label2 = new Label();
|
||||||
listBoxStorages = new ListBox();
|
listBoxStorages = new ListBox();
|
||||||
@ -64,6 +66,8 @@
|
|||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
panel1.BackColor = SystemColors.Info;
|
panel1.BackColor = SystemColors.Info;
|
||||||
|
panel1.Controls.Add(ButtonSortByColor);
|
||||||
|
panel1.Controls.Add(ButtonSortByType);
|
||||||
panel1.Controls.Add(panel2);
|
panel1.Controls.Add(panel2);
|
||||||
panel1.Controls.Add(maskedTextBoxNumber);
|
panel1.Controls.Add(maskedTextBoxNumber);
|
||||||
panel1.Controls.Add(buttonRefreshCol);
|
panel1.Controls.Add(buttonRefreshCol);
|
||||||
@ -75,6 +79,28 @@
|
|||||||
panel1.Size = new Size(204, 517);
|
panel1.Size = new Size(204, 517);
|
||||||
panel1.TabIndex = 4;
|
panel1.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// ButtonSortByColor
|
||||||
|
//
|
||||||
|
ButtonSortByColor.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
ButtonSortByColor.Location = new Point(12, 293);
|
||||||
|
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||||
|
ButtonSortByColor.Size = new Size(179, 41);
|
||||||
|
ButtonSortByColor.TabIndex = 9;
|
||||||
|
ButtonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// ButtonSortByType
|
||||||
|
//
|
||||||
|
ButtonSortByType.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
|
ButtonSortByType.Location = new Point(12, 246);
|
||||||
|
ButtonSortByType.Name = "ButtonSortByType";
|
||||||
|
ButtonSortByType.Size = new Size(179, 41);
|
||||||
|
ButtonSortByType.TabIndex = 8;
|
||||||
|
ButtonSortByType.Text = "Сортировка по типу";
|
||||||
|
ButtonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||||
|
//
|
||||||
// panel2
|
// panel2
|
||||||
//
|
//
|
||||||
panel2.Controls.Add(label2);
|
panel2.Controls.Add(label2);
|
||||||
@ -84,7 +110,7 @@
|
|||||||
panel2.Controls.Add(ButtonAddObject);
|
panel2.Controls.Add(ButtonAddObject);
|
||||||
panel2.Location = new Point(12, 20);
|
panel2.Location = new Point(12, 20);
|
||||||
panel2.Name = "panel2";
|
panel2.Name = "panel2";
|
||||||
panel2.Size = new Size(179, 263);
|
panel2.Size = new Size(179, 209);
|
||||||
panel2.TabIndex = 7;
|
panel2.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// label2
|
// label2
|
||||||
@ -100,15 +126,15 @@
|
|||||||
//
|
//
|
||||||
listBoxStorages.FormattingEnabled = true;
|
listBoxStorages.FormattingEnabled = true;
|
||||||
listBoxStorages.ItemHeight = 20;
|
listBoxStorages.ItemHeight = 20;
|
||||||
listBoxStorages.Location = new Point(17, 109);
|
listBoxStorages.Location = new Point(17, 85);
|
||||||
listBoxStorages.Name = "listBoxStorages";
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
listBoxStorages.Size = new Size(144, 104);
|
listBoxStorages.Size = new Size(144, 84);
|
||||||
listBoxStorages.TabIndex = 9;
|
listBoxStorages.TabIndex = 9;
|
||||||
listBoxStorages.Click += ListBoxObjects_SelectedIndexChanged;
|
listBoxStorages.Click += ListBoxObjects_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// textBoxStorageName
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
textBoxStorageName.Location = new Point(18, 29);
|
textBoxStorageName.Location = new Point(17, 20);
|
||||||
textBoxStorageName.Name = "textBoxStorageName";
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
textBoxStorageName.Size = new Size(143, 27);
|
textBoxStorageName.Size = new Size(143, 27);
|
||||||
textBoxStorageName.TabIndex = 8;
|
textBoxStorageName.TabIndex = 8;
|
||||||
@ -116,9 +142,9 @@
|
|||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
button1.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
button1.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
button1.Location = new Point(18, 219);
|
button1.Location = new Point(16, 174);
|
||||||
button1.Name = "button1";
|
button1.Name = "button1";
|
||||||
button1.Size = new Size(143, 41);
|
button1.Size = new Size(143, 26);
|
||||||
button1.TabIndex = 5;
|
button1.TabIndex = 5;
|
||||||
button1.Text = "Удалить набор";
|
button1.Text = "Удалить набор";
|
||||||
button1.UseVisualStyleBackColor = true;
|
button1.UseVisualStyleBackColor = true;
|
||||||
@ -127,9 +153,9 @@
|
|||||||
// ButtonAddObject
|
// ButtonAddObject
|
||||||
//
|
//
|
||||||
ButtonAddObject.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
ButtonAddObject.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
ButtonAddObject.Location = new Point(18, 62);
|
ButtonAddObject.Location = new Point(18, 51);
|
||||||
ButtonAddObject.Name = "ButtonAddObject";
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
ButtonAddObject.Size = new Size(143, 41);
|
ButtonAddObject.Size = new Size(143, 27);
|
||||||
ButtonAddObject.TabIndex = 6;
|
ButtonAddObject.TabIndex = 6;
|
||||||
ButtonAddObject.Text = "Добавить набор";
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
ButtonAddObject.UseVisualStyleBackColor = true;
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
@ -137,7 +163,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(30, 336);
|
maskedTextBoxNumber.Location = new Point(30, 387);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 4;
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
@ -156,7 +182,7 @@
|
|||||||
// buttonDelMonorail
|
// buttonDelMonorail
|
||||||
//
|
//
|
||||||
buttonDelMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonDelMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonDelMonorail.Location = new Point(12, 369);
|
buttonDelMonorail.Location = new Point(12, 418);
|
||||||
buttonDelMonorail.Name = "buttonDelMonorail";
|
buttonDelMonorail.Name = "buttonDelMonorail";
|
||||||
buttonDelMonorail.Size = new Size(179, 41);
|
buttonDelMonorail.Size = new Size(179, 41);
|
||||||
buttonDelMonorail.TabIndex = 2;
|
buttonDelMonorail.TabIndex = 2;
|
||||||
@ -167,7 +193,7 @@
|
|||||||
// buttonAddMonorail
|
// buttonAddMonorail
|
||||||
//
|
//
|
||||||
buttonAddMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
buttonAddMonorail.Font = new Font("Segoe UI", 7.8F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
buttonAddMonorail.Location = new Point(12, 289);
|
buttonAddMonorail.Location = new Point(12, 340);
|
||||||
buttonAddMonorail.Name = "buttonAddMonorail";
|
buttonAddMonorail.Name = "buttonAddMonorail";
|
||||||
buttonAddMonorail.Size = new Size(179, 41);
|
buttonAddMonorail.Size = new Size(179, 41);
|
||||||
buttonAddMonorail.TabIndex = 1;
|
buttonAddMonorail.TabIndex = 1;
|
||||||
@ -269,5 +295,7 @@
|
|||||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button ButtonSortByColor;
|
||||||
|
private Button ButtonSortByType;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -25,6 +25,11 @@ namespace Monorail
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
readonly int countPlace = 22;
|
readonly int countPlace = 22;
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e) =>
|
||||||
|
CompareMonorails(new MonorailCompareByType());
|
||||||
|
private void ButtonSortByColor_Click(object sender, EventArgs e) =>
|
||||||
|
CompareMonorails(new MonorailCompareByColor());
|
||||||
|
|
||||||
public FormMonorailCollection(ILogger<FormMonorailCollection> logger)
|
public FormMonorailCollection(ILogger<FormMonorailCollection> logger)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -38,7 +43,7 @@ namespace Monorail
|
|||||||
listBoxStorages.Items.Clear();
|
listBoxStorages.Items.Clear();
|
||||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
{
|
{
|
||||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
listBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||||
}
|
}
|
||||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||||
>= listBoxStorages.Items.Count))
|
>= listBoxStorages.Items.Count))
|
||||||
@ -71,6 +76,22 @@ EventArgs e)
|
|||||||
pictureBoxCollection.Image =
|
pictureBoxCollection.Image =
|
||||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowMonorails();
|
||||||
}
|
}
|
||||||
|
private void CompareMonorails(IComparer<DrawningMonorail?> comparer)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxStorages.SelectedIndex == -1)
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
@ -84,7 +105,7 @@ EventArgs e)
|
|||||||
"Удаление", MessageBoxButtons.YesNo,
|
"Удаление", MessageBoxButtons.YesNo,
|
||||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
_storage.DelSet(name);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
_logger.LogInformation($"Удален набор: {name}");
|
_logger.LogInformation($"Удален набор: {name}");
|
||||||
}
|
}
|
||||||
@ -129,10 +150,16 @@ EventArgs e)
|
|||||||
}
|
}
|
||||||
catch (StorageOverflowException ex)
|
catch (StorageOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка",
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogWarning(ex.Message);
|
_logger.LogWarning(ex.Message);
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Такой монорельс уже существует", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
_logger.LogWarning("Такой монорельс уже существует");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void ButtonRemoveMonorail_Click(object sender, EventArgs e)
|
private void ButtonRemoveMonorail_Click(object sender, EventArgs e)
|
||||||
@ -165,14 +192,16 @@ EventArgs e)
|
|||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
var curObj = obj - pos;
|
var curObj = obj - pos;
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = obj.ShowMonorails();
|
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||||
_logger.LogInformation($"Объект удален по позиции: {pos}");
|
_logger.LogInformation($"Объект удален по позиции: {pos}");
|
||||||
}catch(MonorailNotFoundException ex)
|
}
|
||||||
|
catch (MonorailNotFoundException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Ошибка",
|
MessageBox.Show(ex.Message, "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogWarning($"Не удалось удалить объект по позиции {pos}");
|
_logger.LogWarning($"Не удалось удалить объект по позиции {pos}");
|
||||||
}
|
}
|
||||||
|
65
Monorail/Monorail/Generics/DrawningMonorailEqutables.cs
Normal file
65
Monorail/Monorail/Generics/DrawningMonorailEqutables.cs
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.Entities;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class DrawningMonorailEqutables : IEqualityComparer<DrawningMonorail?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningMonorail? x, DrawningMonorail? y)
|
||||||
|
{
|
||||||
|
if(x==null || x.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityMonorail.Speed != y.EntityMonorail.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityMonorail.Weight != y.EntityMonorail.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityMonorail.BodyColor != y.EntityMonorail.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is DrawningSecondMonorail && y is DrawningSecondMonorail)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
EntitySecondMonorail entityX = (EntitySecondMonorail)x.EntityMonorail;
|
||||||
|
EntitySecondMonorail entityY = (EntitySecondMonorail)y.EntityMonorail;
|
||||||
|
if(entityX.AdditionalColor != entityY.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(entityX.Monorails != entityY.Monorails)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(entityX.SecondCabin != entityY.SecondCabin)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] DrawningMonorail obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
52
Monorail/Monorail/Generics/MonorailCompareByColor.cs
Normal file
52
Monorail/Monorail/Generics/MonorailCompareByColor.cs
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
using Monorail.Entities;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class MonorailCompareByColor : IComparer<DrawningMonorail?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningMonorail? x, DrawningMonorail? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if(x.EntityMonorail.BodyColor.Name != y.EntityMonorail.BodyColor.Name)
|
||||||
|
{
|
||||||
|
return x.EntityMonorail.BodyColor.Name.CompareTo(y.EntityMonorail.BodyColor.Name);
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
if (x is DrawningMonorail)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x.GetType().Name == y.GetType().Name && x is DrawningSecondMonorail)
|
||||||
|
{
|
||||||
|
EntitySecondMonorail entityX = (EntitySecondMonorail)x.EntityMonorail;
|
||||||
|
EntitySecondMonorail entityY = (EntitySecondMonorail)y.EntityMonorail;
|
||||||
|
if (entityX.AdditionalColor.Name != entityY.AdditionalColor.Name)
|
||||||
|
{
|
||||||
|
return entityX.AdditionalColor.Name.CompareTo(entityY.AdditionalColor.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var speedCompare =
|
||||||
|
x.EntityMonorail.Speed.CompareTo(y.EntityMonorail.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityMonorail.Weight.CompareTo(y.EntityMonorail.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
35
Monorail/Monorail/Generics/MonorailCompareByType.cs
Normal file
35
Monorail/Monorail/Generics/MonorailCompareByType.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Monorail.DrawningObjects;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class MonorailCompareByType : IComparer<DrawningMonorail?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningMonorail? x, DrawningMonorail? y)
|
||||||
|
{
|
||||||
|
if(x == null || x.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityMonorail == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
var speedCompare =
|
||||||
|
x.EntityMonorail.Speed.CompareTo(y.EntityMonorail.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityMonorail.Weight.CompareTo(y.EntityMonorail.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
Monorail/Monorail/Generics/MonorailsCollectionInfo.cs
Normal file
28
Monorail/Monorail/Generics/MonorailsCollectionInfo.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Monorail.Generics
|
||||||
|
{
|
||||||
|
internal class MonorailsCollectionInfo : IEquatable<MonorailsCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public MonorailsCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(MonorailsCollectionInfo? other)
|
||||||
|
{
|
||||||
|
return Name == other?.Name;
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,9 @@ namespace Monorail.Generics
|
|||||||
private readonly int _placeSizeWidth = 295;
|
private readonly int _placeSizeWidth = 295;
|
||||||
private readonly int _placeSizeHeight = 65;
|
private readonly int _placeSizeHeight = 65;
|
||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
public void Sort(IComparer<T?> comparer) =>
|
||||||
|
_collection.SortSet(comparer);
|
||||||
public MonorailsGenericCollection(int picWidth, int picHeight)
|
public MonorailsGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
@ -26,13 +29,13 @@ namespace Monorail.Generics
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
public static int operator +(MonorailsGenericCollection<T, U> collect, T? obj)
|
public static int operator +(MonorailsGenericCollection<T, U> collect, T obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return collect._collection.Insert(obj);
|
return collect?._collection.Insert(obj, new DrawningMonorailEqutables()) ?? -1;
|
||||||
}
|
}
|
||||||
public static T? operator -(MonorailsGenericCollection<T, U> collect, int pos)
|
public static T? operator -(MonorailsGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
|
@ -14,14 +14,14 @@ namespace Monorail.Generics
|
|||||||
private readonly char _separatorRecords = ';';
|
private readonly char _separatorRecords = ';';
|
||||||
private static readonly char _separatorForObject = ':';
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
readonly Dictionary<string, MonorailsGenericCollection<DrawningMonorail,
|
readonly Dictionary<MonorailsCollectionInfo, MonorailsGenericCollection<DrawningMonorail,
|
||||||
DrawningObjectMonorail>> _monorailsStorages;
|
DrawningObjectMonorail>> _monorailsStorages;
|
||||||
public List<string> Keys => _monorailsStorages.Keys.ToList();
|
public List<MonorailsCollectionInfo> Keys => _monorailsStorages.Keys.ToList();
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
public MonorailsGenericStorage(int pictureWidth, int pictureHeight)
|
public MonorailsGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_monorailsStorages = new Dictionary<string, MonorailsGenericCollection<DrawningMonorail,
|
_monorailsStorages = new Dictionary<MonorailsCollectionInfo, MonorailsGenericCollection<DrawningMonorail,
|
||||||
DrawningObjectMonorail>>();
|
DrawningObjectMonorail>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight; ;
|
_pictureHeight = pictureHeight; ;
|
||||||
@ -29,27 +29,34 @@ namespace Monorail.Generics
|
|||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
//TO DO
|
//TO DO
|
||||||
_monorailsStorages.Add(name, new MonorailsGenericCollection<DrawningMonorail,
|
if(_monorailsStorages.ContainsKey(new MonorailsCollectionInfo(name, string.Empty)))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Словарь уже имеет объект с таким названием", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_monorailsStorages.Add(new MonorailsCollectionInfo(name, string.Empty),
|
||||||
|
new MonorailsGenericCollection<DrawningMonorail,
|
||||||
DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
|
DrawningObjectMonorail>(_pictureWidth, _pictureHeight));
|
||||||
}
|
}
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
if (_monorailsStorages[name] == null)
|
if (_monorailsStorages[new MonorailsCollectionInfo(name, string.Empty)] == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_monorailsStorages.Remove(name);
|
_monorailsStorages.Remove(new MonorailsCollectionInfo(name, string.Empty));
|
||||||
}
|
}
|
||||||
public MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>? this[string ind]
|
public MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail> this[string ind]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
//TO DO
|
MonorailsCollectionInfo index = new MonorailsCollectionInfo(ind, string.Empty);
|
||||||
if (_monorailsStorages[ind] == null)
|
if (_monorailsStorages.ContainsKey(index))
|
||||||
{
|
{
|
||||||
return null;
|
return _monorailsStorages[index];
|
||||||
}
|
}
|
||||||
return _monorailsStorages[ind];
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
@ -60,7 +67,7 @@ namespace Monorail.Generics
|
|||||||
}
|
}
|
||||||
StringBuilder data = new();
|
StringBuilder data = new();
|
||||||
|
|
||||||
foreach (KeyValuePair<string,MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>>
|
foreach (KeyValuePair<MonorailsCollectionInfo,MonorailsGenericCollection<DrawningMonorail, DrawningObjectMonorail>>
|
||||||
record in _monorailsStorages)
|
record in _monorailsStorages)
|
||||||
{
|
{
|
||||||
StringBuilder records = new();
|
StringBuilder records = new();
|
||||||
@ -68,7 +75,7 @@ namespace Monorail.Generics
|
|||||||
{
|
{
|
||||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
}
|
}
|
||||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||||
}
|
}
|
||||||
if (data.Length == 0)
|
if (data.Length == 0)
|
||||||
{
|
{
|
||||||
@ -122,7 +129,7 @@ namespace Monorail.Generics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_monorailsStorages.Add(record[0], collection);
|
_monorailsStorages.Add(new MonorailsCollectionInfo(record[0], string.Empty), collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -18,11 +19,16 @@ namespace Monorail.Generics
|
|||||||
_maxCount = count;
|
_maxCount = count;
|
||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
public int Insert(T monorail)
|
public void SortSet(IComparer<T?> comparer) =>
|
||||||
|
_places.Sort(comparer);
|
||||||
|
public int Insert(T monorail, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
return Insert(monorail, 0);
|
if (_places.Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
Insert(monorail, 0, equal);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
public int Insert(T monorail, int position)
|
public bool Insert(T monorail, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount || position >= _maxCount)
|
if (Count == _maxCount || position >= _maxCount)
|
||||||
throw new StorageOverflowException(Count);
|
throw new StorageOverflowException(Count);
|
||||||
@ -30,16 +36,13 @@ namespace Monorail.Generics
|
|||||||
if (position < 0 || monorail == null)
|
if (position < 0 || monorail == null)
|
||||||
throw new StorageOverflowException("Ошибка. Объект не найден или введённый " +
|
throw new StorageOverflowException("Ошибка. Объект не найден или введённый " +
|
||||||
"номер позиции = отрицательное число");
|
"номер позиции = отрицательное число");
|
||||||
|
if (equal != null)
|
||||||
if (Count == 0)
|
|
||||||
{
|
{
|
||||||
_places.Add(monorail);
|
if (_places.Contains(monorail, equal))
|
||||||
|
throw new ArgumentException(nameof(monorail));
|
||||||
}
|
}
|
||||||
else
|
_places.Insert(position, monorail);
|
||||||
{
|
return true;
|
||||||
_places.Insert(position, monorail);
|
|
||||||
}
|
|
||||||
return Count;
|
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user