Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d3b93cd8e8 | |||
| 171c199ec9 |
@@ -59,7 +59,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static bool operator +(AbstractCompany company, DrawningAircraft aircraft)
|
||||
{
|
||||
return company._collection?.Insert(aircraft) ?? false;
|
||||
return company._collection?.Insert(aircraft, new DrawningAircraftEqutables()) ?? false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,6 +102,14 @@ public abstract class AbstractCompany
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningAircraft?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
protected abstract void DrawBackGround(Graphics g);
|
||||
protected abstract void SetObjectPosition(Graphics g);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.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();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка прошла не успешно</returns>
|
||||
bool Insert(T obj);
|
||||
bool Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
@@ -38,7 +38,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла успешно, false - вставка прошла не успешно</returns>
|
||||
bool Insert(T obj, int position);
|
||||
bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@@ -64,4 +64,10 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
using ProectMilitaryAircraft.Exceptions;
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.Exceptions;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
|
||||
|
||||
@@ -13,12 +16,12 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр : ограничение - ссылочный тип</typeparam>
|
||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
where T : DrawningAircraft
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T?> _collection;
|
||||
/// Список объектов, которые храним
|
||||
/// </summary>
|
||||
private readonly List<T?> _collection;
|
||||
|
||||
/// <summary>
|
||||
/// Максимально допустимое число объектов в списке
|
||||
@@ -66,36 +69,39 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
public bool Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (Count != _maxCount)
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
_collection.Add(obj);
|
||||
return true;
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
if (_collection.Count == _maxCount)
|
||||
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new CollectionOverflowException(_maxCount);
|
||||
MessageBox.Show("Такой объект уже существует");
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
||||
_collection.Add(obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (position > 0 && position <= _maxCount && Count != _maxCount)
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
if (_collection.Count == _maxCount)
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException(_maxCount);
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
if (!(Count >= 0 && Count <= Count))
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new Exception("Неверная позиция для вставки");
|
||||
throw new Exception("Такой объект уже существует в коллекции");
|
||||
}
|
||||
return false;
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Remove(int position)
|
||||
@@ -119,4 +125,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
using ProectMilitaryAircraft.Draw;
|
||||
using ProectMilitaryAircraft.Exceptions;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -13,31 +15,31 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр : Ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : DrawningAircraft
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T?[] _collection;
|
||||
private T?[] _collections;
|
||||
|
||||
public int Count => _collection.Length;
|
||||
public int Count => _collections.Length;
|
||||
|
||||
public int MaxCount {
|
||||
get
|
||||
{
|
||||
return _collection.Length;
|
||||
return _collections.Length;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
if (_collection.Length > 0)
|
||||
if (_collections.Length > 0)
|
||||
{
|
||||
Array.Resize(ref _collection, value);
|
||||
Array.Resize(ref _collections, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_collection = new T?[value];
|
||||
_collections = new T?[value];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,53 +52,42 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
_collections = Array.Empty<T?>();
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position > MaxCount)
|
||||
if (position < 0 || position >= _collections.Length)
|
||||
{
|
||||
throw new CollectionOverflowException(MaxCount);
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
}
|
||||
if (_collection == null)
|
||||
{
|
||||
throw new ObjectNotFoundException();
|
||||
}
|
||||
if (_collection[position] != null)
|
||||
{
|
||||
return _collection[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _collections[position];
|
||||
|
||||
}
|
||||
|
||||
public bool Insert(T obj)
|
||||
public bool Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (_collection.Length > Count)
|
||||
if (_collections.Contains(obj, comparer))
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
MessageBox.Show("Объект уже существует");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < _collection.Length; i++)
|
||||
for (int i = 0; i < _collections.Length; ++i)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
if (_collections[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
_collections[i] = obj;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position)
|
||||
public bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (_collection[position] == null)
|
||||
if (_collections[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
_collections[position] = obj;
|
||||
return true;
|
||||
}
|
||||
if (position > Count)
|
||||
@@ -108,14 +99,23 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
{
|
||||
throw new Exception("Неверная позиция для вставки");
|
||||
}
|
||||
|
||||
if (_collection[position] != null)
|
||||
if (comparer != null)
|
||||
{
|
||||
for (int i = position; i < _collection.Length; i++)
|
||||
if (_collections.Contains(obj, comparer))
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
MessageBox.Show("Объект уже существует");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (_collections[position] != null)
|
||||
{
|
||||
|
||||
for (int i = position; i < _collections.Length; i++)
|
||||
{
|
||||
|
||||
if (_collections[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
_collections[i] = obj;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -123,9 +123,9 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
|
||||
for (int i = position; i <= 0; i--)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
if (_collections[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
_collections[i] = obj;
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
@@ -136,9 +136,9 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (_collection[position] != null)
|
||||
if (_collections[position] != null)
|
||||
{
|
||||
_collection[position] = null;
|
||||
_collections[position] = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -151,9 +151,19 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
{
|
||||
for (int i = 0; i < _collection.Length; ++i)
|
||||
for (int i = 0; i < _collections.Length; ++i)
|
||||
{
|
||||
yield return _collection[i];
|
||||
yield return _collections[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
;
|
||||
if (_collections != null && _collections.Length > 0)
|
||||
{
|
||||
Array.Sort(_collections, comparer);
|
||||
_collections = _collections.OrderBy(element => element == null).ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ namespace ProectMilitaryAircraft.CollectionGenericObjects;
|
||||
public class StorageCollection<T>
|
||||
where T : DrawningAircraft
|
||||
{
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
readonly Dictionary<Collectioninfo, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
public List<Collectioninfo> Keys => _storages.Keys.ToList();
|
||||
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<Collectioninfo, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -38,38 +38,40 @@ public class StorageCollection<T>
|
||||
|
||||
public void AddCollection (string name, CollectionType collectionType)
|
||||
{
|
||||
if (name != null && !_storages.ContainsKey(name))
|
||||
if (name != null && !_storages.ContainsKey(new Collectioninfo(name, collectionType, string.Empty)))
|
||||
{
|
||||
|
||||
if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
_storages.Add(new Collectioninfo(name, collectionType,
|
||||
string.Empty), new MassiveGenericObjects<T>());
|
||||
}
|
||||
if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
_storages.Add(new Collectioninfo(name, collectionType,
|
||||
string.Empty), new ListGenericObjects<T>());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void DelCollection (string name)
|
||||
public void DelCollection (string name, CollectionType collectionType)
|
||||
{
|
||||
if (!_storages.ContainsKey(name))
|
||||
if (!_storages.ContainsKey(new Collectioninfo(name, collectionType, string.Empty)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storages.Remove(name);
|
||||
_storages.Remove(new Collectioninfo(name, collectionType, string.Empty));
|
||||
}
|
||||
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
public ICollectionGenericObjects<T>? this[string name, CollectionType collectionType]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
if (_storages.ContainsKey(new Collectioninfo(name, collectionType, string.Empty)))
|
||||
{
|
||||
return _storages[name];
|
||||
return _storages[new Collectioninfo(name, collectionType, string.Empty)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -94,7 +96,7 @@ public class StorageCollection<T>
|
||||
StringBuilder sb = new();
|
||||
|
||||
sb.Append(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
foreach (KeyValuePair<Collectioninfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
sb.Append(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
@@ -105,9 +107,7 @@ public class StorageCollection<T>
|
||||
|
||||
sb.Append(value.Key);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.GetCollectionType);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.Count);
|
||||
sb.Append(value.Value.MaxCount);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
@@ -165,21 +165,22 @@ public class StorageCollection<T>
|
||||
foreach (string data in strs)
|
||||
{
|
||||
string[] record = data.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);
|
||||
Collectioninfo? collectioninfo = Collectioninfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("Не удалось определить информацию коллекции:" + record[0]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectioninfo.CollectionType);
|
||||
if (collection == null)
|
||||
{
|
||||
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
||||
throw new Exception("Не удалось определить тип коллекции:" + record[0]);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (elem?.CreateDrawningCar() is T car)
|
||||
@@ -188,7 +189,7 @@ public class StorageCollection<T>
|
||||
{
|
||||
if (!collection.Insert(car))
|
||||
{
|
||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[2]);
|
||||
}
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
@@ -197,7 +198,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectioninfo, collection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,17 +33,16 @@ public class DrawningAircraft
|
||||
/// Верхняя координа прорисовки самолета
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
public DrawningAircraft aircraft;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningMilitaryAircraftWidth = 120;
|
||||
private readonly int _drawningAircraftWidth = 120;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawingMilitaryAircraftHeight = 110;
|
||||
private readonly int _drawingAircraftHeight = 110;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -59,12 +58,12 @@ public class DrawningAircraft
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningMilitaryAircraftWidth;
|
||||
public int GetWidth => _drawningAircraftWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawingMilitaryAircraftHeight;
|
||||
public int GetHeight => _drawingAircraftHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
@@ -86,7 +85,7 @@ public class DrawningAircraft
|
||||
|
||||
public DrawningAircraft(int speed, double weight, Color bodyColor, int width, int height) : this()
|
||||
{
|
||||
if (width < _drawingMilitaryAircraftHeight || height < _drawningMilitaryAircraftWidth)
|
||||
if (width < _drawingAircraftHeight || height < _drawningAircraftWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -103,14 +102,14 @@ public class DrawningAircraft
|
||||
|
||||
protected DrawningAircraft(int speed, double weight, Color bodyColor, int width, int height, int drawningMilitaryAircraftWidth, int drawingMilitaryAircraftHeight) : this()
|
||||
{
|
||||
if (width < _drawingMilitaryAircraftHeight || height < _drawningMilitaryAircraftWidth)
|
||||
if (width < _drawingAircraftHeight || height < _drawningAircraftWidth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
_drawningMilitaryAircraftWidth = drawningMilitaryAircraftWidth;
|
||||
_drawingMilitaryAircraftHeight = drawingMilitaryAircraftHeight;
|
||||
_drawningAircraftWidth = drawningMilitaryAircraftWidth;
|
||||
_drawingAircraftHeight = drawingMilitaryAircraftHeight;
|
||||
EntityAircraft = new EntityAircraft(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
@@ -133,8 +132,6 @@ public class DrawningAircraft
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetpictureSize(int width, int height)
|
||||
{
|
||||
// TODO провека, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была установлена
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
return true;
|
||||
@@ -187,7 +184,7 @@ public class DrawningAircraft
|
||||
//Вправо
|
||||
case DirectionType.Right:
|
||||
|
||||
if (_startPosX.Value + _drawningMilitaryAircraftWidth + EntityAircraft.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningAircraftWidth + EntityAircraft.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAircraft.Step;
|
||||
}
|
||||
@@ -197,7 +194,7 @@ public class DrawningAircraft
|
||||
//Влево
|
||||
case DirectionType.Down:
|
||||
|
||||
if (_startPosY.Value + _drawingMilitaryAircraftHeight + EntityAircraft.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawingAircraftHeight + EntityAircraft.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAircraft.Step;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningAircraftCompareByColor : IComparer<DrawningAircraft?>
|
||||
{
|
||||
public int Compare(DrawningAircraft? x, DrawningAircraft? y)
|
||||
{
|
||||
if (x == null || x.EntityAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityAircraft == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.EntityAircraft.BodyColor.Name != y.EntityAircraft.BodyColor.Name)
|
||||
{
|
||||
return x.EntityAircraft.BodyColor.Name.CompareTo(y.EntityAircraft.BodyColor.Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityAircraft.Speed.CompareTo(y.EntityAircraft.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityAircraft.Weight.CompareTo(y.EntityAircraft.Weight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по типу, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningAircraftCompareByType : IComparer<DrawningAircraft?>
|
||||
{
|
||||
public int Compare(DrawningAircraft? x, DrawningAircraft? y)
|
||||
{
|
||||
if (x == null || x.EntityAircraft == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityAircraft == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityAircraft.Speed.CompareTo(y.EntityAircraft.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityAircraft.Weight.CompareTo(y.EntityAircraft.Weight);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using ProectMilitaryAircraft.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Draw;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawningAircraftEqutables : IEqualityComparer<DrawningAircraft?>
|
||||
{
|
||||
public bool Equals(DrawningAircraft? x, DrawningAircraft? y)
|
||||
{
|
||||
if (x == null || x.EntityAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityAircraft == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityAircraft.Speed != y.EntityAircraft.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityAircraft.Weight != y.EntityAircraft.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityAircraft.BodyColor != y.EntityAircraft.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningMilitaryAircraft && y is DrawningMilitaryAircraft)
|
||||
{
|
||||
EntityMilitaryAircraft EntityX =
|
||||
(EntityMilitaryAircraft)x.EntityAircraft;
|
||||
EntityMilitaryAircraft EntityY =
|
||||
(EntityMilitaryAircraft)y.EntityAircraft;
|
||||
if (EntityX.Pin != EntityY.Pin)
|
||||
return false;
|
||||
if (EntityX.Symbolism != EntityY.Symbolism)
|
||||
return false;
|
||||
if (EntityX.Rokets != EntityY.Rokets)
|
||||
return false;
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningAircraft obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProectMilitaryAircraft.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку наличия такого же объекта в коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class ObjectNotUniqueException : ApplicationException
|
||||
{
|
||||
}
|
||||
@@ -52,6 +52,8 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
@@ -75,6 +77,8 @@
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddAircraft);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
@@ -100,7 +104,7 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(4, 229);
|
||||
buttonRefresh.Location = new Point(4, 176);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(178, 45);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
@@ -110,7 +114,7 @@
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(4, 98);
|
||||
maskedTextBox.Location = new Point(4, 45);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(178, 23);
|
||||
@@ -120,7 +124,7 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(4, 178);
|
||||
buttonGoToCheck.Location = new Point(4, 125);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(178, 45);
|
||||
buttonGoToCheck.TabIndex = 4;
|
||||
@@ -131,7 +135,7 @@
|
||||
// buttonRemoveAircraft
|
||||
//
|
||||
buttonRemoveAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveAircraft.Location = new Point(4, 127);
|
||||
buttonRemoveAircraft.Location = new Point(4, 74);
|
||||
buttonRemoveAircraft.Name = "buttonRemoveAircraft";
|
||||
buttonRemoveAircraft.Size = new Size(178, 45);
|
||||
buttonRemoveAircraft.TabIndex = 3;
|
||||
@@ -292,6 +296,28 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByType.Location = new Point(3, 229);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(85, 45);
|
||||
buttonSortByType.TabIndex = 6;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByColor.Location = new Point(94, 229);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(85, 45);
|
||||
buttonSortByColor.TabIndex = 7;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// FormAircraftCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
@@ -341,5 +367,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public partial class FormAircraftCollection : Form
|
||||
private void ButtonAddAircraft_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxCollection.SelectedIndex == -1) return;
|
||||
var obj = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty];
|
||||
var obj = _storageCollection[listBoxCollection.SelectedItem?.ToString() ?? string.Empty, new CollectionType()];
|
||||
if (obj == null) return;
|
||||
|
||||
FormAircraftConfig form = new();
|
||||
@@ -81,9 +81,9 @@ public partial class FormAircraftCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
if (_company + aircraft )
|
||||
if (_company + aircraft)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@@ -168,7 +168,7 @@ public partial class FormAircraftCollection : Form
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (aircraft == null) { return; }
|
||||
@@ -236,7 +236,7 @@ public partial class FormAircraftCollection : Form
|
||||
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem?.ToString()
|
||||
?? string.Empty);
|
||||
?? string.Empty, new CollectionType()) ;
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ public partial class FormAircraftCollection : 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);
|
||||
@@ -268,7 +268,7 @@ public partial class FormAircraftCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
ICollectionGenericObjects<DrawningAircraft>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty, new CollectionType()];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллкция не проиницилизирована");
|
||||
@@ -333,4 +333,25 @@ public partial class FormAircraftCollection : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareAircraft(new DrawningAircraftCompareByType());
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareAircraft(new DrawningAircraftCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareAircraft(IComparer<DrawningAircraft?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user