Лабораторная работа №8
This commit is contained in:
parent
cca684258e
commit
ffa8212cec
@ -56,7 +56,7 @@ public abstract class AbstractCompany
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(AbstractCompany company, DrawingExcavatorEmpty excavator)
|
public static int operator +(AbstractCompany company, DrawingExcavatorEmpty excavator)
|
||||||
{
|
{
|
||||||
return company._collection.Insert(excavator);
|
return company._collection.Insert(excavator, new DrawningExcavatorEqutables());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -115,4 +115,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<DrawingExcavatorEmpty?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsAppExcavator.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,6 @@
|
|||||||
namespace WinFormsAppExcavator.CollectionGenericObjects;
|
using WinFormsAppExcavator.Drawings;
|
||||||
|
|
||||||
|
namespace WinFormsAppExcavator.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Интерфейс описания действий для набора хранимых объектов
|
/// Интерфейс описания действий для набора хранимых объектов
|
||||||
@ -22,7 +24,7 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// </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>
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
@ -30,7 +32,7 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// <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>
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
@ -54,5 +56,11 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IEnumerable<T?> GetItems();
|
IEnumerable<T?> GetItems();
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
void CollectionSort(IComparer<T?> comparer);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
|
|
||||||
|
using ProjectWarmlyShip.Exceptions;
|
||||||
|
using WinFormsAppExcavator.Drawings;
|
||||||
using WinFormsAppExcavator.Exceptions;
|
using WinFormsAppExcavator.Exceptions;
|
||||||
namespace WinFormsAppExcavator.CollectionGenericObjects;
|
namespace WinFormsAppExcavator.CollectionGenericObjects;
|
||||||
|
|
||||||
@ -44,14 +46,28 @@ 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);
|
||||||
@ -72,4 +88,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,6 @@
|
|||||||
|
|
||||||
|
using ProjectWarmlyShip.Exceptions;
|
||||||
|
using WinFormsAppExcavator.Drawings;
|
||||||
using WinFormsAppExcavator.Exceptions;
|
using WinFormsAppExcavator.Exceptions;
|
||||||
|
|
||||||
namespace WinFormsAppExcavator.CollectionGenericObjects;
|
namespace WinFormsAppExcavator.CollectionGenericObjects;
|
||||||
@ -55,8 +57,16 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
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<DrawingExcavatorEmpty>).Equals(obj as DrawingExcavatorEmpty, item as DrawingExcavatorEmpty))
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (index < _collection.Length)
|
while (index < _collection.Length)
|
||||||
{
|
{
|
||||||
@ -72,8 +82,16 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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<DrawingExcavatorEmpty>).Equals(obj as DrawingExcavatorEmpty, item as DrawingExcavatorEmpty))
|
||||||
|
throw new ObjectIsEqualException();
|
||||||
|
}
|
||||||
|
}
|
||||||
if (position >= _collection.Length || position < 0)
|
if (position >= _collection.Length || position < 0)
|
||||||
{
|
{
|
||||||
throw new PositionOutOfCollectionException(position);
|
throw new PositionOutOfCollectionException(position);
|
||||||
@ -125,4 +143,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
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>
|
||||||
/// Добавление коллекции в хранилище
|
/// Добавление коллекции в хранилище
|
||||||
@ -34,13 +34,13 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||||
// TODO Прописать логику для добавления
|
// TODO Прописать логику для добавления
|
||||||
|
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||||
if (_storages.ContainsKey(name)) return;
|
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 +48,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,9 +62,10 @@ 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;
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ public class StorageCollection<T>
|
|||||||
using (StreamWriter writer = new StreamWriter(filename))
|
using (StreamWriter writer = new StreamWriter(filename))
|
||||||
{
|
{
|
||||||
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();
|
||||||
sb.Append(Environment.NewLine);
|
sb.Append(Environment.NewLine);
|
||||||
@ -115,8 +116,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())
|
||||||
@ -161,18 +160,19 @@ public class StorageCollection<T>
|
|||||||
while ((strs = fs.ReadLine()) != null)
|
while ((strs = fs.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
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);
|
|
||||||
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType);
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (elem?.CreateDrawningExcavatorEmpty() is T excavator)
|
if (elem?.CreateDrawningExcavatorEmpty() is T excavator)
|
||||||
@ -190,7 +190,7 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_storages.Add(record[0], collection);
|
_storages.Add(collectionInfo, collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,68 @@
|
|||||||
|
|
||||||
|
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using WinFormsAppExcavator.Entity;
|
||||||
|
|
||||||
|
namespace WinFormsAppExcavator.Drawings;
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация сравнения двух объектов класса-прорисовки
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningExcavatorEqutables : IEqualityComparer<DrawingExcavatorEmpty?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawingExcavatorEmpty? x, DrawingExcavatorEmpty? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityExcavatorEmpty == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityExcavatorEmpty == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityExcavatorEmpty.Speed != y.EntityExcavatorEmpty.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityExcavatorEmpty.Weight != y.EntityExcavatorEmpty.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityExcavatorEmpty.BodyColor != y.EntityExcavatorEmpty.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is EntityExcavator && y is EntityExcavator)
|
||||||
|
{
|
||||||
|
// TODO доделать логику сравнения дополнительных параметров
|
||||||
|
EntityExcavator _x = (EntityExcavator)x.EntityExcavatorEmpty;
|
||||||
|
EntityExcavator _y = (EntityExcavator)x.EntityExcavatorEmpty;
|
||||||
|
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.Bucket != _y.Bucket)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.BulldozerDump != _y.BulldozerDump)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (_x.Support != _y.Support)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] DrawingExcavatorEmpty? obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsAppExcavator.Drawings;
|
||||||
|
/// <summary>
|
||||||
|
/// сравнение по цвету, скорости и весу
|
||||||
|
/// </summary>
|
||||||
|
public class ExcavatorCompareByColor : IComparer<DrawingExcavatorEmpty?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingExcavatorEmpty? x, DrawingExcavatorEmpty? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityExcavatorEmpty == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityExcavatorEmpty == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var bodycolorCompare = x.EntityExcavatorEmpty.BodyColor.Name.CompareTo(y.EntityExcavatorEmpty.BodyColor.Name);
|
||||||
|
if (bodycolorCompare != 0)
|
||||||
|
{
|
||||||
|
return bodycolorCompare;
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityExcavatorEmpty.Speed.CompareTo(y.EntityExcavatorEmpty.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityExcavatorEmpty.Weight.CompareTo(y.EntityExcavatorEmpty.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace WinFormsAppExcavator.Drawings;
|
||||||
|
/// <summary>
|
||||||
|
/// Сравнение по типу, скорости, весу
|
||||||
|
/// </summary>
|
||||||
|
public class ExcavatorCompareByType : IComparer<DrawingExcavatorEmpty?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingExcavatorEmpty? x, DrawingExcavatorEmpty? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityExcavatorEmpty == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityExcavatorEmpty == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityExcavatorEmpty.Speed.CompareTo(y.EntityExcavatorEmpty.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityExcavatorEmpty.Weight.CompareTo(y.EntityExcavatorEmpty.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectWarmlyShip.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();
|
||||||
saveFileDialog = new SaveFileDialog();
|
saveFileDialog = new SaveFileDialog();
|
||||||
openFileDialog = new OpenFileDialog();
|
openFileDialog = new OpenFileDialog();
|
||||||
|
buttonSortByType = new Button();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
panelCompanyTools.SuspendLayout();
|
panelCompanyTools.SuspendLayout();
|
||||||
panelStorage.SuspendLayout();
|
panelStorage.SuspendLayout();
|
||||||
@ -68,13 +70,15 @@
|
|||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(642, 28);
|
groupBoxTools.Location = new Point(642, 28);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(220, 491);
|
groupBoxTools.Size = new Size(220, 555);
|
||||||
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(maskedTextBox);
|
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||||
panelCompanyTools.Controls.Add(buttonAddExcavatorEmpty);
|
panelCompanyTools.Controls.Add(buttonAddExcavatorEmpty);
|
||||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
@ -82,9 +86,9 @@
|
|||||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(3, 314);
|
panelCompanyTools.Location = new Point(3, 319);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(214, 174);
|
panelCompanyTools.Size = new Size(214, 233);
|
||||||
panelCompanyTools.TabIndex = 9;
|
panelCompanyTools.TabIndex = 9;
|
||||||
//
|
//
|
||||||
// maskedTextBox
|
// maskedTextBox
|
||||||
@ -110,7 +114,7 @@
|
|||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonGoToCheck.Location = new Point(6, 107);
|
buttonGoToCheck.Location = new Point(8, 107);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(206, 29);
|
buttonGoToCheck.Size = new Size(206, 29);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
@ -121,7 +125,7 @@
|
|||||||
// buttonRemoveExcavator
|
// buttonRemoveExcavator
|
||||||
//
|
//
|
||||||
buttonRemoveExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRemoveExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRemoveExcavator.Location = new Point(5, 71);
|
buttonRemoveExcavator.Location = new Point(8, 71);
|
||||||
buttonRemoveExcavator.Name = "buttonRemoveExcavator";
|
buttonRemoveExcavator.Name = "buttonRemoveExcavator";
|
||||||
buttonRemoveExcavator.Size = new Size(206, 30);
|
buttonRemoveExcavator.Size = new Size(206, 30);
|
||||||
buttonRemoveExcavator.TabIndex = 4;
|
buttonRemoveExcavator.TabIndex = 4;
|
||||||
@ -132,7 +136,7 @@
|
|||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRefresh.Location = new Point(3, 142);
|
buttonRefresh.Location = new Point(8, 142);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
buttonRefresh.Size = new Size(206, 27);
|
buttonRefresh.Size = new Size(206, 27);
|
||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
@ -248,7 +252,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(642, 491);
|
pictureBox.Size = new Size(642, 555);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -293,11 +297,33 @@
|
|||||||
//
|
//
|
||||||
openFileDialog.Filter = "txt file | *.txt";
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByType.Location = new Point(5, 175);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(206, 29);
|
||||||
|
buttonSortByType.TabIndex = 7;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByColor.Location = new Point(6, 206);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(206, 27);
|
||||||
|
buttonSortByColor.TabIndex = 8;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
// FormExcavatorCollection
|
// FormExcavatorCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(862, 519);
|
ClientSize = new Size(862, 583);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(menuStrip);
|
Controls.Add(menuStrip);
|
||||||
@ -342,5 +368,7 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
private Button buttonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using ProjectWarmlyShip.Exceptions;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using WinFormsAppExcavator.CollectionGenericObjects;
|
using WinFormsAppExcavator.CollectionGenericObjects;
|
||||||
using WinFormsAppExcavator.Drawings;
|
using WinFormsAppExcavator.Drawings;
|
||||||
@ -75,13 +76,19 @@ public partial class FormExcavatorCollection : Form
|
|||||||
catch (ObjectNotFoundException) { }
|
catch (ObjectNotFoundException) { }
|
||||||
catch (CollectionOverflowException ex)
|
catch (CollectionOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект1");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
catch (PositionOutOfCollectionException ex) {
|
catch (PositionOutOfCollectionException ex)
|
||||||
|
{
|
||||||
MessageBox.Show("Выход за границы коллекции");
|
MessageBox.Show("Выход за границы коллекции");
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
|
catch (ObjectIsEqualException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта
|
/// Удаление объекта
|
||||||
@ -210,7 +217,7 @@ public partial class FormExcavatorCollection : 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);
|
||||||
@ -291,7 +298,7 @@ public partial class FormExcavatorCollection : Form
|
|||||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
@ -324,6 +331,38 @@ public partial class FormExcavatorCollection : Form
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareExcavators(new ExcavatorCompareByType());
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Cортировка по цвету
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareExcavators(new ExcavatorCompareByColor());
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по сравнителю
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
private void CompareExcavators(IComparer<DrawingExcavatorEmpty?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,6 +127,6 @@
|
|||||||
<value>310, 17</value>
|
<value>310, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>61</value>
|
<value>123</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user