diff --git a/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs b/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs
index 5513f24..4a4727b 100644
--- a/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs
+++ b/AirFighter/AirFighter/CollectionGenericObjects/AbstractCompany.cs
@@ -60,7 +60,8 @@ public abstract class AbstractCompany
///
public static int operator +(AbstractCompany company, DrawningMilitaryAircraft militaryAircraft)
{
- return company._collection.Insert(militaryAircraft);
+ return company._collection?.Insert(militaryAircraft, new DrawiningMilitaryAircraftEqutables()) ??
+ throw new DrawningEquitablesException();
}
///
@@ -113,6 +114,12 @@ public abstract class AbstractCompany
return bitmap;
}
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
+
///
/// Вывод заднего фона
///
diff --git a/AirFighter/AirFighter/CollectionGenericObjects/CollectionInfo.cs b/AirFighter/AirFighter/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..8f8123f
--- /dev/null
+++ b/AirFighter/AirFighter/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,51 @@
+namespace ProjectAirFighter.CollectionGenericObjects;
+
+public class CollectionInfo : IEquatable
+{
+ public string Name { get; private set; }
+ public CollectionType CollectionType { get; private set; }
+ public string Description { get; private set; }
+ private static readonly string _separator = "-";
+ public CollectionInfo(string name, CollectionType collectionType, string description)
+ {
+ Name = name;
+ CollectionType = collectionType;
+ Description = description;
+ }
+ 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 bool IsEmpty()
+ {
+ if (string.IsNullOrEmpty(Name) && CollectionType != CollectionType.None) return true;
+ return false;
+ }
+
+ public override int GetHashCode()
+ {
+ return Name.GetHashCode();
+ }
+}
diff --git a/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs
index 23cee8c..e55afb2 100644
--- a/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/AirFighter/AirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -24,7 +24,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -32,7 +32,7 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
@@ -58,4 +58,10 @@ public interface ICollectionGenericObjects
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+
+ ///
+ /// Сортировка коллекции
+ ///
+ /// Сравнитель объектов
+ void CollectionSort(IComparer comparer);
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs
index 0e8e5fa..1afa661 100644
--- a/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs
+++ b/AirFighter/AirFighter/CollectionGenericObjects/ListGenericObjects.cs
@@ -52,14 +52,14 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj);
return Count;
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
@@ -82,4 +82,9 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
index 59818b3..b89de50 100644
--- a/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/AirFighter/AirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,5 @@
-using ProjectAirFighter.Exceptions;
+using ProjectAirFighter.Drawnings;
+using ProjectAirFighter.Exceptions;
namespace ProjectAirFighter.CollectionGenericObjects;
@@ -55,9 +56,18 @@ public class MassiveGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
- for (int i = 0; i < Count - 3; i++)
+ if (comparer != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningMilitaryAircraft, item as DrawningMilitaryAircraft))
+ throw new CollectionInsertException();
+ }
+ }
+
+ for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
{
@@ -66,47 +76,46 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
}
throw new CollectionOverflowException(Count);
+
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
- if (position < 0 || position >= Count - 3) throw new PositionOutOfCollectionException(position);
-
- if (_collection[position] != null)
+ if (comparer != null)
{
- bool pushed = false;
- for (int index = position + 1; index < Count; index++)
+ foreach (T? item in _collection)
{
- if (_collection[index] == null)
- {
- position = index;
- pushed = true;
- break;
- }
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningMilitaryAircraft, item as DrawningMilitaryAircraft))
+ throw new CollectionInsertException();
}
+ }
+ if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
- if (!pushed)
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+ else
+ {
+ for (int i = 1; i < Count; ++i)
{
- for (int index = position - 1; index >= 0; index--)
+ if (_collection[position + i] == null)
{
- if (_collection[index] == null)
+ _collection[position + i] = obj;
+ return position + i;
+ }
+ for (i = position - 1; i >= 0; i--)
+ {
+ if (_collection[i] == null)
{
- position = index;
- pushed = true;
- break;
+ _collection[i] = obj;
+ return i;
}
}
}
-
- if (!pushed)
- {
- throw new CollectionOverflowException(Count);
- }
}
-
- // вставка
- _collection[position] = obj;
- return position;
+ throw new CollectionOverflowException(Count);
}
public T? Remove(int position)
@@ -125,4 +134,11 @@ public class MassiveGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ List value = new List(_collection);
+ value.Sort(comparer);
+ value.CopyTo(_collection, 0);
+ }
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs
index 3ed993b..f376dc9 100644
--- a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs
+++ b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs
@@ -14,12 +14,12 @@ public class StorageCollection
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> _storages;
+ readonly Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
/// Ключевое слово, с которого должен начинаться файл
///
@@ -40,7 +40,7 @@ public class StorageCollection
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
@@ -50,18 +50,15 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (name == null || _storages.ContainsKey(name)) { return; }
- switch (collectionType)
-
+ CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
+ if (_storages.ContainsKey(collectionInfo)) throw new CollectionAlreadyExistsException(collectionInfo);
+ else if (collectionType == CollectionType.Massive)
{
- case CollectionType.None:
- return;
- case CollectionType.Massive:
- _storages[name] = new MassiveGenericObjects();
- return;
- case CollectionType.List:
- _storages[name] = new ListGenericObjects();
- return;
+ _storages[collectionInfo] = new MassiveGenericObjects();
+ }
+ else if (collectionType == CollectionType.List)
+ {
+ _storages[collectionInfo] = new ListGenericObjects();
}
}
@@ -71,8 +68,11 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- if (_storages.ContainsKey(name))
- _storages.Remove(name);
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ {
+ _storages.Remove(collectionInfo);
+ }
}
///
@@ -84,8 +84,12 @@ public class StorageCollection
{
get
{
- if (name == null || !_storages.ContainsKey(name)) { return null; }
- return _storages[name];
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ {
+ return _storages[collectionInfo];
+ }
+ return null;
}
}
@@ -111,36 +115,30 @@ public class StorageCollection
{
writer.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
- StringBuilder sb = new();
-
- sb.Append(Environment.NewLine);
+ writer.Write(Environment.NewLine);
if (value.Value.Count == 0)
{
continue;
}
- sb.Append(value.Key);
- sb.Append(_separatorForKeyValue);
- sb.Append(value.Value.GetCollectionType);
- sb.Append(_separatorForKeyValue);
- sb.Append(value.Value.MaxCount);
- sb.Append(_separatorForKeyValue);
+ writer.Write(value.Key);
+ writer.Write(_separatorForKeyValue);
+ writer.Write(value.Value.MaxCount);
+ writer.Write(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
-
if (string.IsNullOrEmpty(data))
{
continue;
}
- sb.Append(data);
- sb.Append(_separatorItems);
+ writer.Write(data);
+ writer.Write(_separatorItems);
}
- writer.Write(sb);
}
}
}
@@ -154,65 +152,58 @@ public class StorageCollection
{
if (!File.Exists(filename))
{
- throw new FileNotFoundException("Файл не существует");
+ throw new Exceptions.FileNotFoundException(filename);
}
+
using (StreamReader fs = File.OpenText(filename))
{
string str = fs.ReadLine();
-
- if (str == null || str.Length == 0)
+ if (string.IsNullOrEmpty(str))
{
- throw new FormatException("В файле неверные данные");
+ throw new EmptyFileExeption(filename);
}
if (!str.StartsWith(_collectionKey))
{
- throw new FormatException("В файле неверные данные");
+ throw new Exceptions.FileFormatException(filename);
}
_storages.Clear();
-
string strs = "";
-
while ((strs = fs.ReadLine()) != null)
{
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
-
- if (record.Length != 4)
+ if (record.Length != 3)
{
continue;
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
+ CollectionInfo? collectionInfo =
+ CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new CollectionInfoException("Не удалось определить информацию коллекции:" + record[0]);
- if (collection == null)
- {
- throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]);
- }
-
- collection.MaxCount = Convert.ToInt32(record[2]);
-
- string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
+ ICollectionGenericObjects? collection =
+ StorageCollection.CreateCollection(collectionInfo.CollectionType) ??
+ throw new CollectionTypeException("Не удалось определить тип коллекции:" + record[1]);
+ collection.MaxCount = Convert.ToInt32(record[1]);
+ string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningMilitaryAircraft() is T militaryAircraft)
{
try
{
- if (collection.Insert(militaryAircraft) == -1)
- {
- throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
- }
+ collection.Insert(militaryAircraft);
}
- catch (CollectionOverflowException ex)
+ catch (Exception ex)
{
- throw new CollectionOverflowException("Коллекция переполнена", ex);
+ throw new Exceptions.FileFormatException(filename, ex);
}
}
}
- _storages.Add(record[0], collection);
+
+ _storages.Add(collectionInfo, collection);
}
}
}
diff --git a/AirFighter/AirFighter/Drawnings/DrawiningMilitaryAircraftEqutables.cs b/AirFighter/AirFighter/Drawnings/DrawiningMilitaryAircraftEqutables.cs
new file mode 100644
index 0000000..436de4c
--- /dev/null
+++ b/AirFighter/AirFighter/Drawnings/DrawiningMilitaryAircraftEqutables.cs
@@ -0,0 +1,69 @@
+using ProjectAirFighter.Entities;
+using System.Diagnostics.CodeAnalysis;
+
+namespace ProjectAirFighter.Drawnings;
+
+///
+/// Реализация сравнения двух объектов класса-прорисовки
+///
+public class DrawiningMilitaryAircraftEqutables : IEqualityComparer
+{
+ public bool Equals(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
+ {
+ if (x == null || x.EntityMilitaryAircraft == null)
+ {
+ return false;
+ }
+
+ if (y == null || y.EntityMilitaryAircraft == null)
+ {
+ return false;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return false;
+ }
+
+ if (x.EntityMilitaryAircraft.Speed != y.EntityMilitaryAircraft.Speed)
+ {
+ return false;
+ }
+
+ if (x.EntityMilitaryAircraft.Weight != y.EntityMilitaryAircraft.Weight)
+ {
+ return false;
+ }
+
+ if (x.EntityMilitaryAircraft.BodyColor != y.EntityMilitaryAircraft.BodyColor)
+ {
+ return false;
+ }
+
+ if (x is DrawningAirFighter && y is DrawningAirFighter)
+ {
+ EntityAirFighter EntityX = (EntityAirFighter)x.EntityMilitaryAircraft;
+ EntityAirFighter EntityY = (EntityAirFighter)y.EntityMilitaryAircraft;
+
+ if (EntityX.Wings != EntityY.Wings)
+ {
+ return false;
+ }
+
+ if (EntityX.Rockets != EntityY.Rockets)
+ {
+ return false;
+ }
+
+ if (EntityX.AdditionalColor != EntityY.AdditionalColor)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ public int GetHashCode([DisallowNull] DrawningMilitaryAircraft obj)
+ {
+ return obj.GetHashCode();
+ }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraftCompareByColor.cs b/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraftCompareByColor.cs
new file mode 100644
index 0000000..c18f2d9
--- /dev/null
+++ b/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraftCompareByColor.cs
@@ -0,0 +1,44 @@
+using ProjectAirFighter.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Drawnings;
+///
+/// Сравнение по цвету, скорости, весу
+///
+public class DrawningMilitaryAircraftCompareByColor : IComparer
+{
+ public int Compare(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
+ {
+ if (x == null && y == null) return 0;
+ if (x == null || x.EntityMilitaryAircraft == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityMilitaryAircraft == null)
+ {
+ return -1;
+ }
+
+ if (ToHex(x.EntityMilitaryAircraft.BodyColor) != ToHex(y.EntityMilitaryAircraft.BodyColor))
+ {
+ return String.Compare(ToHex(x.EntityMilitaryAircraft.BodyColor), ToHex(y.EntityMilitaryAircraft.BodyColor),
+ StringComparison.Ordinal);
+ }
+
+ var speedCompare = x.EntityMilitaryAircraft.Speed.CompareTo(y.EntityMilitaryAircraft.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+
+ return x.EntityMilitaryAircraft.Weight.CompareTo(y.EntityMilitaryAircraft.Weight);
+ }
+
+ private static String ToHex(Color c)
+ => $"#{c.R:X2}{c.G:X2}{c.B:X2}";
+}
diff --git a/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraftCompareByType.cs b/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraftCompareByType.cs
new file mode 100644
index 0000000..6654a02
--- /dev/null
+++ b/AirFighter/AirFighter/Drawnings/DrawningMilitaryAircraftCompareByType.cs
@@ -0,0 +1,31 @@
+namespace ProjectAirFighter.Drawnings;
+
+public class DrawningMilitaryAircraftCompareByType : IComparer
+{
+ public int Compare(DrawningMilitaryAircraft? x, DrawningMilitaryAircraft? y)
+ {
+ if (x == null || x.EntityMilitaryAircraft == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityMilitaryAircraft == null)
+ {
+ return -1;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return x.GetType().Name.CompareTo(y.GetType().Name);
+ }
+
+ var speedCompare = x.EntityMilitaryAircraft.Speed.CompareTo(y.EntityMilitaryAircraft.Speed);
+
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+
+ return x.EntityMilitaryAircraft.Weight.CompareTo(y.EntityMilitaryAircraft.Weight);
+ }
+}
diff --git a/AirFighter/AirFighter/Entities/EntityMilitaryAircraf.cs b/AirFighter/AirFighter/Entities/EntityMilitaryAircraf.cs
new file mode 100644
index 0000000..0773701
--- /dev/null
+++ b/AirFighter/AirFighter/Entities/EntityMilitaryAircraf.cs
@@ -0,0 +1,29 @@
+namespace ProjectAirFighter.Entities;
+
+///
+/// Класс-сущность "Истребитель"
+///
+public class EntityMilitaryAircraf
+{
+ public int Speed { get; private set; }
+
+ public double Weight { get; private set; }
+
+ public Color BodyColor { get; private set; }
+
+ public double Step => Speed * 100 / Weight;
+
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+
+ public EntityMilitaryAircraf (int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/AirFighter/AirFighter/Exceptions/CollectionAlreadyExistsException.cs b/AirFighter/AirFighter/Exceptions/CollectionAlreadyExistsException.cs
new file mode 100644
index 0000000..4c2d371
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/CollectionAlreadyExistsException.cs
@@ -0,0 +1,20 @@
+using ProjectAirFighter.CollectionGenericObjects;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Exceptions;
+
+public class CollectionAlreadyExistsException : Exception
+{
+ public CollectionAlreadyExistsException() : base() { }
+ public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base($"Коллекция {collectionInfo} уже существует!") { }
+ public CollectionAlreadyExistsException(string name, Exception exception) :
+ base($"Коллекция {name} уже существует!", exception)
+ { }
+ protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
diff --git a/AirFighter/AirFighter/Exceptions/CollectionInfoException.cs b/AirFighter/AirFighter/Exceptions/CollectionInfoException.cs
new file mode 100644
index 0000000..a8d789c
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/CollectionInfoException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Exceptions;
+
+public class CollectionInfoException : Exception
+{
+ public CollectionInfoException() : base() { }
+ public CollectionInfoException(string message) : base(message) { }
+ public CollectionInfoException(string message, Exception exception) :
+ base(message, exception)
+ { }
+ protected CollectionInfoException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/Exceptions/CollectionInsertException.cs b/AirFighter/AirFighter/Exceptions/CollectionInsertException.cs
new file mode 100644
index 0000000..532fa18
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/CollectionInsertException.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Exceptions;
+
+public class CollectionInsertException : Exception
+{
+ public CollectionInsertException(object obj) : base($"Объект {obj} не удволетворяет уникальности") { }
+ public CollectionInsertException() : base() { }
+ public CollectionInsertException(string message) : base(message) { }
+ public CollectionInsertException(string message, Exception exception) :
+ base(message, exception)
+ { }
+ protected CollectionInsertException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/Exceptions/CollectionTypeException.cs b/AirFighter/AirFighter/Exceptions/CollectionTypeException.cs
new file mode 100644
index 0000000..2f13ae8
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/CollectionTypeException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Exceptions;
+
+public class CollectionTypeException : Exception
+{
+ public CollectionTypeException() : base() { }
+ public CollectionTypeException(string message) : base(message) { }
+ public CollectionTypeException(string message, Exception exception) :
+ base(message, exception)
+ { }
+ protected CollectionTypeException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/Exceptions/DrawningEquitablesException.cs b/AirFighter/AirFighter/Exceptions/DrawningEquitablesException.cs
new file mode 100644
index 0000000..34a98c8
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/DrawningEquitablesException.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Exceptions;
+
+public class DrawningEquitablesException : Exception
+{
+ public DrawningEquitablesException() : base("Объекты прорисовки одинаковые") { }
+ public DrawningEquitablesException(string message) : base(message) { }
+ public DrawningEquitablesException(string message, Exception exception) :
+ base(message, exception)
+ { }
+ protected DrawningEquitablesException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
diff --git a/AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs b/AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs
new file mode 100644
index 0000000..f075981
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/EmptyFileExeption.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirFighter.Exceptions;
+
+public class EmptyFileExeption : Exception
+{
+ public EmptyFileExeption(string name) : base($"Файл {name} пустой ") { }
+ public EmptyFileExeption() : base("В хранилище отсутствуют коллекции для сохранения") { }
+ public EmptyFileExeption(string name, string message) : base(message) { }
+ public EmptyFileExeption(string name, string message, Exception exception) :
+ base(message, exception)
+ { }
+ protected EmptyFileExeption(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
diff --git a/AirFighter/AirFighter/Exceptions/FileFormatException.cs b/AirFighter/AirFighter/Exceptions/FileFormatException.cs
new file mode 100644
index 0000000..c682749
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/FileFormatException.cs
@@ -0,0 +1,15 @@
+using System.Runtime.Serialization;
+
+
+namespace ProjectAirFighter.Exceptions;
+
+public class FileFormatException : Exception
+{
+ public FileFormatException() : base() { }
+ public FileFormatException(string message) : base(message) { }
+ public FileFormatException(string name, Exception exception) :
+ base($"Файл {name} имеет неверный формат. Ошибка: {exception.Message}", exception)
+ { }
+ protected FileFormatException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/Exceptions/FileNotFoundException.cs b/AirFighter/AirFighter/Exceptions/FileNotFoundException.cs
new file mode 100644
index 0000000..8d82ac4
--- /dev/null
+++ b/AirFighter/AirFighter/Exceptions/FileNotFoundException.cs
@@ -0,0 +1,16 @@
+using System.Runtime.Serialization;
+
+
+namespace ProjectAirFighter.Exceptions;
+
+public class FileNotFoundException : Exception
+{
+ public FileNotFoundException(string name) : base($"Файл {name} не существует ") { }
+ public FileNotFoundException() : base() { }
+ public FileNotFoundException(string name, string message) : base(message) { }
+ public FileNotFoundException(string name, string message, Exception exception) :
+ base(message, exception)
+ { }
+ protected FileNotFoundException(SerializationInfo info, StreamingContext
+ contex) : base(info, contex) { }
+}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs
index 0dbd8f4..5625feb 100644
--- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs
+++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs
@@ -52,6 +52,8 @@
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
+ ButtonSortByColor = new Button();
+ ButtonSortByType = new Button();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@@ -66,15 +68,17 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(744, 28);
+ groupBoxTools.Location = new Point(765, 28);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(206, 639);
+ groupBoxTools.Size = new Size(206, 714);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// panelCompanyTools
//
+ panelCompanyTools.Controls.Add(ButtonSortByColor);
+ panelCompanyTools.Controls.Add(ButtonSortByType);
panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonRemoveMilitaryAircraft);
@@ -84,13 +88,13 @@
panelCompanyTools.Enabled = false;
panelCompanyTools.Location = new Point(3, 357);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(200, 279);
+ panelCompanyTools.Size = new Size(200, 354);
panelCompanyTools.TabIndex = 10;
//
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(0, 227);
+ buttonRefresh.Location = new Point(0, 189);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(192, 49);
buttonRefresh.TabIndex = 7;
@@ -101,7 +105,7 @@
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(3, 178);
+ buttonGoToCheck.Location = new Point(3, 137);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(192, 49);
buttonGoToCheck.TabIndex = 6;
@@ -112,7 +116,7 @@
// buttonRemoveMilitaryAircraft
//
buttonRemoveMilitaryAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveMilitaryAircraft.Location = new Point(4, 129);
+ buttonRemoveMilitaryAircraft.Location = new Point(3, 82);
buttonRemoveMilitaryAircraft.Name = "buttonRemoveMilitaryAircraft";
buttonRemoveMilitaryAircraft.Size = new Size(191, 49);
buttonRemoveMilitaryAircraft.TabIndex = 5;
@@ -134,7 +138,7 @@
// maskedTextBoxPosition
//
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBoxPosition.Location = new Point(3, 96);
+ maskedTextBoxPosition.Location = new Point(4, 58);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(192, 27);
@@ -250,7 +254,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(744, 639);
+ pictureBox.Size = new Size(765, 714);
pictureBox.TabIndex = 3;
pictureBox.TabStop = false;
//
@@ -260,7 +264,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
- menuStrip.Size = new Size(950, 28);
+ menuStrip.Size = new Size(971, 28);
menuStrip.TabIndex = 4;
menuStrip.Text = "menuStrip";
//
@@ -295,11 +299,33 @@
//
openFileDialog.Filter = "txt file | *.txt";
//
+ // ButtonSortByColor
+ //
+ ButtonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ ButtonSortByColor.Location = new Point(3, 299);
+ ButtonSortByColor.Name = "ButtonSortByColor";
+ ButtonSortByColor.Size = new Size(192, 49);
+ ButtonSortByColor.TabIndex = 9;
+ ButtonSortByColor.Text = "Сортировка по цвету";
+ ButtonSortByColor.UseVisualStyleBackColor = true;
+ ButtonSortByColor.Click += ButtonSortByColor_Click;
+ //
+ // ButtonSortByType
+ //
+ ButtonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ ButtonSortByType.Location = new Point(3, 244);
+ ButtonSortByType.Name = "ButtonSortByType";
+ ButtonSortByType.Size = new Size(192, 49);
+ ButtonSortByType.TabIndex = 8;
+ ButtonSortByType.Text = "Сортировка по типу";
+ ButtonSortByType.UseVisualStyleBackColor = true;
+ ButtonSortByType.Click += ButtonSortByType_Click;
+ //
// FormMilitaryAircraftCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(950, 667);
+ ClientSize = new Size(971, 742);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
@@ -344,5 +370,7 @@
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
+ private Button ButtonSortByColor;
+ private Button ButtonSortByType;
}
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs
index 92506fe..5ecfb05 100644
--- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs
+++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs
@@ -219,7 +219,7 @@ public partial class FormMilitaryAircraftCollection : 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);
@@ -291,4 +291,28 @@ public partial class FormMilitaryAircraftCollection : Form
}
}
}
+
+ private void ButtonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareMilitaryAircraft(new DrawningMilitaryAircraftCompareByType());
+ }
+
+ private void ButtonSortByColor_Click(object sender, EventArgs e)
+ {
+ CompareMilitaryAircraft(new DrawningMilitaryAircraftCompareByColor());
+ }
+
+ ///
+ /// Сортировка по сравнителю
+ ///
+ /// Сравнитель объектов
+ private void CompareMilitaryAircraft(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}