Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f03a765cc4 |
@@ -38,7 +38,7 @@ public abstract class AbstractCompany
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight)-6;
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@@ -53,7 +53,7 @@ public abstract class AbstractCompany
|
||||
_collection = collection;
|
||||
_collection.MaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
@@ -62,11 +62,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawingTanker tanker)
|
||||
{
|
||||
if (company._collection.Insert(tanker, new DrawingTankerEqutables()))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
return company._collection.Insert(tanker);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -110,8 +106,6 @@ public abstract class AbstractCompany
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
public void Sort(IComparer<DrawingTanker?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
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>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
bool Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
int Insert(T obj);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
@@ -36,7 +36,7 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>1 - вставка прошла удачно, -1 - вставка не удалась</returns>
|
||||
bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@@ -62,6 +62,4 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using NLog.LayoutRenderers;
|
||||
using ProjectGasolineTanker.CollectionGenericObjects;
|
||||
using ProjectGasolineTanker.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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>
|
||||
where T : class
|
||||
{
|
||||
@@ -19,19 +19,6 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
private int _maxCount;
|
||||
|
||||
public int MaxCount
|
||||
{
|
||||
get => _maxCount;
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
_maxCount = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
public int Count => _collection.Count;
|
||||
|
||||
/// <summary>
|
||||
@@ -42,59 +29,56 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection = new();
|
||||
}
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
public int MaxCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return _maxCount;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
_maxCount = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position > _collection.Count || position < 0)
|
||||
{
|
||||
throw new PositionOutOfCollectionException();
|
||||
}
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
throw new ObjectNotFoundException();
|
||||
}
|
||||
if (position >= Count || position < 0)
|
||||
return null;
|
||||
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
if (Count + 1 > MaxCount)
|
||||
{
|
||||
throw new CollectionOverflowException();
|
||||
}
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectExistException();
|
||||
}
|
||||
if (Count + 1 > _maxCount)
|
||||
return -1;
|
||||
_collection.Add(obj);
|
||||
|
||||
return true;
|
||||
return Count;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (_collection.Count + 1 < _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException();
|
||||
}
|
||||
if (position > _collection.Count || position < 0)
|
||||
{
|
||||
throw new PositionOutOfCollectionException();
|
||||
}
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectExistException(position);
|
||||
}
|
||||
if (Count + 1 > _maxCount)
|
||||
return -1;
|
||||
if (position < 0 || position > Count)
|
||||
return -1;
|
||||
_collection.Insert(position, obj);
|
||||
return true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position > _collection.Count || position < 0)
|
||||
{
|
||||
throw new PositionOutOfCollectionException();
|
||||
}
|
||||
T temp = _collection[position];
|
||||
if (position < 0 || position > Count)
|
||||
return null;
|
||||
|
||||
T? temp = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return temp;
|
||||
}
|
||||
@@ -106,9 +90,4 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
using ProjectGasolineTanker.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasolineTanker.CollectionGenericObjects;
|
||||
|
||||
@@ -47,66 +51,69 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (position < 0 || position > _collection.Length - 1)
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
|
||||
if (position >= _collection.Length && _collection[position] == null)
|
||||
throw new ObjectNotFoundException(position);
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public bool Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj)
|
||||
{
|
||||
int index = Array.IndexOf(_collection, null);
|
||||
if (_collection.Contains(obj, comparer))
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
throw new ObjectExistException(index);
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
if (index >= 0)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return true;
|
||||
}
|
||||
throw new CollectionOverflowException();
|
||||
return -1;
|
||||
}
|
||||
|
||||
public bool Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
if (position < 0 || position > _collection.Length - 1)
|
||||
if (position < 0 || position >= Count)
|
||||
return -1;
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
throw new PositionOutOfCollectionException();
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
if (_collection.Contains(obj, comparer))
|
||||
|
||||
int temp = position + 1;
|
||||
while (temp < Count)
|
||||
{
|
||||
throw new ObjectExistException(position);
|
||||
}
|
||||
for (int i = position; i < _collection.Length; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
if (_collection[temp] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
_collection[temp] = obj;
|
||||
return temp;
|
||||
}
|
||||
temp++;
|
||||
}
|
||||
for (int i = position; i >= 0; i--)
|
||||
|
||||
temp = position - 1;
|
||||
while (temp > 0)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
if (_collection[temp] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return true;
|
||||
_collection[temp] = obj;
|
||||
return temp;
|
||||
}
|
||||
temp--;
|
||||
}
|
||||
return false;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
return null;
|
||||
|
||||
if (_collection[position] == null)
|
||||
throw new ObjectNotFoundException(position);
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
T? temp = _collection[position];
|
||||
_collection[position] = null;
|
||||
@@ -120,15 +127,4 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
if (_collection?.Length > 0)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
Array.Reverse(_collection);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using ProjectGasolineTanker.CollectionGenericObjects;
|
||||
using ProjectGasolineTanker.Drawings;
|
||||
using ProjectGasolineTanker.Exceptions;
|
||||
using ProjectGasolineTanker.Drawings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,12 +13,13 @@ public class StorageCollection<T>
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
/// </summary>
|
||||
@@ -36,13 +35,12 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
private readonly string _separatorItems = ";";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,21 +50,20 @@ public class StorageCollection<T>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||
if (collectionInfo.Name == null || _storages.ContainsKey(collectionInfo)) { return; }
|
||||
switch (collectionInfo.CollectionType)
|
||||
if (name == null || _storages.ContainsKey(name))
|
||||
return;
|
||||
|
||||
switch (collectionType)
|
||||
{
|
||||
case CollectionType.None:
|
||||
return;
|
||||
case CollectionType.Massive:
|
||||
_storages.Add(collectionInfo, new MassiveGenericObjects<T> { });
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
return;
|
||||
case CollectionType.List:
|
||||
_storages.Add(collectionInfo, new ListGenericObjects<T> { });
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -75,9 +72,8 @@ public class StorageCollection<T>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (collectionInfo.Name == null || !_storages.ContainsKey(collectionInfo)) { return; }
|
||||
_storages.Remove(collectionInfo);
|
||||
if (_storages.ContainsKey(name))
|
||||
_storages.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,50 +81,42 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string collectionName]
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
{
|
||||
get
|
||||
{
|
||||
CollectionInfo collectionInfo = new CollectionInfo(collectionName, CollectionType.None, "");
|
||||
if (collectionInfo == null || !_storages.ContainsKey(collectionInfo)) { return null; }
|
||||
return _storages[collectionInfo];
|
||||
if (name == null || !_storages.ContainsKey(name))
|
||||
return null;
|
||||
|
||||
return _storages[name];
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public void SaveData(string filename)
|
||||
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения");
|
||||
|
||||
}
|
||||
return false;
|
||||
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
|
||||
|
||||
using FileStream fs = new(filename, FileMode.Create);
|
||||
using StreamWriter streamWriter = new StreamWriter(fs);
|
||||
streamWriter.Write(_collectionKey);
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
using StreamWriter sw = new StreamWriter(fs);
|
||||
sw.Write(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
streamWriter.Write(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
sw.Write(Environment.NewLine);
|
||||
if (value.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
streamWriter.Write(value.Key);
|
||||
streamWriter.Write(_separatorForKeyValue);
|
||||
streamWriter.Write(value.Value.MaxCount);
|
||||
streamWriter.Write(_separatorForKeyValue);
|
||||
sw.Write(value.Key);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
sw.Write(value.Value.GetCollectionType);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
sw.Write(value.Value.MaxCount);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
{
|
||||
@@ -138,77 +126,68 @@ public class StorageCollection<T>
|
||||
continue;
|
||||
}
|
||||
|
||||
streamWriter.Write(data);
|
||||
streamWriter.Write(_separatorItems);
|
||||
sw.Write(data);
|
||||
sw.Write(_separatorItems);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void LoadData(string filename)
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException("Файл не существует");
|
||||
return false;
|
||||
}
|
||||
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
{
|
||||
using StreamReader streamReader = new StreamReader(fs);
|
||||
string firstString = streamReader.ReadLine();
|
||||
if (firstString == null || firstString.Length == 0)
|
||||
using StreamReader sr = new StreamReader(fs);
|
||||
|
||||
string str = sr.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("В файле нет данных");
|
||||
}
|
||||
if (!firstString.Equals(_collectionKey))
|
||||
{
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new InvalidDataException("В файле неверные данные");
|
||||
return false;
|
||||
}
|
||||
|
||||
_storages.Clear();
|
||||
while (!streamReader.EndOfStream)
|
||||
if (!str.Equals(_collectionKey))
|
||||
{
|
||||
string[] record = streamReader.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 3)
|
||||
return false;
|
||||
}
|
||||
_storages.Clear();
|
||||
|
||||
while (!sr.EndOfStream)
|
||||
{
|
||||
string[] record = sr.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 4)
|
||||
{
|
||||
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]);
|
||||
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
if (collection == null)
|
||||
{
|
||||
if (elem?.CreateDrawingTanker() is T tanker)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!collection.Insert(tanker))
|
||||
{
|
||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
{
|
||||
throw new CollectionOverflowException("Коллекция переполнена", ex);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
_storages.Add(collectionInfo, collection);
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawingTanker() is T airplane)
|
||||
{
|
||||
if (collection.Insert(airplane) == -1)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание коллекции по типу
|
||||
/// </summary>
|
||||
/// <param name="collectionType"></param>
|
||||
/// <returns></returns>
|
||||
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||
{
|
||||
return collectionType switch
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectGasolineTanker.Exceptions;
|
||||
|
||||
[Serializable]
|
||||
internal class CollectionOverflowException : ApplicationException
|
||||
{
|
||||
public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { }
|
||||
|
||||
public CollectionOverflowException() : base() { }
|
||||
|
||||
public CollectionOverflowException(string message) : base(message) { }
|
||||
|
||||
public CollectionOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
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) { }
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectGasolineTanker.Exceptions;
|
||||
|
||||
[Serializable]
|
||||
internal class ObjectNotFoundException : ApplicationException
|
||||
{
|
||||
public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { }
|
||||
|
||||
public ObjectNotFoundException() : base() { }
|
||||
|
||||
public ObjectNotFoundException(string message) : base(message) { }
|
||||
|
||||
public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectGasolineTanker.Exceptions;
|
||||
|
||||
[Serializable]
|
||||
internal class PositionOutOfCollectionException : ApplicationException
|
||||
{
|
||||
public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { }
|
||||
|
||||
public PositionOutOfCollectionException() : base() { }
|
||||
|
||||
public PositionOutOfCollectionException(string message) : base(message) { }
|
||||
|
||||
public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
@@ -30,8 +30,6 @@
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonSortByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
buttonAddTanker = new Button();
|
||||
buttonRefresh = new Button();
|
||||
maskedTextBox1 = new MaskedTextBox();
|
||||
@@ -68,17 +66,15 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(1063, 33);
|
||||
groupBoxTools.Location = new Point(1222, 33);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(258, 791);
|
||||
groupBoxTools.Size = new Size(258, 784);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddTanker);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox1);
|
||||
@@ -86,33 +82,11 @@
|
||||
panelCompanyTools.Controls.Add(buttonDelTanker);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 438);
|
||||
panelCompanyTools.Location = new Point(3, 463);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(252, 350);
|
||||
panelCompanyTools.Size = new Size(252, 318);
|
||||
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.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
@@ -127,9 +101,9 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(13, 196);
|
||||
buttonRefresh.Location = new Point(13, 237);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(230, 43);
|
||||
buttonRefresh.Size = new Size(226, 55);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@@ -137,7 +111,7 @@
|
||||
//
|
||||
// maskedTextBox1
|
||||
//
|
||||
maskedTextBox1.Location = new Point(13, 63);
|
||||
maskedTextBox1.Location = new Point(13, 78);
|
||||
maskedTextBox1.Mask = "00";
|
||||
maskedTextBox1.Name = "maskedTextBox1";
|
||||
maskedTextBox1.Size = new Size(230, 31);
|
||||
@@ -147,9 +121,9 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(13, 149);
|
||||
buttonGoToCheck.Location = new Point(13, 176);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(230, 41);
|
||||
buttonGoToCheck.Size = new Size(230, 55);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@@ -158,9 +132,9 @@
|
||||
// buttonDelTanker
|
||||
//
|
||||
buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonDelTanker.Location = new Point(13, 100);
|
||||
buttonDelTanker.Location = new Point(13, 115);
|
||||
buttonDelTanker.Name = "buttonDelTanker";
|
||||
buttonDelTanker.Size = new Size(230, 43);
|
||||
buttonDelTanker.Size = new Size(230, 55);
|
||||
buttonDelTanker.TabIndex = 4;
|
||||
buttonDelTanker.Text = "Удаление грузовика";
|
||||
buttonDelTanker.UseVisualStyleBackColor = true;
|
||||
@@ -168,7 +142,7 @@
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(16, 359);
|
||||
buttonCreateCompany.Location = new Point(16, 374);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(226, 34);
|
||||
buttonCreateCompany.TabIndex = 8;
|
||||
@@ -188,7 +162,7 @@
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 27);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(252, 326);
|
||||
panelStorage.Size = new Size(252, 328);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
@@ -264,7 +238,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(16, 399);
|
||||
comboBoxSelectorCompany.Location = new Point(16, 417);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(230, 33);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
@@ -275,7 +249,7 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 33);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(1063, 791);
|
||||
pictureBox.Size = new Size(1222, 784);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@@ -285,7 +259,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1321, 33);
|
||||
menuStrip.Size = new Size(1480, 33);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip";
|
||||
//
|
||||
@@ -324,7 +298,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1321, 824);
|
||||
ClientSize = new Size(1480, 817);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
@@ -369,7 +343,5 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -9,9 +9,6 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using ProjectGasolineTanker.Drawings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using ProjectGasolineTanker.Exceptions;
|
||||
using ProjectGasolineTanker.Drawnings;
|
||||
|
||||
namespace ProjectGasolineTanker;
|
||||
|
||||
@@ -23,17 +20,13 @@ public partial class FormTankerCollection : Form
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormTankerCollection(ILogger<FormTankerCollection> logger)
|
||||
public FormTankerCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_storageCollection = new();
|
||||
_logger = logger;
|
||||
_logger.LogInformation("Форма загрузилась");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -56,31 +49,18 @@ public partial class FormTankerCollection : Form
|
||||
private void SetTanker(DrawingTanker tanker)
|
||||
{
|
||||
if (_company == null || tanker == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
if (_company + tanker != -1)
|
||||
{
|
||||
if (_company + tanker != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
_logger.LogInformation("Добавлен объект: " + tanker.GetDataForSave());
|
||||
}
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
catch (ObjectNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
catch (ObjectExistException ex)
|
||||
{
|
||||
MessageBox.Show("Такой объект есть в коллекции");
|
||||
_logger.LogWarning($"Добавление существующего объекта: {ex.Message}");
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,25 +82,14 @@ public partial class FormTankerCollection : Form
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox1.Text);
|
||||
|
||||
try
|
||||
if (_company - pos != null)
|
||||
{
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
_logger.LogInformation("Удален объект по позиции " + pos);
|
||||
}
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
catch (PositionOutOfCollectionException ex)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
catch (ObjectNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,22 +109,11 @@ public partial class FormTankerCollection : Form
|
||||
int counter = 100;
|
||||
while (tanker == null)
|
||||
{
|
||||
try
|
||||
tanker = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
tanker = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (PositionOutOfCollectionException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (ObjectNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,34 +152,14 @@ public partial class FormTankerCollection : Form
|
||||
return;
|
||||
}
|
||||
|
||||
//CollectionType collectionType = CollectionType.None;
|
||||
//if (radioButtonMassive.Checked)
|
||||
// collectionType = CollectionType.Massive;
|
||||
//else if (radioButtonList.Checked)
|
||||
// collectionType = CollectionType.List;
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (radioButtonMassive.Checked)
|
||||
collectionType = CollectionType.Massive;
|
||||
else if (radioButtonList.Checked)
|
||||
collectionType = CollectionType.List;
|
||||
|
||||
//_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
//RefreshListBoxItems();
|
||||
|
||||
try
|
||||
{
|
||||
CollectionType collectionType = CollectionType.None;
|
||||
if (radioButtonMassive.Checked)
|
||||
{
|
||||
collectionType = CollectionType.Massive;
|
||||
}
|
||||
else if (radioButtonList.Checked)
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
RefreshListBoxItems();
|
||||
_logger.LogInformation("Коллекция добавлена " + textBoxCollectionName.Text);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
RefreshListBoxItems();
|
||||
}
|
||||
|
||||
private void RefreshListBoxItems()
|
||||
@@ -229,7 +167,7 @@ public partial class FormTankerCollection : Form
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i].Name;
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
@@ -283,16 +221,13 @@ public partial class FormTankerCollection : Form
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
if (_storageCollection.SaveData(saveFileDialog.FileName))
|
||||
{
|
||||
_storageCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -301,39 +236,15 @@ public partial class FormTankerCollection : Form
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
if (_storageCollection.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
_storageCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
RefreshListBoxItems();
|
||||
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>25</value>
|
||||
<value>57</value>
|
||||
</metadata>
|
||||
</root>
|
||||
@@ -1,8 +1,3 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace ProjectGasolineTanker
|
||||
{
|
||||
internal static class Program
|
||||
@@ -16,27 +11,7 @@ namespace ProjectGasolineTanker
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
ServiceCollection services = new();
|
||||
ConfigureServices(services);
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(serviceProvider.GetRequiredService<FormTankerCollection>());
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||
string pathNeed = "";
|
||||
for (int i = 0; i < path.Length - 3; i++)
|
||||
{
|
||||
pathNeed += path[i] + "\\";
|
||||
}
|
||||
services.AddSingleton<FormTankerCollection>()
|
||||
.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(new ConfigurationBuilder().AddJsonFile($"{pathNeed}serilog.json").Build()).CreateLogger());
|
||||
});
|
||||
Application.Run(new FormTankerCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,6 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.10" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
@@ -37,10 +23,4 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="serilog.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,15 +0,0 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Debug",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": { "path": "log.log" }
|
||||
}
|
||||
],
|
||||
"Properties": {
|
||||
"Application": "Sample"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user