Лабораторная работа 8

This commit is contained in:
RozhVan 2024-05-19 15:08:52 +03:00
parent c9945dab89
commit 79db737a1e
13 changed files with 442 additions and 55 deletions

View File

@ -27,7 +27,18 @@ public abstract class AbstractCompany
public static int operator +(AbstractCompany company, DrawningShip ship)
{
return company._collection.Insert(ship, 0);
try
{
return company._collection.Insert(ship, 0, new DrawningShipEqutables());
}
catch (ObjectAlreadyInCollectionException)
{
return -1;
}
catch (CollectionOverflowException)
{
return -1;
}
}
public static DrawningShip? operator -(AbstractCompany company, int position)
@ -53,6 +64,7 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics);
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
@ -72,4 +84,6 @@ public abstract class AbstractCompany
protected abstract void DrawBackgound(Graphics g);
protected abstract void SetObjectsPosition();
public void Sort(IComparer<DrawningShip?> comparer) => _collection?.CollectionSort(comparer);
}

View File

@ -0,0 +1,77 @@
namespace ProjectPlane.CollectionGenericObjects;
/// <summary>
/// Класс, хранящиий информацию по коллекции
/// </summary>
public class CollectionInfo : IEquatable<CollectionInfo>
{
/// <summary>
/// Название
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Тип
/// </summary>
public CollectionType CollectionType { get; private set; }
/// <summary>
/// Описание
/// </summary>
public string Description { get; private set; }
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separator = "-";
/// <summary>
/// Конструктор
/// </summary>
/// <param name="name">Название</param>
/// <param name="collectionType">Тип</param>
/// <param name="description">Описание</param>
public CollectionInfo(string name, CollectionType collectionType, string description)
{
Name = name;
CollectionType = collectionType;
Description = description;
}
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="data">Строка</param>
/// <returns>Объект или null</returns>
public static CollectionInfo? GetCollectionInfo(string data)
{
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
if (strs.Length < 1 || strs.Length > 3)
{
return null;
}
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]),
strs.Length > 2 ? strs[2] : string.Empty);
}
public override string ToString()
{
return Name + _separator + CollectionType + _separator + Description;
}
public bool Equals(CollectionInfo? other)
{
return Name == other?.Name;
}
public override bool Equals(object? obj)
{
return Equals(obj as CollectionInfo);
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
}

View File

@ -1,4 +1,5 @@
namespace ProjectPlane.CollectionGenericObjects;
using ProjectPlane.Drawnings;
namespace ProjectPlane.CollectionGenericObjects;
public interface ICollectionGenericObjects<T>
where T : class
@ -7,9 +8,9 @@ public interface ICollectionGenericObjects<T>
int MaxCount { get; set; }
int Insert(T obj);
int Insert(T obj, IEqualityComparer<DrawningShip?>? comparer = null);
int Insert(T obj, int position);
int Insert(T obj, int position, IEqualityComparer<DrawningShip?>? comparer = null);
T? Remove(int position);
@ -19,5 +20,6 @@ public interface ICollectionGenericObjects<T>
IEnumerable<T?> GetItems();
void CollectionSort(IComparer<T?> comparer);
}

View File

@ -1,5 +1,5 @@
using ProjectPlane.Exceptions;
using System.CodeDom.Compiler;
using ProjectPlane.Drawnings;
namespace ProjectPlane.CollectionGenericObjects;
@ -32,31 +32,50 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
return _collection[position];
}
public int Insert(T obj)
public int Insert(T obj, IEqualityComparer<DrawningShip?>? comparer = null)
{
// TODO выброс ошибки, если переполнение
// TODO выброс ошибки, если такой объект есть в коллекции
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
}
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
{
throw new ObjectAlreadyInCollectionException(i);
}
}
_collection.Add(obj);
return _collection.Count;
}
public int Insert(T obj, int position)
public int Insert(T obj, int position, IEqualityComparer<DrawningShip?>? comparer = null)
{
// TODO выброс ошибки, если выход за границы списка
// TODO выброс ошибки, если переполнение
// TODO выброс ошибки, если такой объект есть в коллекции
if (position < 0 || position > Count)
{
throw new PositionOutOfCollectionException(position);
}
if (Count == _maxCount)
{
throw new CollectionOverflowException(Count);
}
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
{
throw new ObjectAlreadyInCollectionException(i);
}
}
_collection.Insert(position, obj);
return position;
}
@ -81,4 +100,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
yield return _collection[i];
}
}
public void CollectionSort(IComparer<T?> comparer)
{
// TODO
_collection.Sort(comparer);
}
}

View File

@ -1,4 +1,5 @@
using ProjectPlane.Exceptions;
using ProjectPlane.Drawnings;
namespace ProjectPlane.CollectionGenericObjects;
@ -52,9 +53,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
return _collection[position];
}
public int Insert(T obj)
public int Insert(T obj, IEqualityComparer<DrawningShip?>? comparer = null)
{
// TODO выброс ошибки, если такой объект есть в коллекции
// TODO выброс ошибки, если переполнение
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
{
throw new ObjectAlreadyInCollectionException(i);
}
}
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
@ -67,15 +77,24 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
throw new CollectionOverflowException(Count);
}
public int Insert(T obj, int position)
public int Insert(T obj, int position, IEqualityComparer<DrawningShip?>? comparer = null)
{
// TODO выброс ошибки, если выход за границы массива
// TODO выброс ошибки, если такой объект есть в коллекции
// TODO выброс ошибки, если переполнение
if (position < 0 || position >= Count)
{
throw new PositionOutOfCollectionException(position);
}
for (int i = 0; i < Count; i++)
{
if (comparer.Equals((_collection[i] as DrawningShip), (obj as DrawningShip)))
{
throw new ObjectAlreadyInCollectionException(i);
}
}
if (_collection[position] == null)
{
_collection[position] = obj;
@ -129,4 +148,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
}
}
public void CollectionSort(IComparer<T?> comparer)
{
// TODO
Array.Sort(_collection, comparer);
}
}

View File

@ -1,6 +1,5 @@
using ProjectPlane.Drawnings;
using ProjectPlane.Exceptions;
using System.Text;
namespace ProjectPlane.CollectionGenericObjects;
@ -14,16 +13,16 @@ public class StorageCollection<T>
private readonly string _separatorItems = ";";
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
private Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
public List<string> Keys => _storages.Keys.ToList();
public List<CollectionInfo> Keys => _storages.Keys.ToList();
/// <summary>
/// Конструктор
/// </summary>
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
}
/// <summary>
@ -31,21 +30,21 @@ public class StorageCollection<T>
/// </summary>
/// <param name="name">Название коллекции</param>
/// <param name="collectionType">Тип коллекции</param>
public void AddCollection(string name, CollectionType collectionType)
public void AddCollection(CollectionInfo info)
{
if (name == null || _storages.ContainsKey(name))
if (info == null || _storages.ContainsKey(info))
{
return;
}
if (collectionType == CollectionType.Massive)
if (info.CollectionType == CollectionType.Massive)
{
_storages.Add(name, new MassiveGenericObjects<T>());
_storages.Add(info, new MassiveGenericObjects<T>());
}
if (collectionType == CollectionType.List)
if (info.CollectionType == CollectionType.List)
{
_storages.Add(name, new ListGenericObjects<T>());
_storages.Add(info, new ListGenericObjects<T>());
}
}
@ -53,14 +52,14 @@ public class StorageCollection<T>
/// Удаление коллекции
/// </summary>
/// <param name="name">Название коллекции</param>
public void DelCollection(string name)
public void DelCollection(CollectionInfo info)
{
if (name == null || !_storages.ContainsKey(name))
if (info == null || !_storages.ContainsKey(info))
{
return;
}
_storages.Remove(name);
_storages.Remove(info);
}
public void SaveData(string filename)
@ -79,7 +78,7 @@ public class StorageCollection<T>
{
sw.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
{
sw.Write(Environment.NewLine);
// не сохраняем пустые коллекции
@ -90,8 +89,6 @@ public class StorageCollection<T>
sw.Write(value.Key);
sw.Write(_separatorForKeyValue);
sw.Write(value.Value.GetCollectionType);
sw.Write(_separatorForKeyValue);
sw.Write(value.Value.MaxCount);
sw.Write(_separatorForKeyValue);
@ -134,27 +131,25 @@ public class StorageCollection<T>
while ((line = sr.ReadLine()) != null)
{
string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
if (record.Length != 3)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null)
{
throw new InvalidOperationException("Не удалось создать коллекцию");
}
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
throw new Exception("Не удалось создать коллекцию");
collection.MaxCount = Convert.ToInt32(record[1]);
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningShip() is T ship)
{
try
{
if (collection.Insert(ship) == -1)
if (collection.Insert(ship, new DrawningShipEqutables()) == -1)
{
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
}
@ -163,20 +158,24 @@ public class StorageCollection<T>
{
throw new OverflowException("Коллекция переполнена", ex);
}
catch (ObjectAlreadyInCollectionException ex)
{
throw new InvalidOperationException("Объект уже присутствует в коллекции", ex);
}
}
}
_storages.Add(record[0], collection);
_storages.Add(collectionInfo, collection);
}
}
}
public ICollectionGenericObjects<T>? this[string name]
public ICollectionGenericObjects<T>? this[CollectionInfo info]
{
get
{
if (_storages.ContainsKey(name))
if (_storages.ContainsKey(info))
{
return _storages[name];
return _storages[info];
}
return null;

View File

@ -0,0 +1,42 @@
using ProjectPlane.Entities;
namespace ProjectPlane.Drawnings;
/// <summary>
/// Сравнение по цвету, скорости, весу
/// </summary>
public class DrawningShipCompareByColor : IComparer<DrawningShip?>
{
public int Compare(DrawningShip? x, DrawningShip? y)
{
// TODO прописать логику сравения по цветам, скорости, весу
if (x == null || x.EntityShip == null)
{
return 1;
}
if (y == null || y.EntityShip == null)
{
return -1;
}
var bodyColorCompare = y.EntityShip.ShipColor.Name.CompareTo(x.EntityShip.ShipColor.Name);
if (bodyColorCompare != 0)
{
return bodyColorCompare;
}
if (x is DrawCont && y is DrawCont)
{
var additionalColorCompare = (y.EntityShip as EntityContainer).ContainerColor.Name.CompareTo(
(x.EntityShip as EntityContainer).ContainerColor.Name);
if (additionalColorCompare != 0)
{
return additionalColorCompare;
}
}
var speedCompare = y.EntityShip.Speed.CompareTo(x.EntityShip.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return y.EntityShip.Weight.CompareTo(x.EntityShip.Weight);
}
}

View File

@ -0,0 +1,29 @@
namespace ProjectPlane.Drawnings;
/// <summary>
/// Сравнение по типу, скорости, весу
/// </summary>
public class DrawningShipCompareByType : IComparer<DrawningShip?>
{
public int Compare(DrawningShip? x, DrawningShip? y)
{
if (x == null || x.EntityShip == null)
{
return 1;
}
if (y == null || y.EntityShip == null)
{
return -1;
}
if (x.GetType().Name != y.GetType().Name)
{
return y.GetType().Name.CompareTo(x.GetType().Name);
}
var speedCompare = y.EntityShip.Speed.CompareTo(x.EntityShip.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return y.EntityShip.Weight.CompareTo(x.EntityShip.Weight);
}
}

View File

@ -0,0 +1,63 @@
using ProjectPlane.Entities;
using System.Diagnostics.CodeAnalysis;
namespace ProjectPlane.Drawnings;
/// <summary>
/// Реализация сравнения двух объектов класса-прорисовки
/// </summary>
public class DrawningShipEqutables : IEqualityComparer<DrawningShip?>
{
public bool Equals(DrawningShip? x, DrawningShip? y)
{
if (x == null || x.EntityShip == null)
{
return false;
}
if (y == null || y.EntityShip == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityShip.Speed != y.EntityShip.Speed)
{
return false;
}
if (x.EntityShip.Weight != y.EntityShip.Weight)
{
return false;
}
if (x.EntityShip.ShipColor != y.EntityShip.ShipColor)
{
return false;
}
if (x is DrawCont && y is DrawCont)
{
// TODO доделать логику сравнения дополнительных параметров
if ((x.EntityShip as EntityContainer)?.ContainerColor !=
(y.EntityShip as EntityContainer)?.ContainerColor)
{
return false;
}
if ((x.EntityShip as EntityContainer)?.Container !=
(y.EntityShip as EntityContainer)?.Container)
{
return false;
}
if ((x.EntityShip as EntityContainer)?.Crane !=
(y.EntityShip as EntityContainer)?.Crane)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawningShip? obj)
{
return obj.GetHashCode();
}
}

View File

@ -0,0 +1,20 @@
using System.Runtime.Serialization;
namespace ProjectPlane.Exceptions;
/// <summary>
/// Класс, описывающий ошибку переполнения коллекции
/// </summary>
[Serializable]
internal class ObjectAlreadyInCollectionException : ApplicationException
{
public ObjectAlreadyInCollectionException(int index) : base("Такой объект уже присутствует в коллекции. Позиция " + index) { }
public ObjectAlreadyInCollectionException() : base() { }
public ObjectAlreadyInCollectionException(string message) : base(message) { }
public ObjectAlreadyInCollectionException(string message, Exception exception) : base(message, exception) { }
protected ObjectAlreadyInCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}

View File

@ -30,6 +30,8 @@
{
groupBoxTools = new GroupBox();
panelCompanyTools = new Panel();
buttonSortByColor = new Button();
buttonSortByType = new Button();
ButtonAddShip = new Button();
maskedTextBoxPosition = new MaskedTextBox();
ButtonRefresh = new Button();
@ -75,6 +77,8 @@
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonSortByColor);
panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(ButtonAddShip);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(ButtonRefresh);
@ -83,13 +87,33 @@
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 400);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(194, 274);
panelCompanyTools.Size = new Size(194, 292);
panelCompanyTools.TabIndex = 9;
//
// buttonSortByColor
//
buttonSortByColor.Location = new Point(6, 252);
buttonSortByColor.Name = "buttonSortByColor";
buttonSortByColor.Size = new Size(182, 34);
buttonSortByColor.TabIndex = 8;
buttonSortByColor.Text = "Сортировка по цвету";
buttonSortByColor.UseVisualStyleBackColor = true;
buttonSortByColor.Click += ButtonSortByColor_Click;
//
// buttonSortByType
//
buttonSortByType.Location = new Point(6, 213);
buttonSortByType.Name = "buttonSortByType";
buttonSortByType.Size = new Size(182, 34);
buttonSortByType.TabIndex = 7;
buttonSortByType.Text = "Сортировка по типу";
buttonSortByType.UseVisualStyleBackColor = true;
buttonSortByType.Click += ButtonSortByType_Click;
//
// ButtonAddShip
//
ButtonAddShip.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
ButtonAddShip.Location = new Point(6, 20);
ButtonAddShip.Location = new Point(6, 3);
ButtonAddShip.Name = "ButtonAddShip";
ButtonAddShip.Size = new Size(182, 40);
ButtonAddShip.TabIndex = 1;
@ -99,7 +123,7 @@
//
// maskedTextBoxPosition
//
maskedTextBoxPosition.Location = new Point(6, 111);
maskedTextBoxPosition.Location = new Point(6, 49);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(188, 23);
@ -109,7 +133,7 @@
// ButtonRefresh
//
ButtonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
ButtonRefresh.Location = new Point(6, 230);
ButtonRefresh.Location = new Point(6, 168);
ButtonRefresh.Name = "ButtonRefresh";
ButtonRefresh.Size = new Size(182, 39);
ButtonRefresh.TabIndex = 6;
@ -120,18 +144,18 @@
// ButtonDel
//
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
ButtonDel.Location = new Point(6, 140);
ButtonDel.Location = new Point(6, 78);
ButtonDel.Name = "ButtonDel";
ButtonDel.Size = new Size(182, 39);
ButtonDel.TabIndex = 4;
ButtonDel.Text = "Удплить контейнеровоз";
ButtonDel.Text = "Удалить контейнеровоз";
ButtonDel.UseVisualStyleBackColor = true;
ButtonDel.Click += ButtonDel_Click;
//
// ButtonGoToCheck
//
ButtonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
ButtonGoToCheck.Location = new Point(6, 185);
ButtonGoToCheck.Location = new Point(6, 123);
ButtonGoToCheck.Name = "ButtonGoToCheck";
ButtonGoToCheck.Size = new Size(182, 39);
ButtonGoToCheck.TabIndex = 5;
@ -333,5 +357,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -34,27 +34,40 @@ public partial class FormShipCollection : Form
private void SetShip(DrawningShip? ship)
{
if (_company == null || ship == null)
{
return;
}
try
{
if (_company == null || ship == null)
{
return;
}
if (_company + ship != -1)
{
MessageBox.Show("Объект добавлен");
_logger.LogInformation($"Добавлен объект {ship.GetDataForSave()}");
pictureBox.Image = _company.Show();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
catch (CollectionOverflowException ex)
{
MessageBox.Show(ex.Message);
_logger.LogWarning($"Ошибка: {ex.Message}");
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message);
_logger.LogWarning($"Ошибка: {ex.Message}");
}
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDel_Click(object sender, EventArgs e)
{
@ -122,6 +135,11 @@ public partial class FormShipCollection : Form
}
/// <summary>
/// перерисовка коллекции
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRefresh_Click(object sender, EventArgs e)
{
if (_company == null)
@ -137,7 +155,7 @@ public partial class FormShipCollection : Form
listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{
string? colName = _storageCollection.Keys?[i];
string? colName = _storageCollection.Keys?[i].Name;
if (!string.IsNullOrEmpty(colName))
{
listBoxCollection.Items.Add(colName);
@ -150,6 +168,7 @@ public partial class FormShipCollection : Form
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
{
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError("Ошибка: Заполнены не все данные для добавления коллекции");
return;
}
@ -162,8 +181,10 @@ public partial class FormShipCollection : Form
{
collectionType = CollectionType.List;
}
CollectionInfo collectionInfo = new CollectionInfo(textBoxCollectionName.Text, collectionType, string.Empty);
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
_storageCollection.AddCollection(collectionInfo);
_logger.LogInformation($"Добавлена коллекция: {textBoxCollectionName.Text} типа: {collectionType}");
RerfreshListBoxItems();
}
@ -179,7 +200,10 @@ public partial class FormShipCollection : Form
{
return;
}
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
_storageCollection.DelCollection(collectionInfo);
_logger.LogInformation($"Удалена коллекция: {listBoxCollection.SelectedItem.ToString()}");
RerfreshListBoxItems();
}
@ -191,7 +215,8 @@ public partial class FormShipCollection : Form
return;
}
ICollectionGenericObjects<DrawningShip>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
ICollectionGenericObjects<DrawningShip>? collection = _storageCollection[collectionInfo];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
@ -244,4 +269,24 @@ public partial class FormShipCollection : Form
}
}
}
private void ButtonSortByType_Click(object sender, EventArgs e)
{
CompareShips(new DrawningShipCompareByType());
}
private void ButtonSortByColor_Click(object sender, EventArgs e)
{
CompareShips(new DrawningShipCompareByColor());
}
private void CompareShips(IComparer<DrawningShip?> comparer)
{
if (_company == null)
{
return;
}
_company.Sort(comparer);
pictureBox.Image = _company.Show();
}
}

View File

@ -0,0 +1,21 @@
2024-05-19 14:40:29.0277 | INFORMATION | ProjectPlane.FormShipCollection | Добавлена коллекция: fgjd типа: List
2024-05-19 14:40:36.9497 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Yellow
2024-05-19 14:41:42.9096 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Yellow:Red:True:True
2024-05-19 14:42:44.9889 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Blue
2024-05-19 14:42:55.1814 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Red
2024-05-19 14:43:35.2025 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Blue:Purple:True:True
2024-05-19 14:44:32.1260 | INFORMATION | ProjectPlane.FormShipCollection | Добавлена коллекция: dhd типа: Massive
2024-05-19 14:44:43.1068 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Red
2024-05-19 14:44:49.7075 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Blue
2024-05-19 14:45:05.2935 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Red:Black:True:True
2024-05-19 14:45:34.8489 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Blue:Black:False:True
2024-05-19 15:03:53.6387 | INFORMATION | ProjectPlane.FormShipCollection | Добавлена коллекция: вапр типа: Massive
2024-05-19 15:04:10.5066 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Blue
2024-05-19 15:04:15.2984 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Red
2024-05-19 15:04:21.7942 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Blue:Black:True:True
2024-05-19 15:04:40.3403 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Purple
2024-05-19 15:04:51.3945 | INFORMATION | ProjectPlane.FormShipCollection | Добавлена коллекция: вао типа: List
2024-05-19 15:05:05.4559 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Yellow
2024-05-19 15:05:17.1129 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Purple:Yellow:True:True
2024-05-19 15:06:00.3431 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityContainer:100:100:Blue:Black:True:True
2024-05-19 15:06:12.9361 | INFORMATION | ProjectPlane.FormShipCollection | Добавлен объект EntityShip:100:100:Green