8 лабораторная
This commit is contained in:
parent
ece84af0ad
commit
100266bb26
@ -62,7 +62,11 @@ public abstract class AbstractCompany
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(AbstractCompany company, DrawingTanker tanker)
|
public static int operator +(AbstractCompany company, DrawingTanker tanker)
|
||||||
{
|
{
|
||||||
return company._collection.Insert(tanker);
|
if (company._collection.Insert(tanker, new DrawingTankerEqutables()))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -106,6 +110,8 @@ public abstract class AbstractCompany
|
|||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Sort(IComparer<DrawingTanker?> comparer) => _collection?.CollectionSort(comparer);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Вывод заднего фона
|
/// Вывод заднего фона
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -0,0 +1,76 @@
|
|||||||
|
using ProjectGasolineTanker.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();
|
||||||
|
}
|
||||||
|
}
|
@ -28,7 +28,7 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
int Insert(T obj);
|
bool Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию на конкретную позицию
|
/// Добавление объекта в коллекцию на конкретную позицию
|
||||||
@ -36,7 +36,7 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>1 - вставка прошла удачно, -1 - вставка не удалась</returns>
|
/// <returns>1 - вставка прошла удачно, -1 - вставка не удалась</returns>
|
||||||
int Insert(T obj, int position);
|
bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
@ -62,4 +62,6 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||||
IEnumerable<T?> GetItems();
|
IEnumerable<T?> GetItems();
|
||||||
|
|
||||||
|
void CollectionSort(IComparer<T?> comparer);
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
using ProjectGasolineTanker.Exceptions;
|
using NLog.LayoutRenderers;
|
||||||
using System;
|
using ProjectGasolineTanker.CollectionGenericObjects;
|
||||||
using System.Collections.Generic;
|
using ProjectGasolineTanker.Exceptions;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectGasolineTanker.CollectionGenericObjects;
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Параметризованный набор объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||||
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
@ -20,15 +19,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private int _maxCount;
|
private int _maxCount;
|
||||||
|
|
||||||
public int Count => _collection.Count;
|
|
||||||
|
|
||||||
public int MaxCount
|
public int MaxCount
|
||||||
{
|
{
|
||||||
get
|
get => _maxCount;
|
||||||
{
|
|
||||||
return _maxCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
@ -37,9 +30,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CollectionType GetCollectionType => CollectionType.List;
|
public CollectionType GetCollectionType => CollectionType.List;
|
||||||
|
|
||||||
|
public int Count => _collection.Count;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -50,39 +44,57 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position >= Count || position < 0)
|
if (position > _collection.Count || position < 0)
|
||||||
throw new PositionOutOfCollectionException(position);
|
{
|
||||||
|
throw new PositionOutOfCollectionException();
|
||||||
|
}
|
||||||
|
if (_collection[position] == null)
|
||||||
|
{
|
||||||
|
throw new ObjectNotFoundException();
|
||||||
|
}
|
||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public bool Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
if (Count + 1 > _maxCount)
|
if (Count + 1 > MaxCount)
|
||||||
throw new CollectionOverflowException(Count);
|
{
|
||||||
|
throw new CollectionOverflowException();
|
||||||
|
}
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectExistException();
|
||||||
|
}
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return Count;
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
if (Count + 1 > _maxCount)
|
if (_collection.Count + 1 < _maxCount)
|
||||||
throw new CollectionOverflowException(Count);
|
{
|
||||||
|
throw new CollectionOverflowException();
|
||||||
if (position < 0 || position > Count)
|
}
|
||||||
throw new PositionOutOfCollectionException(position);
|
if (position > _collection.Count || position < 0)
|
||||||
|
{
|
||||||
|
throw new PositionOutOfCollectionException();
|
||||||
|
}
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectExistException(position);
|
||||||
|
}
|
||||||
_collection.Insert(position, obj);
|
_collection.Insert(position, obj);
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T Remove(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position > Count)
|
if (position > _collection.Count || position < 0)
|
||||||
throw new PositionOutOfCollectionException(position);
|
{
|
||||||
|
throw new PositionOutOfCollectionException();
|
||||||
T? temp = _collection[position];
|
}
|
||||||
|
T temp = _collection[position];
|
||||||
_collection.RemoveAt(position);
|
_collection.RemoveAt(position);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@ -94,4 +106,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
_collection.Sort(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,9 +1,4 @@
|
|||||||
using ProjectGasolineTanker.Exceptions;
|
using ProjectGasolineTanker.Exceptions;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ProjectGasolineTanker.CollectionGenericObjects;
|
namespace ProjectGasolineTanker.CollectionGenericObjects;
|
||||||
|
|
||||||
@ -52,7 +47,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public T? Get(int position)
|
public T? Get(int position)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (position < 0 || position > _collection.Length - 1)
|
||||||
throw new PositionOutOfCollectionException(position);
|
throw new PositionOutOfCollectionException(position);
|
||||||
|
|
||||||
if (position >= _collection.Length && _collection[position] == null)
|
if (position >= _collection.Length && _collection[position] == null)
|
||||||
@ -61,52 +56,48 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public bool Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < Count; i++)
|
int index = Array.IndexOf(_collection, null);
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectExistException(index);
|
||||||
|
}
|
||||||
|
if (index >= 0)
|
||||||
|
{
|
||||||
|
_collection[index] = obj;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
throw new CollectionOverflowException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _collection.Length - 1)
|
||||||
|
{
|
||||||
|
throw new PositionOutOfCollectionException();
|
||||||
|
}
|
||||||
|
if (_collection.Contains(obj, comparer))
|
||||||
|
{
|
||||||
|
throw new ObjectExistException(position);
|
||||||
|
}
|
||||||
|
for (int i = position; i < _collection.Length; i++)
|
||||||
{
|
{
|
||||||
if (_collection[i] == null)
|
if (_collection[i] == null)
|
||||||
{
|
{
|
||||||
_collection[i] = obj;
|
_collection[i] = obj;
|
||||||
return i;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
throw new CollectionOverflowException(Count);
|
for (int i = position; i >= 0; i--)
|
||||||
}
|
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
if (_collection[i] == null)
|
||||||
throw new PositionOutOfCollectionException(position);
|
|
||||||
|
|
||||||
if (_collection[position] == null)
|
|
||||||
{
|
{
|
||||||
_collection[position] = obj;
|
_collection[i] = obj;
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int temp = position + 1;
|
|
||||||
while (temp < Count)
|
|
||||||
{
|
|
||||||
if (_collection[temp] == null)
|
|
||||||
{
|
|
||||||
_collection[temp] = obj;
|
|
||||||
return temp;
|
|
||||||
}
|
}
|
||||||
temp++;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
temp = position - 1;
|
|
||||||
while (temp > 0)
|
|
||||||
{
|
|
||||||
if (_collection[temp] == null)
|
|
||||||
{
|
|
||||||
_collection[temp] = obj;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
temp--;
|
|
||||||
}
|
|
||||||
throw new CollectionOverflowException(Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
@ -129,5 +120,15 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
yield return _collection[i];
|
yield return _collection[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CollectionSort(IComparer<T?> comparer)
|
||||||
|
{
|
||||||
|
if (_collection?.Length > 0)
|
||||||
|
{
|
||||||
|
Array.Sort(_collection, comparer);
|
||||||
|
Array.Reverse(_collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using ProjectGasolineTanker.Drawings;
|
using ProjectGasolineTanker.CollectionGenericObjects;
|
||||||
|
using ProjectGasolineTanker.Drawings;
|
||||||
using ProjectGasolineTanker.Exceptions;
|
using ProjectGasolineTanker.Exceptions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -14,13 +15,12 @@ public class StorageCollection<T>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище) с коллекциями
|
/// Словарь (хранилище) с коллекциями
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий коллекций
|
/// Возвращение списка названий коллекций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Keys => _storages.Keys.ToList();
|
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Ключевое слово, с которого должен начинаться файл
|
/// Ключевое слово, с которого должен начинаться файл
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -36,12 +36,13 @@ public class StorageCollection<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly string _separatorItems = ";";
|
private readonly string _separatorItems = ";";
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StorageCollection()
|
public StorageCollection()
|
||||||
{
|
{
|
||||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -51,20 +52,21 @@ 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)
|
||||||
{
|
{
|
||||||
if (name == null || _storages.ContainsKey(name))
|
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||||
return;
|
if (collectionInfo.Name == null || _storages.ContainsKey(collectionInfo)) { return; }
|
||||||
|
switch (collectionInfo.CollectionType)
|
||||||
|
|
||||||
switch (collectionType)
|
|
||||||
{
|
{
|
||||||
case CollectionType.None:
|
case CollectionType.None:
|
||||||
return;
|
return;
|
||||||
case CollectionType.Massive:
|
case CollectionType.Massive:
|
||||||
_storages[name] = new MassiveGenericObjects<T>();
|
_storages.Add(collectionInfo, new MassiveGenericObjects<T> { });
|
||||||
return;
|
return;
|
||||||
case CollectionType.List:
|
case CollectionType.List:
|
||||||
_storages[name] = new ListGenericObjects<T>();
|
_storages.Add(collectionInfo, new ListGenericObjects<T> { });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -73,8 +75,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 CollectionInfo(name, CollectionType.None, string.Empty);
|
||||||
_storages.Remove(name);
|
if (collectionInfo.Name == null || !_storages.ContainsKey(collectionInfo)) { return; }
|
||||||
|
_storages.Remove(collectionInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -82,42 +85,50 @@ public class StorageCollection<T>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public ICollectionGenericObjects<T>? this[string name]
|
public ICollectionGenericObjects<T>? this[string collectionName]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (name == null || !_storages.ContainsKey(name))
|
CollectionInfo collectionInfo = new CollectionInfo(collectionName, CollectionType.None, "");
|
||||||
return null;
|
if (collectionInfo == null || !_storages.ContainsKey(collectionInfo)) { return null; }
|
||||||
|
return _storages[collectionInfo];
|
||||||
return _storages[name];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
public void SaveData(string filename)
|
public void SaveData(string filename)
|
||||||
{
|
{
|
||||||
if (_storages.Count == 0)
|
if (_storages.Count == 0)
|
||||||
throw new InvalidDataException("В хранилище отсутсвуют коллекции для сохранения");
|
{
|
||||||
|
throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (File.Exists(filename))
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
using FileStream fs = new(filename, FileMode.Create);
|
using FileStream fs = new(filename, FileMode.Create);
|
||||||
using StreamWriter sw = new StreamWriter(fs);
|
using StreamWriter streamWriter = new StreamWriter(fs);
|
||||||
sw.Write(_collectionKey);
|
streamWriter.Write(_collectionKey);
|
||||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||||
{
|
{
|
||||||
sw.Write(Environment.NewLine);
|
streamWriter.Write(Environment.NewLine);
|
||||||
|
// не сохраняем пустые коллекции
|
||||||
if (value.Value.Count == 0)
|
if (value.Value.Count == 0)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Write(value.Key);
|
streamWriter.Write(value.Key);
|
||||||
sw.Write(_separatorForKeyValue);
|
streamWriter.Write(_separatorForKeyValue);
|
||||||
sw.Write(value.Value.GetCollectionType);
|
streamWriter.Write(value.Value.MaxCount);
|
||||||
sw.Write(_separatorForKeyValue);
|
streamWriter.Write(_separatorForKeyValue);
|
||||||
sw.Write(value.Value.MaxCount);
|
|
||||||
sw.Write(_separatorForKeyValue);
|
|
||||||
|
|
||||||
foreach (T? item in value.Value.GetItems())
|
foreach (T? item in value.Value.GetItems())
|
||||||
{
|
{
|
||||||
@ -127,8 +138,8 @@ public class StorageCollection<T>
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sw.Write(data);
|
streamWriter.Write(data);
|
||||||
sw.Write(_separatorItems);
|
streamWriter.Write(_separatorItems);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,60 +153,62 @@ public class StorageCollection<T>
|
|||||||
|
|
||||||
using (FileStream fs = new(filename, FileMode.Open))
|
using (FileStream fs = new(filename, FileMode.Open))
|
||||||
{
|
{
|
||||||
using StreamReader sr = new StreamReader(fs);
|
using StreamReader streamReader = new StreamReader(fs);
|
||||||
|
string firstString = streamReader.ReadLine();
|
||||||
string str = sr.ReadLine();
|
if (firstString == null || firstString.Length == 0)
|
||||||
if (str == null || str.Length == 0)
|
|
||||||
{
|
{
|
||||||
throw new InvalidDataException("В файле нет данных");
|
throw new ArgumentException("В файле нет данных");
|
||||||
|
}
|
||||||
|
if (!firstString.Equals(_collectionKey))
|
||||||
|
{
|
||||||
|
//если нет такой записи, то это не те данные
|
||||||
|
throw new InvalidDataException("В файле неверные данные");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!str.Equals(_collectionKey))
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("В файле неверные данные");
|
|
||||||
}
|
|
||||||
_storages.Clear();
|
_storages.Clear();
|
||||||
|
while (!streamReader.EndOfStream)
|
||||||
while (!sr.EndOfStream)
|
|
||||||
{
|
{
|
||||||
string[] record = sr.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
string[] record = streamReader.ReadLine().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]);
|
||||||
|
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||||
|
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
||||||
|
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||||
|
|
||||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
|
||||||
if (collection == null)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Не удалось создать коллекцию");
|
|
||||||
}
|
|
||||||
|
|
||||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
|
||||||
|
|
||||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
|
||||||
foreach (string elem in set)
|
foreach (string elem in set)
|
||||||
{
|
{
|
||||||
if (elem?.CreateDrawingTanker() is T tanker)
|
if (elem?.CreateDrawingTanker() is T tanker)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (collection.Insert(tanker) == -1)
|
if (!collection.Insert(tanker))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CollectionOverflowException ex)
|
catch (CollectionOverflowException ex)
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("Коллекция переполнена", ex);
|
throw new CollectionOverflowException("Коллекция переполнена", ex);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_storages.Add(record[0], collection);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_storages.Add(collectionInfo, collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание коллекции по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collectionType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||||
{
|
{
|
||||||
return collectionType switch
|
return collectionType switch
|
||||||
|
@ -0,0 +1,36 @@
|
|||||||
|
using ProjectGasolineTanker.Drawings;
|
||||||
|
|
||||||
|
namespace ProjectGasolineTanker.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сравнение по цвету, скорости, весу
|
||||||
|
/// </summary>
|
||||||
|
public class TankerCompareByColor : IComparer<DrawingTanker?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingTanker? x, DrawingTanker? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (x == null || x.EntityTanker == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityTanker == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x.EntityTanker.BodyColor.Name != y.EntityTanker.BodyColor.Name)
|
||||||
|
{
|
||||||
|
return x.EntityTanker.BodyColor.Name.CompareTo(y.EntityTanker.BodyColor.Name);
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
using ProjectGasolineTanker.Drawings;
|
||||||
|
|
||||||
|
namespace ProjectGasolineTanker.Drawnings;
|
||||||
|
/// <summary>
|
||||||
|
/// Сравнение по типу, скорости, весу
|
||||||
|
/// </summary>
|
||||||
|
public class TankerCompareByType : IComparer<DrawingTanker?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawingTanker? x, DrawingTanker? y)
|
||||||
|
{
|
||||||
|
if (x == null && y == null)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (x == null || x.EntityTanker == null)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityTanker == null)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!x.GetType().Name.Equals(y.GetType().Name))
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
using ProjectGasolineTanker.Entities;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
|
||||||
|
namespace ProjectGasolineTanker.Drawings;
|
||||||
|
|
||||||
|
public class DrawingTankerEqutables : IEqualityComparer<DrawingTanker?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawingTanker? x, DrawingTanker? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityTanker == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y == null || y.EntityTanker == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityTanker.Speed != y.EntityTanker.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityTanker.Weight != y.EntityTanker.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is DrawingGasolineTanker && y is DrawingGasolineTanker)
|
||||||
|
{
|
||||||
|
EntityGasolineTanker entityX = (EntityGasolineTanker)x.EntityTanker;
|
||||||
|
EntityGasolineTanker entityY = (EntityGasolineTanker)y.EntityTanker;
|
||||||
|
if (entityX.OrnamentWheels != entityY.OrnamentWheels)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entityX.Tank != entityY.Tank)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entityX.AdditionalColor != entityY.AdditionalColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int GetHashCode([DisallowNull] DrawingTanker obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectGasolineTanker.Exceptions;
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
internal class ObjectExistException : ApplicationException
|
||||||
|
{
|
||||||
|
public ObjectExistException(int count) : base("Вставка уже существующего объекта") { }
|
||||||
|
|
||||||
|
public ObjectExistException() : base() { }
|
||||||
|
|
||||||
|
public ObjectExistException(string message) : base(message) { }
|
||||||
|
|
||||||
|
public ObjectExistException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
|
||||||
|
protected ObjectExistException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,8 @@
|
|||||||
{
|
{
|
||||||
groupBoxTools = new GroupBox();
|
groupBoxTools = new GroupBox();
|
||||||
panelCompanyTools = new Panel();
|
panelCompanyTools = new Panel();
|
||||||
|
buttonSortByColor = new Button();
|
||||||
|
buttonSortByType = new Button();
|
||||||
buttonAddTanker = new Button();
|
buttonAddTanker = new Button();
|
||||||
buttonRefresh = new Button();
|
buttonRefresh = new Button();
|
||||||
maskedTextBox1 = new MaskedTextBox();
|
maskedTextBox1 = new MaskedTextBox();
|
||||||
@ -66,15 +68,17 @@
|
|||||||
groupBoxTools.Controls.Add(panelStorage);
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(1222, 33);
|
groupBoxTools.Location = new Point(1063, 33);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(258, 784);
|
groupBoxTools.Size = new Size(258, 791);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// panelCompanyTools
|
// panelCompanyTools
|
||||||
//
|
//
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||||
|
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||||
panelCompanyTools.Controls.Add(buttonAddTanker);
|
panelCompanyTools.Controls.Add(buttonAddTanker);
|
||||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||||
panelCompanyTools.Controls.Add(maskedTextBox1);
|
panelCompanyTools.Controls.Add(maskedTextBox1);
|
||||||
@ -82,11 +86,33 @@
|
|||||||
panelCompanyTools.Controls.Add(buttonDelTanker);
|
panelCompanyTools.Controls.Add(buttonDelTanker);
|
||||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(3, 463);
|
panelCompanyTools.Location = new Point(3, 438);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(252, 318);
|
panelCompanyTools.Size = new Size(252, 350);
|
||||||
panelCompanyTools.TabIndex = 2;
|
panelCompanyTools.TabIndex = 2;
|
||||||
//
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByColor.Location = new Point(13, 294);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new Size(230, 43);
|
||||||
|
buttonSortByColor.TabIndex = 8;
|
||||||
|
buttonSortByColor.Text = "Сортировка по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
|
buttonSortByType.Location = new Point(13, 245);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new Size(230, 43);
|
||||||
|
buttonSortByType.TabIndex = 7;
|
||||||
|
buttonSortByType.Text = "Сортировка по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
|
//
|
||||||
// buttonAddTanker
|
// buttonAddTanker
|
||||||
//
|
//
|
||||||
buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
@ -101,9 +127,9 @@
|
|||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonRefresh.Location = new Point(13, 237);
|
buttonRefresh.Location = new Point(13, 196);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
buttonRefresh.Size = new Size(226, 55);
|
buttonRefresh.Size = new Size(230, 43);
|
||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
buttonRefresh.Text = "Обновить";
|
buttonRefresh.Text = "Обновить";
|
||||||
buttonRefresh.UseVisualStyleBackColor = true;
|
buttonRefresh.UseVisualStyleBackColor = true;
|
||||||
@ -111,7 +137,7 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBox1
|
// maskedTextBox1
|
||||||
//
|
//
|
||||||
maskedTextBox1.Location = new Point(13, 78);
|
maskedTextBox1.Location = new Point(13, 63);
|
||||||
maskedTextBox1.Mask = "00";
|
maskedTextBox1.Mask = "00";
|
||||||
maskedTextBox1.Name = "maskedTextBox1";
|
maskedTextBox1.Name = "maskedTextBox1";
|
||||||
maskedTextBox1.Size = new Size(230, 31);
|
maskedTextBox1.Size = new Size(230, 31);
|
||||||
@ -121,9 +147,9 @@
|
|||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonGoToCheck.Location = new Point(13, 176);
|
buttonGoToCheck.Location = new Point(13, 149);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(230, 55);
|
buttonGoToCheck.Size = new Size(230, 41);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
buttonGoToCheck.Text = "Передать на тесты";
|
buttonGoToCheck.Text = "Передать на тесты";
|
||||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||||
@ -132,9 +158,9 @@
|
|||||||
// buttonDelTanker
|
// buttonDelTanker
|
||||||
//
|
//
|
||||||
buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
buttonDelTanker.Location = new Point(13, 115);
|
buttonDelTanker.Location = new Point(13, 100);
|
||||||
buttonDelTanker.Name = "buttonDelTanker";
|
buttonDelTanker.Name = "buttonDelTanker";
|
||||||
buttonDelTanker.Size = new Size(230, 55);
|
buttonDelTanker.Size = new Size(230, 43);
|
||||||
buttonDelTanker.TabIndex = 4;
|
buttonDelTanker.TabIndex = 4;
|
||||||
buttonDelTanker.Text = "Удаление грузовика";
|
buttonDelTanker.Text = "Удаление грузовика";
|
||||||
buttonDelTanker.UseVisualStyleBackColor = true;
|
buttonDelTanker.UseVisualStyleBackColor = true;
|
||||||
@ -142,7 +168,7 @@
|
|||||||
//
|
//
|
||||||
// buttonCreateCompany
|
// buttonCreateCompany
|
||||||
//
|
//
|
||||||
buttonCreateCompany.Location = new Point(16, 374);
|
buttonCreateCompany.Location = new Point(16, 359);
|
||||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||||
buttonCreateCompany.Size = new Size(226, 34);
|
buttonCreateCompany.Size = new Size(226, 34);
|
||||||
buttonCreateCompany.TabIndex = 8;
|
buttonCreateCompany.TabIndex = 8;
|
||||||
@ -162,7 +188,7 @@
|
|||||||
panelStorage.Dock = DockStyle.Top;
|
panelStorage.Dock = DockStyle.Top;
|
||||||
panelStorage.Location = new Point(3, 27);
|
panelStorage.Location = new Point(3, 27);
|
||||||
panelStorage.Name = "panelStorage";
|
panelStorage.Name = "panelStorage";
|
||||||
panelStorage.Size = new Size(252, 328);
|
panelStorage.Size = new Size(252, 326);
|
||||||
panelStorage.TabIndex = 7;
|
panelStorage.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// buttonCollectionDel
|
// buttonCollectionDel
|
||||||
@ -238,7 +264,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(16, 417);
|
comboBoxSelectorCompany.Location = new Point(16, 399);
|
||||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||||
comboBoxSelectorCompany.Size = new Size(230, 33);
|
comboBoxSelectorCompany.Size = new Size(230, 33);
|
||||||
comboBoxSelectorCompany.TabIndex = 0;
|
comboBoxSelectorCompany.TabIndex = 0;
|
||||||
@ -249,7 +275,7 @@
|
|||||||
pictureBox.Dock = DockStyle.Fill;
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
pictureBox.Location = new Point(0, 33);
|
pictureBox.Location = new Point(0, 33);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(1222, 784);
|
pictureBox.Size = new Size(1063, 791);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -259,7 +285,7 @@
|
|||||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Size = new Size(1480, 33);
|
menuStrip.Size = new Size(1321, 33);
|
||||||
menuStrip.TabIndex = 2;
|
menuStrip.TabIndex = 2;
|
||||||
menuStrip.Text = "menuStrip";
|
menuStrip.Text = "menuStrip";
|
||||||
//
|
//
|
||||||
@ -298,7 +324,7 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1480, 817);
|
ClientSize = new Size(1321, 824);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
Controls.Add(menuStrip);
|
Controls.Add(menuStrip);
|
||||||
@ -343,5 +369,7 @@
|
|||||||
private ToolStripMenuItem loadToolStripMenuItem;
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
private SaveFileDialog saveFileDialog;
|
private SaveFileDialog saveFileDialog;
|
||||||
private OpenFileDialog openFileDialog;
|
private OpenFileDialog openFileDialog;
|
||||||
|
private Button buttonSortByColor;
|
||||||
|
private Button buttonSortByType;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,6 +11,7 @@ using System.Windows.Forms;
|
|||||||
using ProjectGasolineTanker.Drawings;
|
using ProjectGasolineTanker.Drawings;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using ProjectGasolineTanker.Exceptions;
|
using ProjectGasolineTanker.Exceptions;
|
||||||
|
using ProjectGasolineTanker.Drawnings;
|
||||||
|
|
||||||
namespace ProjectGasolineTanker;
|
namespace ProjectGasolineTanker;
|
||||||
|
|
||||||
@ -76,6 +77,11 @@ public partial class FormTankerCollection : Form
|
|||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||||
}
|
}
|
||||||
|
catch (ObjectExistException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Такой объект есть в коллекции");
|
||||||
|
_logger.LogWarning($"Добавление существующего объекта: {ex.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -223,11 +229,13 @@ public partial class FormTankerCollection : 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -307,4 +315,25 @@ public partial class FormTankerCollection : Form
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareTankers(new TankerCompareByType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
CompareTankers(new TankerCompareByColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CompareTankers(IComparer<DrawingTanker?> comparer)
|
||||||
|
{
|
||||||
|
if (_company == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_company.Sort(comparer);
|
||||||
|
pictureBox.Image = _company.Show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,6 +127,6 @@
|
|||||||
<value>355, 17</value>
|
<value>355, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>57</value>
|
<value>25</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
Loading…
Reference in New Issue
Block a user