From f22ab5da667b821317a5ba6a39f8aa854c7187d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Wed, 27 Dec 2023 22:48:46 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9D=D0=B5=D1=82=20=D0=BE=D1=88=D0=B8?= =?UTF-8?q?=D0=B1=D0=BA=D0=B8=20=D0=BD=D0=B0=20=D0=BF=D0=BE=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B5=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawiningLocomotiveEqutables.cs | 57 +++++++++++++++++++ .../DrawningElectricLocomotive.cs | 6 +- .../FormLocomotiveCollection.Designer.cs | 42 +++++++++++--- .../FormLocomotiveCollection.cs | 23 +++++++- .../FormLocomotiveCollection.resx | 8 ++- .../LocomotiveCompareByColor.cs | 49 ++++++++++++++++ .../LocomotiveCompareByType.cs | 35 ++++++++++++ .../LocomotiveGenericStorage.cs | 25 ++++---- .../LocomotivesCollectionInfo.cs | 35 ++++++++++++ .../LocomotivesGenericCollection.cs | 11 ++-- .../ElectricLocomotive/SetGeneric.cs | 31 +++++++--- .../StorageOverflowException.cs | 2 +- 12 files changed, 280 insertions(+), 44 deletions(-) create mode 100644 ElectricLocomotive/ElectricLocomotive/DrawiningLocomotiveEqutables.cs create mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByColor.cs create mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByType.cs create mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotivesCollectionInfo.cs diff --git a/ElectricLocomotive/ElectricLocomotive/DrawiningLocomotiveEqutables.cs b/ElectricLocomotive/ElectricLocomotive/DrawiningLocomotiveEqutables.cs new file mode 100644 index 0000000..733fe19 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/DrawiningLocomotiveEqutables.cs @@ -0,0 +1,57 @@ +using ElectricLocomotive.DrawningObject; +using ElectricLocomotive.Entities; +using System.Diagnostics.CodeAnalysis; + +namespace ElectricLocomotive +{ + internal class DrawningLocomotiveEqutables : IEqualityComparer + { + public bool Equals(DrawningLocomotive? x, DrawningLocomotive? y) + { + if (x == null || x.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + if (x.EntityLocomotive.Speed != y.EntityLocomotive.Speed) + { + return false; + } + if (x.EntityLocomotive.Weight != y.EntityLocomotive.Weight) + { + return false; + } + if (x.EntityLocomotive.BodyColor != y.EntityLocomotive.BodyColor) + { + return false; + } + if (x is DrawningElectricLocomotive && y is DrawningElectricLocomotive) + { + if ((x.EntityLocomotive as EntityElectroLocomotive).AdditionalColor != (y.EntityLocomotive as EntityElectroLocomotive).AdditionalColor) + { + return false; + } + if ((x.EntityLocomotive as EntityElectroLocomotive).Horns_1 != (y.EntityLocomotive as EntityElectroLocomotive).Horns_1) + { + return false; + } + if ((x.EntityLocomotive as EntityElectroLocomotive).Horns_2 != (y.EntityLocomotive as EntityElectroLocomotive).Horns_2) + { + return false; + } + } + return true; + } + public int GetHashCode([DisallowNull] DrawningLocomotive obj) + { + return obj.GetHashCode(); + } + } +} diff --git a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs index aa3c61e..e1747bc 100644 --- a/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/DrawningElectricLocomotive.cs @@ -1,10 +1,6 @@ using ElectricLocomotive.DrawningObject; using ElectricLocomotive.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace ElectricLocomotive { diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index 37297ef..812a13f 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -31,6 +31,8 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLocomotiveCollection)); CollectionPictureBox = new PictureBox(); ToolsBox = new GroupBox(); + button2 = new Button(); + button1 = new Button(); NaborGroupBox = new GroupBox(); ButtomRemoveNabor = new Button(); listBoxStorage = new ListBox(); @@ -62,6 +64,8 @@ // // ToolsBox // + ToolsBox.Controls.Add(button2); + ToolsBox.Controls.Add(button1); ToolsBox.Controls.Add(NaborGroupBox); ToolsBox.Controls.Add(Input); ToolsBox.Controls.Add(RefreshCollection); @@ -74,6 +78,26 @@ ToolsBox.TabStop = false; ToolsBox.Text = "Инструменты"; // + // button2 + // + button2.Location = new Point(13, 273); + button2.Name = "button2"; + button2.Size = new Size(173, 29); + button2.TabIndex = 5; + button2.Text = "Сортировать по цвету"; + button2.UseVisualStyleBackColor = true; + button2.Click += ButtonSortByColor_Click; + // + // button1 + // + button1.Location = new Point(13, 241); + button1.Name = "button1"; + button1.Size = new Size(173, 29); + button1.TabIndex = 4; + button1.Text = "Сортировать по типу"; + button1.UseVisualStyleBackColor = true; + button1.Click += ButtonSortByType_Click; + // // NaborGroupBox // NaborGroupBox.Controls.Add(ButtomRemoveNabor); @@ -82,14 +106,14 @@ NaborGroupBox.Controls.Add(textBoxStorageName); NaborGroupBox.Location = new Point(7, 22); NaborGroupBox.Name = "NaborGroupBox"; - NaborGroupBox.Size = new Size(185, 280); + NaborGroupBox.Size = new Size(185, 213); NaborGroupBox.TabIndex = 4; NaborGroupBox.TabStop = false; NaborGroupBox.Text = "Наборы"; // // ButtomRemoveNabor // - ButtomRemoveNabor.Location = new Point(6, 221); + ButtomRemoveNabor.Location = new Point(6, 159); ButtomRemoveNabor.Name = "ButtomRemoveNabor"; ButtomRemoveNabor.Size = new Size(173, 48); ButtomRemoveNabor.TabIndex = 3; @@ -101,17 +125,17 @@ // listBoxStorage.FormattingEnabled = true; listBoxStorage.ItemHeight = 15; - listBoxStorage.Location = new Point(6, 112); + listBoxStorage.Location = new Point(6, 89); listBoxStorage.Name = "listBoxStorage"; - listBoxStorage.Size = new Size(173, 94); + listBoxStorage.Size = new Size(173, 64); listBoxStorage.TabIndex = 2; listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged; // // AddNabor // - AddNabor.Location = new Point(6, 63); + AddNabor.Location = new Point(6, 51); AddNabor.Name = "AddNabor"; - AddNabor.Size = new Size(173, 43); + AddNabor.Size = new Size(173, 32); AddNabor.TabIndex = 1; AddNabor.Text = "Добавить набор"; AddNabor.UseVisualStyleBackColor = true; @@ -119,7 +143,7 @@ // // textBoxStorageName // - textBoxStorageName.Location = new Point(6, 34); + textBoxStorageName.Location = new Point(6, 22); textBoxStorageName.Name = "textBoxStorageName"; textBoxStorageName.Size = new Size(173, 23); textBoxStorageName.TabIndex = 0; @@ -212,9 +236,9 @@ Controls.Add(menuStrip); Controls.Add(ToolsBox); Controls.Add(CollectionPictureBox); + MainMenuStrip = menuStrip; Name = "FormLocomotiveCollection"; Text = "Коллекция"; - MainMenuStrip = menuStrip; ((System.ComponentModel.ISupportInitialize)CollectionPictureBox).EndInit(); ToolsBox.ResumeLayout(false); ToolsBox.PerformLayout(); @@ -246,5 +270,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private ToolStripMenuItem SaveToolStripMenuItem; private GroupBox groupBoxMenu; + private Button button2; + private Button button1; } } \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 051b4c6..f147a44 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -3,6 +3,7 @@ using ElectricLocomotive.Generics; using Microsoft.Extensions.Logging; using ProjectElectricLocomotive; using ProjectElectricLocomotive.Exceptions; +using ProjectElectricLocomotive.Generics; namespace ElectricLocomotive { @@ -114,6 +115,7 @@ namespace ElectricLocomotive catch (StorageOverflowException ex) { MessageBox.Show(ex.Message); + _logger.LogInformation("Не удалось добавить объект"); } //проверяем, удалось ли нам загрузить объект @@ -136,7 +138,7 @@ namespace ElectricLocomotive int pos = Convert.ToInt32(Input.Text); try { - if ( obj - pos != null ) + if (obj - pos != null) { MessageBox.Show("Объект удален"); _logger.LogInformation($"Удален объект с позиции{pos}"); @@ -165,6 +167,25 @@ namespace ElectricLocomotive } CollectionPictureBox.Image = obj.ShowLocomotives(); } + private void ButtonSortByType_Click(object sender, EventArgs e) => CompareLocomotives(new LocomotiveCompareByType()); + + private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareLocomotives(new LocomotiveCompareByColor()); + + private void CompareLocomotives(IComparer comparer) + { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + obj.Sort(comparer); + CollectionPictureBox.Image = obj.ShowLocomotives(); + } /// /// Обработка нажатия "Сохранение" diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx index 974a777..e3b9d5f 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - 19, 13 + 279, 17 @@ -141,4 +141,10 @@ hqArRNaMLA7CYANAAGYISIA0/O0/AID67ECmnhNDAAAAAElFTkSuQmCC + + 17, 17 + + + 146, 17 + \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByColor.cs b/ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByColor.cs new file mode 100644 index 0000000..b65eb96 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByColor.cs @@ -0,0 +1,49 @@ + + +using ElectricLocomotive.DrawningObject; +using ElectricLocomotive.Entities; + +namespace ElectricLocomotive +{ + internal class LocomotiveCompareByColor : IComparer + { + public int Compare(DrawningLocomotive? x, DrawningLocomotive? y) + { + if (x == null || x.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.EntityLocomotive.BodyColor.Name != y.EntityLocomotive.BodyColor.Name) + { + return x.EntityLocomotive.BodyColor.Name.CompareTo(y.EntityLocomotive.BodyColor.Name); + } + if (x.GetType().Name != y.GetType().Name) + { + if (x is DrawningLocomotive) + return -1; + else + return 1; + } + if (x.GetType().Name == y.GetType().Name && x is DrawningLocomotive) + { + EntityElectroLocomotive entityX = (EntityElectroLocomotive)x.EntityLocomotive; + EntityElectroLocomotive entityY = (EntityElectroLocomotive)y.EntityLocomotive; + if (entityX.AdditionalColor.Name != entityY.AdditionalColor.Name) + { + return entityX.AdditionalColor.Name.CompareTo(entityY.AdditionalColor.Name); + } + } + var speedCompare = + x.EntityLocomotive.Speed.CompareTo(y.EntityLocomotive.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityLocomotive.Weight.CompareTo(y.EntityLocomotive.Weight); + } + } +} diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByType.cs b/ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByType.cs new file mode 100644 index 0000000..7758fa5 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/LocomotiveCompareByType.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ElectricLocomotive.DrawningObject; +using ProjectElectricLocomotive.DrawingObjects; + +namespace ProjectElectricLocomotive.Generics +{ + internal class LocomotiveCompareByType : IComparer + { + public int Compare(DrawningLocomotive? x, DrawningLocomotive? y) + { + if (x == null || x.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityLocomotive == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + var speedCompare = x.EntityLocomotive.Speed.CompareTo(y.EntityLocomotive.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityLocomotive.Weight.CompareTo(y.EntityLocomotive.Weight); + } + } +} diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs index 6045226..d664b04 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs @@ -13,12 +13,12 @@ namespace ElectricLocomotive.Generics /// /// Словарь (хранилище) /// - readonly Dictionary> _locomotivesStorage; + readonly Dictionary> _locomotivesStorage; /// /// Возвращение списка названий наборов /// - public List Keys => _locomotivesStorage.Keys.ToList(); + public List Keys => _locomotivesStorage.Keys.ToList(); /// /// Разделитель для записи ключа и значения элемента словаря /// @@ -32,7 +32,6 @@ namespace ElectricLocomotive.Generics /// private static readonly char _separatorForObject = ':'; - private readonly int _pictureWidth; private readonly int _pictureHeight; @@ -44,7 +43,7 @@ namespace ElectricLocomotive.Generics /// public LocomotiveGenericStorage(int pictureWidth, int pictureHeight) { - _locomotivesStorage = new Dictionary>(); + _locomotivesStorage = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -54,9 +53,10 @@ namespace ElectricLocomotive.Generics /// Название набора public void AddSet(string name) { - if (!_locomotivesStorage.ContainsKey(name)) + if (!_locomotivesStorage.ContainsKey(new LocomotivesCollectionInfo(name, ""))) { - _locomotivesStorage.Add(name, new LocomotivesGenericCollection(_pictureWidth, _pictureHeight)); + _locomotivesStorage.Add(new LocomotivesCollectionInfo(name, ""), + new LocomotivesGenericCollection(_pictureWidth, _pictureHeight)); } } @@ -66,9 +66,9 @@ namespace ElectricLocomotive.Generics /// Название набора public void DelSet(string name) { - if (_locomotivesStorage.ContainsKey(name)) + if (_locomotivesStorage.ContainsKey(new LocomotivesCollectionInfo(name, ""))) { - _locomotivesStorage.Remove(name); + _locomotivesStorage.Remove(new LocomotivesCollectionInfo(name, "")); } } @@ -83,10 +83,9 @@ namespace ElectricLocomotive.Generics { get { - // TODO Продумать логику получения набора - if (_locomotivesStorage.ContainsKey(ind)) + if (_locomotivesStorage.ContainsKey(new LocomotivesCollectionInfo(ind, ""))) { - return _locomotivesStorage[ind]; + return _locomotivesStorage[new LocomotivesCollectionInfo(ind, "")]; } return null; } @@ -104,7 +103,7 @@ namespace ElectricLocomotive.Generics File.Delete(filename); } StringBuilder data = new(); - foreach (KeyValuePair> record in _locomotivesStorage) + foreach (KeyValuePair> record in _locomotivesStorage) { StringBuilder records = new(); foreach (DrawningLocomotive? elem in record.Value.GetLocomotives) @@ -176,7 +175,7 @@ namespace ElectricLocomotive.Generics } } } - _locomotivesStorage.Add(record[0], collection); + _locomotivesStorage.Add(new LocomotivesCollectionInfo(record[0], string.Empty), collection); } return; } diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesCollectionInfo.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesCollectionInfo.cs new file mode 100644 index 0000000..07d8c66 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesCollectionInfo.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricLocomotive.Generics +{ + internal class LocomotivesCollectionInfo : IEquatable + { + public string Name { get; private set; } + public string Description { get; private set; } + public LocomotivesCollectionInfo(string name, string description) + { + Name = name; + Description = description; + } + public bool Equals(LocomotivesCollectionInfo other) + { + if (Name != other?.Name) + return false; + return true; + } + + public override int GetHashCode() + { + return Name.GetHashCode(); + } + + public override string ToString() + { + return Name; + } + } +} diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index 41373ce..380b4db 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ElectricLocomotive.DrawningObject; +using ElectricLocomotive.DrawningObject; using ElectricLocomotive.MovementStrategy; using ProjectElectricLocomotive.Generics; @@ -19,6 +14,8 @@ namespace ElectricLocomotive.Generics private readonly int _placeSizeHeight = 90; private readonly SetGeneric _collection; + public void Sort(IComparer comparer) => _collection.SortSet(comparer); + public LocomotivesGenericCollection(int picWidth, int picHeight) { int width = picWidth / _placeSizeWidth; @@ -33,7 +30,7 @@ namespace ElectricLocomotive.Generics { return -1; } - return collect._collection.Insert(locomotive); + return collect._collection.Insert(locomotive, new DrawningLocomotiveEqutables()); } diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 92bc661..2729311 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -1,11 +1,12 @@ -using ProjectElectricLocomotive.Exceptions; +using ProjectElectricLocomotive; +using ProjectElectricLocomotive.Exceptions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectElectricLocomotive.Generics +namespace ElectricLocomotive { internal class SetGeneric where T : class { @@ -13,26 +14,40 @@ namespace ProjectElectricLocomotive.Generics public int Count => _places.Count; /// Максимальное количество объектов в списке private readonly int _maxCount; + + public void SortSet(IComparer comparer) => _places.Sort(comparer); public SetGeneric(int count) { _maxCount = count; _places = new List(count); } - public int Insert(T loco) - { - return Insert(loco, 0); - } - - public int Insert(T loco, int position) + public int Insert(T loco, IEqualityComparer? equal = null) { if (_places.Count >= _maxCount) throw new StorageOverflowException(_maxCount); + return Insert(loco, 0, equal); + } + + public int Insert(T loco, int position, IEqualityComparer? equal = null) + { + if (position < 0 || position >= _maxCount) { return -1; } + if (equal != null) + { + foreach (var secondLoco in _places) + { + if (equal.Equals(loco, secondLoco)) + { + throw new ArgumentException("Текст"); + } + } + } + _places.Insert(position, loco); return position; } diff --git a/ElectricLocomotive/ElectricLocomotive/StorageOverflowException.cs b/ElectricLocomotive/ElectricLocomotive/StorageOverflowException.cs index 98ccf57..03a5fb7 100644 --- a/ElectricLocomotive/ElectricLocomotive/StorageOverflowException.cs +++ b/ElectricLocomotive/ElectricLocomotive/StorageOverflowException.cs @@ -5,7 +5,7 @@ using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; -namespace ProjectElectricLocomotive +namespace ElectricLocomotive { [Serializable] internal class StorageOverflowException : ApplicationException -- 2.25.1 From dfce5be428d8316e15e849860d1d503b4adc415e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Wed, 27 Dec 2023 23:04:55 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/FormLocomotiveCollection.cs | 6 ++++++ ElectricLocomotive/ElectricLocomotive/SetGeneric.cs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index f147a44..aa0584f 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -117,6 +117,12 @@ namespace ElectricLocomotive MessageBox.Show(ex.Message); _logger.LogInformation("Не удалось добавить объект"); } + catch (ArgumentException) + { + _logger.LogWarning("Добавляемый объект уже существует в коллекции"); + MessageBox.Show("Добавляемый объект уже сущесвует в коллекции"); + } + //проверяем, удалось ли нам загрузить объект } diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 2729311..c418fda 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -43,7 +43,7 @@ namespace ElectricLocomotive { if (equal.Equals(loco, secondLoco)) { - throw new ArgumentException("Текст"); + throw new ArgumentException(); } } } -- 2.25.1 From 0eecc892111b0db5a21313d02867dbdc14758a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C=20=D0=93=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B5=D0=B5=D0=B2?= <89176335310x@gmail.com> Date: Fri, 29 Dec 2023 11:02:11 +0400 Subject: [PATCH 3/3] Full --- .../ElectricLocomotive/FormLocomotiveCollection.cs | 2 -- .../ElectricLocomotive/LocomotiveGenericStorage.cs | 1 - .../ElectricLocomotive/LocomotivesGenericCollection.cs | 2 -- ElectricLocomotive/ElectricLocomotive/SetGeneric.cs | 2 -- 4 files changed, 7 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index aa0584f..262f01c 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -9,7 +9,6 @@ namespace ElectricLocomotive { public partial class FormLocomotiveCollection : Form { - private readonly LocomotiveGenericStorage _storage; /// /// Логер @@ -124,7 +123,6 @@ namespace ElectricLocomotive } //проверяем, удалось ли нам загрузить объект - } private void ButtonRemoveLocomotive_Click(object sender, EventArgs e) diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs index d664b04..ee2e8f0 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotiveGenericStorage.cs @@ -151,7 +151,6 @@ namespace ElectricLocomotive.Generics string strs = ""; while ((strs = fs.ReadLine()) != null) { - if (strs == null) { throw new FileNotFoundException("Нет данных для загрузки"); diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index 380b4db..10313ce 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -32,8 +32,6 @@ namespace ElectricLocomotive.Generics } return collect._collection.Insert(locomotive, new DrawningLocomotiveEqutables()); } - - /// Перегрузка оператора вычитания public static T? operator -(LocomotivesGenericCollection collect, int pos) { diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index c418fda..b0a790c 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -30,8 +30,6 @@ namespace ElectricLocomotive public int Insert(T loco, int position, IEqualityComparer? equal = null) { - - if (position < 0 || position >= _maxCount) { return -1; -- 2.25.1