Ievlewa_lab8_Base #8
55
speed_Boat/speed_Boat/BoatCompareByColor.cs
Normal file
55
speed_Boat/speed_Boat/BoatCompareByColor.cs
Normal file
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SpeedBoatLab.Drawings;
|
||||
using SpeedBoatLab.Entity;
|
||||
|
||||
namespace speed_Boat.Generics
|
||||
{
|
||||
internal class BoatCompareByColor : IComparer<DrawingBoat?>
|
||||
{
|
||||
public int Compare(DrawingBoat? x, DrawingBoat? y)
|
||||
{
|
||||
// TODO реализовать логику сравнения
|
||||
if (x == null || x._entityBoat == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y._entityBoat == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if(x._entityBoat.MainColor.Name != y._entityBoat.MainColor.Name)
|
||||
{
|
||||
return x._entityBoat.MainColor.Name.CompareTo(y._entityBoat.MainColor.Name);
|
||||
}
|
||||
if(x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
if (x is DrawingBoat)
|
||||
return -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
if(x.GetType().Name == y.GetType().Name && x is DrawingSpeedBoat)
|
||||
{
|
||||
EntitySpeedboat _speedboatX = (EntitySpeedboat)x._entityBoat;
|
||||
EntitySpeedboat _speedboatY = (EntitySpeedboat)y._entityBoat;
|
||||
|
||||
if (_speedboatX.SecondColor.Name != _speedboatY.SecondColor.Name)
|
||||
{
|
||||
return _speedboatX.SecondColor.Name.CompareTo(_speedboatY.SecondColor.Name);
|
||||
}
|
||||
}
|
||||
|
||||
var speedCompare = x._entityBoat.Speed.CompareTo(y._entityBoat.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x._entityBoat.Weight.CompareTo(y._entityBoat.Weight);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
35
speed_Boat/speed_Boat/BoatCompareByType.cs
Normal file
35
speed_Boat/speed_Boat/BoatCompareByType.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SpeedBoatLab.Drawings;
|
||||
|
||||
namespace speed_Boat.Generics
|
||||
{
|
||||
internal class BoatCompareByType : IComparer<DrawingBoat?>
|
||||
{
|
||||
public int Compare(DrawingBoat? x, DrawingBoat? y)
|
||||
{
|
||||
if (x == null || x._entityBoat == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y._entityBoat == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x._entityBoat.Speed.CompareTo(y._entityBoat.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x._entityBoat.Weight.CompareTo(y._entityBoat.Weight);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
28
speed_Boat/speed_Boat/BoatsCollectionInfo.cs
Normal file
28
speed_Boat/speed_Boat/BoatsCollectionInfo.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace speed_Boat.Generics
|
||||
{
|
||||
internal class BoatsCollectionInfo : IEquatable<BoatsCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public BoatsCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(BoatsCollectionInfo? other)
|
||||
{
|
||||
// TODO прописать логику сравнения по свойству Name
|
||||
return Name == other.Name;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return this.Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
@ -18,6 +18,11 @@ namespace speed_Boat.Generics
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetBoats => _collection.GetBoats();
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
@ -56,7 +61,7 @@ namespace speed_Boat.Generics
|
||||
{
|
||||
if (obj != null)
|
||||
{
|
||||
return collect?._collection.Insert(obj) ?? -1;
|
||||
return collect?._collection.Insert(obj, new DrawingBoatEquatable()) ?? -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,14 +16,14 @@ namespace speed_Boat.Generics
|
||||
/// </summary>
|
||||
internal class BoatsGenericStorage
|
||||
{
|
||||
///<summary>
|
||||
/// Словарь(хранилище)
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>> _boatStorages;
|
||||
readonly Dictionary<BoatsCollectionInfo, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>> _boatStorages;
|
||||
///<summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _boatStorages.Keys.ToList();
|
||||
public List<BoatsCollectionInfo> Keys => _boatStorages.Keys.ToList();
|
||||
///<summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -51,7 +51,7 @@ namespace speed_Boat.Generics
|
||||
/// </summary>
|
||||
public BoatsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_boatStorages = new Dictionary<string, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>>();
|
||||
_boatStorages = new Dictionary<BoatsCollectionInfo, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -71,14 +71,14 @@ namespace speed_Boat.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>> record in _boatStorages)
|
||||
foreach (KeyValuePair<BoatsCollectionInfo, BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>> record in _boatStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawingBoat? elem in record.Value.GetBoats)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if(data.Length == 0)
|
||||
{
|
||||
@ -139,7 +139,7 @@ namespace speed_Boat.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_boatStorages.Add(record[0], collection);
|
||||
_boatStorages.Add(new BoatsCollectionInfo(record[0], string.Empty), collection);
|
||||
str = sr.ReadLine();
|
||||
} while (str != null);
|
||||
}
|
||||
@ -151,14 +151,14 @@ namespace speed_Boat.Generics
|
||||
/// </summary>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_boatStorages.ContainsKey(name))
|
||||
if (_boatStorages.ContainsKey(new BoatsCollectionInfo(name, string.Empty)))
|
||||
{
|
||||
MessageBox.Show("Словарь уже содержит набор с таким названием", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
_boatStorages.Add(name, new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>(_pictureWidth, _pictureHeight));
|
||||
_boatStorages.Add(new BoatsCollectionInfo(name, string.Empty), new BoatsGenericCollection<DrawingBoat, DrawingObjectBoat>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -168,9 +168,9 @@ namespace speed_Boat.Generics
|
||||
public void DelSet(string name)
|
||||
{
|
||||
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> boat;
|
||||
if (_boatStorages.TryGetValue(name, out boat))
|
||||
if (_boatStorages.TryGetValue(new BoatsCollectionInfo(name, string.Empty), out boat))
|
||||
{
|
||||
_boatStorages.Remove(name);
|
||||
_boatStorages.Remove(new BoatsCollectionInfo(name, string.Empty));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -182,11 +182,10 @@ namespace speed_Boat.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> boat;
|
||||
//проверка есть ли в словаре обьект с ключом ind
|
||||
if (_boatStorages.TryGetValue(ind, out boat))
|
||||
BoatsCollectionInfo infBoat = new BoatsCollectionInfo(ind, string.Empty);
|
||||
if(_boatStorages.ContainsKey(infBoat))
|
||||
{
|
||||
return boat;
|
||||
return _boatStorages[infBoat];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
66
speed_Boat/speed_Boat/DrawingBoatEquatable.cs
Normal file
66
speed_Boat/speed_Boat/DrawingBoatEquatable.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using SpeedBoatLab.Drawings;
|
||||
using SpeedBoatLab.Entity;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace speed_Boat.Generics
|
||||
{
|
||||
internal class DrawingBoatEquatable : IEqualityComparer<DrawingBoat?>
|
||||
{
|
||||
public bool Equals(DrawingBoat? x, DrawingBoat? y)
|
||||
{
|
||||
if (x == null || x._entityBoat == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y._entityBoat == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._entityBoat.Speed != y._entityBoat.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._entityBoat.Weight != y._entityBoat.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._entityBoat.MainColor != y._entityBoat.MainColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawingSpeedBoat && y is DrawingSpeedBoat)
|
||||
{
|
||||
// TODO доделать логику сравнения дополнительных параметров
|
||||
EntitySpeedboat _speedboatX = (EntitySpeedboat)x._entityBoat;
|
||||
EntitySpeedboat _speedboatY = (EntitySpeedboat)y._entityBoat;
|
||||
if (_speedboatX.isMotor != _speedboatY.isMotor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_speedboatX.isProtectedGlass != _speedboatY.isProtectedGlass)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(_speedboatX.SecondColor != _speedboatY.SecondColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawingBoat obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
62
speed_Boat/speed_Boat/FormBoatCollection.Designer.cs
generated
62
speed_Boat/speed_Boat/FormBoatCollection.Designer.cs
generated
@ -30,6 +30,9 @@ namespace SpeedBoatLab
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBox1 = new System.Windows.Forms.GroupBox();
|
||||
groupBox3 = new System.Windows.Forms.GroupBox();
|
||||
button1 = new System.Windows.Forms.Button();
|
||||
button2 = new System.Windows.Forms.Button();
|
||||
groupBox2 = new System.Windows.Forms.GroupBox();
|
||||
deleteStorageButton = new System.Windows.Forms.Button();
|
||||
storagesListBox = new System.Windows.Forms.ListBox();
|
||||
@ -48,6 +51,7 @@ namespace SpeedBoatLab
|
||||
openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
groupBox1.SuspendLayout();
|
||||
groupBox3.SuspendLayout();
|
||||
groupBox2.SuspendLayout();
|
||||
menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
@ -55,6 +59,7 @@ namespace SpeedBoatLab
|
||||
//
|
||||
// groupBox1
|
||||
//
|
||||
groupBox1.Controls.Add(groupBox3);
|
||||
groupBox1.Controls.Add(groupBox2);
|
||||
groupBox1.Controls.Add(label1);
|
||||
groupBox1.Controls.Add(maskedTextBoxNumber);
|
||||
@ -64,11 +69,42 @@ namespace SpeedBoatLab
|
||||
groupBox1.Controls.Add(menuStrip1);
|
||||
groupBox1.Location = new System.Drawing.Point(581, 2);
|
||||
groupBox1.Name = "groupBox1";
|
||||
groupBox1.Size = new System.Drawing.Size(205, 471);
|
||||
groupBox1.Size = new System.Drawing.Size(205, 586);
|
||||
groupBox1.TabIndex = 0;
|
||||
groupBox1.TabStop = false;
|
||||
groupBox1.Text = "Настройки";
|
||||
//
|
||||
// groupBox3
|
||||
//
|
||||
groupBox3.Controls.Add(button1);
|
||||
groupBox3.Controls.Add(button2);
|
||||
groupBox3.Location = new System.Drawing.Point(6, 439);
|
||||
groupBox3.Name = "groupBox3";
|
||||
groupBox3.Size = new System.Drawing.Size(193, 102);
|
||||
groupBox3.TabIndex = 7;
|
||||
groupBox3.TabStop = false;
|
||||
groupBox3.Text = "Сортировки";
|
||||
//
|
||||
// button1
|
||||
//
|
||||
button1.Location = new System.Drawing.Point(6, 61);
|
||||
button1.Name = "button1";
|
||||
button1.Size = new System.Drawing.Size(181, 29);
|
||||
button1.TabIndex = 7;
|
||||
button1.Text = "Сортировка по типу";
|
||||
button1.UseVisualStyleBackColor = true;
|
||||
button1.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// button2
|
||||
//
|
||||
button2.Location = new System.Drawing.Point(6, 26);
|
||||
button2.Name = "button2";
|
||||
button2.Size = new System.Drawing.Size(181, 29);
|
||||
button2.TabIndex = 8;
|
||||
button2.Text = "Сортировка по цвету";
|
||||
button2.UseVisualStyleBackColor = true;
|
||||
button2.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// groupBox2
|
||||
//
|
||||
groupBox2.Controls.Add(deleteStorageButton);
|
||||
@ -122,7 +158,7 @@ namespace SpeedBoatLab
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new System.Drawing.Point(6, 299);
|
||||
label1.Location = new System.Drawing.Point(6, 308);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new System.Drawing.Size(135, 20);
|
||||
label1.TabIndex = 4;
|
||||
@ -130,14 +166,14 @@ namespace SpeedBoatLab
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new System.Drawing.Point(6, 322);
|
||||
maskedTextBoxNumber.Location = new System.Drawing.Point(6, 331);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new System.Drawing.Size(193, 27);
|
||||
maskedTextBoxNumber.TabIndex = 3;
|
||||
//
|
||||
// UpdateCollectionButton
|
||||
//
|
||||
UpdateCollectionButton.Location = new System.Drawing.Point(6, 391);
|
||||
UpdateCollectionButton.Location = new System.Drawing.Point(6, 400);
|
||||
UpdateCollectionButton.Name = "UpdateCollectionButton";
|
||||
UpdateCollectionButton.Size = new System.Drawing.Size(193, 29);
|
||||
UpdateCollectionButton.TabIndex = 2;
|
||||
@ -147,7 +183,7 @@ namespace SpeedBoatLab
|
||||
//
|
||||
// DeleteBoatButton
|
||||
//
|
||||
DeleteBoatButton.Location = new System.Drawing.Point(6, 355);
|
||||
DeleteBoatButton.Location = new System.Drawing.Point(6, 364);
|
||||
DeleteBoatButton.Name = "DeleteBoatButton";
|
||||
DeleteBoatButton.Size = new System.Drawing.Size(193, 30);
|
||||
DeleteBoatButton.TabIndex = 1;
|
||||
@ -157,7 +193,7 @@ namespace SpeedBoatLab
|
||||
//
|
||||
// AddBoatButton
|
||||
//
|
||||
AddBoatButton.Location = new System.Drawing.Point(6, 268);
|
||||
AddBoatButton.Location = new System.Drawing.Point(6, 277);
|
||||
AddBoatButton.Name = "AddBoatButton";
|
||||
AddBoatButton.Size = new System.Drawing.Size(193, 28);
|
||||
AddBoatButton.TabIndex = 0;
|
||||
@ -170,7 +206,7 @@ namespace SpeedBoatLab
|
||||
menuStrip1.Dock = System.Windows.Forms.DockStyle.Bottom;
|
||||
menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip1.Location = new System.Drawing.Point(3, 440);
|
||||
menuStrip1.Location = new System.Drawing.Point(3, 555);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new System.Drawing.Size(199, 28);
|
||||
menuStrip1.TabIndex = 6;
|
||||
@ -186,14 +222,14 @@ namespace SpeedBoatLab
|
||||
// загрузкаToolStripMenuItem
|
||||
//
|
||||
загрузкаToolStripMenuItem.Name = "загрузкаToolStripMenuItem";
|
||||
загрузкаToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
загрузкаToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||
загрузкаToolStripMenuItem.Text = "Загрузка";
|
||||
загрузкаToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// сохранениеToolStripMenuItem
|
||||
//
|
||||
сохранениеToolStripMenuItem.Name = "сохранениеToolStripMenuItem";
|
||||
сохранениеToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
сохранениеToolStripMenuItem.Size = new System.Drawing.Size(177, 26);
|
||||
сохранениеToolStripMenuItem.Text = "Сохранение";
|
||||
сохранениеToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
@ -201,7 +237,7 @@ namespace SpeedBoatLab
|
||||
//
|
||||
pictureBoxCollection.Location = new System.Drawing.Point(12, 12);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(554, 527);
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(554, 576);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
@ -218,7 +254,7 @@ namespace SpeedBoatLab
|
||||
//
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(800, 551);
|
||||
ClientSize = new System.Drawing.Size(800, 600);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(groupBox1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
@ -226,6 +262,7 @@ namespace SpeedBoatLab
|
||||
Text = "Коллекция катеров";
|
||||
groupBox1.ResumeLayout(false);
|
||||
groupBox1.PerformLayout();
|
||||
groupBox3.ResumeLayout(false);
|
||||
groupBox2.ResumeLayout(false);
|
||||
groupBox2.PerformLayout();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
@ -254,5 +291,8 @@ namespace SpeedBoatLab
|
||||
private System.Windows.Forms.ToolStripMenuItem сохранениеToolStripMenuItem;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
private System.Windows.Forms.GroupBox groupBox3;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Button button2;
|
||||
}
|
||||
}
|
@ -49,7 +49,7 @@ namespace SpeedBoatLab
|
||||
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
storagesListBox.Items.Add(_storage.Keys[i]);
|
||||
storagesListBox.Items.Add(_storage.Keys[i].Name);
|
||||
}
|
||||
|
||||
if (storagesListBox.Items.Count > 0 && (index == -1 ||
|
||||
@ -73,13 +73,12 @@ namespace SpeedBoatLab
|
||||
if (string.IsNullOrEmpty(nameStorageTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Пустое название набора");
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(nameStorageTextBox.Text);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Добавлен набор:{nameStorageTextBox.Text}");
|
||||
_logger.LogInformation($"Добавлен набор: {nameStorageTextBox.Text}");
|
||||
|
||||
}
|
||||
///<summary>
|
||||
@ -122,15 +121,49 @@ namespace SpeedBoatLab
|
||||
{
|
||||
if (storagesListBox.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Набор для добавления обьекта не выбран");
|
||||
return;
|
||||
}
|
||||
var FormBoatConfig = new FormBoatConfig();
|
||||
FormBoatConfig.AddEvent(new(AddBoat));
|
||||
FormBoatConfig.Show();
|
||||
var obj = _storage[storagesListBox.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormBoatConfig form = new();
|
||||
form.Show();
|
||||
Action<DrawingBoat>? boatDelegate = new((boat) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = obj + boat;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation($"Добавлен объект в коллекцию {storagesListBox.SelectedItem.ToString() ?? string.Empty}");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
_logger.LogWarning($"Коллекция {storagesListBox.SelectedItem.ToString() ?? string.Empty} переполнена");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
_logger.LogWarning($"Добавляемый объект уже существует в коллекции {storagesListBox.SelectedItem.ToString() ?? string.Empty}");
|
||||
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
||||
}
|
||||
});
|
||||
form.AddEvent(boatDelegate);
|
||||
/* if (storagesListBox.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Набор для добавления обьекта не выбран");
|
||||
return;
|
||||
}
|
||||
var FormBoatConfig = new FormBoatConfig();
|
||||
|
||||
FormBoatConfig.Show();
|
||||
FormBoatConfig.AddEvent(new(AddBoat));*/
|
||||
}
|
||||
|
||||
public void AddBoat(DrawingBoat? boat)
|
||||
/* public void AddBoat(DrawingBoat? boat)
|
||||
{
|
||||
if (storagesListBox.SelectedIndex == -1)
|
||||
{
|
||||
@ -147,15 +180,20 @@ namespace SpeedBoatLab
|
||||
{
|
||||
_ = obj + boat;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
_logger.LogInformation($"Добавлен объект в набор {storagesListBox.SelectedItem.ToString()}");
|
||||
_logger.LogInformation($"Добавлен объект в набор {storagesListBox.SelectedItem.ToString() ?? string.Empty}");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
catch(StorageOverflowException ex)
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning($"{ex.Message} в наборе {storagesListBox.SelectedItem.ToString()}");
|
||||
_logger.LogWarning($"{ex.Message} в наборе {storagesListBox.SelectedItem.ToString() ?? string.Empty}");
|
||||
}
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show("Добавляемый объект уже существует в коллекции");
|
||||
_logger.LogWarning($"Добавляемый объект уже существует в коллекции {storagesListBox.SelectedItem.ToString() ?? string.Empty}");
|
||||
}
|
||||
}*/
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
@ -203,13 +241,13 @@ namespace SpeedBoatLab
|
||||
_logger.LogInformation($"Не удалось удалить объект из набора {storagesListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
catch(BoatNotFoundException ex)
|
||||
catch (BoatNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"{ex.Message} из набора {storagesListBox.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
else if(insertPosition == string.Empty)
|
||||
else if (insertPosition == string.Empty)
|
||||
{
|
||||
MessageBox.Show("Неверный формат позиции");
|
||||
_logger.LogWarning($"Неверный формат позиции:{insertPosition}");
|
||||
@ -285,5 +323,39 @@ namespace SpeedBoatLab
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareBoats(new BoatCompareByType());
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareBoats(new BoatCompareByColor());
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
private void CompareBoats(IComparer<DrawingBoat?> comparer)
|
||||
{
|
||||
if (storagesListBox.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[storagesListBox.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,12 @@ namespace speed_Boat.Generics
|
||||
/// Максимальное количество обьектов в списке
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -35,31 +40,12 @@ namespace speed_Boat.Generics
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор
|
||||
/// </summary>
|
||||
public int Insert(T boat)
|
||||
public int Insert(T boat, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if(_places.Count == 0)
|
||||
{
|
||||
_places.Add(boat);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(boat);
|
||||
for(int i = 0; i < _places.Count; i++)
|
||||
{
|
||||
T temp = _places[i];
|
||||
_places[i] = _places[_places.Count - 1];
|
||||
_places[_places.Count - 1] = temp;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new StorageOverflowException();
|
||||
}
|
||||
}
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(boat, 0, equal);
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию.
|
||||
@ -67,19 +53,30 @@ namespace speed_Boat.Generics
|
||||
/// Если позиция занята, то происходит сдвиг элементов
|
||||
/// вправо(при возможности) на одну позицию.
|
||||
/// </summary>
|
||||
public bool Insert(T boat, int position)
|
||||
public bool Insert(T boat, int position, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if (position < 0 || position >= Count)
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
if (_places == null)
|
||||
if (equal != null)
|
||||
{
|
||||
if (_places.Contains(boat, equal))
|
||||
{
|
||||
throw new ArgumentException((nameof(boat)));
|
||||
}
|
||||
}
|
||||
if (_places.Count == 0 && position == 0)
|
||||
{
|
||||
_places.Add(boat);
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (_places.Count == 0 && position != 0)
|
||||
return false;
|
||||
|
||||
if (_places[position] == null)
|
||||
{
|
||||
_places[position] = boat;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_places.Count < _maxCount)
|
||||
{
|
||||
_places.Add(boat);
|
||||
|
@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="carlog-${shortdate}.log" />
|
||||
</targets>
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user