From 4751e54ae11b970cd97c7ffda83278da63173738 Mon Sep 17 00:00:00 2001 From: marusya Date: Sat, 16 Dec 2023 20:14:18 +0400 Subject: [PATCH] lab8 --- .../DrawningUsta.cs | 2 +- .../DrawningUstaEqutables.cs | 59 ++++++++++ ...opelledArtilleryUnitCollection.Designer.cs | 102 +++++++++++++----- ...ormSelfPropelledArtilleryUnitCollection.cs | 26 ++++- .../SelfPropelledArtilleryUnit/SetGeneric.cs | 28 ++--- .../UstaCollectionInfo.cs | 28 +++++ .../UstaCompareByColor .cs | 50 +++++++++ .../UstaCompareByType.cs | 32 ++++++ .../UstaGenericCollection.cs | 9 +- .../UstaGenericStorage.cs | 25 ++--- 10 files changed, 300 insertions(+), 61 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUstaEqutables.cs create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCollectionInfo.cs create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByColor .cs create mode 100644 SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByType.cs diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs index 8095c73..8f5ecf9 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUsta.cs @@ -95,7 +95,7 @@ namespace SelfPropelledArtilleryUnit.DrawningObjects public void SetPosition(int x, int y) { // TODO: Изменение x, y, если при установке объект выходит за границы - if (x < 0 || y < 0 ) + if (x < 0 || y < 0 || x + _ustaWidth > _pictureWidth || y + _ustaHeight > _pictureHeight) { x = 10; y = 10; diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUstaEqutables.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUstaEqutables.cs new file mode 100644 index 0000000..5a8f240 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningUstaEqutables.cs @@ -0,0 +1,59 @@ +using SelfPropelledArtilleryUnit.DrawningObjects; +using SelfPropelledArtilleryUnit.Entities; +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit +{ + internal class DrawningUstaEqutables : IEqualityComparer + { + public bool Equals(DrawningUsta? x, DrawningUsta? y) + { + if (x == null || x.EntityUsta == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityUsta == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + if (x.EntityUsta.Speed != y.EntityUsta.Speed) + { + return false; + } + if (x.EntityUsta.Weight != y.EntityUsta.Weight) + { + return false; + } + if (x.EntityUsta.BodyColor != y.EntityUsta.BodyColor) + { + return false; + } + if (x is EntityUstaBat && y is EntityUstaBat) + { + EntityUstaBat EntityX = (EntityUstaBat)x.EntityUsta; + EntityUstaBat EntityY = (EntityUstaBat)y.EntityUsta; + if (EntityX.AdditionalColor != EntityY.AdditionalColor) + return false; + if (EntityX.Pushka != EntityY.Pushka) + return false; + if (EntityX.BodyKit != EntityY.BodyKit) + return false; + } + return true; + } + + public int GetHashCode([DisallowNull] DrawningUsta obj) + { + return obj.GetHashCode(); + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs index 3170d81..91252b4 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.Designer.cs @@ -34,6 +34,8 @@ pictureBoxCollection = new PictureBox(); maskedTextBoxNumber = new MaskedTextBox(); groupBox1 = new GroupBox(); + ButtonSortByType = new Button(); + ButtonSortByColor = new Button(); groupBox2 = new GroupBox(); listBoxStorage = new ListBox(); ButtonDelObject = new Button(); @@ -53,9 +55,10 @@ // // ButtonAddUsta // - ButtonAddUsta.Location = new Point(26, 366); + ButtonAddUsta.Location = new Point(30, 557); + ButtonAddUsta.Margin = new Padding(3, 4, 3, 4); ButtonAddUsta.Name = "ButtonAddUsta"; - ButtonAddUsta.Size = new Size(166, 40); + ButtonAddUsta.Size = new Size(190, 35); ButtonAddUsta.TabIndex = 0; ButtonAddUsta.Text = "Добавить арт. установку"; ButtonAddUsta.UseVisualStyleBackColor = true; @@ -63,9 +66,10 @@ // // ButtonRemoveUsta // - ButtonRemoveUsta.Location = new Point(26, 457); + ButtonRemoveUsta.Location = new Point(30, 643); + ButtonRemoveUsta.Margin = new Padding(3, 4, 3, 4); ButtonRemoveUsta.Name = "ButtonRemoveUsta"; - ButtonRemoveUsta.Size = new Size(166, 39); + ButtonRemoveUsta.Size = new Size(190, 37); ButtonRemoveUsta.TabIndex = 1; ButtonRemoveUsta.Text = "Удалить арт. установку"; ButtonRemoveUsta.UseVisualStyleBackColor = true; @@ -73,9 +77,10 @@ // // ButtonRefreshCollection // - ButtonRefreshCollection.Location = new Point(26, 502); + ButtonRefreshCollection.Location = new Point(30, 695); + ButtonRefreshCollection.Margin = new Padding(3, 4, 3, 4); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - ButtonRefreshCollection.Size = new Size(166, 40); + ButtonRefreshCollection.Size = new Size(190, 41); ButtonRefreshCollection.TabIndex = 2; ButtonRefreshCollection.Text = "Обновить коллекцию"; ButtonRefreshCollection.UseVisualStyleBackColor = true; @@ -84,8 +89,9 @@ // pictureBoxCollection // pictureBoxCollection.Location = new Point(0, 0); + pictureBoxCollection.Margin = new Padding(3, 4, 3, 4); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(637, 583); + pictureBoxCollection.Size = new Size(728, 777); pictureBoxCollection.SizeMode = PictureBoxSizeMode.Zoom; pictureBoxCollection.TabIndex = 3; pictureBoxCollection.TabStop = false; @@ -93,37 +99,66 @@ // maskedTextBoxNumber // maskedTextBoxNumber.Font = new Font("Showcard Gothic", 9F, FontStyle.Regular, GraphicsUnit.Point); - maskedTextBoxNumber.Location = new Point(58, 429); + maskedTextBoxNumber.Location = new Point(66, 604); + maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4); maskedTextBoxNumber.Mask = "00"; maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(100, 22); + maskedTextBoxNumber.Size = new Size(114, 26); maskedTextBoxNumber.TabIndex = 4; maskedTextBoxNumber.ValidatingType = typeof(int); // // groupBox1 // + groupBox1.Controls.Add(ButtonSortByType); + groupBox1.Controls.Add(ButtonSortByColor); groupBox1.Controls.Add(groupBox2); groupBox1.Controls.Add(ButtonAddUsta); groupBox1.Controls.Add(ButtonRefreshCollection); groupBox1.Controls.Add(maskedTextBoxNumber); groupBox1.Controls.Add(ButtonRemoveUsta); groupBox1.Controls.Add(menuStrip); - groupBox1.Location = new Point(643, 12); + groupBox1.Location = new Point(735, 16); + groupBox1.Margin = new Padding(3, 4, 3, 4); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(209, 560); + groupBox1.Padding = new Padding(3, 4, 3, 4); + groupBox1.Size = new Size(239, 747); groupBox1.TabIndex = 5; groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; // + // ButtonSortByType + // + ButtonSortByType.Location = new Point(30, 471); + ButtonSortByType.Margin = new Padding(3, 4, 3, 4); + ButtonSortByType.Name = "ButtonSortByType"; + ButtonSortByType.Size = new Size(190, 35); + ButtonSortByType.TabIndex = 9; + ButtonSortByType.Text = "Сортировка по типу"; + ButtonSortByType.UseVisualStyleBackColor = true; + ButtonSortByType.Click += ButtonSortByType_Click; + // + // ButtonSortByColor + // + ButtonSortByColor.Location = new Point(30, 514); + ButtonSortByColor.Margin = new Padding(3, 4, 3, 4); + ButtonSortByColor.Name = "ButtonSortByColor"; + ButtonSortByColor.Size = new Size(190, 35); + ButtonSortByColor.TabIndex = 8; + ButtonSortByColor.Text = "Сортировка по цвету"; + ButtonSortByColor.UseVisualStyleBackColor = true; + ButtonSortByColor.Click += ButtonSortByColor_Click; + // // groupBox2 // groupBox2.Controls.Add(listBoxStorage); groupBox2.Controls.Add(ButtonDelObject); groupBox2.Controls.Add(ButtonAddObject); groupBox2.Controls.Add(textBoxStorageName); - groupBox2.Location = new Point(6, 64); + groupBox2.Location = new Point(7, 85); + groupBox2.Margin = new Padding(3, 4, 3, 4); groupBox2.Name = "groupBox2"; - groupBox2.Size = new Size(197, 274); + groupBox2.Padding = new Padding(3, 4, 3, 4); + groupBox2.Size = new Size(225, 365); groupBox2.TabIndex = 6; groupBox2.TabStop = false; groupBox2.Text = "Наборы"; @@ -131,18 +166,20 @@ // listBoxStorage // listBoxStorage.FormattingEnabled = true; - listBoxStorage.ItemHeight = 15; - listBoxStorage.Location = new Point(20, 106); + listBoxStorage.ItemHeight = 20; + listBoxStorage.Location = new Point(23, 141); + listBoxStorage.Margin = new Padding(3, 4, 3, 4); listBoxStorage.Name = "listBoxStorage"; - listBoxStorage.Size = new Size(158, 109); + listBoxStorage.Size = new Size(180, 144); listBoxStorage.TabIndex = 9; listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged; // // ButtonDelObject // - ButtonDelObject.Location = new Point(33, 235); + ButtonDelObject.Location = new Point(38, 313); + ButtonDelObject.Margin = new Padding(3, 4, 3, 4); ButtonDelObject.Name = "ButtonDelObject"; - ButtonDelObject.Size = new Size(136, 33); + ButtonDelObject.Size = new Size(155, 44); ButtonDelObject.TabIndex = 8; ButtonDelObject.Text = "Удалить набор"; ButtonDelObject.UseVisualStyleBackColor = true; @@ -150,9 +187,10 @@ // // ButtonAddObject // - ButtonAddObject.Location = new Point(33, 54); + ButtonAddObject.Location = new Point(38, 72); + ButtonAddObject.Margin = new Padding(3, 4, 3, 4); ButtonAddObject.Name = "ButtonAddObject"; - ButtonAddObject.Size = new Size(136, 33); + ButtonAddObject.Size = new Size(155, 44); ButtonAddObject.TabIndex = 7; ButtonAddObject.Text = "Добавить набор"; ButtonAddObject.UseVisualStyleBackColor = true; @@ -160,17 +198,20 @@ // // textBoxStorageName // - textBoxStorageName.Location = new Point(20, 22); + textBoxStorageName.Location = new Point(23, 29); + textBoxStorageName.Margin = new Padding(3, 4, 3, 4); textBoxStorageName.Name = "textBoxStorageName"; - textBoxStorageName.Size = new Size(158, 23); + textBoxStorageName.Size = new Size(180, 27); textBoxStorageName.TabIndex = 0; // // menuStrip // + menuStrip.ImageScalingSize = new Size(20, 20); menuStrip.Items.AddRange(new ToolStripItem[] { fileToolStripMenuItem }); - menuStrip.Location = new Point(3, 19); + menuStrip.Location = new Point(3, 24); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(203, 24); + menuStrip.Padding = new Padding(7, 3, 0, 3); + menuStrip.Size = new Size(233, 30); menuStrip.TabIndex = 7; menuStrip.Text = "menuStrip1"; // @@ -178,20 +219,20 @@ // fileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem }); fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - fileToolStripMenuItem.Size = new Size(48, 20); + fileToolStripMenuItem.Size = new Size(59, 24); fileToolStripMenuItem.Text = "Файл"; // // SaveToolStripMenuItem // SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - SaveToolStripMenuItem.Size = new Size(180, 22); + SaveToolStripMenuItem.Size = new Size(177, 26); SaveToolStripMenuItem.Text = "Сохранение"; SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // // LoadToolStripMenuItem // LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - LoadToolStripMenuItem.Size = new Size(180, 22); + LoadToolStripMenuItem.Size = new Size(177, 26); LoadToolStripMenuItem.Text = "Загрузка"; LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; // @@ -208,12 +249,13 @@ // // FormSelfPropelledArtilleryUnitCollection // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(867, 584); + ClientSize = new Size(991, 779); Controls.Add(groupBox1); Controls.Add(pictureBoxCollection); MainMenuStrip = menuStrip; + Margin = new Padding(3, 4, 3, 4); Name = "FormSelfPropelledArtilleryUnitCollection"; Text = "Набор арт. установок"; ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); @@ -245,5 +287,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private OpenFileDialog openFileDialog; private SaveFileDialog saveFileDialog; + private Button ButtonSortByType; + private Button ButtonSortByColor; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs index 24c77fa..cbb1e79 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnitCollection.cs @@ -41,7 +41,7 @@ namespace SelfPropelledArtilleryUnit listBoxStorage.Items.Clear(); for (int i = 0; i < _storage.Keys.Count; i++) { - listBoxStorage.Items.Add(_storage.Keys[i]); + listBoxStorage.Items.Add(_storage.Keys[i].Name); } if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count)) @@ -70,7 +70,7 @@ namespace SelfPropelledArtilleryUnit } _storage.AddSet(textBoxStorageName.Text); ReloadObjects(); - _logger.LogInformation($"Добавлен набор:{ textBoxStorageName.Text}"); + _logger.LogInformation($"Добавлен набор:{textBoxStorageName.Text}"); } /// @@ -254,11 +254,31 @@ namespace SelfPropelledArtilleryUnit catch (Exception ex) { MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogWarning($"Не удалось сохранить наборы с ошибкой: {ex.Message}"); + _logger.LogWarning($"Не удалось загрузить наборы с ошибкой: {ex.Message}"); } } } + private void ButtonSortByType_Click(object sender, EventArgs e) => CompareUsta(new UstaCompareByType()); + + private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareUsta(new UstaCompareByColor()); + + private void CompareUsta(IComparer comparer) + { + if (listBoxStorage.SelectedIndex == -1) + { + return; + } + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? + string.Empty]; + if (obj == null) + { + return; + } + obj.Sort(comparer); + pictureBoxCollection.Image = obj.ShowUsta(); + } + } } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs index e7f9ac4..40e4944 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SetGeneric.cs @@ -1,4 +1,5 @@ -using System; +using SelfPropelledArtilleryUnit.Exceptions; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -26,6 +27,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// Максимальное количество объектов в списке /// private readonly int _maxCount; + public void SortSet(IComparer comparer) => _places.Sort(comparer); /// /// Конструктор /// @@ -33,29 +35,31 @@ namespace SelfPropelledArtilleryUnit.Generics public SetGeneric(int count) { _maxCount = count; - _places = new List(count); + _places = new List(_maxCount); } /// /// Добавление объекта в набор - public int Insert(T usta) + public bool Insert(T usta, IEqualityComparer? equal = null) { - - return Insert(usta, 0); + Insert(usta, 0, equal); + return true; } /// - public int Insert(T usta, int position) + public bool Insert(T usta, int position, IEqualityComparer? equal = null) { if (position < 0 || position >= _maxCount) - return -1; + throw new UstaNotFoundException(position); if (Count >= _maxCount) - return -1; - - - + throw new StorageOverflowException(position); + if (equal != null) + { + if (_places.Contains(usta, equal)) + throw new ArgumentException(nameof(usta)); + } _places.Insert(position, usta); - return position; + return true; } /// diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCollectionInfo.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCollectionInfo.cs new file mode 100644 index 0000000..52a6869 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCollectionInfo.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit +{ + internal class UstaCollectionInfo : IEquatable + { + public string Name { get; private set; } + public string Description { get; private set; } + public UstaCollectionInfo(string name, string description) + { + Name = name; + Description = description; + } + public bool Equals(UstaCollectionInfo? other) + { + return Name == other.Name; + } + + public override int GetHashCode() + { + return this.Name.GetHashCode(); + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByColor .cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByColor .cs new file mode 100644 index 0000000..111796e --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByColor .cs @@ -0,0 +1,50 @@ +using SelfPropelledArtilleryUnit.DrawningObjects; +using SelfPropelledArtilleryUnit.Entities; +using SelfPropelledArtilleryUnit.Generics; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit +{ + internal class UstaCompareByColor : IComparer + { + public int Compare(DrawningUsta? x, DrawningUsta? y) + { + if (x == null || x.EntityUsta == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null || y.EntityUsta == null) + throw new ArgumentNullException(nameof(y)); + + if (x.EntityUsta.BodyColor.Name != y.EntityUsta.BodyColor.Name) + { + return x.EntityUsta.BodyColor.Name.CompareTo(y.EntityUsta.BodyColor.Name); + } + if (x.GetType().Name != y.GetType().Name) + { + if (x is EntityUsta) + return -1; + else + return 1; + } + if (x.GetType().Name == y.GetType().Name && x is DrawningUstaBat) + { + EntityUstaBat EntityX = (EntityUstaBat)x.EntityUsta; + EntityUstaBat EntityY = (EntityUstaBat)y.EntityUsta; + if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name) + { + return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name); + } + } + var speedCompare = x.EntityUsta.Speed.CompareTo(y.EntityUsta.Speed); + + if (speedCompare != 0) + return speedCompare; + + return x.EntityUsta.Weight.CompareTo(y.EntityUsta.Weight); + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByType.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByType.cs new file mode 100644 index 0000000..02195ef --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaCompareByType.cs @@ -0,0 +1,32 @@ +using SelfPropelledArtilleryUnit.DrawningObjects; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit +{ + internal class UstaCompareByType : IComparer + { + public int Compare(DrawningUsta? x, DrawningUsta? y) + { + if (x == null || x.EntityUsta == null) + throw new ArgumentNullException(nameof(x)); + + if (y == null || y.EntityUsta == null) + throw new ArgumentNullException(nameof(y)); + + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + var speedCompare = x.EntityUsta.Speed.CompareTo(y.EntityUsta.Speed); + + if (speedCompare != 0) + return speedCompare; + + return x.EntityUsta.Weight.CompareTo(y.EntityUsta.Weight); + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs index 7857c8d..08a3c7e 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericCollection.cs @@ -38,6 +38,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// Набор объектов /// private readonly SetGeneric _collection; + public void Sort(IComparer comparer) => _collection.SortSet(comparer); /// /// Конструктор /// @@ -57,14 +58,14 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// /// - public static int operator +(UstaGenericCollection collect, T? + public static bool operator +(UstaGenericCollection collect, T? obj) { if (obj == null) { - return -1; + return false; } - return collect?._collection.Insert(obj) ?? -1; + return collect?._collection.Insert(obj, new DrawningUstaEqutables()) ?? false; } /// /// Перегрузка оператора вычитания @@ -72,7 +73,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// /// - public static T operator -(UstaGenericCollection collect, int + public static T? operator -(UstaGenericCollection collect, int pos) { T obj = collect._collection[pos]; diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs index ef36e8d..1bb6ba4 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/UstaGenericStorage.cs @@ -16,12 +16,12 @@ namespace SelfPropelledArtilleryUnit.Generics /// /// Словарь (хранилище) /// - readonly Dictionary> _ustaStorages; /// /// Возвращение списка названий наборов /// - public List Keys => _ustaStorages.Keys.ToList(); + public List Keys => _ustaStorages.Keys.ToList(); /// /// Ширина окна отрисовки /// @@ -49,7 +49,7 @@ namespace SelfPropelledArtilleryUnit.Generics /// public UstaGenericStorage(int pictureWidth, int pictureHeight) { - _ustaStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; @@ -61,10 +61,10 @@ namespace SelfPropelledArtilleryUnit.Generics public void AddSet(string name) { // TODO Прописать логику для добавления - if (!_ustaStorages.ContainsKey(name)) + if (!_ustaStorages.ContainsKey(new UstaCollectionInfo(name, string.Empty))) { var ustaCollection = new UstaGenericCollection(_pictureWidth, _pictureHeight); - _ustaStorages.Add(name, ustaCollection); + _ustaStorages.Add(new UstaCollectionInfo(name, string.Empty), ustaCollection); } } /// @@ -74,9 +74,9 @@ namespace SelfPropelledArtilleryUnit.Generics public void DelSet(string name) { // TODO Прописать логику для удаления - if (_ustaStorages.ContainsKey(name)) + if (_ustaStorages.ContainsKey(new UstaCollectionInfo(name, string.Empty))) { - _ustaStorages.Remove(name); + _ustaStorages.Remove(new UstaCollectionInfo(name, string.Empty)); } } /// @@ -88,10 +88,11 @@ namespace SelfPropelledArtilleryUnit.Generics { get { + UstaCollectionInfo indObj = new UstaCollectionInfo(ind, string.Empty); // TODO Продумать логику получения набора - if (_ustaStorages.ContainsKey(ind)) + if (_ustaStorages.ContainsKey(indObj)) { - return _ustaStorages[ind]; + return _ustaStorages[indObj]; } return null; @@ -109,14 +110,14 @@ namespace SelfPropelledArtilleryUnit.Generics File.Delete(filename); } StringBuilder data = new(); - foreach (KeyValuePair> record in _ustaStorages) + foreach (KeyValuePair> record in _ustaStorages) { StringBuilder records = new(); foreach (DrawningUsta? elem in record.Value.GetUsta) { records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); } - data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}"); } if (data.Length == 0) { @@ -185,7 +186,7 @@ namespace SelfPropelledArtilleryUnit.Generics } } } - _ustaStorages.Add(name, collection); + _ustaStorages.Add(new UstaCollectionInfo(name, string.Empty), collection); } } } -- 2.25.1