Лабораторная работа 8
This commit is contained in:
parent
b63e7a1c12
commit
0e3a9a94a8
@ -1,4 +1,5 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectAircraftCarrier_.Exceptions;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -65,7 +66,18 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningMachine machine)
|
||||
{
|
||||
return company._collection.Insert(machine, 0);
|
||||
try
|
||||
{
|
||||
return company._collection.Insert(machine, 0, new DrawningMachineEqutables());
|
||||
}
|
||||
catch (ObjectAlreadyInCollectionException)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
catch (CollectionOverflowException)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -125,6 +137,12 @@ public abstract class AbstractCompany
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningMachine?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, хранящиий информацию по коллекции
|
||||
/// </summary>
|
||||
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// Название
|
||||
/// </summary>
|
||||
public string Name { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Тип
|
||||
/// </summary>
|
||||
public CollectionType CollectionType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Описание
|
||||
/// </summary>
|
||||
public string Description { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly string _separator = "-";
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="name">Название</param>
|
||||
/// <param name="collectionType">Тип</param>
|
||||
/// <param name="description">Описание</param>
|
||||
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||
{
|
||||
Name = name;
|
||||
CollectionType = collectionType;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="data">Строка</param>
|
||||
/// <returns>Объект или null</returns>
|
||||
public static CollectionInfo? GetCollectionInfo(string data)
|
||||
{
|
||||
string[] strs = data.Split(_separator, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs.Length < 1 || strs.Length > 3)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CollectionInfo(strs[0], (CollectionType)Enum.Parse(typeof(CollectionType), strs[1]),
|
||||
strs.Length > 2 ? strs[2] : string.Empty);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name + _separator + CollectionType + _separator + Description;
|
||||
}
|
||||
|
||||
public bool Equals(CollectionInfo? other)
|
||||
{
|
||||
return Name == other?.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return Equals(obj as CollectionInfo);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using ProjectGasMachine.CollectionGenericObjects;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -28,16 +29,18 @@ public interface ICollectionGenericObjects<T>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="comparer">Сравнение двух объектов</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, IEqualityComparer<DrawningMachine?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <param name="comparer">Сравнение двух объектов</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
int Insert(T obj, int position, IEqualityComparer<DrawningMachine?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@ -63,4 +66,10 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
using ProjectAircraftCarrier_.Exceptions;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
@ -46,9 +48,16 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<DrawningMachine?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если переполнение
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningMachine), (obj as DrawningMachine)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new CollectionOverflowException(Count);
|
||||
@ -58,10 +67,17 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection.Count;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<DrawningMachine?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы списка
|
||||
// TODO выброс ошибки, если переполнение
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningMachine), (obj as DrawningMachine)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
if (position < 0 || position > Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
@ -96,4 +112,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
using ProjectAircraftCarrier_.Exceptions;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
using System.Linq;
|
||||
|
||||
@ -69,9 +71,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
}
|
||||
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<DrawningMachine?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если переполнение
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningMachine), (obj as DrawningMachine)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
@ -84,10 +95,18 @@ 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<DrawningMachine?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если выход за границы массива
|
||||
// TODO выброс ошибки, если переполнение
|
||||
for (int i = 0; i < Count; i++)
|
||||
{
|
||||
if (comparer.Equals((_collection[i] as DrawningMachine), (obj as DrawningMachine)))
|
||||
{
|
||||
throw new ObjectAlreadyInCollectionException(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
@ -146,4 +165,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectAircraftCarrier_.Exceptions;
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using ProjectGasMachine.Exceptions;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
@ -13,12 +14,12 @@ public class StorageCollection<T>
|
||||
/// <summary>
|
||||
/// словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
private Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
private Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
@ -38,7 +39,7 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -46,21 +47,21 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="name">название коллекции</param>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
public void AddCollection(CollectionInfo info)
|
||||
{
|
||||
if (name == null || _storages.ContainsKey(name))
|
||||
if (info == null || _storages.ContainsKey(info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (collectionType == CollectionType.Massive)
|
||||
if (info.CollectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
_storages.Add(info, new MassiveGenericObjects<T>());
|
||||
}
|
||||
|
||||
if (collectionType == CollectionType.List)
|
||||
if (info.CollectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
_storages.Add(info, new ListGenericObjects<T>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,14 +69,14 @@ public class StorageCollection<T>
|
||||
/// Удаление коллекции
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
public void DelCollection(string name)
|
||||
public void DelCollection(CollectionInfo info)
|
||||
{
|
||||
if (name == null || !_storages.ContainsKey(name))
|
||||
if (info == null || !_storages.ContainsKey(info))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_storages.Remove(name);
|
||||
_storages.Remove(info);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -83,13 +84,13 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
/// <returns></returns>
|
||||
public ICollectionGenericObjects<T>? this[string name]
|
||||
public ICollectionGenericObjects<T>? this[CollectionInfo info]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
if (_storages.ContainsKey(info))
|
||||
{
|
||||
return _storages[name];
|
||||
return _storages[info];
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -117,7 +118,7 @@ public class StorageCollection<T>
|
||||
{
|
||||
sw.Write(_collectionKey);
|
||||
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
sw.Write(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
@ -128,8 +129,6 @@ public class StorageCollection<T>
|
||||
|
||||
sw.Write(value.Key);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
sw.Write(value.Value.GetCollectionType);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
sw.Write(value.Value.MaxCount);
|
||||
sw.Write(_separatorForKeyValue);
|
||||
|
||||
@ -178,27 +177,25 @@ public class StorageCollection<T>
|
||||
while ((line = sr.ReadLine()) != null)
|
||||
{
|
||||
string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 4)
|
||||
if (record.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
if (collection == null)
|
||||
{
|
||||
throw new InvalidOperationException("Не удалось создать коллекцию");
|
||||
}
|
||||
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||
throw new Exception("Не удалось создать коллекцию");
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawningMachine() is T machine)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (collection.Insert(machine) == -1)
|
||||
if (collection.Insert(machine, new DrawningMachineEqutables()) == -1)
|
||||
{
|
||||
throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
@ -207,9 +204,13 @@ public class StorageCollection<T>
|
||||
{
|
||||
throw new OverflowException("Коллекция переполнена", ex);
|
||||
}
|
||||
catch (ObjectAlreadyInCollectionException ex)
|
||||
{
|
||||
throw new InvalidOperationException("Объект уже присутствует в коллекции", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,52 @@
|
||||
using ProjectGasMachine.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
|
||||
public class DrawningMachineCompareByColor : IComparer<DrawningMachine?>
|
||||
{
|
||||
public int Compare(DrawningMachine? x, DrawningMachine? y)
|
||||
{
|
||||
if (x == null || x.EntityGas == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (y == null || y.EntityGas == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return y.GetType().Name.CompareTo(x.GetType().Name);
|
||||
}
|
||||
var bodyColorCompare = y.EntityGas.BodyColor.Name.CompareTo(x.EntityGas.BodyColor.Name);
|
||||
if (bodyColorCompare != 0)
|
||||
{
|
||||
return bodyColorCompare;
|
||||
}
|
||||
if (x is DrawningGasMachine && y is DrawningGasMachine)
|
||||
{
|
||||
var additionalColorCompare = (y.EntityGas as EntityMachine).AdditionalColor.Name.CompareTo(
|
||||
(x.EntityGas as EntityMachine).AdditionalColor.Name);
|
||||
if (additionalColorCompare != 0)
|
||||
{
|
||||
return additionalColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = y.EntityGas.Speed.CompareTo(x.EntityGas.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return y.EntityGas.Weight.CompareTo(x.EntityGas.Weight);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using ProjectGasMachine.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по типу, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningMachineCompareByType : IComparer<DrawningMachine?>
|
||||
{
|
||||
public int Compare(DrawningMachine? x, DrawningMachine? y)
|
||||
{
|
||||
if (x == null || x.EntityGas == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (y == null || y.EntityGas == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return y.GetType().Name.CompareTo(x.GetType().Name);
|
||||
}
|
||||
var speedCompare = y.EntityGas.Speed.CompareTo(x.EntityGas.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return y.EntityGas.Weight.CompareTo(x.EntityGas.Weight);
|
||||
}
|
||||
}
|
68
ProjectCar/ProjectCar/Drawnings/DrawningMachineEqutables.cs
Normal file
68
ProjectCar/ProjectCar/Drawnings/DrawningMachineEqutables.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using ProjectGasMachine.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectGasMachine.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawningMachineEqutables : IEqualityComparer<DrawningMachine?>
|
||||
{
|
||||
public bool Equals(DrawningMachine? x, DrawningMachine? y)
|
||||
{
|
||||
if (x == null || x.EntityGas == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityGas == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityGas.Speed != y.EntityGas.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityGas.Weight != y.EntityGas.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityGas.BodyColor != y.EntityGas.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningGasMachine && y is DrawningGasMachine)
|
||||
{
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
if ((x.EntityGas as EntityMachine)?.AdditionalColor !=
|
||||
(y.EntityGas as EntityMachine)?.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityGas as EntityMachine)?.Gas !=
|
||||
(y.EntityGas as EntityMachine)?.Gas)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityGas as EntityMachine)?.Beacon !=
|
||||
(y.EntityGas as EntityMachine)?.Beacon)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningMachine? obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectAircraftCarrier_.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку переполнения коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class ObjectAlreadyInCollectionException : ApplicationException
|
||||
{
|
||||
public ObjectAlreadyInCollectionException(int index) : base("Такой объект уже присутствует в коллекции. Позиция " + index) { }
|
||||
|
||||
public ObjectAlreadyInCollectionException() : base() { }
|
||||
|
||||
public ObjectAlreadyInCollectionException(string message) : base(message) { }
|
||||
|
||||
public ObjectAlreadyInCollectionException(string message, Exception exception) : base(message, exception) { }
|
||||
|
||||
protected ObjectAlreadyInCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
@ -52,6 +52,8 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
ButtonSortByColor = new Button();
|
||||
ButtonSortByType = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
@ -68,13 +70,15 @@
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(780, 24);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(196, 534);
|
||||
groupBoxTools.Size = new Size(196, 557);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(ButtonSortByColor);
|
||||
panelCompanyTools.Controls.Add(ButtonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddMachine);
|
||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
@ -82,9 +86,9 @@
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 338);
|
||||
panelCompanyTools.Location = new Point(3, 292);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(190, 193);
|
||||
panelCompanyTools.Size = new Size(190, 262);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// buttonAddMachine
|
||||
@ -110,7 +114,7 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(10, 152);
|
||||
buttonRefresh.Location = new Point(10, 144);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(174, 32);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
@ -142,7 +146,7 @@
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(6, 294);
|
||||
buttonCreateCompany.Location = new Point(6, 263);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(184, 23);
|
||||
buttonCreateCompany.TabIndex = 7;
|
||||
@ -162,12 +166,12 @@
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 19);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(190, 239);
|
||||
panelStorage.Size = new Size(190, 209);
|
||||
panelStorage.TabIndex = 8;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(3, 206);
|
||||
buttonCollectionDel.Location = new Point(3, 176);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(184, 23);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
@ -181,7 +185,7 @@
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(3, 106);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(184, 94);
|
||||
listBoxCollection.Size = new Size(184, 64);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
@ -238,7 +242,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 265);
|
||||
comboBoxSelectorCompany.Location = new Point(6, 234);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(184, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
@ -249,7 +253,7 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(780, 534);
|
||||
pictureBox.Size = new Size(780, 557);
|
||||
pictureBox.TabIndex = 3;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -293,11 +297,33 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
ButtonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonSortByColor.Location = new Point(10, 217);
|
||||
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
ButtonSortByColor.Size = new Size(174, 32);
|
||||
ButtonSortByColor.TabIndex = 9;
|
||||
ButtonSortByColor.Text = "Сортировка по цвету";
|
||||
ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
ButtonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonSortByType.Location = new Point(10, 182);
|
||||
ButtonSortByType.Name = "ButtonSortByType";
|
||||
ButtonSortByType.Size = new Size(174, 29);
|
||||
ButtonSortByType.TabIndex = 8;
|
||||
ButtonSortByType.Text = "Сортировка по типу";
|
||||
ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// FormGasMachineCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(976, 558);
|
||||
ClientSize = new Size(976, 581);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
@ -342,5 +368,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button ButtonSortByColor;
|
||||
private Button ButtonSortByType;
|
||||
}
|
||||
}
|
@ -51,7 +51,7 @@ namespace ProjectGasMachine
|
||||
/// <param name="machine"></param>
|
||||
private void SetMachine(DrawningMachine? machine)
|
||||
{
|
||||
try
|
||||
try
|
||||
{
|
||||
if (_company == null || machine == null)
|
||||
{
|
||||
@ -203,8 +203,9 @@ namespace ProjectGasMachine
|
||||
{
|
||||
collectionType = CollectionType.List;
|
||||
}
|
||||
CollectionInfo collectionInfo = new CollectionInfo(textBoxCollectionName.Text, collectionType, string.Empty);
|
||||
|
||||
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType);
|
||||
_storageCollection.AddCollection(collectionInfo);
|
||||
_logger.LogInformation($"Добавлена коллекция: {textBoxCollectionName.Text} типа: {collectionType}");
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
@ -226,7 +227,9 @@ namespace ProjectGasMachine
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
|
||||
|
||||
_storageCollection.DelCollection(collectionInfo);
|
||||
_logger.LogInformation($"Удалена коллекция: {listBoxCollection.SelectedItem.ToString()}");
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
@ -239,7 +242,7 @@ namespace ProjectGasMachine
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
string? colName = _storageCollection.Keys?[i].Name;
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
@ -260,7 +263,8 @@ namespace ProjectGasMachine
|
||||
return;
|
||||
}
|
||||
|
||||
ICollectionGenericObjects<DrawningMachine>? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
|
||||
CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
|
||||
ICollectionGenericObjects<DrawningMachine>? collection = _storageCollection[collectionInfo];
|
||||
if (collection == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не проинициализирована");
|
||||
@ -323,5 +327,39 @@ namespace ProjectGasMachine
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMachines(new DrawningMachineCompareByType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareMachines(new DrawningMachineCompareByColor());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
private void CompareMachines(IComparer<DrawningMachine?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -127,6 +127,6 @@
|
||||
<value>261, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>60</value>
|
||||
<value>25</value>
|
||||
</metadata>
|
||||
</root>
|
@ -15,7 +15,7 @@
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "D:\\12121212121212\\log.txt",
|
||||
"path": "C:\\Пользователи\\artem\\OneDrive\\Рабочий стол\\уник\\ООП\\log.txt",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.ffff} | {Level:u} | {SourceContext} | {Message:1j}{NewLine}{Exception}"
|
||||
}
|
||||
|
22
log20240514.txt
Normal file
22
log20240514.txt
Normal file
@ -0,0 +1,22 @@
|
||||
2024-05-14 13:53:59.8481 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: фыва типа: Massive
|
||||
2024-05-14 13:54:29.4113 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: фываывап типа: List
|
||||
2024-05-14 13:54:41.0738 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Blue
|
||||
2024-05-14 13:55:19.1076 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Black:Blue:True:True
|
||||
2024-05-14 13:55:52.9101 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Yellow
|
||||
2024-05-14 13:56:31.6484 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Black:Yellow:True:True
|
||||
2024-05-14 13:56:44.9675 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Yellow:Yellow:True:True
|
||||
2024-05-14 13:57:36.3335 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: ываыва типа: List
|
||||
2024-05-14 13:57:42.8871 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Black
|
||||
2024-05-14 13:57:48.2548 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Purple
|
||||
2024-05-14 13:57:56.5151 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Purple:Purple:True:True
|
||||
2024-05-14 13:58:03.4258 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Black:Black:True:True
|
||||
2024-05-14 13:59:41.8731 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: ываыва типа: List
|
||||
2024-05-14 14:00:04.7790 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Purple
|
||||
2024-05-14 14:00:09.8389 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Blue
|
||||
2024-05-14 14:00:19.3544 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Purple:Purple:True:True
|
||||
2024-05-14 14:00:24.6927 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Blue:Blue:True:True
|
||||
2024-05-14 14:00:50.6958 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлена коллекция: ываываыва типа: Massive
|
||||
2024-05-14 14:01:00.2608 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Green
|
||||
2024-05-14 14:01:06.5536 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Green:Green:True:True
|
||||
2024-05-14 14:01:10.7312 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityGas:100:100:Black
|
||||
2024-05-14 14:01:15.4086 | INFORMATION | ProjectGasMachine.FormGasMachineCollection | Добавлен объект EntityMachine:100:100:Black:Black:True:True
|
Loading…
Reference in New Issue
Block a user