Лаб 8
This commit is contained in:
parent
3a938f6349
commit
e6f0b327af
@ -51,7 +51,7 @@ public abstract class AbstractCompany
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(AbstractCompany company, Drawningplane plane)
|
public static int operator +(AbstractCompany company, Drawningplane plane)
|
||||||
{
|
{
|
||||||
return company._collection.Insert(plane);
|
return company._collection.Insert(plane, new DrawningPlaneEqutables());
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора удаления для класса
|
/// Перегрузка оператора удаления для класса
|
||||||
@ -103,4 +103,10 @@ public abstract class AbstractCompany
|
|||||||
/// Расстановка объектов
|
/// Расстановка объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected abstract void SetObjectsPosition();
|
protected abstract void SetObjectsPosition();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
public void Sort(IComparer<Drawningplane?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
}
|
}
|
@ -0,0 +1,74 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAiroplane.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
namespace ProjectAiroplane.CollectionGenericObjects;
|
namespace ProjectAiroplane.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Интерфейс описания действий для набора хранимых объектов
|
/// Интерфейс описания действий для набора хранимых объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -24,14 +25,14 @@ where T : class
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
int Insert(T obj);
|
int Insert(T obj, IEqualityComparer<T?>? compaper = null);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
int Insert(T obj, int position);
|
int Insert(T obj, int position, IEqualityComparer<T?>? compaper = null);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -54,4 +55,5 @@ where T : class
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<T?> GetItems();
|
IEnumerable<T?> GetItems();
|
||||||
|
void CollectionSort(IComparer<T?> comparer);
|
||||||
}
|
}
|
||||||
|
@ -45,20 +45,37 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
public int Insert(T obj)
|
public int Insert(T obj, IEqualityComparer<T?>? compaper = null)
|
||||||
{
|
{
|
||||||
|
if (compaper != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, compaper))
|
||||||
|
{
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Count == _maxCount) throw new CollectionOverflowException();
|
if (Count == _maxCount) throw new CollectionOverflowException();
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return Count;
|
return Count;
|
||||||
}
|
}
|
||||||
public int Insert(T obj, int position)
|
|
||||||
|
public int Insert(T obj, int position, IEqualityComparer<T?>? compaper = null)
|
||||||
{
|
{
|
||||||
|
if (compaper != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, compaper))
|
||||||
|
{
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||||
|
|
||||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||||
_collection.Insert(position, obj);
|
_collection.Insert(position, obj);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
@ -76,4 +93,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
_collection.Sort(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ProjectAiroplane.Exceptions;
|
using ProjectAiroplane.Drawnings;
|
||||||
|
using ProjectAiroplane.Exceptions;
|
||||||
|
|
||||||
namespace ProjectAiroplane.CollectionGenericObjects;
|
namespace ProjectAiroplane.CollectionGenericObjects;
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ where T : class
|
|||||||
{
|
{
|
||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
@ -56,8 +58,17 @@ where T : class
|
|||||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
public int Insert(T obj)
|
public int Insert(T obj, IEqualityComparer<T?>? compaper = null)
|
||||||
{
|
{
|
||||||
|
if (compaper != null)
|
||||||
|
{
|
||||||
|
foreach (T? item in _collection)
|
||||||
|
{
|
||||||
|
if ((compaper as IEqualityComparer<Drawningplane>).Equals(obj as Drawningplane, item as Drawningplane))
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO вставка в свободное место набора
|
// TODO вставка в свободное место набора
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (index < _collection.Length)
|
while (index < _collection.Length)
|
||||||
@ -72,8 +83,17 @@ where T : class
|
|||||||
}
|
}
|
||||||
throw new CollectionOverflowException(Count);
|
throw new CollectionOverflowException(Count);
|
||||||
}
|
}
|
||||||
public int Insert(T obj, int position)
|
public int Insert(T obj, int position, IEqualityComparer<T?>? compaper = null)
|
||||||
{
|
{
|
||||||
|
if (compaper != null)
|
||||||
|
{
|
||||||
|
foreach (T? item in _collection)
|
||||||
|
{
|
||||||
|
if ((compaper as IEqualityComparer<Drawningplane>).Equals(obj as Drawningplane, item as Drawningplane))
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO проверка позиции
|
// TODO проверка позиции
|
||||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||||
// ищется свободное место после этой позиции и идет вставка туда
|
// ищется свободное место после этой позиции и идет вставка туда
|
||||||
@ -119,7 +139,7 @@ where T : class
|
|||||||
{
|
{
|
||||||
throw new PositionOutOfCollectionException(position);
|
throw new PositionOutOfCollectionException(position);
|
||||||
}
|
}
|
||||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);//выброс1
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
T obj = _collection[position];
|
T obj = _collection[position];
|
||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return obj;
|
return obj;
|
||||||
@ -133,4 +153,9 @@ where T : class
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
Array.Sort(_collection, comparer);
|
||||||
|
}
|
||||||
}
|
}
|
@ -13,17 +13,17 @@ public class StorageCollection<T>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище) с коллекциями
|
/// Словарь (хранилище) с коллекциями
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий коллекций
|
/// Возвращение списка названий коллекций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Keys => _storages.Keys.ToList();
|
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StorageCollection()
|
public StorageCollection()
|
||||||
{
|
{
|
||||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление коллекции в хранилище
|
/// Добавление коллекции в хранилище
|
||||||
@ -35,12 +35,13 @@ public class StorageCollection<T>
|
|||||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||||
// TODO Прописать логику для добавления
|
// TODO Прописать логику для добавления
|
||||||
|
|
||||||
if (_storages.ContainsKey(name)) return;
|
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||||
|
if (_storages.ContainsKey(collectionInfo)) return;
|
||||||
if (collectionType == CollectionType.None) return;
|
if (collectionType == CollectionType.None) return;
|
||||||
else if (collectionType == CollectionType.Massive)
|
else if (collectionType == CollectionType.Massive)
|
||||||
_storages[name] = new MassiveGenericObjects<T>();
|
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||||
else if (collectionType == CollectionType.List)
|
else if (collectionType == CollectionType.List)
|
||||||
_storages[name] = new ListGenericObjects<T>();
|
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление коллекции
|
/// Удаление коллекции
|
||||||
@ -48,9 +49,9 @@ public class StorageCollection<T>
|
|||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
public void DelCollection(string name)
|
public void DelCollection(string name)
|
||||||
{
|
{
|
||||||
// TODO Прописать логику для удаления коллекции
|
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
if (_storages.ContainsKey(name))
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
_storages.Remove(name);
|
_storages.Remove(collectionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,10 +63,13 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO Продумать логику получения объекта
|
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
if (_storages.ContainsKey(name))
|
|
||||||
return _storages[name];
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
|
return _storages[collectionInfo];
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +108,7 @@ public class StorageCollection<T>
|
|||||||
|
|
||||||
{
|
{
|
||||||
writer.Write(_collectionKey);
|
writer.Write(_collectionKey);
|
||||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||||
|
|
||||||
{
|
{
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
@ -117,8 +121,6 @@ public class StorageCollection<T>
|
|||||||
|
|
||||||
sb.Append(value.Key);
|
sb.Append(value.Key);
|
||||||
sb.Append(_separatorForKeyValue);
|
sb.Append(_separatorForKeyValue);
|
||||||
sb.Append(value.Value.GetCollectionType);
|
|
||||||
sb.Append(_separatorForKeyValue);
|
|
||||||
sb.Append(value.Value.MaxCount);
|
sb.Append(value.Value.MaxCount);
|
||||||
sb.Append(_separatorForKeyValue);
|
sb.Append(_separatorForKeyValue);
|
||||||
foreach (T? item in value.Value.GetItems())
|
foreach (T? item in value.Value.GetItems())
|
||||||
@ -167,13 +169,14 @@ public class StorageCollection<T>
|
|||||||
|
|
||||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
if (record.Length != 4)
|
if (record.Length != 3)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);//////////////////CreateCollection
|
|
||||||
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType);
|
||||||
|
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
|
|
||||||
@ -181,8 +184,8 @@ public class StorageCollection<T>
|
|||||||
throw new Exception("Не удалось создать коллекцию");
|
throw new Exception("Не удалось создать коллекцию");
|
||||||
}
|
}
|
||||||
|
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -209,7 +212,7 @@ public class StorageCollection<T>
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_storages.Add(record[0], collection);
|
_storages.Add(collectionInfo, collection);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,72 @@
|
|||||||
|
namespace ProjectAiroplane.Drawnings;
|
||||||
|
using ProjectAiroplane.Entities;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация сравнения двух объектов класса-прорисовки
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningPlaneEqutables : IEqualityComparer<Drawningplane?>
|
||||||
|
{
|
||||||
|
public bool Equals(Drawningplane? x, Drawningplane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.Entityplane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.Entityplane == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.Entityplane.Speed != y.Entityplane.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.Entityplane.Weight != y.Entityplane.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.Entityplane.BodyColor != y.Entityplane.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x is EntityAiroplane && y is EntityAiroplane)
|
||||||
|
{
|
||||||
|
// TODO доделать логику сравнения дополнительных параметров
|
||||||
|
EntityAiroplane _x = (EntityAiroplane)x.Entityplane ;
|
||||||
|
|
||||||
|
EntityAiroplane _y = (EntityAiroplane)x.Entityplane;
|
||||||
|
|
||||||
|
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_x.Toplivbak != _y.Toplivbak)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_x.Radar != _y.Radar)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] Drawningplane? obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAiroplane.Drawnings;
|
||||||
|
|
||||||
|
internal class PlaneCompareByColor : IComparer<Drawningplane?>
|
||||||
|
{
|
||||||
|
public int Compare(Drawningplane? x, Drawningplane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.Entityplane == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.Entityplane == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var bodycolorCompare = x.Entityplane.BodyColor.Name.CompareTo(y.Entityplane.BodyColor.Name);
|
||||||
|
if (bodycolorCompare != 0)
|
||||||
|
{
|
||||||
|
return bodycolorCompare;
|
||||||
|
}
|
||||||
|
var speedCompare = x.Entityplane.Speed.CompareTo(y.Entityplane.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.Entityplane.Weight.CompareTo(y.Entityplane.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
using ProjectAiroplane.Drawnings;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAiroplane.CollectionGenericObjects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сравнение по типу, скорости, весу
|
||||||
|
/// </summary>
|
||||||
|
public class PlaneCompareByType : IComparer<Drawningplane?>
|
||||||
|
{
|
||||||
|
public int Compare(Drawningplane? x, Drawningplane? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.Entityplane == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.Entityplane == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = x.Entityplane.Speed.CompareTo(y.Entityplane.Speed);
|
||||||
|
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.Entityplane.Weight.CompareTo(y.Entityplane.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace ProjectAiroplane.Exceptions;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку переполнения коллекции
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
public class ObjectIsEqualException : ApplicationException
|
||||||
|
{
|
||||||
|
public ObjectIsEqualException(int count) : base("В коллекции содержится одинаковый элемент: " + count) { }
|
||||||
|
public ObjectIsEqualException() : base() { }
|
||||||
|
public ObjectIsEqualException(string message) : base(message) { }
|
||||||
|
public ObjectIsEqualException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected ObjectIsEqualException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
@ -52,6 +52,8 @@
|
|||||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
openFileDialog = new OpenFileDialog();
|
openFileDialog = new OpenFileDialog();
|
||||||
saveFileDialog = new SaveFileDialog();
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
panelCompanyTools.SuspendLayout();
|
panelCompanyTools.SuspendLayout();
|
||||||
panelStorage.SuspendLayout();
|
panelStorage.SuspendLayout();
|
||||||
@ -68,27 +70,29 @@
|
|||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(859, 28);
|
groupBoxTools.Location = new Point(859, 28);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(277, 652);
|
groupBoxTools.Size = new Size(277, 689);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// panelCompanyTools
|
// panelCompanyTools
|
||||||
//
|
//
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||||
panelCompanyTools.Controls.Add(buttonAddPlane);
|
panelCompanyTools.Controls.Add(buttonAddPlane);
|
||||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
panelCompanyTools.Controls.Add(buttonDelPlane);
|
panelCompanyTools.Controls.Add(buttonDelPlane);
|
||||||
panelCompanyTools.Controls.Add(maskedTextBox1);
|
panelCompanyTools.Controls.Add(maskedTextBox1);
|
||||||
panelCompanyTools.Controls.Add(buttonReFresh);
|
panelCompanyTools.Controls.Add(buttonReFresh);
|
||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(9, 380);
|
panelCompanyTools.Location = new Point(9, 364);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(268, 322);
|
panelCompanyTools.Size = new Size(268, 338);
|
||||||
panelCompanyTools.TabIndex = 9;
|
panelCompanyTools.TabIndex = 9;
|
||||||
//
|
//
|
||||||
// buttonAddPlane
|
// buttonAddPlane
|
||||||
//
|
//
|
||||||
buttonAddPlane.Location = new Point(7, 14);
|
buttonAddPlane.Location = new Point(4, 3);
|
||||||
buttonAddPlane.Name = "buttonAddPlane";
|
buttonAddPlane.Name = "buttonAddPlane";
|
||||||
buttonAddPlane.Size = new Size(252, 40);
|
buttonAddPlane.Size = new Size(252, 40);
|
||||||
buttonAddPlane.TabIndex = 1;
|
buttonAddPlane.TabIndex = 1;
|
||||||
@ -98,7 +102,7 @@
|
|||||||
//
|
//
|
||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Location = new Point(4, 168);
|
buttonGoToCheck.Location = new Point(4, 131);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(254, 42);
|
buttonGoToCheck.Size = new Size(254, 42);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
@ -108,7 +112,7 @@
|
|||||||
//
|
//
|
||||||
// buttonDelPlane
|
// buttonDelPlane
|
||||||
//
|
//
|
||||||
buttonDelPlane.Location = new Point(4, 119);
|
buttonDelPlane.Location = new Point(4, 82);
|
||||||
buttonDelPlane.Name = "buttonDelPlane";
|
buttonDelPlane.Name = "buttonDelPlane";
|
||||||
buttonDelPlane.Size = new Size(254, 43);
|
buttonDelPlane.Size = new Size(254, 43);
|
||||||
buttonDelPlane.TabIndex = 4;
|
buttonDelPlane.TabIndex = 4;
|
||||||
@ -118,7 +122,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBox1
|
// maskedTextBox1
|
||||||
//
|
//
|
||||||
maskedTextBox1.Location = new Point(7, 74);
|
maskedTextBox1.Location = new Point(6, 49);
|
||||||
maskedTextBox1.Mask = "00";
|
maskedTextBox1.Mask = "00";
|
||||||
maskedTextBox1.Name = "maskedTextBox1";
|
maskedTextBox1.Name = "maskedTextBox1";
|
||||||
maskedTextBox1.Size = new Size(252, 27);
|
maskedTextBox1.Size = new Size(252, 27);
|
||||||
@ -127,7 +131,7 @@
|
|||||||
//
|
//
|
||||||
// buttonReFresh
|
// buttonReFresh
|
||||||
//
|
//
|
||||||
buttonReFresh.Location = new Point(4, 220);
|
buttonReFresh.Location = new Point(4, 179);
|
||||||
buttonReFresh.Name = "buttonReFresh";
|
buttonReFresh.Name = "buttonReFresh";
|
||||||
buttonReFresh.Size = new Size(252, 40);
|
buttonReFresh.Size = new Size(252, 40);
|
||||||
buttonReFresh.TabIndex = 6;
|
buttonReFresh.TabIndex = 6;
|
||||||
@ -137,7 +141,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCreateCompany
|
// buttonCreateCompany
|
||||||
//
|
//
|
||||||
buttonCreateCompany.Location = new Point(13, 346);
|
buttonCreateCompany.Location = new Point(13, 330);
|
||||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
buttonCreateCompany.Size = new Size(252, 28);
|
buttonCreateCompany.Size = new Size(252, 28);
|
||||||
buttonCreateCompany.TabIndex = 8;
|
buttonCreateCompany.TabIndex = 8;
|
||||||
@ -157,7 +161,7 @@
|
|||||||
panelStorage.Dock = DockStyle.Top;
|
panelStorage.Dock = DockStyle.Top;
|
||||||
panelStorage.Location = new Point(3, 23);
|
panelStorage.Location = new Point(3, 23);
|
||||||
panelStorage.Name = "panelStorage";
|
panelStorage.Name = "panelStorage";
|
||||||
panelStorage.Size = new Size(271, 283);
|
panelStorage.Size = new Size(271, 270);
|
||||||
panelStorage.TabIndex = 7;
|
panelStorage.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// buttonCollectionDel
|
// buttonCollectionDel
|
||||||
@ -233,7 +237,7 @@
|
|||||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
comboBoxSelectorCompany.Location = new Point(13, 312);
|
comboBoxSelectorCompany.Location = new Point(13, 296);
|
||||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
comboBoxSelectorCompany.Size = new Size(252, 28);
|
comboBoxSelectorCompany.Size = new Size(252, 28);
|
||||||
comboBoxSelectorCompany.TabIndex = 0;
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
@ -244,7 +248,7 @@
|
|||||||
pictureBox.Dock = DockStyle.Fill;
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
pictureBox.Location = new Point(0, 28);
|
pictureBox.Location = new Point(0, 28);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(859, 652);
|
pictureBox.Size = new Size(859, 689);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -289,11 +293,31 @@
|
|||||||
//
|
//
|
||||||
saveFileDialog.Filter = "txt file | *.txt";
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new Point(4, 225);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(254, 42);
|
||||||
|
buttonSortByType.TabIndex = 7;
|
||||||
|
buttonSortByType.Text = "Сортировать по Типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new Point(4, 273);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(252, 40);
|
||||||
|
buttonSortByColor.TabIndex = 8;
|
||||||
|
buttonSortByColor.Text = "Сортировать по Цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
// FormPlaneCollection
|
// FormPlaneCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1136, 680);
|
ClientSize = new Size(1136, 717);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(menuStrip1);
|
Controls.Add(menuStrip1);
|
||||||
@ -338,5 +362,7 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
private Button buttonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -77,18 +77,15 @@ public partial class FormPlaneCollection : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (ObjectNotFoundException) { MessageBox.Show("Не удалось добавить объект");//ловлю ошибку1
|
catch (ObjectNotFoundException) { }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
catch (CollectionOverflowException ex)
|
catch (CollectionOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
catch (PositionOutOfCollectionException ex)
|
catch (ObjectIsEqualException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Выход за границы коллекции");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -125,7 +122,7 @@ public partial class FormPlaneCollection : Form
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);//отсюда идут в ткс2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -248,7 +245,7 @@ public partial class FormPlaneCollection : Form
|
|||||||
listBoxCollection.Items.Clear();
|
listBoxCollection.Items.Clear();
|
||||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||||
{
|
{
|
||||||
string? colName = _storageCollection.Keys?[i];
|
string? colName = _storageCollection.Keys?[i].Name;
|
||||||
if (!string.IsNullOrEmpty(colName))
|
if (!string.IsNullOrEmpty(colName))
|
||||||
{
|
{
|
||||||
listBoxCollection.Items.Add(colName);
|
listBoxCollection.Items.Add(colName);
|
||||||
@ -325,4 +322,28 @@ public partial class FormPlaneCollection : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ComparePlane(new PlaneCompareByType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
ComparePlane(new PlaneCompareByColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по сравнителю
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
private void ComparePlane(IComparer<Drawningplane?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user