PIbd-11 Karakozov_AK LabWork08 Simple #8
@ -59,7 +59,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningBulldozer bulldozer)
|
||||
{
|
||||
return company._collection.Insert(bulldozer);
|
||||
return company._collection.Insert(bulldozer, new DrawningExcavatorEqutables());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -103,6 +103,12 @@ public abstract class AbstractCompany
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравниватель объектов</param>
|
||||
public void Sort(IComparer<DrawningBulldozer?> comparer) => _collection?.CollectionSort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Вывод фона
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,72 @@
|
||||
namespace ProjectExcavator.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;
|
||||
}
|
||||
|
||||
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,6 @@
|
||||
namespace ProjectExcavator.CollectionGenericObjects;
|
||||
using ProjectExcavator.Drawnings;
|
||||
|
||||
namespace ProjectExcavator.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
@ -21,16 +23,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<DrawningBulldozer?>? 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<DrawningBulldozer?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@ -56,4 +60,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,4 @@
|
||||
|
||||
using ProjectExcavator.Drawnings;
|
||||
using ProjectExcavator.Exceptions;
|
||||
|
||||
namespace ProjectExcavator.CollectionGenericObjects;
|
||||
@ -39,8 +39,13 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<DrawningBulldozer?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
if (comparer != null && _collection.Contains(obj))
|
||||
{
|
||||
throw new CollectionAlreadyExistsException();
|
||||
}
|
||||
// проверка, что не превышено максимальное количество элементов
|
||||
if (_collection.Count >= _maxCount)
|
||||
{
|
||||
@ -51,8 +56,13 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _maxCount;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<DrawningBulldozer?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
if (comparer != null && _collection.Contains(obj))
|
||||
{
|
||||
throw new CollectionAlreadyExistsException();
|
||||
}
|
||||
// проверка, что не превышено максимальное количество элементов
|
||||
if (Count >= _maxCount)
|
||||
throw new CollectionOverflowException(_maxCount);
|
||||
@ -83,4 +93,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
|
||||
using ProjectExcavator.Drawnings;
|
||||
using ProjectExcavator.Exceptions;
|
||||
|
||||
namespace ProjectExcavator.CollectionGenericObjects;
|
||||
@ -60,8 +61,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<DrawningBulldozer?>? comparer = null)
|
||||
{
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
if (comparer != null && _collection.Contains(obj))
|
||||
{
|
||||
throw new CollectionAlreadyExistsException();
|
||||
}
|
||||
// вставка в свободное место набора
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
@ -76,8 +82,15 @@ 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<DrawningBulldozer?>? comparer = null)
|
||||
{
|
||||
|
||||
// TODO выброс ошибки, если такой объект есть в коллекции
|
||||
if (comparer != null && _collection.Contains(obj))
|
||||
{
|
||||
throw new CollectionAlreadyExistsException();
|
||||
}
|
||||
|
||||
// проверка позиции
|
||||
if (position >= _collection.Length || position < 0)
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
@ -138,4 +151,14 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
public void CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
List<T?> lst = [.. _collection];
|
||||
lst.Sort(comparer.Compare);
|
||||
for (int i = 0; i < _collection.Length; ++i)
|
||||
{
|
||||
_collection[i] = lst[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,12 +13,12 @@ public class StorageCollection<T>
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с коллекциями
|
||||
/// </summary>
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Ключевое слово, с которого должен начинаться файл
|
||||
@ -40,7 +40,7 @@ public class StorageCollection<T>
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -51,18 +51,19 @@ public class StorageCollection<T>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
// проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
|
||||
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(new CollectionInfo(name, collectionType, string.Empty)))
|
||||
{
|
||||
MessageBox.Show("Коллекция с таким именем уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
// прописать логику для добавления
|
||||
if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
_storages.Add(new CollectionInfo(name, collectionType, string.Empty), new ListGenericObjects<T>());
|
||||
}
|
||||
if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
_storages.Add(new CollectionInfo(name, collectionType, string.Empty), new MassiveGenericObjects<T>());
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,8 +74,8 @@ public class StorageCollection<T>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
// прописать логику для удаления коллекции
|
||||
if (!_storages.ContainsKey(name)) return;
|
||||
_storages.Remove(name);
|
||||
if (!_storages.ContainsKey(new CollectionInfo(name, CollectionType.None, string.Empty))) return;
|
||||
_storages.Remove(new CollectionInfo(name, CollectionType.None, string.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -87,9 +88,9 @@ public class StorageCollection<T>
|
||||
get
|
||||
{
|
||||
// продумать логику получения объекта
|
||||
if (_storages.ContainsKey((string)name))
|
||||
if (_storages.ContainsKey(new CollectionInfo(name, CollectionType.None, string.Empty)))
|
||||
{
|
||||
return _storages[name];
|
||||
return _storages[new CollectionInfo(name, CollectionType.None, string.Empty)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -114,7 +115,7 @@ public class StorageCollection<T>
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
writer.Write(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
@ -125,8 +126,6 @@ public class StorageCollection<T>
|
||||
|
||||
writer.Write(value.Key);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.GetCollectionType);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.MaxCount);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
|
||||
@ -176,21 +175,18 @@ public class StorageCollection<T>
|
||||
while ((strs = reader.ReadLine()) != null)
|
||||
{
|
||||
string[] record = strs.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 Exception("Не удалось создать коллекцию");
|
||||
}
|
||||
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]);
|
||||
|
||||
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?.CreateDrawningBulldozer() is T bulldozer)
|
||||
@ -209,7 +205,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
}
|
||||
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
using ProjectExcavator.Entities;
|
||||
|
||||
namespace ProjectExcavator.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по цвету, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningExcavatorCompareByColor : IComparer<DrawningBulldozer?>
|
||||
{
|
||||
public int Compare(DrawningBulldozer? x, DrawningBulldozer? y)
|
||||
{
|
||||
// TODO прописать логику сравнения по цветам, скорости, весу
|
||||
if (x == null || x.EntityBulldozer == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityBulldozer == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.EntityBulldozer.BodyColor != y.EntityBulldozer.BodyColor)
|
||||
{
|
||||
return x.EntityBulldozer.BodyColor.Name.CompareTo(y.EntityBulldozer.BodyColor.Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityBulldozer.Speed.CompareTo(y.EntityBulldozer.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityBulldozer.Weight.CompareTo(y.EntityBulldozer.Weight);
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
namespace ProjectExcavator.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Сравнение по типу, скорости, весу
|
||||
/// </summary>
|
||||
public class DrawningExcavatorCompareByType : IComparer<DrawningBulldozer?>
|
||||
{
|
||||
public int Compare(DrawningBulldozer? x, DrawningBulldozer? y)
|
||||
{
|
||||
if (x == null || x.EntityBulldozer == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityBulldozer == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityBulldozer.Speed.CompareTo(y.EntityBulldozer.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityBulldozer.Weight.CompareTo(y.EntityBulldozer.Weight);
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using ProjectExcavator.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace ProjectExcavator.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawningExcavatorEqutables : IEqualityComparer<DrawningBulldozer?>
|
||||
{
|
||||
public bool Equals(DrawningBulldozer? x, DrawningBulldozer? y)
|
||||
{
|
||||
if (x == null || x.EntityBulldozer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityBulldozer == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.EntityBulldozer.Speed != y.EntityBulldozer.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.EntityBulldozer.Weight != y.EntityBulldozer.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x.EntityBulldozer.BodyColor != y.EntityBulldozer.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (x is DrawningExcavator && y is DrawningExcavator)
|
||||
{
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
EntityExcavator xExcavator = (EntityExcavator)x.EntityBulldozer;
|
||||
EntityExcavator yExcavator = (EntityExcavator)y.EntityBulldozer;
|
||||
|
||||
if(xExcavator.AdditionalColor != yExcavator.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (xExcavator.Ladle != yExcavator.Ladle)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (xExcavator.Prop != yExcavator.Prop)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningBulldozer obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using ProjectExcavator.CollectionGenericObjects;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectExcavator.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку повторяющегося элемента в коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class CollectionAlreadyExistsException : ApplicationException
|
||||
{
|
||||
public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base("В коллекции уже есть такой элемент: " + collectionInfo) { }
|
||||
public CollectionAlreadyExistsException() : base() { }
|
||||
public CollectionAlreadyExistsException(string message) : base(message) { }
|
||||
public CollectionAlreadyExistsException(string message, Exception exception) : base(message, exception) { }
|
||||
protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
@ -2,6 +2,9 @@
|
||||
|
||||
namespace ProjectExcavator.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку, что позиция вышла за границы коллекции
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
internal class PositionOutOfCollectionException : ApplicationException
|
||||
{
|
||||
|
@ -52,6 +52,8 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
@ -68,13 +70,15 @@
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(774, 24);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(187, 576);
|
||||
groupBoxTools.Size = new Size(187, 671);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonAddBulldozer);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveCar);
|
||||
@ -84,7 +88,7 @@
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 328);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(181, 245);
|
||||
panelCompanyTools.Size = new Size(181, 340);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
@ -249,7 +253,7 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(774, 576);
|
||||
pictureBox.Size = new Size(774, 671);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -293,11 +297,33 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByType.Location = new Point(12, 245);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(160, 42);
|
||||
buttonSortByType.TabIndex = 7;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByColor.Location = new Point(12, 293);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(160, 42);
|
||||
buttonSortByColor.TabIndex = 8;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// FormBulldozerCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(961, 600);
|
||||
ClientSize = new Size(961, 695);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
@ -342,5 +368,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByType;
|
||||
private Button buttonSortByColor;
|
||||
}
|
||||
}
|
@ -235,7 +235,7 @@ public partial class FormBulldozerCollection : Form
|
||||
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);
|
||||
@ -290,7 +290,7 @@ public partial class FormBulldozerCollection : Form
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
@ -314,11 +314,42 @@ public partial class FormBulldozerCollection : Form
|
||||
RefreshListBoxItems();
|
||||
_logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName);
|
||||
}
|
||||
catch(Exception ex)
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareExcavators(new DrawningExcavatorCompareByType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareExcavators(new DrawningExcavatorCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareExcavators(IComparer<DrawningBulldozer?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user