diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs index f998fb9..a2cea48 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs @@ -31,7 +31,7 @@ public abstract class AbstractCompany public static int operator +(AbstractCompany company, DrawingBase sau) { - return company._collection.Insert(sau); + return company._collection.Insert(sau, new DrawingSAUEqutables()); } public static DrawingBase operator -(AbstractCompany company, int position) @@ -66,4 +66,5 @@ public abstract class AbstractCompany protected abstract void SetObjectPosition(int position, int MaxPos, DrawingBase? sau); + public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer); } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/CollectionInfo.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/CollectionInfo.cs new file mode 100644 index 0000000..5be11c9 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/CollectionInfo.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects; + +internal 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(); + } +} diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs index 63c2930..853f5b5 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -11,11 +11,12 @@ public interface ICollectionGenericObjects { int Count { get; } int MaxCount { get; set; } - int Insert(T obj); - int Insert(T obj, int position); + int Insert(T obj, IEqualityComparer? comparer = null); + int Insert(T obj, int position, IEqualityComparer? comparer = null); T? Remove(int position); T? Get(int position); CollectionType GetCollectionType { get; } IEnumerable GetItems(); + void CollectionSort(IComparer comparer); } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs index 7de6a98..d230653 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs @@ -1,5 +1,6 @@ using Project_SelfPropelledArtilleryUnit.Exceptions; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; @@ -44,8 +45,15 @@ 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 ObjectNotUniqueException(); + } + } if (Count == _maxCount) { throw new CollectionOverflowException(Count); @@ -54,8 +62,15 @@ public class ListGenericObjects : ICollectionGenericObjects 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 ObjectNotUniqueException(); + } + } if (Count == _maxCount) { throw new CollectionOverflowException(Count); @@ -86,4 +101,8 @@ public class ListGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } + void ICollectionGenericObjects.CollectionSort(IComparer comparer) + { + _collection.Sort(comparer); + } } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs index 4df3bdb..9163ce7 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs @@ -52,8 +52,18 @@ public class MassiveGenericObjects : ICollectionGenericObjects 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 DrawingBase, item as DrawingBase)) + { + throw new ObjectNotUniqueException(); + } + } + } for (int i = 0; i < Count; i++) { if (_collection[i] == null) @@ -66,7 +76,7 @@ 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) { if (position < 0 || position >= Count) { @@ -126,4 +136,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } + void ICollectionGenericObjects.CollectionSort(IComparer comparer) + { + Array.Sort(_collection, comparer); + } } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs index 5618128..b2e6916 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs @@ -11,9 +11,8 @@ namespace Project_SelfPropelledArtilleryUnit.CollectionGenericObjects; internal class StorageCollection where T : DrawingBase { - private Dictionary> _storages; - - public List Keys => _storages.Keys.ToList(); + readonly Dictionary> _storages; + public List Keys => _storages.Keys.ToList(); private readonly string _collectionKey = "CollectionsStorage"; @@ -23,36 +22,47 @@ internal class StorageCollection public StorageCollection() { - _storages = new Dictionary>(); + _storages = new Dictionary>(); } public void AddCollection(string name, CollectionType collectionType) { - if (_storages.ContainsKey(name) || name == "") return; + CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty); - if (collectionType == CollectionType.Massive) + if (_storages.ContainsKey(collectionInfo) || collectionInfo.CollectionType == CollectionType.None) { - _storages[name] = new MassiveGenericObjects(); + return; } - else + + switch (collectionInfo.CollectionType) { - _storages[name] = new ListGenericObjects(); + case CollectionType.Massive: + _storages[collectionInfo] = new MassiveGenericObjects(); + break; + case CollectionType.List: + _storages[collectionInfo] = new ListGenericObjects(); + break; } } public void DelCollection(string name) { - _storages.Remove(name); + CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty); + if (_storages.ContainsKey(collectionInfo) && collectionInfo != null) + { + _storages.Remove(collectionInfo); + } } public ICollectionGenericObjects? this[string name] { get { - if (name == "") + CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty); + if (_storages.ContainsKey(collectionInfo)) { - return null; + return _storages[collectionInfo]; } - return _storages[name]; + return null; } } @@ -68,23 +78,24 @@ internal class StorageCollection File.Delete(filename); } - using (StreamWriter writer = new(filename)) + using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(_collectionKey); - foreach (KeyValuePair> value in _storages) + foreach (KeyValuePair> value in _storages) { - writer.Write(Environment.NewLine); + StringBuilder sb = new(); + + sb.Append(Environment.NewLine); // не сохраняем пустые коллекции if (value.Value.Count == 0) { continue; } - writer.Write(value.Key); - writer.Write(_separatorForKeyValue); - writer.Write(value.Value.GetCollectionType); - writer.Write(_separatorForKeyValue); - writer.Write(value.Value.MaxCount); - writer.Write(_separatorForKeyValue); + + sb.Append(value.Key); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.MaxCount); + sb.Append(_separatorForKeyValue); foreach (T? item in value.Value.GetItems()) { @@ -93,9 +104,12 @@ internal class StorageCollection { continue; } - writer.Write(data); - writer.Write(_separatorItems); + + sb.Append(data); + sb.Append(_separatorItems); } + + writer.Write(sb); } } } @@ -106,68 +120,68 @@ internal class StorageCollection { throw new FileNotFoundException("Файл не существует"); } - using (StreamReader reader = new(filename)) + using (StreamReader fs = File.OpenText(filename)) { - string line = reader.ReadLine(); - if (line == null || line.Length == 0) + string str = fs.ReadLine(); + + if (str == null || str.Length == 0) { throw new IOException("В файле нет данных"); } - if (!line.Equals(_collectionKey)) + + if (!str.StartsWith(_collectionKey)) { throw new IOException("В файле неверные данные"); - } + _storages.Clear(); - while ((line = reader.ReadLine()) != null) + string strs = ""; + while ((strs = fs.ReadLine()) != null) { - string[] record = line.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - 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); - if (collection == null) - { - throw new IOException("В файле нет данных"); - } - collection.MaxCount = Convert.ToInt32(record[2]); - string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); + + CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? + throw new Exception("Не удалось определить информацию коллекции:" + record[0]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ?? + throw new Exception("Не удалось определить тип коллекции: " + record[1]); + collection.MaxCount = Convert.ToInt32(record[1]); + + string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { - if (elem?.CreateDrawningBase() is T truck) + if (elem?.CreateDrawningBase() is T airbus) { - if (collection.Insert(truck) == -1) + try { - try + if (collection.Insert(airbus) == -1) { - if (collection.Insert(truck) == -1) - { - throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); - } - } - catch (CollectionOverflowException ex) - { - throw new Exception("Коллекция переполнена", ex); + throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); } } + catch (CollectionOverflowException ex) + { + throw new Exception("Коллекция переполнена", ex); + } } } - _storages.Add(record[0], collection); + _storages.Add(collectionInfo, collection); } } } - private static ICollectionGenericObjects? - CreateCollection(CollectionType collectionType) + private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) { return collectionType switch { CollectionType.Massive => new MassiveGenericObjects(), CollectionType.List => new ListGenericObjects(), - _ => null, + _ => null }; } + } diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAUEqutables.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAUEqutables.cs new file mode 100644 index 0000000..aad25f4 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/DrawingSAUEqutables.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Project_SelfPropelledArtilleryUnit.Entity; +using System.Diagnostics.CodeAnalysis; + +namespace Project_SelfPropelledArtilleryUnit.Drawings; + +public class DrawingSAUEqutables : IEqualityComparer +{ + public bool Equals(DrawingBase? x, DrawingBase? y) + { + if (x == null || x.BaseSAU == null) return false; + + if (y == null || y.BaseSAU == null) return false; + + if (x.GetType().Name != y.GetType().Name) return false; + + if (x.BaseSAU.Speed != y.BaseSAU.Speed) return false; + + if (x.BaseSAU.Weight != y.BaseSAU.Weight) return false; + + if (x.BaseSAU.BodyColor != y.BaseSAU.BodyColor) return false; + + if (x is DrawingSAU bigX && y is DrawingSAU bigY) + { + + EntitySAU _x = (EntitySAU)x.BaseSAU; + EntitySAU _y = (EntitySAU)y.BaseSAU; + + if (_x.Tracks != _y.Tracks) return false; + if (_x.Guns != _y.Guns) return false; + if (_x.AdditionalColor != _y.AdditionalColor) return false; + } + + return true; + } + + public int GetHashCode([DisallowNull] DrawingBase obj) + { + return obj.GetHashCode(); + } +} diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/SAUCompareByColor.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/SAUCompareByColor.cs new file mode 100644 index 0000000..a2d81d6 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/SAUCompareByColor.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project_SelfPropelledArtilleryUnit.Drawings; + +public class SAUCompareByColor : IComparer +{ + public int Compare(DrawingBase? x, DrawingBase? y) + { + if (x == null || x.BaseSAU == null) return 1; + + if (y == null || y.BaseSAU == null) return -1; + + var bodycolorCompare = x.BaseSAU.BodyColor.Name.CompareTo(y.BaseSAU.BodyColor.Name); + if (bodycolorCompare != 0) return bodycolorCompare; + + var speedCompare = x.BaseSAU.Speed.CompareTo(y.BaseSAU.Speed); + if (speedCompare != 0) return speedCompare; + + return x.BaseSAU.Weight.CompareTo(y.BaseSAU.Weight); + } + +} diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/SAUCompareByType.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/SAUCompareByType.cs new file mode 100644 index 0000000..e31de13 --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Drawings/SAUCompareByType.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Project_SelfPropelledArtilleryUnit.Drawings; + +public class SAUCompareByType : IComparer +{ + public int Compare(DrawingBase? x, DrawingBase? y) + { + if (x == null || x.BaseSAU == null) return 1; + + if (y == null || y.BaseSAU == null) return -1; + + if (x.GetType().Name != y.GetType().Name) return x.GetType().Name.CompareTo(y.GetType().Name); + + var speedCompare = x.BaseSAU.Speed.CompareTo(y.BaseSAU.Speed); + if (speedCompare != 0) return speedCompare; + + return x.BaseSAU.Weight.CompareTo(y.BaseSAU.Weight); + } +} diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Exceptions/ObjectNotUniqueException.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Exceptions/ObjectNotUniqueException.cs new file mode 100644 index 0000000..9aee3ee --- /dev/null +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/Exceptions/ObjectNotUniqueException.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Runtime.Serialization; + + +namespace Project_SelfPropelledArtilleryUnit.Exceptions; +[Serializable] + +internal class ObjectNotUniqueException: ApplicationException +{ + public ObjectNotUniqueException(object i) : base("В коллекции уже есть такой элемент " + i) { } + public ObjectNotUniqueException() : base() { } + public ObjectNotUniqueException(string message) : base(message) { } + public ObjectNotUniqueException(string message, Exception exception) : base(message, exception) + { } + protected ObjectNotUniqueException(SerializationInfo info, StreamingContext context) : base(info, context) { } +} diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs index 4a91d09..269a5cf 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.Designer.cs @@ -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(); @@ -66,13 +68,15 @@ groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(1123, 28); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(218, 639); + groupBoxTools.Size = new Size(218, 669); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // // panelCompanyTools // + panelCompanyTools.Controls.Add(buttonSortByColor); + panelCompanyTools.Controls.Add(buttonSortByType); panelCompanyTools.Controls.Add(buttonAddBaseSAU); panelCompanyTools.Controls.Add(buttonUpdate); panelCompanyTools.Controls.Add(buttonGoToCheck); @@ -80,9 +84,9 @@ panelCompanyTools.Controls.Add(buttonRemoveSAU); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 367); + panelCompanyTools.Location = new Point(3, 370); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(212, 269); + panelCompanyTools.Size = new Size(212, 296); panelCompanyTools.TabIndex = 10; // // buttonAddBaseSAU @@ -97,7 +101,7 @@ // // buttonUpdate // - buttonUpdate.Location = new Point(3, 224); + buttonUpdate.Location = new Point(3, 246); buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Size = new Size(203, 41); buttonUpdate.TabIndex = 8; @@ -107,7 +111,7 @@ // // buttonGoToCheck // - buttonGoToCheck.Location = new Point(3, 177); + buttonGoToCheck.Location = new Point(3, 133); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(203, 41); buttonGoToCheck.TabIndex = 7; @@ -117,7 +121,7 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(3, 97); + maskedTextBox.Location = new Point(3, 53); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(203, 27); @@ -126,7 +130,7 @@ // // buttonRemoveSAU // - buttonRemoveSAU.Location = new Point(3, 130); + buttonRemoveSAU.Location = new Point(3, 86); buttonRemoveSAU.Name = "buttonRemoveSAU"; buttonRemoveSAU.Size = new Size(203, 41); buttonRemoveSAU.TabIndex = 6; @@ -243,7 +247,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 28); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1123, 639); + pictureBox.Size = new Size(1123, 669); pictureBox.TabIndex = 4; pictureBox.TabStop = false; // @@ -288,11 +292,31 @@ // openFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByType + // + buttonSortByType.Location = new Point(3, 177); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(97, 63); + buttonSortByType.TabIndex = 9; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // + // buttonSortByColor + // + buttonSortByColor.Location = new Point(106, 177); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(97, 63); + buttonSortByColor.TabIndex = 10; + buttonSortByColor.Text = "Сортировка по цвету"; + buttonSortByColor.UseVisualStyleBackColor = true; + buttonSortByColor.Click += buttonSortByColor_Click; + // // FormSAUCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1341, 667); + ClientSize = new Size(1341, 697); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); @@ -337,5 +361,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/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs index 9e79d51..77f90ad 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUCollection.cs @@ -165,7 +165,7 @@ public partial class FormSAUCollection : 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); @@ -262,4 +262,24 @@ public partial class FormSAUCollection : Form } UpdateListBoxItems(); } + private void CompareSAU(IComparer comparer) + { + if (_company == null) + { + return; + } + + _company.Sort(comparer); + pictureBox.Image = _company.Show(); + } + + private void buttonSortByType_Click(object sender, EventArgs e) + { + CompareSAU(new SAUCompareByType()); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) + { + CompareSAU(new SAUCompareByColor()); + } } \ No newline at end of file diff --git a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs index f09e979..6b4964a 100644 --- a/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs +++ b/Project_SelfPropelledArtilleryUnit/Project_SelfPropelledArtilleryUnit/FormSAUConfig.Designer.cs @@ -29,6 +29,7 @@ private void InitializeComponent() { groupBoxConfig = new GroupBox(); + checkBoxTracks = new CheckBox(); groupBoxColors = new GroupBox(); panelPurple = new Panel(); panelBlack = new Panel(); @@ -51,7 +52,6 @@ panelObject = new Panel(); labelAdditionalColor = new Label(); labelBodyColor = new Label(); - checkBoxTracks = new CheckBox(); groupBoxConfig.SuspendLayout(); groupBoxColors.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit(); @@ -79,6 +79,16 @@ groupBoxConfig.TabStop = false; groupBoxConfig.Text = "Параметры"; // + // checkBoxTracks + // + checkBoxTracks.AutoSize = true; + checkBoxTracks.Location = new Point(12, 135); + checkBoxTracks.Name = "checkBoxTracks"; + checkBoxTracks.Size = new Size(213, 24); + checkBoxTracks.TabIndex = 9; + checkBoxTracks.Text = "Признак наличия гусениц"; + checkBoxTracks.UseVisualStyleBackColor = true; + // // groupBoxColors // groupBoxColors.Controls.Add(panelPurple); @@ -312,16 +322,6 @@ labelBodyColor.DragDrop += labelBodyColor_DragDrop; labelBodyColor.DragEnter += labelBodyColor_DragEnter; // - // checkBoxTracks - // - checkBoxTracks.AutoSize = true; - checkBoxTracks.Location = new Point(12, 135); - checkBoxTracks.Name = "checkBoxTracks"; - checkBoxTracks.Size = new Size(232, 24); - checkBoxTracks.TabIndex = 9; - checkBoxTracks.Text = "Признак наличия пулеметов"; - checkBoxTracks.UseVisualStyleBackColor = true; - // // FormSAUConfig // AutoScaleDimensions = new SizeF(8F, 20F);