Лабораторная 8
This commit is contained in:
parent
cf54a61f9e
commit
a2e1040683
@ -1,4 +1,5 @@
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.CollectionGenericObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -110,4 +111,11 @@ public abstract class AbstractCompany
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectPosition();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningBaseLocomotive?> comparer) => _collection?.CollectionSort(comparer);
|
||||
}
|
||||
|
@ -0,0 +1,51 @@
|
||||
namespace LocomativeProject.CollectionGenericObjects
|
||||
{
|
||||
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public CollectionType CollectionType { get; private set; }
|
||||
|
||||
public string Description { get; private set; }
|
||||
private static readonly string _separator = "-";
|
||||
|
||||
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||
{
|
||||
Name = name;
|
||||
CollectionType = collectionType;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public static CollectionInfo? GetCollectionInfo(string data)
|
||||
{
|
||||
string[] strs = data.Split(_separator,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs.Length < 1 || strs.Length > 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new CollectionInfo(strs[0],
|
||||
(CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ?
|
||||
strs[2] : string.Empty);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name + _separator + CollectionType + _separator + Description;
|
||||
}
|
||||
|
||||
public bool Equals(CollectionInfo? other)
|
||||
{
|
||||
return Name == other?.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return Equals(obj as CollectionInfo);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
namespace LocomativeProject.CollectionGenericObjects;
|
||||
/// <summary>
|
||||
/// Тип коллекции
|
||||
/// </summary>
|
||||
|
@ -1,47 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
|
||||
namespace LocomativeProject.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Кол-во объектов в коллекции
|
||||
/// Количество объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Установка макс. кол-ва элементов
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int MaxCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">позиция</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj,int position);
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление обьекта из коллекции с конкретной позиции
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="positon">позиция</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int positon);
|
||||
T? Remove(int position);
|
||||
|
||||
/// <summary>
|
||||
/// получение объекта по позиции
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="positon">позиция</param>
|
||||
/// <returns>Обьект</returns>
|
||||
T? Get(int positon);
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
|
||||
/// <summary>
|
||||
/// Получение типа коллекции
|
||||
@ -53,4 +58,11 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементный вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Exceptions;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
namespace LocomativeProject.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
@ -29,8 +27,8 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
get { return Count; }
|
||||
set { if (value > 0) { _maxCount = value; } }
|
||||
}
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.List;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -40,41 +38,65 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
_collection = new();
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position < 0 || position >= _collection.Count) throw new PositionOutOfCollectionException(position);
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (_collection.Count >= _maxCount) return -1;
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
if (_collection.Count + 1 > _maxCount) throw new CollectionOverflowException(_maxCount);
|
||||
|
||||
_collection.Add(obj);
|
||||
return _collection.Count + 1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
if (_collection.Count >= _maxCount || _collection[position] == null || position < 0) { return -1; }
|
||||
_collection.Insert(position, obj);
|
||||
return Count;
|
||||
}
|
||||
|
||||
public T? Get(int position)
|
||||
if (comparer != null)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (!_collection.Any()) { return null; }
|
||||
if (_collection.Count <= position || position < 0 || position >= _maxCount) { return null; }
|
||||
return _collection[position];
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
if (position < 0 || position > _collection.Count || _collection[position] != null) throw new PositionOutOfCollectionException(position);
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из списка
|
||||
if (position >= Count || position < 0) return null;
|
||||
T obj = _collection[position];
|
||||
_collection.RemoveAt(position);
|
||||
return obj;
|
||||
|
||||
if (position < 0 || position > _collection.Count) throw new PositionOutOfCollectionException(position);
|
||||
|
||||
T temp = _collection[position];
|
||||
|
||||
_collection[position] = null;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
@ -84,4 +106,10 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
namespace LocomativeProject.CollectionGenericObjects;
|
||||
|
||||
public class LocomotiveSharingService : AbstractCompany
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
namespace LocomativeProject.CollectionGenericObjects;
|
||||
|
||||
public class LocomotiveStation : AbstractCompany
|
||||
{
|
||||
|
@ -1,19 +1,16 @@
|
||||
using LocomativeProject.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomativeProject.Exceptions;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects;
|
||||
|
||||
namespace LocomativeProject.CollectionGenericObjects;
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T[] _collection;
|
||||
private T?[] _collection;
|
||||
|
||||
public int Count => _collection.Length;
|
||||
|
||||
@ -38,28 +35,37 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// конструктор
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T>();
|
||||
}
|
||||
|
||||
public T? Get(int positon)
|
||||
public T? Get(int position)
|
||||
{
|
||||
if (positon <= Count || positon > 0)
|
||||
{
|
||||
return _collection[positon];
|
||||
}
|
||||
return null;
|
||||
// TODO проверка позиции
|
||||
if (!(position >= 0 && position < Count) || _collection[position] == null) return null;
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningBaseLocomotive>).Equals(obj as DrawningBaseLocomotive, item as DrawningBaseLocomotive))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (InsertingElementCollection(i, obj)) return i;
|
||||
@ -68,13 +74,22 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
throw new CollectionOverflowException("Превышение лимита Count");
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningBaseLocomotive>).Equals(obj as DrawningBaseLocomotive, item as DrawningBaseLocomotive))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (!(position >= 0 && position < Count)) throw new PositionOutOfCollectionException(position);
|
||||
if (InsertingElementCollection(position, obj)) return position;
|
||||
|
||||
@ -91,7 +106,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
throw new CollectionOverflowException("Нет свободного места для вставки");
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
@ -104,6 +119,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Если элемент массива пустой, то происходит вставка нового элемента
|
||||
/// </summary>
|
||||
/// <param name="index">Индекс элемента</param>
|
||||
/// <param name="obj">Элемент</param>
|
||||
/// <returns>false - элемент массива не равен null, true - равен null</returns>
|
||||
private bool InsertingElementCollection(int index, T obj)
|
||||
{
|
||||
if (_collection[index] != null) return false;
|
||||
@ -119,4 +140,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ using LocomativeProject.Exceptions;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace LocomotiveProject.CollectionGenericObjects
|
||||
namespace LocomativeProject.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-хранилище коллекций
|
||||
|
@ -0,0 +1,61 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomotiveProject.Drawnings;
|
||||
using LocomotiveProject.Entities;
|
||||
|
||||
namespace LocomativeProject.Drawnings
|
||||
{
|
||||
public class DrawiningLocomotiveEqutables : IEqualityComparer<DrawningBaseLocomotive?>
|
||||
{
|
||||
public bool Equals(DrawningBaseLocomotive? x, DrawningBaseLocomotive? y)
|
||||
{
|
||||
if (x == null || x._EntityBaseLocomotive == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y._EntityBaseLocomotive == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._EntityBaseLocomotive.Speed != y._EntityBaseLocomotive.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._EntityBaseLocomotive.Weight != y._EntityBaseLocomotive.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._EntityBaseLocomotive.BodyColor != y._EntityBaseLocomotive.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningLocomotive && y is DrawningLocomotive)
|
||||
{
|
||||
EntityLocomotive _x = (EntityLocomotive)x._EntityBaseLocomotive;
|
||||
EntityLocomotive _y = (EntityLocomotive)x._EntityBaseLocomotive;
|
||||
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.FuelCompartment != _y.FuelCompartment)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.ExehaustPipe != _y.ExehaustPipe)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningBaseLocomotive obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
namespace LocomativeProject.Drawnings
|
||||
{
|
||||
public class DrawningLocomotiveCompareByColor : IComparer<DrawningBaseLocomotive?>
|
||||
{
|
||||
public int Compare(DrawningBaseLocomotive? x, DrawningBaseLocomotive? y)
|
||||
{
|
||||
if (x == null || x._EntityBaseLocomotive == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y._EntityBaseLocomotive == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x._EntityBaseLocomotive.BodyColor.Name.CompareTo(y._EntityBaseLocomotive.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x._EntityBaseLocomotive.Speed.CompareTo(y._EntityBaseLocomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x._EntityBaseLocomotive.Weight.CompareTo(y._EntityBaseLocomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using LocomativeProject.Drawnings;
|
||||
|
||||
namespace LocomativeProject.Drawnings
|
||||
{
|
||||
public class DrawningLocomotiveCompareByType : IComparer<DrawningBaseLocomotive?>
|
||||
{
|
||||
public int Compare(DrawningBaseLocomotive? x, DrawningBaseLocomotive? y)
|
||||
{
|
||||
if (x == null || x._EntityBaseLocomotive == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y._EntityBaseLocomotive == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x._EntityBaseLocomotive.Speed.CompareTo(y._EntityBaseLocomotive.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x._EntityBaseLocomotive.Weight.CompareTo(y._EntityBaseLocomotive.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ namespace LocomativeProject.Drawnings
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityMonorail
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningMonorail
|
||||
public static class ExtentionDrawningLocomotive
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
@ -34,9 +34,9 @@ namespace LocomativeProject.Drawnings
|
||||
/// </summary>
|
||||
/// <param name="drawingMonorail"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetDataForSave(this DrawningBaseLocomotive drawningBaseLocomotive)
|
||||
public static string GetDataForSave(this DrawningBaseLocomotive drawingMonorail)
|
||||
{
|
||||
string[]? array = drawningBaseLocomotive?._EntityBaseLocomotive?.GetStringRepresention();
|
||||
string[]? array = drawingMonorail?._EntityBaseLocomotive?.GetStringRepresention();
|
||||
|
||||
if (array == null)
|
||||
return string.Empty;
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LocomativeProject.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
public class ObjectIsEqualException : ApplicationException
|
||||
{
|
||||
public ObjectIsEqualException(int count) : base("В коллекции содержится равный элемент: " + count) { }
|
||||
public ObjectIsEqualException() : base() { }
|
||||
public ObjectIsEqualException(string message) : base(message) { }
|
||||
public ObjectIsEqualException(string message, Exception exception) : base(message, exception) { }
|
||||
protected ObjectIsEqualException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
namespace LocomotiveProject
|
||||
namespace LocomativeProject
|
||||
{
|
||||
partial class FormLocomotiveCollection
|
||||
{
|
||||
@ -30,6 +30,8 @@
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
buttonAddMonorail = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonRefresh = new Button();
|
||||
@ -75,6 +77,8 @@
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddMonorail);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
@ -88,20 +92,40 @@
|
||||
panelCompanyTools.Size = new Size(235, 322);
|
||||
panelCompanyTools.TabIndex = 8;
|
||||
//
|
||||
// buttonByColor
|
||||
//
|
||||
buttonByColor.Location = new Point(8, 279);
|
||||
buttonByColor.Name = "buttonByColor";
|
||||
buttonByColor.Size = new Size(217, 23);
|
||||
buttonByColor.TabIndex = 8;
|
||||
buttonByColor.Text = "Сортировать по значению";
|
||||
buttonByColor.UseVisualStyleBackColor = true;
|
||||
buttonByColor.Click += buttonByColor_Click;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(8, 250);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(217, 23);
|
||||
buttonSortByType.TabIndex = 7;
|
||||
buttonSortByType.Text = "Сортировать по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonAddMonorail
|
||||
//
|
||||
buttonAddMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddMonorail.Location = new Point(8, 32);
|
||||
buttonAddMonorail.Location = new Point(8, 5);
|
||||
buttonAddMonorail.Name = "buttonAddMonorail";
|
||||
buttonAddMonorail.Size = new Size(221, 48);
|
||||
buttonAddMonorail.TabIndex = 1;
|
||||
buttonAddMonorail.Text = "Добавление локомотива";
|
||||
buttonAddMonorail.Text = "Добавление монорельса";
|
||||
buttonAddMonorail.UseVisualStyleBackColor = true;
|
||||
buttonAddMonorail.Click += ButtonAddLocomotive_Click;
|
||||
buttonAddMonorail.Click += ButtonAddMonorail_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(5, 130);
|
||||
maskedTextBox.Location = new Point(5, 59);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(223, 23);
|
||||
@ -111,7 +135,7 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(8, 267);
|
||||
buttonRefresh.Location = new Point(8, 196);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(219, 48);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
@ -122,18 +146,18 @@
|
||||
// buttonRemoveMonorail
|
||||
//
|
||||
buttonRemoveMonorail.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveMonorail.Location = new Point(8, 159);
|
||||
buttonRemoveMonorail.Location = new Point(8, 88);
|
||||
buttonRemoveMonorail.Name = "buttonRemoveMonorail";
|
||||
buttonRemoveMonorail.Size = new Size(221, 48);
|
||||
buttonRemoveMonorail.TabIndex = 4;
|
||||
buttonRemoveMonorail.Text = "Удалить локомотив";
|
||||
buttonRemoveMonorail.Text = "Удалить монорельс";
|
||||
buttonRemoveMonorail.UseVisualStyleBackColor = true;
|
||||
buttonRemoveMonorail.Click += buttonRemoveLocomotive_Click;
|
||||
buttonRemoveMonorail.Click += buttonRemoveMonorail_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(8, 213);
|
||||
buttonGoToCheck.Location = new Point(8, 142);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(220, 48);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
@ -302,7 +326,7 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormLocomotiveCollection
|
||||
// FormMonorailCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
@ -311,8 +335,8 @@
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Name = "FormLocomotiveCollection";
|
||||
Text = "Коллекция локомотивов";
|
||||
Name = "FormMonorailCollection";
|
||||
Text = "Коллекция монорельсов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
panelCompanyTools.ResumeLayout(false);
|
||||
panelCompanyTools.PerformLayout();
|
||||
@ -351,5 +375,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -1,25 +1,28 @@
|
||||
using LocomativeProject.Drawnings;
|
||||
using LocomativeProject.Exceptions;
|
||||
using LocomotiveProject.CollectionGenericObjects;
|
||||
using LocomotiveProject.CollectionGenericObjects;
|
||||
using LocomativeProject.Drawnings;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using LocomotiveProject;
|
||||
using LocomativeProject.Exceptions;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
using LocomativeProject.CollectionGenericObjects;
|
||||
|
||||
namespace LocomotiveProject
|
||||
namespace LocomativeProject
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormLocomotiveCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Хранилище коллекций
|
||||
/// </summary>
|
||||
private readonly StorageCollection<DrawningBaseLocomotive> _storageCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Хранилище коллекций
|
||||
/// </summary>
|
||||
private readonly StorageCollection<DrawningBaseLocomotive> _storageCollection;
|
||||
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
@ -51,20 +54,20 @@ namespace LocomotiveProject
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonAddLocomotive_Click(object sender, EventArgs e)
|
||||
private void ButtonAddMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
FormLocomotiveConfig form = new FormLocomotiveConfig();
|
||||
form.Show();
|
||||
form.AddEventListener_Locomotive(SetLocomotive);
|
||||
form.AddEventListener_Locomotive(SetMonorail);
|
||||
}
|
||||
|
||||
private void SetLocomotive(DrawningBaseLocomotive locomotive)
|
||||
private void SetMonorail(DrawningBaseLocomotive monorail)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (locomotive == null || _company == null) return;
|
||||
if (monorail == null || _company == null) return;
|
||||
|
||||
if (_company + locomotive != -1)
|
||||
if (_company + monorail != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.Image = _company.Show();
|
||||
@ -78,35 +81,7 @@ namespace LocomotiveProject
|
||||
}
|
||||
}
|
||||
|
||||
private void LogException(Exception ex)
|
||||
{
|
||||
if (ex is CollectionOverflowException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((CollectionOverflowException)ex).Message);
|
||||
}
|
||||
else if (ex is FileEmptyException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((FileEmptyException)ex).Message);
|
||||
}
|
||||
else if (ex is FileDoesNotExistException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((FileDoesNotExistException)ex).Message);
|
||||
}
|
||||
else if (ex is ObjectNotFoundException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((ObjectNotFoundException)ex).Message);
|
||||
}
|
||||
else if (ex is PositionOutOfCollectionException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((PositionOutOfCollectionException)ex).Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||
private void buttonRemoveMonorail_Click(object sender, EventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -134,19 +109,19 @@ namespace LocomotiveProject
|
||||
{
|
||||
if (_company == null) return;
|
||||
|
||||
DrawningBaseLocomotive? Locomotive = null;
|
||||
DrawningBaseLocomotive? locomotive = null;
|
||||
int coutner = 100;
|
||||
|
||||
while (Locomotive == null && coutner-- > 0)
|
||||
while (locomotive == null && coutner-- > 0)
|
||||
{
|
||||
Locomotive = _company.GetRandomObject();
|
||||
locomotive = _company.GetRandomObject();
|
||||
}
|
||||
|
||||
if (Locomotive == null) return;
|
||||
if (locomotive == null) return;
|
||||
|
||||
LocomotiveProjectForm form = new LocomotiveProjectForm()
|
||||
{
|
||||
SetLocomotive = Locomotive
|
||||
SetLocomotive = locomotive
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
@ -317,5 +292,68 @@ namespace LocomotiveProject
|
||||
LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogException(Exception ex)
|
||||
{
|
||||
if (ex is CollectionOverflowException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((CollectionOverflowException)ex).Message);
|
||||
}
|
||||
else if (ex is FileEmptyException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((FileEmptyException)ex).Message);
|
||||
}
|
||||
else if (ex is FileDoesNotExistException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((FileDoesNotExistException)ex).Message);
|
||||
}
|
||||
else if (ex is ObjectNotFoundException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((ObjectNotFoundException)ex).Message);
|
||||
}
|
||||
else if (ex is PositionOutOfCollectionException)
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ((PositionOutOfCollectionException)ex).Message);
|
||||
}
|
||||
else if (ex is ObjectIsEqualException)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogError("Ошибка {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareBaseLocomotive(new DrawningLocomotiveCompareByType());
|
||||
}
|
||||
|
||||
private void buttonByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareBaseLocomotive(new DrawningLocomotiveCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareMonorail(IComparer<DrawningBaseLocomotive?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
private void CompareBaseLocomotive(IComparer<DrawningBaseLocomotive?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using LocomativeProject;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
|
@ -6,3 +6,18 @@
|
||||
2024-05-20 11:55:34.488 +04:00 [INF] Коллекция добавлена dfgdfg
|
||||
2024-05-20 11:55:40.963 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 11:55:43.055 +04:00 [ERR] Ошибка Входные дынне пустые
|
||||
2024-05-20 12:54:22.173 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 12:54:26.672 +04:00 [INF] Коллекция добавлена jhjgh
|
||||
2024-05-20 12:54:35.923 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:54:41.721 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:54:47.432 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:54:59.128 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:55:08.872 +04:00 [ERR] Ошибка Не найден объект по позиции 10
|
||||
2024-05-20 12:55:15.324 +04:00 [INF] Форма загрузилась
|
||||
2024-05-20 12:55:19.608 +04:00 [INF] Коллекция добавлена 5252
|
||||
2024-05-20 12:55:25.794 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:55:34.129 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:55:40.288 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:56:08.337 +04:00 [INF] Объект добавлен
|
||||
2024-05-20 12:56:21.864 +04:00 [INF] Объект удален
|
||||
2024-05-20 12:56:39.544 +04:00 [INF] Объект добавлен
|
||||
|
Loading…
Reference in New Issue
Block a user