Фулл 8 лаба надеюсь
This commit is contained in:
parent
8c7a4a2c6b
commit
5af581e096
36
Liner/FormLinerCollection.Designer.cs
generated
36
Liner/FormLinerCollection.Designer.cs
generated
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
Storages = new GroupBox();
|
||||
listBoxStorages = new ListBox();
|
||||
buttonDeleteSet = new Button();
|
||||
@ -53,6 +55,8 @@
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonSortByType);
|
||||
groupBoxTools.Controls.Add(buttonSortByColor);
|
||||
groupBoxTools.Controls.Add(Storages);
|
||||
groupBoxTools.Controls.Add(buttonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(buttonDeleteLiner);
|
||||
@ -67,6 +71,28 @@
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Tools";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(28, 413);
|
||||
buttonSortByType.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(190, 41);
|
||||
buttonSortByType.TabIndex = 8;
|
||||
buttonSortByType.Text = "Sort By Type";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Location = new Point(28, 462);
|
||||
buttonSortByColor.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(190, 41);
|
||||
buttonSortByColor.TabIndex = 7;
|
||||
buttonSortByColor.Text = "Sort By Color";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// Storages
|
||||
//
|
||||
Storages.Controls.Add(listBoxStorages);
|
||||
@ -125,7 +151,7 @@
|
||||
//
|
||||
// buttonRefreshCollection
|
||||
//
|
||||
buttonRefreshCollection.Location = new Point(13, 668);
|
||||
buttonRefreshCollection.Location = new Point(13, 691);
|
||||
buttonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonRefreshCollection.Name = "buttonRefreshCollection";
|
||||
buttonRefreshCollection.Size = new Size(222, 53);
|
||||
@ -136,7 +162,7 @@
|
||||
//
|
||||
// buttonDeleteLiner
|
||||
//
|
||||
buttonDeleteLiner.Location = new Point(13, 544);
|
||||
buttonDeleteLiner.Location = new Point(13, 607);
|
||||
buttonDeleteLiner.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonDeleteLiner.Name = "buttonDeleteLiner";
|
||||
buttonDeleteLiner.Size = new Size(222, 53);
|
||||
@ -147,7 +173,7 @@
|
||||
//
|
||||
// textBoxNumber
|
||||
//
|
||||
textBoxNumber.Location = new Point(47, 491);
|
||||
textBoxNumber.Location = new Point(47, 572);
|
||||
textBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||
textBoxNumber.Name = "textBoxNumber";
|
||||
textBoxNumber.Size = new Size(158, 27);
|
||||
@ -155,7 +181,7 @@
|
||||
//
|
||||
// buttonAddLiner
|
||||
//
|
||||
buttonAddLiner.Location = new Point(13, 417);
|
||||
buttonAddLiner.Location = new Point(13, 511);
|
||||
buttonAddLiner.Margin = new Padding(3, 4, 3, 4);
|
||||
buttonAddLiner.Name = "buttonAddLiner";
|
||||
buttonAddLiner.Size = new Size(222, 53);
|
||||
@ -256,5 +282,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByType;
|
||||
private Button buttonSortByColor;
|
||||
}
|
||||
}
|
@ -85,6 +85,11 @@ namespace Liner
|
||||
_logger.LogWarning($"Добавление лайнера в {listBoxStorages.SelectedItem.ToString()} не удалось (переполнение коллекции)");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Не удалось добавить объект: {ex.Message}");
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора
|
||||
@ -224,7 +229,7 @@ namespace Liner
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
listBoxStorages.Items.Add(_storage.Keys[i].Name);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index >= listBoxStorages.Items.Count))
|
||||
{
|
||||
@ -272,5 +277,35 @@ namespace Liner
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по сравнителю
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
private void CompareLiners(IComparer<DrawingLiner?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowLiners();
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка по типу
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareLiners(new LinerCompareByType());
|
||||
/// <summary>
|
||||
/// Сортировка по цвету
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareLiners(new LinerCompareByColor());
|
||||
}
|
||||
}
|
||||
|
64
Liner/Generics/DrawingLinerEqutables.cs
Normal file
64
Liner/Generics/DrawingLinerEqutables.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Liner.Drawing;
|
||||
using Liner.Entities;
|
||||
namespace Liner.Generics
|
||||
{
|
||||
internal class DrawingLinerEqutables : IEqualityComparer<DrawingLiner?>
|
||||
{
|
||||
public bool Equals(DrawingLiner? x, DrawingLiner? y)
|
||||
{
|
||||
if (x == null || x.EntityLiner == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityLiner == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityLiner.Speed != y.EntityLiner.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityLiner.Weight != y.EntityLiner.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityLiner.BottomColor != y.EntityLiner.BottomColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawingBigLiner && y is DrawingBigLiner)
|
||||
{
|
||||
EntityBigLiner _LinerX = (EntityBigLiner)x.EntityLiner;
|
||||
EntityBigLiner _LinerY = (EntityBigLiner)y.EntityLiner;
|
||||
if (_LinerX.SwimmingPool != _LinerY.SwimmingPool)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_LinerX.Deck != _LinerY.Deck)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_LinerX.BodyColor != _LinerY.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawingLiner obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
30
Liner/Generics/LinerCollectionInfo.cs
Normal file
30
Liner/Generics/LinerCollectionInfo.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Liner.Generics
|
||||
{
|
||||
public class LinerCollectionInfo : IEquatable<LinerCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public LinerCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(LinerCollectionInfo? other)
|
||||
{
|
||||
if (Name == other?.Name)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
44
Liner/Generics/LinerCompareByColor.cs
Normal file
44
Liner/Generics/LinerCompareByColor.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Liner.Entities;
|
||||
using Liner.Drawing;
|
||||
|
||||
namespace Liner.Generics
|
||||
{
|
||||
internal class LinerCompareByColor : IComparer<DrawingLiner?>
|
||||
{
|
||||
public int Compare(DrawingLiner? x, DrawingLiner? y)
|
||||
{
|
||||
if (x == null || x.EntityLiner == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityLiner == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
var bottomColorCompare = x.EntityLiner.BottomColor.Name.CompareTo(y.EntityLiner.BottomColor.Name);
|
||||
if (bottomColorCompare != 0)
|
||||
{
|
||||
return bottomColorCompare;
|
||||
}
|
||||
if (x.EntityLiner is EntityBigLiner _entityBigLinerX && y.EntityLiner is EntityBigLiner _entityBigLinerY)
|
||||
{
|
||||
var bodyColorCompare = _entityBigLinerX.BodyColor.Name.CompareTo(_entityBigLinerY.BodyColor.Name);
|
||||
if (bodyColorCompare != 0)
|
||||
{
|
||||
return bodyColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = x.EntityLiner.Speed.CompareTo(y.EntityLiner.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityLiner.Weight.CompareTo(y.EntityLiner.Weight);
|
||||
}
|
||||
}
|
||||
}
|
34
Liner/Generics/LinerCompareByType.cs
Normal file
34
Liner/Generics/LinerCompareByType.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Liner.Drawing;
|
||||
using Liner.Entities;
|
||||
namespace Liner.Generics
|
||||
{
|
||||
internal class LinerCompareByType : IComparer<DrawingLiner?>
|
||||
{
|
||||
public int Compare(DrawingLiner? x, DrawingLiner? y)
|
||||
{
|
||||
if (x == null || x.EntityLiner == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y.EntityLiner == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x.EntityLiner.Speed.CompareTo(y.EntityLiner.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityLiner.Weight.CompareTo(y.EntityLiner.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -54,7 +54,11 @@ namespace Liner.Generics
|
||||
/// Получение объектов коллекции
|
||||
/// <summary>
|
||||
public IEnumerable<T?> GetLiners => _collection.GetLiners();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
/// Перегрузка оператора сложения
|
||||
/// </summary>
|
||||
/// <param name="collect"></param>
|
||||
@ -66,7 +70,7 @@ namespace Liner.Generics
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return collect?._collection.Insert(obj);
|
||||
return collect._collection.Insert(obj, new DrawingLinerEqutables());
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
|
@ -16,11 +16,11 @@ namespace Liner.Generics
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, LinerGenericCollection<DrawingLiner, DrawingObjectLiner>> _linerStorages;
|
||||
readonly Dictionary<LinerCollectionInfo, LinerGenericCollection<DrawingLiner, DrawingObjectLiner>> _linerStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _linerStorages.Keys.ToList();
|
||||
public List<LinerCollectionInfo> Keys => _linerStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
@ -48,7 +48,7 @@ namespace Liner.Generics
|
||||
/// <param name="pictureHeight"></param>
|
||||
public LinersGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_linerStorages = new Dictionary<string, LinerGenericCollection<DrawingLiner, DrawingObjectLiner>>();
|
||||
_linerStorages = new Dictionary<LinerCollectionInfo, LinerGenericCollection<DrawingLiner, DrawingObjectLiner>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -58,11 +58,11 @@ namespace Liner.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if(_linerStorages.ContainsKey(name))
|
||||
if(_linerStorages.ContainsKey(new LinerCollectionInfo(name, string.Empty)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
_linerStorages.Add(name, new LinerGenericCollection<DrawingLiner, DrawingObjectLiner>(_pictureWidth,_pictureHeight));
|
||||
_linerStorages.Add(new LinerCollectionInfo(name, string.Empty), new LinerGenericCollection<DrawingLiner, DrawingObjectLiner>(_pictureWidth,_pictureHeight));
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
@ -70,9 +70,9 @@ namespace Liner.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (_linerStorages.ContainsKey(name))
|
||||
if (_linerStorages.ContainsKey(new LinerCollectionInfo(name, string.Empty)))
|
||||
{
|
||||
_linerStorages.Remove(name);
|
||||
_linerStorages.Remove(new LinerCollectionInfo(name, string.Empty));
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@ -84,7 +84,7 @@ namespace Liner.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_linerStorages.ContainsKey(ind)) { return _linerStorages[ind]; }
|
||||
if (_linerStorages.ContainsKey(new LinerCollectionInfo(ind, string.Empty))) { return _linerStorages[new LinerCollectionInfo(ind, string.Empty)]; }
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -99,7 +99,7 @@ namespace Liner.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string,
|
||||
foreach (KeyValuePair<LinerCollectionInfo,
|
||||
LinerGenericCollection<DrawingLiner, DrawingObjectLiner>> record in _linerStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
@ -107,7 +107,7 @@ namespace Liner.Generics
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
@ -167,7 +167,7 @@ namespace Liner.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_linerStorages.Add(name, collection);
|
||||
_linerStorages.Add(new LinerCollectionInfo(name, string.Empty), collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,13 +40,13 @@ namespace Liner.Generics
|
||||
/// </summary>
|
||||
/// <param name="liner">Добавляемый лайнер</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T liner)
|
||||
public int Insert(T liner, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_places.Count);
|
||||
}
|
||||
_places.Insert(0, liner);
|
||||
return Insert(liner,0, equal);
|
||||
return 0;
|
||||
|
||||
}
|
||||
@ -56,7 +56,7 @@ namespace Liner.Generics
|
||||
/// <param name="liner">Добавляемый лайнер</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public int Insert(T liner, int position)
|
||||
public int Insert(T liner, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if(_places.Count >= _maxCount)
|
||||
{
|
||||
@ -66,6 +66,10 @@ namespace Liner.Generics
|
||||
{
|
||||
throw new LinerNotFoundException(position);
|
||||
}
|
||||
if (equal != null && _places.Contains(liner, equal))
|
||||
{
|
||||
throw new ArgumentException("Этот объект уже существует в коллекции");
|
||||
}
|
||||
_places.Insert(position, liner);
|
||||
return position;
|
||||
}
|
||||
@ -83,6 +87,7 @@ namespace Liner.Generics
|
||||
}
|
||||
throw new LinerNotFoundException(position);
|
||||
}
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
/// </summary>
|
||||
|
Loading…
x
Reference in New Issue
Block a user