diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs
index 47de47a..4c5e96d 100644
--- a/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectCar/ProjectCar/CollectionGenericObjects/AbstractCompany.cs
@@ -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
///
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;
+ }
}
///
@@ -125,6 +137,12 @@ public abstract class AbstractCompany
return bitmap;
}
+ ///
+ /// Сортировка
+ ///
+ /// Сравнитель объектов
+ public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer);
+
///
/// Вывод заднего фона
///
diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/CollectionInfo.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/CollectionInfo.cs
new file mode 100644
index 0000000..1b74797
--- /dev/null
+++ b/ProjectCar/ProjectCar/CollectionGenericObjects/CollectionInfo.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectGasMachine.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;
+ }
+
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка
+ /// Объект или null
+ 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();
+ }
+}
diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/ICollectionGenericObjects.cs
index 5aeb486..4d8a8b7 100644
--- a/ProjectCar/ProjectCar/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectCar/ProjectCar/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -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
/// Добавление объекта в коллекцию
///
/// Добавляемый объект
+ /// Сравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj);
+ int Insert(T obj, IEqualityComparer? comparer = null);
///
/// Добавление объекта в коллекцию на конкретную позицию
///
/// Добавляемый объект
/// Позиция
+ /// Сравнение двух объектов
/// true - вставка прошла удачно, false - вставка не удалась
- int Insert(T obj, int position);
+ int Insert(T obj, int position, IEqualityComparer? comparer = null);
///
/// Удаление объекта из коллекции с конкретной позиции
@@ -63,4 +66,10 @@ public interface ICollectionGenericObjects
///
/// Поэлементый вывод элементов коллекции
IEnumerable GetItems();
+
+ ///
+ /// Сортировка коллекции
+ ///
+ /// Сравнитель объектов
+ void CollectionSort(IComparer comparer);
}
diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs
index ec822ac..75c20dc 100644
--- a/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectCar/ProjectCar/CollectionGenericObjects/ListGenericObjects.cs
@@ -1,4 +1,6 @@
+using ProjectAircraftCarrier_.Exceptions;
+using ProjectGasMachine.Drawnings;
using ProjectGasMachine.Exceptions;
namespace ProjectGasMachine.CollectionGenericObjects;
@@ -46,9 +48,16 @@ public class ListGenericObjects : ICollectionGenericObjects
return _collection[position];
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? 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 : ICollectionGenericObjects
return _collection.Count;
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? 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 : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ _collection.Sort(comparer);
+ }
}
diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs
index 04bf4a1..156d640 100644
--- a/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectCar/ProjectCar/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,4 +1,6 @@
+using ProjectAircraftCarrier_.Exceptions;
+using ProjectGasMachine.Drawnings;
using ProjectGasMachine.Exceptions;
using System.Linq;
@@ -69,9 +71,18 @@ public class MassiveGenericObjects : ICollectionGenericObjects
}
- public int Insert(T obj)
+ public int Insert(T obj, IEqualityComparer? 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 : ICollectionGenericObjects
throw new CollectionOverflowException(Count);
}
- public int Insert(T obj, int position)
+ public int Insert(T obj, int position, IEqualityComparer? 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 : ICollectionGenericObjects
yield return _collection[i];
}
}
+
+ public void CollectionSort(IComparer comparer)
+ {
+ Array.Sort(_collection, comparer);
+ }
}
diff --git a/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs b/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs
index 8c1bbc4..5c89875 100644
--- a/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectCar/ProjectCar/CollectionGenericObjects/StorageCollection.cs
@@ -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
///
/// словарь (хранилище) с коллекциями
///
- private Dictionary> _storages;
+ private Dictionary> _storages;
///
/// Возвращение списка названий коллекций
///
- public List Keys => _storages.Keys.ToList();
+ public List Keys => _storages.Keys.ToList();
///
/// Ключевое слово, с которого должен начинаться файл
@@ -38,7 +39,7 @@ public class StorageCollection
///
public StorageCollection()
{
- _storages = new Dictionary>();
+ _storages = new Dictionary>();
}
///
@@ -46,21 +47,21 @@ public class StorageCollection
///
/// название коллекции
/// тип коллекции
- 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());
+ _storages.Add(info, new MassiveGenericObjects());
}
- if (collectionType == CollectionType.List)
+ if (info.CollectionType == CollectionType.List)
{
- _storages.Add(name, new ListGenericObjects());
+ _storages.Add(info, new ListGenericObjects());
}
}
@@ -68,14 +69,14 @@ public class StorageCollection
/// Удаление коллекции
///
///
- 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);
}
///
@@ -83,13 +84,13 @@ public class StorageCollection
///
/// Название коллекции
///
- public ICollectionGenericObjects? this[string name]
+ public ICollectionGenericObjects? 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
{
sw.Write(_collectionKey);
- foreach (KeyValuePair> value in _storages)
+ foreach (KeyValuePair> value in _storages)
{
sw.Write(Environment.NewLine);
// не сохраняем пустые коллекции
@@ -128,8 +129,6 @@ public class StorageCollection
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
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? collection = StorageCollection.CreateCollection(collectionType);
- if (collection == null)
- {
- throw new InvalidOperationException("Не удалось создать коллекцию");
- }
+ CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
+ throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
+ ICollectionGenericObjects? collection = StorageCollection.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
{
throw new OverflowException("Коллекция переполнена", ex);
}
+ catch (ObjectAlreadyInCollectionException ex)
+ {
+ throw new InvalidOperationException("Объект уже присутствует в коллекции", ex);
+ }
}
}
- _storages.Add(record[0], collection);
+ _storages.Add(collectionInfo, collection);
}
}
}
diff --git a/ProjectCar/ProjectCar/Drawnings/DrawningMachineCompareByColor.cs b/ProjectCar/ProjectCar/Drawnings/DrawningMachineCompareByColor.cs
new file mode 100644
index 0000000..0144d79
--- /dev/null
+++ b/ProjectCar/ProjectCar/Drawnings/DrawningMachineCompareByColor.cs
@@ -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;
+
+///
+/// Сравнение по цвету, скорости, весу
+///
+
+public class DrawningMachineCompareByColor : IComparer
+{
+ 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);
+
+ }
+}
diff --git a/ProjectCar/ProjectCar/Drawnings/DrawningMachineCompareByType.cs b/ProjectCar/ProjectCar/Drawnings/DrawningMachineCompareByType.cs
new file mode 100644
index 0000000..e6d6b81
--- /dev/null
+++ b/ProjectCar/ProjectCar/Drawnings/DrawningMachineCompareByType.cs
@@ -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;
+
+///
+/// Сравнение по типу, скорости, весу
+///
+public class DrawningMachineCompareByType : IComparer
+{
+ 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);
+ }
+}
diff --git a/ProjectCar/ProjectCar/Drawnings/DrawningMachineEqutables.cs b/ProjectCar/ProjectCar/Drawnings/DrawningMachineEqutables.cs
new file mode 100644
index 0000000..ca4514f
--- /dev/null
+++ b/ProjectCar/ProjectCar/Drawnings/DrawningMachineEqutables.cs
@@ -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;
+
+///
+/// Реализация сравнения двух объектов класса-прорисовки
+///
+public class DrawningMachineEqutables : IEqualityComparer
+{
+ 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();
+ }
+}
diff --git a/ProjectCar/ProjectCar/Exceptions/ObjectAlreadyInCollectionException.cs b/ProjectCar/ProjectCar/Exceptions/ObjectAlreadyInCollectionException.cs
new file mode 100644
index 0000000..3bd0d10
--- /dev/null
+++ b/ProjectCar/ProjectCar/Exceptions/ObjectAlreadyInCollectionException.cs
@@ -0,0 +1,20 @@
+using System.Runtime.Serialization;
+
+namespace ProjectAircraftCarrier_.Exceptions;
+
+///
+/// Класс, описывающий ошибку переполнения коллекции
+///
+[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) { }
+}
\ No newline at end of file
diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs b/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs
index b27ca9e..b0e5711 100644
--- a/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs
+++ b/ProjectCar/ProjectCar/FormGasMachineCollection.Designer.cs
@@ -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;
}
}
\ No newline at end of file
diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.cs b/ProjectCar/ProjectCar/FormGasMachineCollection.cs
index f1fcd82..1abb173 100644
--- a/ProjectCar/ProjectCar/FormGasMachineCollection.cs
+++ b/ProjectCar/ProjectCar/FormGasMachineCollection.cs
@@ -51,7 +51,7 @@ namespace ProjectGasMachine
///
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? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty];
+ CollectionInfo collectionInfo = new CollectionInfo(listBoxCollection.SelectedItem.ToString(), CollectionType.None, string.Empty);
+ ICollectionGenericObjects? collection = _storageCollection[collectionInfo];
if (collection == null)
{
MessageBox.Show("Коллекция не проинициализирована");
@@ -323,5 +327,39 @@ namespace ProjectGasMachine
}
}
}
+
+ ///
+ /// Сортировка по типу
+ ///
+ ///
+ ///
+ private void ButtonSortByType_Click(object sender, EventArgs e)
+ {
+ CompareMachines(new DrawningMachineCompareByType());
+ }
+
+ ///
+ /// Сортировка по цвету
+ ///
+ ///
+ ///
+ private void ButtonSortByColor_Click(object sender, EventArgs e)
+ {
+ CompareMachines(new DrawningMachineCompareByColor());
+ }
+
+ ///
+ /// Сортировка по сравнителю
+ ///
+ /// Сравнитель объектов
+ private void CompareMachines(IComparer comparer)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ _company.Sort(comparer);
+ pictureBox.Image = _company.Show();
+ }
}
}
diff --git a/ProjectCar/ProjectCar/FormGasMachineCollection.resx b/ProjectCar/ProjectCar/FormGasMachineCollection.resx
index e8f33d6..ca20953 100644
--- a/ProjectCar/ProjectCar/FormGasMachineCollection.resx
+++ b/ProjectCar/ProjectCar/FormGasMachineCollection.resx
@@ -127,6 +127,6 @@
261, 17
- 60
+ 25
\ No newline at end of file
diff --git a/ProjectCar/ProjectCar/serilogConfig.json b/ProjectCar/ProjectCar/serilogConfig.json
index 4e8d9cb..fff6dcd 100644
--- a/ProjectCar/ProjectCar/serilogConfig.json
+++ b/ProjectCar/ProjectCar/serilogConfig.json
@@ -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}"
}
diff --git a/log20240514.txt b/log20240514.txt
new file mode 100644
index 0000000..88b164e
--- /dev/null
+++ b/log20240514.txt
@@ -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