From 55723d34bceed945498069524cf30c096397b670 Mon Sep 17 00:00:00 2001
From: Roman-Klemendeev <147613551+Roman-Klemendeev@users.noreply.github.com>
Date: Sun, 9 Jun 2024 23:19:22 +0400
Subject: [PATCH] lab8
---
.../AbstractCompany.cs | 8 ++-
.../CollectionInfo.cs | 44 ++++++++++++++
.../ICollectionGenericObjects.cs | 9 ++-
.../ListGenericObjects.cs | 22 ++++++-
.../MassiveGenericObjects.cs | 28 ++++++++-
.../StorageCollection.cs | 58 ++++++++++---------
.../Drawnings/DrawningTankerCompareByColor.cs | 29 ++++++++++
.../Drawnings/DrawningTankerCompareByType.cs | 30 ++++++++++
.../Drawnings/DrawningTankerEqutables.cs | 56 ++++++++++++++++++
.../Exceptions/ObjectIsEqualException.cs | 18 ++++++
.../FormTankerCollection.Designer.cs | 55 +++++++++++++-----
.../FormTankerCollection.cs | 26 ++++++++-
.../FormTankerConfig.Designer.cs | 8 +--
13 files changed, 337 insertions(+), 54 deletions(-)
create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs
create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByColor.cs
create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByType.cs
create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerEqutables.cs
create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectIsEqualException.cs
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs
index c79246f..229ef34 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs
@@ -59,7 +59,7 @@ public abstract class AbstractCompany
///
public static int operator +(AbstractCompany company, DrawningTanker tanker)
{
- return company._collection?.Insert(tanker) ?? -1;
+ return company._collection?.Insert(tanker, new DrawningTankerEqutables()) ?? -1;
}
///
@@ -118,4 +118,10 @@ public abstract class AbstractCompany
/// Расстановка объектов
///
protected abstract void SetObjectsPosition();
+
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..2956676
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,44 @@
+
+namespace ProjectGasolineTanker.CollectionGenericObjects;
+
+public class CollectionInfo : IEquatable
+{
+ 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();
+ }
+}
\ No newline at end of file
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
index 2b24287..ac92291 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -18,7 +18,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -26,7 +26,7 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
@@ -52,4 +52,9 @@ public interface ICollectionGenericObjects
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+ ///
+ /// Сортировка коллекции
+ ///
+ /// Сравнитель объектов
+ void CollectionSort(IComparer comparer);
}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs
index 0733007..fe03776 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs
@@ -37,15 +37,29 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? comparer = null)
{
+ if (comparer != null)
+ {
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectIsEqualException();
+ }
+ }
if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj);
return Count;
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
+ if (comparer != null)
+ {
+ if (_collection.Contains(obj, comparer))
+ {
+ throw new ObjectIsEqualException();
+ }
+ }
if (position < 0 || position >= Count)
throw new PositionOutOfCollectionException(position);
@@ -71,4 +85,8 @@ public class ListGenericObjects : ICollectionGenericObjects
yield return _collection[i];
}
}
+ void ICollectionGenericObjects.CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
index 9eb1cdb..0557fb7 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,5 @@
-using ProjectGasolineTanker.Exceptions;
+using ProjectGasolineTanker.Drawnings;
+using ProjectGasolineTanker.Exceptions;
namespace ProjectGasolineTanker.CollectionGenericObjects;
@@ -51,8 +52,16 @@ where T : class
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer comparer = null)
{
+ if (comparer != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningTanker, item as DrawningTanker))
+ throw new ObjectIsEqualException();
+ }
+ }
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
@@ -64,8 +73,16 @@ where T : class
throw new CollectionOverflowException(Count);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? comparer = null)
{
+ if (comparer != null)
+ {
+ foreach (T? item in _collection)
+ {
+ if ((comparer as IEqualityComparer).Equals(obj as DrawningTanker, item as DrawningTanker))
+ throw new ObjectIsEqualException();
+ }
+ }
if (position < 0 || position >= Count)
{
throw new PositionOutOfCollectionException(position);
@@ -115,4 +132,9 @@ where T : class
yield return _collection[i];
}
}
+ void ICollectionGenericObjects.CollectionSort(IComparer comparer)
+ {
+ Array.Sort(_collection, comparer);
+ }
}
+
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs
index 8f4676e..b7c8ffd 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs
@@ -9,12 +9,12 @@ public class StorageCollection
///
/// Словарь (хранилище) с коллекциями
///
- readonly Dictionary> _storages;
+ readonly Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
///
/// Ключевое слово, с которого должен начинаться файл
@@ -36,7 +36,7 @@ public class StorageCollection
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
@@ -46,17 +46,18 @@ public class StorageCollection
/// тип коллекции
public void AddCollection(string name, CollectionType collectionType)
{
- if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
+ CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
{
return;
}
switch (collectionType)
{
case CollectionType.Massive:
- _storages[name] = new MassiveGenericObjects();
+ _storages[collectionInfo] = new MassiveGenericObjects();
break;
case CollectionType.List:
- _storages[name] = new ListGenericObjects();
+ _storages[collectionInfo] = new ListGenericObjects();
break;
default:
return;
@@ -69,9 +70,10 @@ public class StorageCollection
/// Название коллекции
public void DelCollection(string name)
{
- if (_storages.ContainsKey(name))
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
{
- _storages.Remove(name);
+ _storages.Remove(collectionInfo);
}
}
@@ -85,10 +87,9 @@ public class StorageCollection
{
get
{
- if (_storages.ContainsKey(name))
- {
- return _storages[name];
- }
+ CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
+ if (_storages.ContainsKey(collectionInfo))
+ return _storages[collectionInfo];
return null;
}
}
@@ -115,15 +116,13 @@ public class StorageCollection
using (StreamWriter sw = new StreamWriter(filename))
{
sw.WriteLine(_collectionKey.ToString());
- foreach (KeyValuePair> kvpair in _storages)
+ foreach (KeyValuePair> kvpair in _storages)
{
// не сохраняем пустые коллекции
if (kvpair.Value.Count == 0)
continue;
sb.Append(kvpair.Key);
sb.Append(_separatorForKeyValue);
- sb.Append(kvpair.Value.GetCollectionType);
- sb.Append(_separatorForKeyValue);
sb.Append(kvpair.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in kvpair.Value.GetItems())
@@ -158,34 +157,37 @@ public class StorageCollection
str = sr.ReadLine();
if (str == null || str.Length == 0)
throw new Exception("В файле нет данных");
- if (str != _collectionKey.ToString())
+ if (!str.StartsWith(_collectionKey))
throw new Exception("В файле неверные данные");
_storages.Clear();
- while ((str = sr.ReadLine()) != null)
+ string strs = "";
+ while ((strs = sr.ReadLine()) != null)
{
- string[] record = str.Split(_separatorForKeyValue);
- if (record.Length != 4)
+ string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ if (record.Length != 3)
{
continue;
}
- CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
- ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType);
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
+ ICollectionGenericObjects? collection = StorageCollection.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?.CreateDrawningTanker() is T tanker)
+ if (elem?.CreateDrawningTanker() is T tank)
{
try
{
- if (collection.Insert(tanker) == -1)
+ if (collection.Insert(tank) == -1)
+ {
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
+ }
}
catch (CollectionOverflowException ex)
{
@@ -193,7 +195,7 @@ public class StorageCollection
}
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
}
}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByColor.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByColor.cs
new file mode 100644
index 0000000..a06d201
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByColor.cs
@@ -0,0 +1,29 @@
+
+namespace ProjectGasolineTanker.Drawnings;
+
+public class DrawningTankerCompareByColor : IComparer
+{
+ public int Compare(DrawningTanker? x, DrawningTanker? y)
+ {
+ if (x == null || x.EntityTanker == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityTanker == null)
+ {
+ return -1;
+ }
+ var bodycolorCompare = x.EntityTanker.BodyColor.Name.CompareTo(y.EntityTanker.BodyColor.Name);
+ if (bodycolorCompare != 0)
+ {
+ return bodycolorCompare;
+ }
+ var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight);
+ }
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByType.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByType.cs
new file mode 100644
index 0000000..c89183e
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerCompareByType.cs
@@ -0,0 +1,30 @@
+
+namespace ProjectGasolineTanker.Drawnings;
+
+public class DrawningTankerCompareByType : IComparer
+{
+ public int Compare(DrawningTanker? x, DrawningTanker? y)
+ {
+ if (x == null || x.EntityTanker == null)
+ {
+ return 1;
+ }
+
+ if (y == null || y.EntityTanker == null)
+ {
+ return -1;
+ }
+
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return x.GetType().Name.CompareTo(y.GetType().Name);
+ }
+
+ var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed);
+ if (speedCompare != 0)
+ {
+ return speedCompare;
+ }
+ return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight);
+ }
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerEqutables.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerEqutables.cs
new file mode 100644
index 0000000..ef4761a
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTankerEqutables.cs
@@ -0,0 +1,56 @@
+using ProjectGasolineTanker.Entities;
+using System.Diagnostics.CodeAnalysis;
+namespace ProjectGasolineTanker.Drawnings;
+
+public class DrawningTankerEqutables : IEqualityComparer
+{
+ public bool Equals(DrawningTanker? x, DrawningTanker? y)
+ {
+ if (x == null || x.EntityTanker == null)
+ {
+ return false;
+ }
+ if (y == null || y.EntityTanker == null)
+ {
+ return false;
+ }
+ if (x.GetType().Name != y.GetType().Name)
+ {
+ return false;
+ }
+ if (x.EntityTanker.Speed != y.EntityTanker.Speed)
+ {
+ return false;
+ }
+ if (x.EntityTanker.Weight != y.EntityTanker.Weight)
+ {
+ return false;
+ }
+ if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor)
+ {
+ return false;
+ }
+ if (x is DrawningGasolineTanker && y is DrawningGasolineTanker)
+ {
+ EntityGasolineTanker _x = (EntityGasolineTanker)x.EntityTanker;
+ EntityGasolineTanker _y = (EntityGasolineTanker)x.EntityTanker;
+ if (_x.AdditionalColor != _y.AdditionalColor)
+ {
+ return false;
+ }
+ if (_x.Tank != _y.Tank)
+ {
+ return false;
+ }
+ if (_x.Signalbeacon != _y.Signalbeacon)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+ public int GetHashCode([DisallowNull] DrawningTanker obj)
+ {
+ return obj.GetHashCode();
+ }
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectIsEqualException.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectIsEqualException.cs
new file mode 100644
index 0000000..ff58040
--- /dev/null
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectIsEqualException.cs
@@ -0,0 +1,18 @@
+
+using System.Runtime.Serialization;
+
+namespace ProjectGasolineTanker.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) { }
+}
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs
index c164f6e..ca90f32 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs
@@ -54,6 +54,8 @@ namespace ProjectGasolineTanker
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
+ buttonSortByType = new Button();
+ buttonByColor = new Button();
Инструменты.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
@@ -70,13 +72,15 @@ namespace ProjectGasolineTanker
Инструменты.Dock = DockStyle.Right;
Инструменты.Location = new Point(861, 24);
Инструменты.Name = "Инструменты";
- Инструменты.Size = new Size(225, 627);
+ Инструменты.Size = new Size(225, 650);
Инструменты.TabIndex = 0;
Инструменты.TabStop = false;
Инструменты.Text = "Инструменты";
//
// panelCompanyTools
//
+ panelCompanyTools.Controls.Add(buttonByColor);
+ panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonAddTanker);
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Controls.Add(buttonGoToCheck);
@@ -85,15 +89,15 @@ namespace ProjectGasolineTanker
panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.Location = new Point(3, 380);
panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(219, 244);
+ panelCompanyTools.Size = new Size(219, 267);
panelCompanyTools.TabIndex = 8;
//
// buttonAddTanker
//
buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddTanker.Location = new Point(3, 21);
+ buttonAddTanker.Location = new Point(0, 0);
buttonAddTanker.Name = "buttonAddTanker";
- buttonAddTanker.Size = new Size(213, 37);
+ buttonAddTanker.Size = new Size(216, 48);
buttonAddTanker.TabIndex = 1;
buttonAddTanker.Text = "Добавление грузовика";
buttonAddTanker.UseVisualStyleBackColor = true;
@@ -101,7 +105,7 @@ namespace ProjectGasolineTanker
//
// maskedTextBoxPosition
//
- maskedTextBoxPosition.Location = new Point(3, 86);
+ maskedTextBoxPosition.Location = new Point(3, 54);
maskedTextBoxPosition.Mask = "00";
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
maskedTextBoxPosition.Size = new Size(213, 23);
@@ -111,9 +115,9 @@ namespace ProjectGasolineTanker
// buttonGoToCheck
//
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(3, 161);
+ buttonGoToCheck.Location = new Point(3, 119);
buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(213, 40);
+ buttonGoToCheck.Size = new Size(213, 30);
buttonGoToCheck.TabIndex = 6;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@@ -122,9 +126,9 @@ namespace ProjectGasolineTanker
// buttonRemoveTanker
//
buttonRemoveTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRemoveTanker.Location = new Point(3, 115);
+ buttonRemoveTanker.Location = new Point(3, 83);
buttonRemoveTanker.Name = "buttonRemoveTanker";
- buttonRemoveTanker.Size = new Size(213, 40);
+ buttonRemoveTanker.Size = new Size(213, 30);
buttonRemoveTanker.TabIndex = 4;
buttonRemoveTanker.Text = "Удаление автомобиль";
buttonRemoveTanker.UseVisualStyleBackColor = true;
@@ -133,9 +137,9 @@ namespace ProjectGasolineTanker
// buttonRefresh
//
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(3, 207);
+ buttonRefresh.Location = new Point(0, 155);
buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(213, 40);
+ buttonRefresh.Size = new Size(216, 28);
buttonRefresh.TabIndex = 5;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@@ -250,7 +254,7 @@ namespace ProjectGasolineTanker
pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(861, 627);
+ pictureBox.Size = new Size(861, 650);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
@@ -294,12 +298,35 @@ namespace ProjectGasolineTanker
//
openFileDialog.Filter = "txt file | *.txt";
//
+ // buttonSortByType
+ //
+ buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonSortByType.Location = new Point(3, 189);
+ buttonSortByType.Name = "buttonSortByType";
+ buttonSortByType.Size = new Size(213, 29);
+ buttonSortByType.TabIndex = 8;
+ buttonSortByType.Text = "Сортировка по типу";
+ buttonSortByType.UseVisualStyleBackColor = true;
+ buttonSortByType.Click += buttonSortByType_Click;
+ //
+ // buttonByColor
+ //
+ buttonByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonByColor.Font = new Font("Segoe UI", 8.25F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonByColor.Location = new Point(3, 224);
+ buttonByColor.Name = "buttonByColor";
+ buttonByColor.Size = new Size(213, 29);
+ buttonByColor.TabIndex = 9;
+ buttonByColor.Text = "Сортировка по цвету";
+ buttonByColor.UseVisualStyleBackColor = true;
+ buttonByColor.Click += buttonByColor_Click;
+ //
// FormTankerCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
AutoScroll = true;
- ClientSize = new Size(1086, 651);
+ ClientSize = new Size(1086, 674);
Controls.Add(pictureBox);
Controls.Add(Инструменты);
Controls.Add(menuStrip);
@@ -344,5 +371,7 @@ namespace ProjectGasolineTanker
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
+ private Button buttonByColor;
+ private Button buttonSortByType;
}
}
\ No newline at end of file
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs
index 2566905..dbad02a 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs
@@ -80,6 +80,11 @@ public partial class FormTankerCollection : Form
MessageBox.Show("В коллекции превышено допустимое количество элементов");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
+ catch (ObjectIsEqualException ex)
+ {
+ MessageBox.Show("Такой объект уже существует в коллекции");
+ _logger.LogError("Ошибка: {Message}", ex.Message);
+ }
}
///
/// Удаление объекта
@@ -210,7 +215,7 @@ public partial class FormTankerCollection : 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);
@@ -319,5 +324,24 @@ public partial class FormTankerCollection : Form
}
}
+ private void buttonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareTanker(new DrawningTankerCompareByType());
+ }
+
+ private void buttonByColor_Click(object sender, EventArgs e)
+ {
+ CompareTanker(new DrawningTankerCompareByColor());
+ }
+
+ private void CompareTanker(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}
\ No newline at end of file
diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.Designer.cs
index 83a84c0..b59638a 100644
--- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.Designer.cs
+++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.Designer.cs
@@ -165,9 +165,9 @@
checkBoxSignalbeacon.AutoSize = true;
checkBoxSignalbeacon.Location = new Point(12, 168);
checkBoxSignalbeacon.Name = "checkBoxSignalbeacon";
- checkBoxSignalbeacon.Size = new Size(232, 34);
+ checkBoxSignalbeacon.Size = new Size(151, 19);
checkBoxSignalbeacon.TabIndex = 9;
- checkBoxSignalbeacon.Text = "Признак наличия сигнального маяка\r\n\r\n";
+ checkBoxSignalbeacon.Text = "Признак наличия бака";
checkBoxSignalbeacon.UseVisualStyleBackColor = true;
//
// checkBoxTanker
@@ -175,9 +175,9 @@
checkBoxTanker.AutoSize = true;
checkBoxTanker.Location = new Point(12, 125);
checkBoxTanker.Name = "checkBoxTanker";
- checkBoxTanker.Size = new Size(154, 19);
+ checkBoxTanker.Size = new Size(235, 19);
checkBoxTanker.TabIndex = 8;
- checkBoxTanker.Text = "Признак наличия бака \r\n";
+ checkBoxTanker.Text = "Признак наличия сигнального маяка \r\n";
checkBoxTanker.UseVisualStyleBackColor = true;
//
// numericUpDownWeight