PIbd-11_Chechevitcyn_S.A_AntiAircraftGun_Simple_LabWork8(Last) #10

Closed
shaman_stepan wants to merge 2 commits from LabWork8(Last) into LabWork7
13 changed files with 398 additions and 70 deletions

View File

@ -51,7 +51,7 @@ public abstract class AbstractCompany
/// <returns></returns>
public static bool operator +(AbstractCompany company, DrawningGun gun)
{
return company._collection.Insert(gun);
return company._collection.Insert(gun,new DrawningGunEqutables());
}
/// <summary>
@ -104,4 +104,10 @@ public abstract class AbstractCompany
/// </summary>
protected abstract void SetObjectsPosition();
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<DrawningGun?> comparer) => _collection?.CollectionSort(comparer);
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.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; }
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();
}
}

View File

@ -1,4 +1,6 @@
namespace AntiAircraftGun.CollectionGenericObjects;
using AntiAircraftGun.Drawnings;
namespace AntiAircraftGun.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
@ -21,14 +23,14 @@ public interface ICollectionGenericObjects<T>
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj);
bool Insert(T obj,IEqualityComparer<T?>? comparer=null);
/// <summary>
/// Добавление объекта в коллекцию на конкретную позицию
/// </summary>
/// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
bool Insert(T obj, int position);
bool Insert(T obj, int position, IEqualityComparer<T?>? comparer=null);
/// <summary>
/// Удаление объекта из коллекции с конкретной позиции
/// </summary>
@ -50,4 +52,10 @@ public interface ICollectionGenericObjects<T>
/// </summary>
/// <returns></returns>
IEnumerable<T?> GetItems();
/// <summary>
/// Сортировка коллекции
/// </summary>
/// <param name="comparer"></param>
void CollectionSort(IComparer<T?>? comparer);
}

View File

@ -1,9 +1,5 @@
using AntiAircraftGun.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntiAircraftGun.Drawnings;
using AntiAircraftGun.Exceptions;
namespace AntiAircraftGun.CollectionGenericObjects;
/// <summary>
@ -37,21 +33,35 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
// +-
if (!_collection.Any()) { return null; }
if (_collection.Count <= position || position < 0 || position >= _maxCount) {
throw new PostiionOutOfCollectionException(Count);
throw new PositionOutOfCollectionException(Count);
}
return _collection[position];
}
public bool Insert(T obj)
public bool Insert(T obj, IEqualityComparer<T?> comparer = null)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO вставка в конец набора
// TODO выброс ошибки, если переполнение
// +-
if (comparer != null)
{
foreach (T? item in _collection)
Review

У списка есть метод Contains для проверки

У списка есть метод Contains для проверки
{
if (item == null) continue;
if ((comparer as IEqualityComparer<DrawningGun>).Equals(obj as DrawningGun, item as DrawningGun))
{
throw new ObjectIsEqualException();
}
}
}
if (_collection.Count>=_maxCount) throw new CollectionOverflowExecption(_maxCount);
_collection.Add(obj);
return true;
}
public bool Insert(T obj, int position)
public bool Insert(T obj, int position, IEqualityComparer<T?> comparer = null)
{
// TODO проверка, что не превышено максимальное количество элементов
// TODO проверка позиции
@ -59,8 +69,21 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
// TODO выброс ошибки, если выход за границу
// TODO выброс ошибки, если переполнение
// +-
if (comparer != null)
{
foreach (T? item in _collection)
{
if (item == null) continue;
if ((comparer as IEqualityComparer<DrawningGun>).Equals(obj as DrawningGun, item as DrawningGun))
{
throw new ObjectIsEqualException();
}
}
}
if (Count>=_maxCount) throw new CollectionOverflowExecption(_maxCount);
if (position >= Count || position < 0) { throw new PostiionOutOfCollectionException(position); }
if (position >= Count || position < 0) { throw new PositionOutOfCollectionException(position); }
_collection.Insert(position, obj);
return true;
}
@ -70,7 +93,7 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
// TODO удаление объекта из списка
// TODO выброс ошибки, если выход за границу массива
// +-
if(position < 0 || position >= _maxCount) throw new PostiionOutOfCollectionException(position);
if(position < 0 || position >= _maxCount) throw new PositionOutOfCollectionException(position);
if (_collection[position] == null)
{
return false;
@ -85,4 +108,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
{
for(int i=0; i<_collection.Count; i++) yield return _collection[i];
}
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
{
_collection.Sort(comparer);
}
}

View File

@ -1,4 +1,5 @@
using AntiAircraftGun.Exceptions;
using AntiAircraftGun.Drawnings;
using AntiAircraftGun.Exceptions;
using System.Data.Entity.Core;
using System.Diagnostics;
@ -55,14 +56,23 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
}
if (position >= _collection.Length || position<0)
{
throw new PostiionOutOfCollectionException(position);
throw new PositionOutOfCollectionException(position);
}
return _collection[position];
}
public bool Insert(T obj)
public bool Insert(T obj, IEqualityComparer<T?> comparer = null)
{
// TODO вставка в свободное место набора
// TODO выброс ошибки, если переполнение
if (comparer != null)
{
foreach (T? item in _collection)
{
if ((comparer as IEqualityComparer<DrawningGun>).Equals(obj as DrawningGun, item as DrawningGun))
throw new ObjectIsEqualException();
}
}
for (int i = 0; i < Count; i++)
{
if (InsertingElementCollection(i, obj)) return true;
@ -70,7 +80,7 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
throw new CollectionOverflowExecption(Count);
}
public bool Insert(T obj, int position)
public bool Insert(T obj, int position, IEqualityComparer<T?> comparer = null)
{
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
@ -80,9 +90,19 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
// TODO выброс ошибки, если переполнение
// TODO выброс ошибки, если выход за границу массива
// +-
if(position>=_collection.Length||position<0)
if (comparer != null)
{
throw new PostiionOutOfCollectionException(position);
foreach (T? item in _collection)
{
if ((comparer as IEqualityComparer<DrawningGun>).Equals(obj as DrawningGun, item as DrawningGun))
throw new ObjectIsEqualException();
}
}
if (position>=_collection.Length||position<0)
{
throw new PositionOutOfCollectionException(position);
}
if (InsertingElementCollection(position, obj)) return true;
@ -105,7 +125,7 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
// TODO выброс ошибки, если выход за границу
// TODO выброс ошибки, если пустой
// +-
if(position >= _collection.Length || position < 0) throw new PostiionOutOfCollectionException(position);
if(position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
if (_collection[position] == null) throw new Exceptions.ObjectNotFoundException(position);
_collection[position] = null;
return true;
@ -132,4 +152,9 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
{
for (int i=0; i < _collection.Length; i++) yield return _collection[i];
}
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
{
Array.Sort(_collection, comparer);
}
}

View File

@ -13,11 +13,11 @@ where T : DrawningGun
/// <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();
private readonly string _collectionKey = "CollectionStorage";
@ -28,7 +28,7 @@ where T : DrawningGun
/// </summary>
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
}
/// <summary>
/// Добавление коллекции в хранилище
@ -39,21 +39,13 @@ where T : DrawningGun
{
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
if (name.Length<=0 || _storages.ContainsKey(name))
{
return;
}
switch(collectionType)
{
case CollectionType.List:
_storages.Add(name, new ListGenericObjects<T>());
break;
case CollectionType.Massive:
_storages.Add(name, new MassiveGenericObjects<T>());
break;
default:
return;
}
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
if (_storages.ContainsKey(collectionInfo)) return;
if (collectionType == CollectionType.None) return;
else if (collectionType == CollectionType.Massive)
_storages[collectionInfo] = new MassiveGenericObjects<T>();
else if (collectionType == CollectionType.List)
_storages[collectionInfo] = new ListGenericObjects<T>();
}
/// <summary>
/// Удаление коллекции
@ -62,8 +54,9 @@ where T : DrawningGun
public void DelCollection(string name)
{
// TODO Прописать логику для удаления коллекции
if(!_storages.ContainsKey(name)) { return; }
_storages.Remove(name);
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
if (!_storages.ContainsKey(collectionInfo)) { return; }
_storages.Remove(collectionInfo);
}
/// <summary>
/// Доступ к коллекции
@ -75,8 +68,9 @@ where T : DrawningGun
get
{
// TODO Продумать логику получения объекта
if (!_storages.ContainsKey(name)) { return null; }
return _storages[name];
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
if (!_storages.ContainsKey(collectionInfo)) { return null; }
return _storages[collectionInfo];
}
}
/// <summary>
@ -94,15 +88,13 @@ where T : DrawningGun
StringBuilder sb = new();
sb.Append(_collectionKey);
foreach (KeyValuePair<string,ICollectionGenericObjects<T>> value in _storages)
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
{
sb.Append(Environment.NewLine);
// Не сохраняем пустые коллекции
if (value.Value.Count == 0) continue;
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
@ -145,18 +137,20 @@ where T : DrawningGun
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);
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
throw new Exception("Не удалось создать коллекцию");
if (collection == null)
{
throw new Exception("Не удалось создать коллекцию");
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
collection.MaxCount = Convert.ToInt32(record[1]);
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningCun() is T gun)
@ -165,16 +159,16 @@ where T : DrawningGun
{
if (!collection.Insert(gun))
{
throw new Exception("Объект не удалось добавить в коллекию: " + record[3]);
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowExecption ex)
{
throw new Exception("Коллекция переполнена",ex);
throw new Exception("Коллекция переполнена", ex);
}
}
}
_storages.Add(record[0], collection);
_storages.Add(collectionInfo, collection);
}
}
}

View File

@ -0,0 +1,28 @@
namespace AntiAircraftGun.Drawnings;
public class DrawningGunCompareByColor : IComparer<DrawningGun?>
{
public int Compare(DrawningGun? x, DrawningGun? y)
{
if (x == null || x.EntityGun == null)
{
return 1;
}
if (y == null || y.EntityGun == null)
{
return -1;
}
var bodycolorCompare = x.EntityGun.BodyColor.Name.CompareTo(y.EntityGun.BodyColor.Name);
if (bodycolorCompare != 0)
{
return bodycolorCompare;
}
var speedCompare = x.EntityGun.Speed.CompareTo(y.EntityGun.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityGun.Weight.CompareTo(y.EntityGun.Weight);
}
}

View File

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AntiAircraftGun.Drawnings;
/// <summary>
/// Сравнение по типу, скорости, весу
/// </summary>
public class DrawningGunCompareByType : IComparer<DrawningGun?>
{
public int Compare(DrawningGun? x, DrawningGun? y)
{
if (x == null || x.EntityGun == null)
{
return -1;
}
if (y == null || y.EntityGun == null)
{
return 1;
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityGun.Speed.CompareTo(y.EntityGun.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityGun.Weight.CompareTo(y.EntityGun.Weight);
}
}

View File

@ -0,0 +1,64 @@

using AntiAircraftGun.Entities;
using System.Diagnostics.CodeAnalysis;
namespace AntiAircraftGun.Drawnings;
/// <summary>
/// Реализатор сравнения двух объектов
/// </summary>
public class DrawningGunEqutables : IEqualityComparer<DrawningGun?>
{
public bool Equals(DrawningGun? x, DrawningGun? y)
{
if (x == null || x.EntityGun == null)
{
return false;
}
if (y == null || y.EntityGun == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityGun.Speed != y.EntityGun.Speed)
{
return false;
}
if (x.EntityGun.Weight != y.EntityGun.Weight)
{
return false;
}
if (x.EntityGun.BodyColor != y.EntityGun.BodyColor)
{
return false;
}
if (x is DrawningAntiAircraftGun xa && y is DrawningAntiAircraftGun ya )
{
// TODO доделать логику сравнения дополнительных параметров
if(xa.EntityGun is EntityAntiAircraftGun left && ya.EntityGun is EntityAntiAircraftGun right)
{
if (left.OptionalElementsColor != right.OptionalElementsColor)
{
return false;
}
if (left.Radar != right.Radar)
{
return false;
}
if (left.Hatch != right.Hatch)
{
return false;
}
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawningGun? obj)
{
return obj.GetHashCode();
}
}

View File

@ -0,0 +1,16 @@
using System.Runtime.Serialization;
namespace AntiAircraftGun.Exceptions;
/// <summary>
/// Ошибка переполнения
/// </summary>
[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) { }
}

View File

@ -7,11 +7,11 @@ using System.Threading.Tasks;
namespace AntiAircraftGun.Exceptions;
public class PostiionOutOfCollectionException:ApplicationException
public class PositionOutOfCollectionException:ApplicationException
{
public PostiionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { }
public PostiionOutOfCollectionException() : base() { }
public PostiionOutOfCollectionException(string message) : base(message) { }
public PostiionOutOfCollectionException(string message, Exception innerException) : base(message, innerException) { }
protected PostiionOutOfCollectionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { }
public PositionOutOfCollectionException() : base() { }
public PositionOutOfCollectionException(string message) : base(message) { }
public PositionOutOfCollectionException(string message, Exception innerException) : base(message, innerException) { }
protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}

View File

@ -52,6 +52,8 @@
downloadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
buttonSortByColor = new Button();
buttonSortByType = new Button();
groupBox1.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@ -64,15 +66,17 @@
groupBox1.Controls.Add(panelCompanyTools);
groupBox1.Controls.Add(panelStorage);
groupBox1.Dock = DockStyle.Right;
groupBox1.Location = new Point(981, 28);
groupBox1.Location = new Point(1011, 28);
groupBox1.Name = "groupBox1";
groupBox1.Size = new Size(235, 744);
groupBox1.Size = new Size(235, 855);
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Инструменты";
//
// panelCompanyTools
//
panelCompanyTools.Controls.Add(buttonSortByColor);
panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonCreateCompany);
panelCompanyTools.Controls.Add(comboBoxSelectorCompany);
panelCompanyTools.Controls.Add(buttonAddGun);
@ -81,9 +85,9 @@
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonRemoveGun);
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Location = new Point(3, 384);
panelCompanyTools.Location = new Point(3, 395);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(229, 357);
panelCompanyTools.Size = new Size(229, 457);
panelCompanyTools.TabIndex = 9;
//
// buttonCreateCompany
@ -248,7 +252,7 @@
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(981, 744);
pictureBox.Size = new Size(1011, 855);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@ -258,7 +262,7 @@
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1216, 28);
menuStrip.Size = new Size(1246, 28);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip1";
//
@ -293,11 +297,33 @@
//
openFileDialog.Filter = "txt files|*.txt";
//
// buttonSortByColor
//
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonSortByColor.Location = new Point(9, 397);
buttonSortByColor.Name = "buttonSortByColor";
buttonSortByColor.Size = new Size(214, 39);
buttonSortByColor.TabIndex = 10;
buttonSortByColor.Text = "Сортировка по цвету";
buttonSortByColor.UseVisualStyleBackColor = true;
buttonSortByColor.Click += buttonSortByColor_Click;
//
// buttonSortByType
//
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonSortByType.Location = new Point(9, 358);
buttonSortByType.Name = "buttonSortByType";
buttonSortByType.Size = new Size(214, 33);
buttonSortByType.TabIndex = 9;
buttonSortByType.Text = "Сортировка по типу";
buttonSortByType.UseVisualStyleBackColor = true;
buttonSortByType.Click += buttonSortByType_Click;
//
// FormGunCollections
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1216, 772);
ClientSize = new Size(1246, 883);
Controls.Add(pictureBox);
Controls.Add(groupBox1);
Controls.Add(menuStrip);
@ -342,5 +368,7 @@
private ToolStripMenuItem downloadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -54,7 +54,7 @@ public partial class FormGunCollections : Form
/// Добавление автомобиля в коллекцию
/// </summary>
/// <param name="gun"></param>
private void SetGun(DrawningGun gun)
private void SetGun(DrawningGun? gun)
{
try
{
@ -72,6 +72,11 @@ public partial class FormGunCollections : Form
MessageBox.Show("Не удалось добавить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
catch (ObjectIsEqualException ex)
{
MessageBox.Show("Не удалось добавить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
}
/// <summary>
@ -262,7 +267,7 @@ listBoxCollection.SelectedItem == null)
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);
@ -316,4 +321,35 @@ listBoxCollection.SelectedItem == null)
}
}
}
/// <summary>
/// Сортировка по типу
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByType_Click(object sender, EventArgs e)
{
CompareGun(new DrawningGunCompareByType());
}
/// <summary>
/// Сортировка по цвету
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByColor_Click(object sender, EventArgs e)
{
CompareGun(new DrawningGunCompareByColor());
}
/// <summary>
/// Сортировка по сравнителю
/// </summary>
/// <param name="comparer"></param>
private void CompareGun(IComparer<DrawningGun?> comparer)
{
if (comparer == null) return;
_company.Sort(comparer);
pictureBox.Image = _company.Show();
}
}