Доработка классов. Готовая лаба.
This commit is contained in:
parent
ec986c5a2c
commit
caf208b305
@ -25,6 +25,8 @@ namespace ProjectBulldozer
|
|||||||
сохранитьToolStripMenuItem = new ToolStripMenuItem();
|
сохранитьToolStripMenuItem = new ToolStripMenuItem();
|
||||||
загрузитьToolStripMenuItem = new ToolStripMenuItem();
|
загрузитьToolStripMenuItem = new ToolStripMenuItem();
|
||||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||||
|
ButtonSortByType = new Button();
|
||||||
|
ButtonSortByColor = new Button();
|
||||||
((ISupportInitialize)pictureBoxCollections).BeginInit();
|
((ISupportInitialize)pictureBoxCollections).BeginInit();
|
||||||
groupBox1.SuspendLayout();
|
groupBox1.SuspendLayout();
|
||||||
Instruments.SuspendLayout();
|
Instruments.SuspendLayout();
|
||||||
@ -34,17 +36,17 @@ namespace ProjectBulldozer
|
|||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
maskedTextBoxNumber.Location = new Point(33, 356);
|
maskedTextBoxNumber.Location = new Point(35, 379);
|
||||||
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
|
maskedTextBoxNumber.Margin = new Padding(3, 2, 3, 2);
|
||||||
maskedTextBoxNumber.Mask = "00";
|
maskedTextBoxNumber.Mask = "00";
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(131, 23);
|
maskedTextBoxNumber.Size = new Size(132, 23);
|
||||||
maskedTextBoxNumber.TabIndex = 4;
|
maskedTextBoxNumber.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonRefreshCollection.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonRefreshCollection.Location = new Point(33, 499);
|
ButtonRefreshCollection.Location = new Point(33, 441);
|
||||||
ButtonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
|
ButtonRefreshCollection.Margin = new Padding(3, 2, 3, 2);
|
||||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
ButtonRefreshCollection.Size = new Size(131, 31);
|
ButtonRefreshCollection.Size = new Size(131, 31);
|
||||||
@ -56,7 +58,7 @@ namespace ProjectBulldozer
|
|||||||
// ButtonRemoveTractor
|
// ButtonRemoveTractor
|
||||||
//
|
//
|
||||||
ButtonRemoveTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonRemoveTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonRemoveTractor.Location = new Point(33, 393);
|
ButtonRemoveTractor.Location = new Point(35, 406);
|
||||||
ButtonRemoveTractor.Margin = new Padding(3, 2, 3, 2);
|
ButtonRemoveTractor.Margin = new Padding(3, 2, 3, 2);
|
||||||
ButtonRemoveTractor.Name = "ButtonRemoveTractor";
|
ButtonRemoveTractor.Name = "ButtonRemoveTractor";
|
||||||
ButtonRemoveTractor.Size = new Size(131, 31);
|
ButtonRemoveTractor.Size = new Size(131, 31);
|
||||||
@ -68,7 +70,7 @@ namespace ProjectBulldozer
|
|||||||
// ButtonAddTractor
|
// ButtonAddTractor
|
||||||
//
|
//
|
||||||
ButtonAddTractor.Anchor = AnchorStyles.Top;
|
ButtonAddTractor.Anchor = AnchorStyles.Top;
|
||||||
ButtonAddTractor.Location = new Point(33, 323);
|
ButtonAddTractor.Location = new Point(35, 337);
|
||||||
ButtonAddTractor.Margin = new Padding(3, 2, 3, 2);
|
ButtonAddTractor.Margin = new Padding(3, 2, 3, 2);
|
||||||
ButtonAddTractor.Name = "ButtonAddTractor";
|
ButtonAddTractor.Name = "ButtonAddTractor";
|
||||||
ButtonAddTractor.Size = new Size(131, 29);
|
ButtonAddTractor.Size = new Size(131, 29);
|
||||||
@ -83,14 +85,14 @@ namespace ProjectBulldozer
|
|||||||
pictureBoxCollections.Location = new Point(0, 26);
|
pictureBoxCollections.Location = new Point(0, 26);
|
||||||
pictureBoxCollections.Margin = new Padding(3, 2, 3, 2);
|
pictureBoxCollections.Margin = new Padding(3, 2, 3, 2);
|
||||||
pictureBoxCollections.Name = "pictureBoxCollections";
|
pictureBoxCollections.Name = "pictureBoxCollections";
|
||||||
pictureBoxCollections.Size = new Size(697, 404);
|
pictureBoxCollections.Size = new Size(697, 474);
|
||||||
pictureBoxCollections.TabIndex = 1;
|
pictureBoxCollections.TabIndex = 1;
|
||||||
pictureBoxCollections.TabStop = false;
|
pictureBoxCollections.TabStop = false;
|
||||||
pictureBoxCollections.Click += pictureBoxCollections_Click;
|
pictureBoxCollections.Click += pictureBoxCollections_Click;
|
||||||
//
|
//
|
||||||
// textBoxStorageName
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
textBoxStorageName.Location = new Point(27, 32);
|
textBoxStorageName.Location = new Point(27, 22);
|
||||||
textBoxStorageName.Name = "textBoxStorageName";
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
textBoxStorageName.Size = new Size(131, 23);
|
textBoxStorageName.Size = new Size(131, 23);
|
||||||
textBoxStorageName.TabIndex = 5;
|
textBoxStorageName.TabIndex = 5;
|
||||||
@ -103,7 +105,7 @@ namespace ProjectBulldozer
|
|||||||
groupBox1.Controls.Add(textBoxStorageName);
|
groupBox1.Controls.Add(textBoxStorageName);
|
||||||
groupBox1.Location = new Point(6, 22);
|
groupBox1.Location = new Point(6, 22);
|
||||||
groupBox1.Name = "groupBox1";
|
groupBox1.Name = "groupBox1";
|
||||||
groupBox1.Size = new Size(189, 296);
|
groupBox1.Size = new Size(189, 219);
|
||||||
groupBox1.TabIndex = 5;
|
groupBox1.TabIndex = 5;
|
||||||
groupBox1.TabStop = false;
|
groupBox1.TabStop = false;
|
||||||
groupBox1.Text = "Наборы";
|
groupBox1.Text = "Наборы";
|
||||||
@ -112,7 +114,7 @@ namespace ProjectBulldozer
|
|||||||
//
|
//
|
||||||
listBoxStorage.FormattingEnabled = true;
|
listBoxStorage.FormattingEnabled = true;
|
||||||
listBoxStorage.ItemHeight = 15;
|
listBoxStorage.ItemHeight = 15;
|
||||||
listBoxStorage.Location = new Point(27, 122);
|
listBoxStorage.Location = new Point(27, 84);
|
||||||
listBoxStorage.Name = "listBoxStorage";
|
listBoxStorage.Name = "listBoxStorage";
|
||||||
listBoxStorage.Size = new Size(131, 94);
|
listBoxStorage.Size = new Size(131, 94);
|
||||||
listBoxStorage.TabIndex = 9;
|
listBoxStorage.TabIndex = 9;
|
||||||
@ -121,7 +123,7 @@ namespace ProjectBulldozer
|
|||||||
// ButtonAddObject
|
// ButtonAddObject
|
||||||
//
|
//
|
||||||
ButtonAddObject.Anchor = AnchorStyles.Top;
|
ButtonAddObject.Anchor = AnchorStyles.Top;
|
||||||
ButtonAddObject.Location = new Point(27, 72);
|
ButtonAddObject.Location = new Point(27, 50);
|
||||||
ButtonAddObject.Margin = new Padding(3, 2, 3, 2);
|
ButtonAddObject.Margin = new Padding(3, 2, 3, 2);
|
||||||
ButtonAddObject.Name = "ButtonAddObject";
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
ButtonAddObject.Size = new Size(131, 29);
|
ButtonAddObject.Size = new Size(131, 29);
|
||||||
@ -133,7 +135,7 @@ namespace ProjectBulldozer
|
|||||||
// ButtonRemoveObject
|
// ButtonRemoveObject
|
||||||
//
|
//
|
||||||
ButtonRemoveObject.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
ButtonRemoveObject.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||||
ButtonRemoveObject.Location = new Point(27, 244);
|
ButtonRemoveObject.Location = new Point(27, 181);
|
||||||
ButtonRemoveObject.Margin = new Padding(3, 2, 3, 2);
|
ButtonRemoveObject.Margin = new Padding(3, 2, 3, 2);
|
||||||
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
||||||
ButtonRemoveObject.Size = new Size(131, 33);
|
ButtonRemoveObject.Size = new Size(131, 33);
|
||||||
@ -144,14 +146,16 @@ namespace ProjectBulldozer
|
|||||||
//
|
//
|
||||||
// Instruments
|
// Instruments
|
||||||
//
|
//
|
||||||
|
Instruments.Controls.Add(ButtonSortByColor);
|
||||||
|
Instruments.Controls.Add(ButtonSortByType);
|
||||||
Instruments.Controls.Add(ButtonRefreshCollection);
|
Instruments.Controls.Add(ButtonRefreshCollection);
|
||||||
Instruments.Controls.Add(groupBox1);
|
Instruments.Controls.Add(groupBox1);
|
||||||
Instruments.Controls.Add(maskedTextBoxNumber);
|
Instruments.Controls.Add(maskedTextBoxNumber);
|
||||||
Instruments.Controls.Add(ButtonAddTractor);
|
Instruments.Controls.Add(ButtonAddTractor);
|
||||||
Instruments.Controls.Add(ButtonRemoveTractor);
|
Instruments.Controls.Add(ButtonRemoveTractor);
|
||||||
Instruments.Location = new Point(697, 4);
|
Instruments.Location = new Point(703, 26);
|
||||||
Instruments.Name = "Instruments";
|
Instruments.Name = "Instruments";
|
||||||
Instruments.Size = new Size(200, 541);
|
Instruments.Size = new Size(201, 464);
|
||||||
Instruments.TabIndex = 6;
|
Instruments.TabIndex = 6;
|
||||||
Instruments.TabStop = false;
|
Instruments.TabStop = false;
|
||||||
Instruments.Text = "Инструменты";
|
Instruments.Text = "Инструменты";
|
||||||
@ -207,11 +211,31 @@ namespace ProjectBulldozer
|
|||||||
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||||
toolStripMenuItem1.Size = new Size(32, 19);
|
toolStripMenuItem1.Size = new Size(32, 19);
|
||||||
//
|
//
|
||||||
|
// ButtonSortByType
|
||||||
|
//
|
||||||
|
ButtonSortByType.Location = new Point(33, 247);
|
||||||
|
ButtonSortByType.Name = "ButtonSortByType";
|
||||||
|
ButtonSortByType.Size = new Size(131, 41);
|
||||||
|
ButtonSortByType.TabIndex = 7;
|
||||||
|
ButtonSortByType.Text = "Сортировать по типу";
|
||||||
|
ButtonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||||
|
//
|
||||||
|
// ButtonSortByColor
|
||||||
|
//
|
||||||
|
ButtonSortByColor.Location = new Point(33, 294);
|
||||||
|
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||||
|
ButtonSortByColor.Size = new Size(131, 38);
|
||||||
|
ButtonSortByColor.TabIndex = 8;
|
||||||
|
ButtonSortByColor.Text = "Сортировать по цвету";
|
||||||
|
ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||||
|
//
|
||||||
// FormTractorCollections
|
// FormTractorCollections
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(904, 439);
|
ClientSize = new Size(904, 509);
|
||||||
Controls.Add(Instruments);
|
Controls.Add(Instruments);
|
||||||
Controls.Add(pictureBoxCollections);
|
Controls.Add(pictureBoxCollections);
|
||||||
Controls.Add(menuStrip1);
|
Controls.Add(menuStrip1);
|
||||||
@ -267,5 +291,7 @@ namespace ProjectBulldozer
|
|||||||
private ToolStripMenuItem сохранитьToolStripMenuItem;
|
private ToolStripMenuItem сохранитьToolStripMenuItem;
|
||||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||||
private ToolStripMenuItem toolStripMenuItem1;
|
private ToolStripMenuItem toolStripMenuItem1;
|
||||||
|
private Button ButtonSortByColor;
|
||||||
|
private Button ButtonSortByType;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,17 +3,14 @@ using ProjectBulldozer.Generics;
|
|||||||
using ProjectBulldozer.Drawning;
|
using ProjectBulldozer.Drawning;
|
||||||
using ProjectBulldozer.Exceptions;
|
using ProjectBulldozer.Exceptions;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Xml.Linq;
|
|
||||||
namespace ProjectBulldozer
|
namespace ProjectBulldozer
|
||||||
{
|
{
|
||||||
public partial class FormTractorCollections : Form
|
public partial class FormTractorCollections : Form
|
||||||
{
|
{
|
||||||
private readonly TractorGenericStorage _storage;
|
private readonly TractorGenericStorage _storage;
|
||||||
private readonly TractorGenericCollection<DrawingTractor, DrawingObjectTractor> _tractors;
|
|
||||||
readonly int countPlace = 10;
|
|
||||||
private readonly ILogger _logger;
|
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
readonly int countPlace = 12;
|
||||||
public FormTractorCollections()
|
public FormTractorCollections()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@ -25,7 +22,6 @@ namespace ProjectBulldozer
|
|||||||
_storage = new TractorGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
|
_storage = new TractorGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ReloadObjects()
|
private void ReloadObjects()
|
||||||
{
|
{
|
||||||
int index = listBoxStorage.SelectedIndex;
|
int index = listBoxStorage.SelectedIndex;
|
||||||
@ -99,15 +95,19 @@ namespace ProjectBulldozer
|
|||||||
tractor._pictureHeight = pictureBoxCollections.Height;
|
tractor._pictureHeight = pictureBoxCollections.Height;
|
||||||
|
|
||||||
if (listBoxStorage.SelectedIndex == -1) return;
|
if (listBoxStorage.SelectedIndex == -1) return;
|
||||||
|
|
||||||
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||||
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
|
string name = listBoxStorage.SelectedItem.ToString() ?? string.Empty;
|
||||||
|
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (obj + tractor)
|
|
||||||
|
int addedIndex = obj + tractor;
|
||||||
|
if (addedIndex != -1 && addedIndex < countPlace)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollections.Image = obj.ShowTractors();
|
pictureBoxCollections.Image = obj.ShowTractors();
|
||||||
@ -124,6 +124,11 @@ namespace ProjectBulldozer
|
|||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
_logger.LogWarning($"{ex.Message}. Не удалось добавить объект");
|
_logger.LogWarning($"{ex.Message}. Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
_logger.LogWarning($"{ex.Message}. Не удалось добавить объект");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
private void ButtonRemoveTractor_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -160,7 +165,6 @@ namespace ProjectBulldozer
|
|||||||
_logger.LogWarning($"{ex.Message}. Не удалось удалить объект");
|
_logger.LogWarning($"{ex.Message}. Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (listBoxStorage.SelectedIndex == -1) return;
|
if (listBoxStorage.SelectedIndex == -1) return;
|
||||||
@ -206,6 +210,24 @@ namespace ProjectBulldozer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareTractors(new TractorCompareByType());
|
||||||
|
|
||||||
|
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareTractors(new TractorCompareByColor());
|
||||||
|
|
||||||
|
private void CompareTractors(IComparer<DrawingTractor?> comparer)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxCollections.Image = obj.ShowTractors();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,4 +126,7 @@
|
|||||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>286, 17</value>
|
<value>286, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>25</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -5,8 +5,10 @@ namespace ProjectBulldozer.Generics
|
|||||||
{
|
{
|
||||||
internal class TractorGenericCollection<T, U> where T : DrawingTractor where U : IMoveableObject
|
internal class TractorGenericCollection<T, U> where T : DrawingTractor where U : IMoveableObject
|
||||||
{
|
{
|
||||||
|
//ширина/высота окна
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
|
//ширина/высота занимаемого места
|
||||||
private readonly int _placeSizeWidth = 150;
|
private readonly int _placeSizeWidth = 150;
|
||||||
private readonly int _placeSizeHeight = 130;
|
private readonly int _placeSizeHeight = 130;
|
||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
@ -19,10 +21,11 @@ namespace ProjectBulldozer.Generics
|
|||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
public static bool operator +(TractorGenericCollection<T, U> collect, T? tract)
|
public static int operator +(TractorGenericCollection<T, U> collect, T? tractor)
|
||||||
{
|
{
|
||||||
if (tract == null) return false;
|
if (tractor == null) return -1;
|
||||||
return collect._collection.Insert(tract);
|
|
||||||
|
return collect?._collection.Insert(tractor, new DrawingBulldozerEqutables())??-1;
|
||||||
}
|
}
|
||||||
public static T? operator -(TractorGenericCollection<T, U> collect, int pos)
|
public static T? operator -(TractorGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
@ -33,6 +36,10 @@ namespace ProjectBulldozer.Generics
|
|||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
public U? GetU(int pos)
|
||||||
|
{
|
||||||
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
|
}
|
||||||
public Bitmap ShowTractors()
|
public Bitmap ShowTractors()
|
||||||
{
|
{
|
||||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
@ -48,7 +55,7 @@ namespace ProjectBulldozer.Generics
|
|||||||
{
|
{
|
||||||
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
|
||||||
{
|
{
|
||||||
//линия рамзетки места
|
//линия разметки места
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight);
|
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight);
|
||||||
}
|
}
|
||||||
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
|
||||||
@ -60,17 +67,21 @@ namespace ProjectBulldozer.Generics
|
|||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
for (int i = 0; i < _collection.Count; i++)
|
||||||
{
|
{
|
||||||
|
// Получение объекта
|
||||||
var obj = _collection[i];
|
var obj = _collection[i];
|
||||||
|
// Установка позиции
|
||||||
obj?.SetPosition(
|
obj?.SetPosition(
|
||||||
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
(int)((width - 1) * _placeSizeWidth - (i % width * _placeSizeWidth)),
|
||||||
(int)((height - 1) * _placeSizeHeight - (i / width * _placeSizeHeight))
|
(int)((height - 1) * _placeSizeHeight - (i / width * _placeSizeHeight))
|
||||||
);
|
);
|
||||||
|
// Прорисовка объекта
|
||||||
obj?.DrawTransport(g);
|
obj?.DrawTransport(g);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
55
ProjectBulldozer/Generics/DrawingBulldozerEqutables.cs.cs
Normal file
55
ProjectBulldozer/Generics/DrawingBulldozerEqutables.cs.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using ProjectBulldozer.Drawning;
|
||||||
|
using ProjectBulldozer.Entities;
|
||||||
|
|
||||||
|
namespace ProjectBulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class DrawingBulldozerEqutables : IEqualityComparer<DrawingTractor?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawingTractor? x, DrawingTractor? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityTractor == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityTractor == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityTractor.Speed != y.EntityTractor.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityTractor.Weight != y.EntityTractor.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityTractor.BodyColor != y.EntityTractor.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is DrawingBulldozer && y is DrawingBulldozer)
|
||||||
|
{
|
||||||
|
if ((x.EntityTractor as EntityBulldozer).Otval != (y.EntityTractor as EntityBulldozer).Otval)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((x.EntityTractor as EntityBulldozer).ThirdWheel != (y.EntityTractor as EntityBulldozer).ThirdWheel)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode([DisallowNull] DrawingTractor obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -13,11 +13,14 @@ namespace ProjectBulldozer.Generics
|
|||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
public bool Insert(T tract)
|
public int Insert(T tractor, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
return Insert(tract, 0);
|
if (_places.Count == _maxCount)
|
||||||
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
Insert(tractor, 0, equal);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
public bool Insert(T tract, int position)
|
public bool Insert(T tractor, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount)
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
{
|
||||||
@ -27,7 +30,17 @@ namespace ProjectBulldozer.Generics
|
|||||||
{
|
{
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
}
|
}
|
||||||
_places.Insert(position, tract);
|
if (equal != null)
|
||||||
|
{
|
||||||
|
foreach (var i in _places)
|
||||||
|
{
|
||||||
|
if (equal.Equals(i, tractor))
|
||||||
|
{
|
||||||
|
throw new ApplicationException($"Объект уже существует");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_places.Insert(position, tractor);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
@ -67,5 +80,7 @@ namespace ProjectBulldozer.Generics
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
38
ProjectBulldozer/Generics/TractorCompareByColor.cs
Normal file
38
ProjectBulldozer/Generics/TractorCompareByColor.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using ProjectBulldozer.Drawning;
|
||||||
|
using ProjectBulldozer.Entities;
|
||||||
|
|
||||||
|
namespace ProjectBulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class TractorCompareByColor : IComparer<DrawingTractor?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingTractor? x, DrawingTractor? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityTractor == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityTractor == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.EntityTractor.BodyColor != y.EntityTractor.BodyColor)
|
||||||
|
{
|
||||||
|
return x.EntityTractor.BodyColor.Name.CompareTo(y.EntityTractor.BodyColor.Name);
|
||||||
|
}
|
||||||
|
if (x.EntityTractor is EntityBulldozer _BulldozerX && y.EntityTractor is EntityBulldozer _BulldozertY)
|
||||||
|
{
|
||||||
|
var ElementsColorCompare = _BulldozerX.AdditionalColor.Name.CompareTo(_BulldozertY.AdditionalColor.Name);
|
||||||
|
if (ElementsColorCompare != 0)
|
||||||
|
{
|
||||||
|
return ElementsColorCompare;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityTractor.Speed.CompareTo(y.EntityTractor.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityTractor.Weight.CompareTo(y.EntityTractor.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
ProjectBulldozer/Generics/TractorCompareByType.cs
Normal file
29
ProjectBulldozer/Generics/TractorCompareByType.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using ProjectBulldozer.Drawning;
|
||||||
|
|
||||||
|
namespace ProjectBulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class TractorCompareByType : IComparer<DrawingTractor?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingTractor? x, DrawingTractor? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityTractor == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityTractor == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityTractor.Speed.CompareTo(y.EntityTractor.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityTractor.Weight.CompareTo(y.EntityTractor.Weight);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -9,38 +9,36 @@ namespace ProjectBulldozer.Generics
|
|||||||
private static readonly char _separatorForKeyValue = '|';
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
private readonly char _separatorRecords = ';';
|
private readonly char _separatorRecords = ';';
|
||||||
private static readonly char _separatorForObject = ':';
|
private static readonly char _separatorForObject = ':';
|
||||||
readonly Dictionary<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> _TractorsStorage;
|
readonly Dictionary<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> _TractorsStorage;
|
||||||
public List<string> Keys => _TractorsStorage.Keys.ToList();
|
public List<TractorsCollectionInfo> Keys => _TractorsStorage.Keys.ToList();
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
public TractorGenericStorage(int pictureWidth, int pictureHeight)
|
public TractorGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_TractorsStorage = new Dictionary<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>>();
|
_TractorsStorage = new Dictionary<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
if (!_TractorsStorage.ContainsKey(name))
|
if (!_TractorsStorage.ContainsKey(new TractorsCollectionInfo(name, "")))
|
||||||
{
|
{
|
||||||
_TractorsStorage.Add(name, new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(_pictureWidth, _pictureHeight));
|
_TractorsStorage.Add(new TractorsCollectionInfo(name, ""), new TractorGenericCollection<DrawingTractor, DrawingObjectTractor>(_pictureWidth, _pictureHeight));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
if (_TractorsStorage.ContainsKey(name))
|
if (_TractorsStorage.ContainsKey(new TractorsCollectionInfo(name, "")))
|
||||||
{
|
{
|
||||||
_TractorsStorage.Remove(name);
|
_TractorsStorage.Remove(new TractorsCollectionInfo(name, ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public TractorGenericCollection<DrawingTractor, DrawingObjectTractor>? this[string ind]
|
public TractorGenericCollection<DrawingTractor, DrawingObjectTractor>? this[string ind]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_TractorsStorage.ContainsKey(ind))
|
var info = new TractorsCollectionInfo(ind, "");
|
||||||
{
|
if (_TractorsStorage.ContainsKey(info)) return _TractorsStorage[info];
|
||||||
return _TractorsStorage[ind];
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -51,9 +49,7 @@ namespace ProjectBulldozer.Generics
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
StringBuilder data = new();
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<TractorsCollectionInfo, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>> record in _TractorsStorage)
|
||||||
foreach (KeyValuePair<string, TractorGenericCollection<DrawingTractor, DrawingObjectTractor>>
|
|
||||||
record in _TractorsStorage)
|
|
||||||
{
|
{
|
||||||
StringBuilder records = new();
|
StringBuilder records = new();
|
||||||
foreach (DrawingTractor? elem in record.Value.GetTractors)
|
foreach (DrawingTractor? elem in record.Value.GetTractors)
|
||||||
@ -112,13 +108,13 @@ namespace ProjectBulldozer.Generics
|
|||||||
_pictureWidth, _pictureHeight);
|
_pictureWidth, _pictureHeight);
|
||||||
if (tractor != null)
|
if (tractor != null)
|
||||||
{
|
{
|
||||||
if ((collection + tractor))
|
if ((collection + tractor)==-1)
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Ошибка добавления в коллекцию");
|
throw new ApplicationException("Ошибка добавления в коллекцию");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_TractorsStorage.Add(record[0], collection);
|
_TractorsStorage.Add(new TractorsCollectionInfo(record[0], string.Empty), collection);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
29
ProjectBulldozer/Generics/TractorsCollectionInfo.cs
Normal file
29
ProjectBulldozer/Generics/TractorsCollectionInfo.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
namespace ProjectBulldozer.Generics
|
||||||
|
{
|
||||||
|
internal class TractorsCollectionInfo : IEquatable<TractorsCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
|
||||||
|
public string Description { get; private set; }
|
||||||
|
|
||||||
|
public TractorsCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(TractorsCollectionInfo? other)
|
||||||
|
{
|
||||||
|
return Name == other.Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return Name.GetHashCode();
|
||||||
|
}
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user