Лабораторная работа 8
This commit is contained in:
parent
3a7858e07a
commit
88cbd86feb
@ -52,15 +52,15 @@ public abstract class AbstractCompany
|
|||||||
_collection.MaxCount = GetMaxCount;
|
_collection.MaxCount = GetMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора сложения для класса
|
/// Перегрузка оператора сложения для класса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="company">Компания</param>
|
/// <param name="company">Компания</param>
|
||||||
/// <param name="bomber">Добавляемый объект</param>
|
/// <param name="bomber">Добавляемый объект</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(AbstractCompany company, DrawningBomber bomber)
|
public static int operator +(AbstractCompany company, DrawningBomber bomber)
|
||||||
{
|
{
|
||||||
return company._collection.Insert(bomber);
|
return company._collection.Insert(bomber, new DrawningAirCraftEqutables());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -110,6 +110,12 @@ public abstract class AbstractCompany
|
|||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
public void Sort(IComparer<DrawningBomber?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод заднего фона
|
/// Вывод заднего фона
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
namespace ProjectAirBomber.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,61 +1,71 @@
|
|||||||
using ProjectAirBomber.Drawnings;
|
using ProjectAirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
namespace ProjectAirBomber.CollectionGenericObjects;
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Интерфейс описания действий для набора хранимых объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Интерфейс описания действий для набора хранимых объектов
|
/// Интерфейс описания действий для набора хранимых объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
public interface ICollectionGenericObjects<T>
|
public interface ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в коллекции
|
/// Количество объектов в коллекции
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Установка максимального количества элементов
|
|
||||||
/// </summary>
|
|
||||||
int MaxCount { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в коллекцию
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
|
||||||
int Insert(T obj);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
|
||||||
int Insert(T obj, int position);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
|
||||||
T? Remove(int position);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получение объекта по позиции
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="position">Позиция</param>
|
|
||||||
/// <returns>Объект</returns>
|
|
||||||
T? Get(int position);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение типа коллекции
|
/// Установка максимального количества элементов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CollectionType GetCollectionType { get; }
|
int MaxCount { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="comparer">Cравнение двух объектов</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <param name="comparer">Cравнение двух объектов</param>
|
||||||
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
|
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||||
|
T? Remove(int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объекта по позиции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="position">Позиция</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
T? Get(int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение типа коллекции
|
||||||
|
/// </summary>
|
||||||
|
CollectionType GetCollectionType { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение объектов коллекции по одному
|
/// Получение объектов коллекции по одному
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||||
IEnumerable<T?> GetItems();
|
IEnumerable<T?> GetItems();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка коллекции
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
void CollectionSort(IComparer<T?> comparer);
|
||||||
}
|
}
|
@ -1,9 +1,4 @@
|
|||||||
using ProjectAirBomber.Exceptions;
|
using ProjectAirBomber.Exceptions;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
|
|
||||||
namespace ProjectAirBomber.CollectionGenericObjects;
|
namespace ProjectAirBomber.CollectionGenericObjects;
|
||||||
@ -24,9 +19,6 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private int _maxCount;
|
private int _maxCount;
|
||||||
public int Count => _collection.Count;
|
public int Count => _collection.Count;
|
||||||
|
|
||||||
public CollectionType GetCollectionType => CollectionType.List;
|
|
||||||
|
|
||||||
public int MaxCount
|
public int MaxCount
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -42,6 +34,8 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.List;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -55,16 +49,30 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
if (_collection[position] == null) throw new ObjectNotFoundException();
|
if (_collection[position] == null) throw new ObjectNotFoundException();
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
public int Insert(T obj)
|
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
if (Count + 1 > _maxCount) throw new CollectionOverflowException(Count);
|
if (Count + 1 > _maxCount) throw new CollectionOverflowException(Count);
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectAlreadyExistsException();
|
||||||
|
}
|
||||||
|
}
|
||||||
_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?>? comparer = null)
|
||||||
{
|
{
|
||||||
if (Count + 1 > _maxCount) throw new CollectionOverflowException(Count);
|
if (Count + 1 > _maxCount) throw new CollectionOverflowException(Count);
|
||||||
if (position < 0 || position > Count) throw new PositionOutOfCollectionException(position);
|
if (position < 0 || position > Count) throw new PositionOutOfCollectionException(position);
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectAlreadyExistsException(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
_collection.Insert(position, obj);
|
_collection.Insert(position, obj);
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
@ -83,4 +91,8 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
_collection.Sort(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,7 @@
|
|||||||
using System.Runtime.Remoting;
|
|
||||||
using ProjectAirBomber.Drawnings;
|
using ProjectAirBomber.CollectionGenericObjects;
|
||||||
using ProjectAirBomber.Exceptions;
|
using ProjectAirBomber.Exceptions;
|
||||||
|
|
||||||
namespace ProjectAirBomber.CollectionGenericObjects;
|
namespace ProjectAirBomber.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -9,7 +10,6 @@ namespace ProjectAirBomber.CollectionGenericObjects;
|
|||||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
|
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Массив объектов, которые храним
|
||||||
@ -45,6 +45,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
public MassiveGenericObjects()
|
public MassiveGenericObjects()
|
||||||
{
|
{
|
||||||
_collection = Array.Empty<T?>();
|
_collection = Array.Empty<T?>();
|
||||||
@ -57,29 +58,40 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
// вставка в свободное место набора
|
if (comparer != null)
|
||||||
for (int i = 0; i < Count; i++)
|
|
||||||
{
|
{
|
||||||
if (_collection[i] == null)
|
foreach (T? i in _collection)
|
||||||
{
|
{
|
||||||
_collection[i] = obj;
|
if (comparer.Equals(i, obj))
|
||||||
return i;
|
{
|
||||||
|
throw new ObjectAlreadyExistsException(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Insert(obj, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (position < 0 || position >= Count)
|
||||||
|
{
|
||||||
|
throw new PositionOutOfCollectionException();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (comparer != null)
|
||||||
|
{
|
||||||
|
foreach (T? i in _collection)
|
||||||
|
{
|
||||||
|
if (comparer.Equals(i, obj))
|
||||||
|
{
|
||||||
|
throw new ObjectAlreadyExistsException(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new CollectionOverflowException(Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
|
||||||
{
|
|
||||||
// проверка позиции
|
|
||||||
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
|
|
||||||
|
|
||||||
// проверка, что элемент массива по этой позиции пустой, если нет, то
|
|
||||||
// ищется свободное место после этой позиции и идет вставка туда
|
|
||||||
// если нет после, ищем до
|
|
||||||
if (_collection[position] != null)
|
if (_collection[position] != null)
|
||||||
{
|
{
|
||||||
bool pushed = false;
|
bool pushed = false;
|
||||||
@ -112,23 +124,19 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// вставка
|
|
||||||
_collection[position] = obj;
|
_collection[position] = obj;
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
{
|
{
|
||||||
// проверка позиции
|
|
||||||
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
|
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
|
||||||
|
|
||||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||||
|
|
||||||
T? temp = _collection[position];
|
T? temp = _collection[position];
|
||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<T?> GetItems()
|
public IEnumerable<T?> GetItems()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _collection.Length; ++i)
|
for (int i = 0; i < _collection.Length; ++i)
|
||||||
@ -136,4 +144,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
List<T?> lst = [.. _collection];
|
||||||
|
lst.Sort(comparer.Compare);
|
||||||
|
for (int i = 0; i < _collection.Length; ++i)
|
||||||
|
{
|
||||||
|
_collection[i] = lst[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
using ProjectAirBomber.Drawnings;
|
using ProjectAirBomber.Exceptions;
|
||||||
using ProjectAirBomber.Exceptions;
|
using ProjectAirBomber.Drawnings;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@ -10,17 +10,17 @@ namespace ProjectAirBomber.CollectionGenericObjects;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class StorageCollection<T>
|
public class StorageCollection<T>
|
||||||
where T : DrawningBomber
|
where T : DrawningAirBomber
|
||||||
{
|
{
|
||||||
/// <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>
|
||||||
/// Ключевое слово, с которого должен начинаться файл
|
/// Ключевое слово, с которого должен начинаться файл
|
||||||
@ -42,7 +42,7 @@ public class StorageCollection<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public StorageCollection()
|
public StorageCollection()
|
||||||
{
|
{
|
||||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -52,13 +52,13 @@ public class StorageCollection<T>
|
|||||||
/// <param name="collectionType">тип коллекции</param>
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
{
|
{
|
||||||
|
CollectionInfo collectionInfo = new(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>
|
||||||
@ -67,8 +67,9 @@ public class StorageCollection<T>
|
|||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
public void DelCollection(string name)
|
public void DelCollection(string name)
|
||||||
{
|
{
|
||||||
if (_storages.ContainsKey(name))
|
CollectionInfo collectionInfo = new(name, CollectionType.None, string.Empty);
|
||||||
_storages.Remove(name);
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
|
_storages.Remove(collectionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -80,8 +81,9 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_storages.ContainsKey(name))
|
CollectionInfo collectionInfo = new(name, CollectionType.None, string.Empty);
|
||||||
return _storages[name];
|
if (_storages.ContainsKey(collectionInfo))
|
||||||
|
return _storages[collectionInfo];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -105,7 +107,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);
|
||||||
@ -118,10 +120,9 @@ 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())
|
||||||
{
|
{
|
||||||
string data = item?.GetDataForSave() ?? string.Empty;
|
string data = item?.GetDataForSave() ?? string.Empty;
|
||||||
@ -134,6 +135,7 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
writer.Write(sb);
|
writer.Write(sb);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,18 +166,20 @@ 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;
|
||||||
}
|
}
|
||||||
|
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||||
|
throw new Exception("Не удалось определить информацию коллекции" + record[0]);
|
||||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType);
|
||||||
if (collection == null)
|
if (collection == null)
|
||||||
{
|
{
|
||||||
throw new InvalidCastException("Не удалось определить тип коллекции:" + record[1]);
|
throw new InvalidOperationException("Не удалось создать коллекцию");
|
||||||
}
|
}
|
||||||
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?.CreateDrawningBomber() is T bomber)
|
if (elem?.CreateDrawningBomber() is T bomber)
|
||||||
@ -184,7 +188,7 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
if (collection.Insert(bomber) == -1)
|
if (collection.Insert(bomber) == -1)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
throw new ConstraintException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CollectionOverflowException ex)
|
catch (CollectionOverflowException ex)
|
||||||
@ -193,7 +197,7 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_storages.Add(record[0], collection);
|
_storages.Add(collectionInfo, collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
using ProjectAirBomber.Entities;
|
using ProjectAirBomber.Entities;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectAirBomber.Drawnings;
|
namespace ProjectAirBomber.Drawnings;
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
namespace ProjectAirBomber.Drawnings;
|
||||||
|
public class DrawningBomberCompareByColor : IComparer<DrawningBomber?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningBomber? x, DrawningBomber? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityBomber == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityBomber == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var bodycolorCompare = x.EntityBomber.BodyColor.Name.CompareTo(y.EntityBomber.BodyColor.Name);
|
||||||
|
if (bodycolorCompare != 0)
|
||||||
|
{
|
||||||
|
return bodycolorCompare;
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityBomber.Speed.CompareTo(y.EntityBomber.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityBomber.Weight.CompareTo(y.EntityBomber.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
using ProjectAirBomber.Drawnings;
|
||||||
|
|
||||||
|
public class DrawingBomberCompareByType : IComparer<DrawningBomber?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningBomber? x, DrawningBomber? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null) return 0;
|
||||||
|
if (x == null || x.EntityBomber == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityBomber == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = x.EntityBomber.Speed.CompareTo(y.EntityBomber.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
return x.EntityBomber.Weight.CompareTo(y.EntityBomber.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
using ProjectAirBomber.Entities;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace ProjectAirBomber.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Реализация сравнения двух объектов класса-прорисовки
|
||||||
|
/// </summary>
|
||||||
|
public class DrawningAirCraftEqutables : IEqualityComparer<DrawningBomber?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningBomber? x, DrawningBomber? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityBomber == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityBomber == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityBomber.Speed != y.EntityBomber.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityBomber.Weight != y.EntityBomber.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityBomber.BodyColor != y.EntityBomber.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x is DrawningAirBomber && y is DrawningAirBomber)
|
||||||
|
{
|
||||||
|
EntityAirBomber entityX = (EntityAirBomber)x.EntityBomber;
|
||||||
|
EntityAirBomber entityY = (EntityAirBomber)y.EntityBomber;
|
||||||
|
if (entityX.FuelTanks != entityY.FuelTanks)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entityX.Bombs != entityY.Bombs)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entityX.AdditionalColor != entityY.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode([DisallowNull] DrawningBomber obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectAirBomber.Exceptions;
|
||||||
|
/// <summary>
|
||||||
|
/// Класс, описывающий ошибку, что в коллекции уже есть такой элемент
|
||||||
|
/// </summary>
|
||||||
|
[Serializable]
|
||||||
|
public class ObjectAlreadyExistsException : ApplicationException
|
||||||
|
{
|
||||||
|
public ObjectAlreadyExistsException(object i) : base("В коллекции уже есть такой элемент " + i) { }
|
||||||
|
public ObjectAlreadyExistsException() : base() { }
|
||||||
|
public ObjectAlreadyExistsException(string message) : base(message) { }
|
||||||
|
public ObjectAlreadyExistsException(string message, Exception exception) : base(message, exception)
|
||||||
|
{ }
|
||||||
|
protected ObjectAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
using System.Runtime.Serialization;
|
|
||||||
|
|
||||||
|
|
||||||
namespace ProjectAirBomber.Exceptions;
|
namespace ProjectAirBomber.Exceptions;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
{
|
{
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
panelCompanyTools = new Panel();
|
panelCompanyTools = new Panel();
|
||||||
|
buttonSortByType = new Button();
|
||||||
buttonAddBomber = new Button();
|
buttonAddBomber = new Button();
|
||||||
maskedTextBoxPosition = new MaskedTextBox();
|
maskedTextBoxPosition = new MaskedTextBox();
|
||||||
buttonRefresh = new Button();
|
buttonRefresh = new Button();
|
||||||
@ -52,6 +53,8 @@
|
|||||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
saveFileDialog = new SaveFileDialog();
|
saveFileDialog = new SaveFileDialog();
|
||||||
openFileDialog = new OpenFileDialog();
|
openFileDialog = new OpenFileDialog();
|
||||||
|
button2 = new Button();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
panelCompanyTools.SuspendLayout();
|
panelCompanyTools.SuspendLayout();
|
||||||
panelStorage.SuspendLayout();
|
panelStorage.SuspendLayout();
|
||||||
@ -75,6 +78,8 @@
|
|||||||
//
|
//
|
||||||
// panelCompanyTools
|
// panelCompanyTools
|
||||||
//
|
//
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||||
panelCompanyTools.Controls.Add(buttonAddBomber);
|
panelCompanyTools.Controls.Add(buttonAddBomber);
|
||||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
@ -82,15 +87,26 @@
|
|||||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(3, 521);
|
panelCompanyTools.Location = new Point(3, 491);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(262, 285);
|
panelCompanyTools.Size = new Size(262, 315);
|
||||||
panelCompanyTools.TabIndex = 9;
|
panelCompanyTools.TabIndex = 9;
|
||||||
//
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByType.Location = new Point(3, 225);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(253, 42);
|
||||||
|
buttonSortByType.TabIndex = 8;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
// buttonAddBomber
|
// buttonAddBomber
|
||||||
//
|
//
|
||||||
buttonAddBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonAddBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonAddBomber.Location = new Point(3, 3);
|
buttonAddBomber.Location = new Point(3, 0);
|
||||||
buttonAddBomber.Name = "buttonAddBomber";
|
buttonAddBomber.Name = "buttonAddBomber";
|
||||||
buttonAddBomber.Size = new Size(253, 42);
|
buttonAddBomber.Size = new Size(253, 42);
|
||||||
buttonAddBomber.TabIndex = 1;
|
buttonAddBomber.TabIndex = 1;
|
||||||
@ -100,7 +116,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
maskedTextBoxPosition.Location = new Point(3, 99);
|
maskedTextBoxPosition.Location = new Point(3, 48);
|
||||||
maskedTextBoxPosition.Mask = "00";
|
maskedTextBoxPosition.Mask = "00";
|
||||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
maskedTextBoxPosition.Size = new Size(253, 23);
|
maskedTextBoxPosition.Size = new Size(253, 23);
|
||||||
@ -110,7 +126,7 @@
|
|||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRefresh.Location = new Point(3, 228);
|
buttonRefresh.Location = new Point(3, 177);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
buttonRefresh.Size = new Size(253, 42);
|
buttonRefresh.Size = new Size(253, 42);
|
||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
@ -121,7 +137,7 @@
|
|||||||
// buttonRemoveBomber
|
// buttonRemoveBomber
|
||||||
//
|
//
|
||||||
buttonRemoveBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRemoveBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRemoveBomber.Location = new Point(3, 128);
|
buttonRemoveBomber.Location = new Point(3, 77);
|
||||||
buttonRemoveBomber.Name = "buttonRemoveBomber";
|
buttonRemoveBomber.Name = "buttonRemoveBomber";
|
||||||
buttonRemoveBomber.Size = new Size(253, 42);
|
buttonRemoveBomber.Size = new Size(253, 42);
|
||||||
buttonRemoveBomber.TabIndex = 4;
|
buttonRemoveBomber.TabIndex = 4;
|
||||||
@ -132,7 +148,7 @@
|
|||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonGoToCheck.Location = new Point(3, 176);
|
buttonGoToCheck.Location = new Point(3, 125);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(253, 46);
|
buttonGoToCheck.Size = new Size(253, 46);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
@ -142,7 +158,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCreateCompany
|
// buttonCreateCompany
|
||||||
//
|
//
|
||||||
buttonCreateCompany.Location = new Point(3, 481);
|
buttonCreateCompany.Location = new Point(3, 448);
|
||||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
buttonCreateCompany.Size = new Size(262, 44);
|
buttonCreateCompany.Size = new Size(262, 44);
|
||||||
buttonCreateCompany.TabIndex = 8;
|
buttonCreateCompany.TabIndex = 8;
|
||||||
@ -238,7 +254,7 @@
|
|||||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||||
comboBoxSelectorCompany.Location = new Point(3, 438);
|
comboBoxSelectorCompany.Location = new Point(3, 419);
|
||||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
comboBoxSelectorCompany.Size = new Size(262, 23);
|
comboBoxSelectorCompany.Size = new Size(262, 23);
|
||||||
comboBoxSelectorCompany.TabIndex = 0;
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
@ -294,6 +310,27 @@
|
|||||||
openFileDialog.FileName = "openFileDialog1";
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
openFileDialog.Filter = "txt file|*.txt";
|
openFileDialog.Filter = "txt file|*.txt";
|
||||||
//
|
//
|
||||||
|
// button2
|
||||||
|
//
|
||||||
|
button2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
button2.Location = new Point(3, 225);
|
||||||
|
button2.Name = "button2";
|
||||||
|
button2.Size = new Size(253, 46);
|
||||||
|
button2.TabIndex = 7;
|
||||||
|
button2.Text = "Передать на тесты";
|
||||||
|
button2.UseVisualStyleBackColor = true;
|
||||||
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByColor.Location = new Point(3, 270);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(253, 42);
|
||||||
|
buttonSortByColor.TabIndex = 9;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
// FormBomberCollection
|
// FormBomberCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -305,6 +342,7 @@
|
|||||||
MainMenuStrip = menuStrip;
|
MainMenuStrip = menuStrip;
|
||||||
Name = "FormBomberCollection";
|
Name = "FormBomberCollection";
|
||||||
Text = "Коллекция самолетов";
|
Text = "Коллекция самолетов";
|
||||||
|
Load += FormBomberCollection_Load;
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
panelCompanyTools.ResumeLayout(false);
|
panelCompanyTools.ResumeLayout(false);
|
||||||
panelCompanyTools.PerformLayout();
|
panelCompanyTools.PerformLayout();
|
||||||
@ -345,5 +383,8 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
private Button button2;
|
||||||
|
private Button buttonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,15 +2,6 @@
|
|||||||
using ProjectAirBomber.CollectionGenericObjects;
|
using ProjectAirBomber.CollectionGenericObjects;
|
||||||
using ProjectAirBomber.Drawnings;
|
using ProjectAirBomber.Drawnings;
|
||||||
using ProjectAirBomber.Exceptions;
|
using ProjectAirBomber.Exceptions;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace ProjectAirBomber;
|
namespace ProjectAirBomber;
|
||||||
|
|
||||||
@ -72,7 +63,7 @@ public partial class FormBomberCollection : Form
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление военного самолёта в коллекцию
|
/// Добавление военного самолёта в коллекцию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="aircraft"></param>
|
/// <param name="bomber"></param>
|
||||||
private void SetBomber(DrawningBomber? bomber)
|
private void SetBomber(DrawningBomber? bomber)
|
||||||
{
|
{
|
||||||
if (_company == null || bomber == null)
|
if (_company == null || bomber == null)
|
||||||
@ -245,7 +236,7 @@ public partial class FormBomberCollection : 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);
|
||||||
@ -329,4 +320,44 @@ public partial class FormBomberCollection : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FormBomberCollection_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareBomber(new DrawingBomberCompareByType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по цвету
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareBomber(new DrawningBomberCompareByColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка по сравнителю
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer">Сравнитель объектов</param>
|
||||||
|
private void CompareBomber(IComparer<DrawningBomber?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
}
|
}
|
@ -126,4 +126,7 @@
|
|||||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
<value>261, 17</value>
|
<value>261, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
|
<value>25</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user