PIbd-23. Radaev A.V. Lab work 08 #15
27
Catamaran/CatamaranCollectionInfo.cs
Normal file
27
Catamaran/CatamaranCollectionInfo.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
internal class CatamaranCollectionInfo : IEquatable<CatamaranCollectionInfo>
|
||||||
|
{
|
||||||
|
public string Name { get; private set; }
|
||||||
|
public string Description { get; private set; }
|
||||||
|
public CatamaranCollectionInfo(string name, string description)
|
||||||
|
{
|
||||||
|
Name = name;
|
||||||
|
Description = description;
|
||||||
|
}
|
||||||
|
public bool Equals(CatamaranCollectionInfo? other)
|
||||||
|
{
|
||||||
|
return Name == other.Name;
|
||||||
|
|||||||
|
}
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
return this.Name.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
Catamaran/CatamaranCompareByColor.cs
Normal file
48
Catamaran/CatamaranCompareByColor.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
internal class CatamaranCompareByColor: IComparer<DrawningCatamaran?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningCatamaran? x, DrawningCatamaran? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCatamaran == null)
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
|
||||||
|
if (y == null || y.EntityCatamaran == null)
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
|
||||||
|
if (x.EntityCatamaran.BodyColor.Name != y.EntityCatamaran.BodyColor.Name)
|
||||||
|
{
|
||||||
|
return x.EntityCatamaran.BodyColor.Name.CompareTo(y.EntityCatamaran.BodyColor.Name);
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
eegov
commented
Требовалось сортировать по критериям: цвет, скорость, вес Требовалось сортировать по критериям: цвет, скорость, вес
|
|||||||
|
{
|
||||||
|
if (x is DrawningCatamaran)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (x.GetType().Name == y.GetType().Name && x is DrawningCatamaranPro)
|
||||||
|
{
|
||||||
|
EntityCatamaranPro EntityX = (EntityCatamaranPro)x.EntityCatamaran;
|
||||||
|
EntityCatamaranPro EntityY = (EntityCatamaranPro)y.EntityCatamaran;
|
||||||
|
if (EntityX.AdditionalColor.Name != EntityY.AdditionalColor.Name)
|
||||||
|
{
|
||||||
|
return EntityX.AdditionalColor.Name.CompareTo(EntityY.AdditionalColor.Name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityCatamaran.Speed.CompareTo(y.EntityCatamaran.Speed);
|
||||||
|
|
||||||
|
if (speedCompare != 0)
|
||||||
|
return speedCompare;
|
||||||
|
|
||||||
|
return x.EntityCatamaran.Weight.CompareTo(y.EntityCatamaran.Weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
34
Catamaran/CatamaranCompareByType.cs
Normal file
34
Catamaran/CatamaranCompareByType.cs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
internal class CatamaranCompareByType: IComparer<DrawningCatamaran?>
|
||||||
|
{
|
||||||
|
public int Compare(DrawningCatamaran? x, DrawningCatamaran? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCatamaran == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityCatamaran == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||||
|
}
|
||||||
|
var speedCompare = x.EntityCatamaran.Speed.CompareTo(y.EntityCatamaran.Speed);
|
||||||
|
if (speedCompare != 0)
|
||||||
|
{
|
||||||
|
return speedCompare;
|
||||||
|
}
|
||||||
|
return x.EntityCatamaran.Weight.CompareTo(y.EntityCatamaran.Weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
namespace Catamaran
|
namespace Catamaran
|
||||||
{
|
{
|
||||||
@ -22,6 +23,8 @@ namespace Catamaran
|
|||||||
|
|
||||||
private readonly SetGeneric<T> _collection;
|
private readonly SetGeneric<T> _collection;
|
||||||
|
|
||||||
|
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||||
|
|
||||||
public CatamaransGenericCollection(int picWidth, int picHeight)
|
public CatamaransGenericCollection(int picWidth, int picHeight)
|
||||||
{
|
{
|
||||||
int width = picWidth / _placeSizeWidth;
|
int width = picWidth / _placeSizeWidth;
|
||||||
@ -35,7 +38,7 @@ namespace Catamaran
|
|||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
return false;
|
return false;
|
||||||
return collect?._collection.Insert(obj) ?? false;
|
return collect?._collection.Insert(obj, new DrawningCatamaranEqutables()) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T? operator -(CatamaransGenericCollection<T, U> collect, int pos)
|
public static T? operator -(CatamaransGenericCollection<T, U> collect, int pos)
|
||||||
|
@ -8,10 +8,9 @@ namespace Catamaran
|
|||||||
{
|
{
|
||||||
internal class CatamaransGenericStorage
|
internal class CatamaransGenericStorage
|
||||||
{
|
{
|
||||||
readonly Dictionary<string, CatamaransGenericCollection<DrawningCatamaran,
|
|
||||||
DrawningObjectCatamaran>> _catStorages;
|
|
||||||
|
|
||||||
public List<string> Keys => _catStorages.Keys.ToList();
|
readonly Dictionary<CatamaranCollectionInfo, CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>> _catStorages;
|
||||||
|
public List<CatamaranCollectionInfo> Keys => _catStorages.Keys.ToList();
|
||||||
|
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
@ -25,8 +24,8 @@ namespace Catamaran
|
|||||||
|
|
||||||
public CatamaransGenericStorage(int pictureWidth, int pictureHeight)
|
public CatamaransGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
{
|
{
|
||||||
_catStorages = new Dictionary<string,
|
_catStorages = new Dictionary<CatamaranCollectionInfo,
|
||||||
CatamaransGenericCollection<DrawningCatamaran,DrawningObjectCatamaran>>();
|
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>>();
|
||||||
_pictureWidth = pictureWidth;
|
_pictureWidth = pictureWidth;
|
||||||
_pictureHeight = pictureHeight;
|
_pictureHeight = pictureHeight;
|
||||||
}
|
}
|
||||||
@ -38,7 +37,7 @@ namespace Catamaran
|
|||||||
File.Delete(filename);
|
File.Delete(filename);
|
||||||
}
|
}
|
||||||
StringBuilder data = new();
|
StringBuilder data = new();
|
||||||
foreach (KeyValuePair<string,
|
foreach (KeyValuePair<CatamaranCollectionInfo,
|
||||||
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>> record in _catStorages)
|
CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>> record in _catStorages)
|
||||||
{
|
{
|
||||||
StringBuilder records = new();
|
StringBuilder records = new();
|
||||||
@ -46,7 +45,7 @@ namespace Catamaran
|
|||||||
{
|
{
|
||||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
}
|
}
|
||||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.Length == 0)
|
if (data.Length == 0)
|
||||||
@ -108,7 +107,7 @@ namespace Catamaran
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_catStorages.Add(record[0], collection);
|
_catStorages.Add(new CatamaranCollectionInfo(record[0], string.Empty), collection);
|
||||||
|
|
||||||
str = sr.ReadLine();
|
str = sr.ReadLine();
|
||||||
} while (str != null);
|
} while (str != null);
|
||||||
@ -118,22 +117,23 @@ namespace Catamaran
|
|||||||
|
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
_catStorages.Add(name, new CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>(_pictureWidth, _pictureHeight));
|
_catStorages.Add(new CatamaranCollectionInfo(name, string.Empty), new CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>(_pictureWidth, _pictureHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
if (!_catStorages.ContainsKey(name))
|
if (!_catStorages.ContainsKey(new CatamaranCollectionInfo(name, string.Empty)))
|
||||||
return;
|
return;
|
||||||
_catStorages.Remove(name);
|
_catStorages.Remove(new CatamaranCollectionInfo(name, string.Empty));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>? this[string ind]
|
public CatamaransGenericCollection<DrawningCatamaran, DrawningObjectCatamaran>? this[string ind]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_catStorages.ContainsKey(ind))
|
CatamaranCollectionInfo indObj = new CatamaranCollectionInfo(ind, string.Empty);
|
||||||
return _catStorages[ind];
|
if (_catStorages.ContainsKey(indObj))
|
||||||
|
return _catStorages[indObj];
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
Catamaran/DrawningCatamaranEqutables.cs
Normal file
59
Catamaran/DrawningCatamaranEqutables.cs
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Catamaran
|
||||||
|
{
|
||||||
|
internal class DrawningCatamaranEqutables: IEqualityComparer<DrawningCatamaran?>
|
||||||
|
{
|
||||||
|
public bool Equals(DrawningCatamaran? x, DrawningCatamaran? y)
|
||||||
|
{
|
||||||
|
if (x == null || x.EntityCatamaran == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(x));
|
||||||
|
}
|
||||||
|
if (y == null || y.EntityCatamaran == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(y));
|
||||||
|
}
|
||||||
|
if (x.GetType().Name != y.GetType().Name)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityCatamaran.Speed != y.EntityCatamaran.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityCatamaran.Weight != y.EntityCatamaran.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x.EntityCatamaran.BodyColor != y.EntityCatamaran.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (x is DrawningCatamaranPro && y is DrawningCatamaranPro)
|
||||||
|
{
|
||||||
|
EntityCatamaranPro EntityX = (EntityCatamaranPro)x.EntityCatamaran;
|
||||||
|
EntityCatamaranPro EntityY = (EntityCatamaranPro)y.EntityCatamaran;
|
||||||
|
if (EntityX.Motor != EntityY.Motor)
|
||||||
|
return false;
|
||||||
|
if (EntityX.BodyKit != EntityY.BodyKit)
|
||||||
|
return false;
|
||||||
|
if (EntityX.Sail != EntityY.Sail)
|
||||||
|
return false;
|
||||||
|
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
public int GetHashCode([DisallowNull] DrawningCatamaran obj)
|
||||||
|
{
|
||||||
|
return obj.GetHashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
42
Catamaran/FormCatamaranCollection.Designer.cs
generated
42
Catamaran/FormCatamaranCollection.Designer.cs
generated
@ -21,6 +21,8 @@
|
|||||||
{
|
{
|
||||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCatamaranCollection));
|
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormCatamaranCollection));
|
||||||
groupBoxCollection=new GroupBox();
|
groupBoxCollection=new GroupBox();
|
||||||
|
buttonSortByColor=new Button();
|
||||||
|
buttonSortByType=new Button();
|
||||||
setsBox=new GroupBox();
|
setsBox=new GroupBox();
|
||||||
DeleteSetButton=new Button();
|
DeleteSetButton=new Button();
|
||||||
SetslistBox=new ListBox();
|
SetslistBox=new ListBox();
|
||||||
@ -95,6 +97,8 @@
|
|||||||
//
|
//
|
||||||
// groupBoxCollection
|
// groupBoxCollection
|
||||||
//
|
//
|
||||||
|
groupBoxCollection.Controls.Add(buttonSortByColor);
|
||||||
|
groupBoxCollection.Controls.Add(buttonSortByType);
|
||||||
groupBoxCollection.Controls.Add(setsBox);
|
groupBoxCollection.Controls.Add(setsBox);
|
||||||
groupBoxCollection.Controls.Add(maskedTextBox);
|
groupBoxCollection.Controls.Add(maskedTextBox);
|
||||||
groupBoxCollection.Controls.Add(buttonUpdateCollection);
|
groupBoxCollection.Controls.Add(buttonUpdateCollection);
|
||||||
@ -107,13 +111,33 @@
|
|||||||
groupBoxCollection.TabStop=false;
|
groupBoxCollection.TabStop=false;
|
||||||
groupBoxCollection.Text="Инструменты";
|
groupBoxCollection.Text="Инструменты";
|
||||||
//
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location=new Point(21, 410);
|
||||||
|
buttonSortByColor.Name="buttonSortByColor";
|
||||||
|
buttonSortByColor.Size=new Size(204, 34);
|
||||||
|
buttonSortByColor.TabIndex=5;
|
||||||
|
buttonSortByColor.Text="Сортировать по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor=true;
|
||||||
|
buttonSortByColor.Click+=ButtonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location=new Point(21, 361);
|
||||||
|
buttonSortByType.Name="buttonSortByType";
|
||||||
|
buttonSortByType.Size=new Size(204, 34);
|
||||||
|
buttonSortByType.TabIndex=4;
|
||||||
|
buttonSortByType.Text="Сортировать по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor=true;
|
||||||
|
buttonSortByType.Click+=ButtonSortByType_Click;
|
||||||
|
//
|
||||||
// setsBox
|
// setsBox
|
||||||
//
|
//
|
||||||
setsBox.Controls.Add(DeleteSetButton);
|
setsBox.Controls.Add(DeleteSetButton);
|
||||||
setsBox.Controls.Add(SetslistBox);
|
setsBox.Controls.Add(SetslistBox);
|
||||||
setsBox.Controls.Add(setAddBox);
|
setsBox.Controls.Add(setAddBox);
|
||||||
setsBox.Controls.Add(AddSetButton);
|
setsBox.Controls.Add(AddSetButton);
|
||||||
setsBox.Location=new Point(6, 41);
|
setsBox.Location=new Point(6, 30);
|
||||||
setsBox.Name="setsBox";
|
setsBox.Name="setsBox";
|
||||||
setsBox.RightToLeft=RightToLeft.No;
|
setsBox.RightToLeft=RightToLeft.No;
|
||||||
setsBox.Size=new Size(219, 305);
|
setsBox.Size=new Size(219, 305);
|
||||||
@ -160,16 +184,16 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBox
|
// maskedTextBox
|
||||||
//
|
//
|
||||||
maskedTextBox.Location=new Point(21, 457);
|
maskedTextBox.Location=new Point(21, 525);
|
||||||
maskedTextBox.Name="maskedTextBox";
|
maskedTextBox.Name="maskedTextBox";
|
||||||
maskedTextBox.Size=new Size(204, 31);
|
maskedTextBox.Size=new Size(204, 31);
|
||||||
maskedTextBox.TabIndex=2;
|
maskedTextBox.TabIndex=2;
|
||||||
//
|
//
|
||||||
// buttonUpdateCollection
|
// buttonUpdateCollection
|
||||||
//
|
//
|
||||||
buttonUpdateCollection.Location=new Point(21, 577);
|
buttonUpdateCollection.Location=new Point(21, 606);
|
||||||
buttonUpdateCollection.Name="buttonUpdateCollection";
|
buttonUpdateCollection.Name="buttonUpdateCollection";
|
||||||
buttonUpdateCollection.Size=new Size(204, 54);
|
buttonUpdateCollection.Size=new Size(204, 39);
|
||||||
buttonUpdateCollection.TabIndex=2;
|
buttonUpdateCollection.TabIndex=2;
|
||||||
buttonUpdateCollection.Text="Обновить коллекцию";
|
buttonUpdateCollection.Text="Обновить коллекцию";
|
||||||
buttonUpdateCollection.UseVisualStyleBackColor=true;
|
buttonUpdateCollection.UseVisualStyleBackColor=true;
|
||||||
@ -177,9 +201,9 @@
|
|||||||
//
|
//
|
||||||
// buttonDeleteCat
|
// buttonDeleteCat
|
||||||
//
|
//
|
||||||
buttonDeleteCat.Location=new Point(21, 504);
|
buttonDeleteCat.Location=new Point(21, 562);
|
||||||
buttonDeleteCat.Name="buttonDeleteCat";
|
buttonDeleteCat.Name="buttonDeleteCat";
|
||||||
buttonDeleteCat.Size=new Size(204, 54);
|
buttonDeleteCat.Size=new Size(204, 38);
|
||||||
buttonDeleteCat.TabIndex=1;
|
buttonDeleteCat.TabIndex=1;
|
||||||
buttonDeleteCat.Text="Удалить катамаран";
|
buttonDeleteCat.Text="Удалить катамаран";
|
||||||
buttonDeleteCat.UseVisualStyleBackColor=true;
|
buttonDeleteCat.UseVisualStyleBackColor=true;
|
||||||
@ -187,9 +211,9 @@
|
|||||||
//
|
//
|
||||||
// buttonAddCat
|
// buttonAddCat
|
||||||
//
|
//
|
||||||
buttonAddCat.Location=new Point(21, 385);
|
buttonAddCat.Location=new Point(21, 481);
|
||||||
buttonAddCat.Name="buttonAddCat";
|
buttonAddCat.Name="buttonAddCat";
|
||||||
buttonAddCat.Size=new Size(204, 54);
|
buttonAddCat.Size=new Size(204, 38);
|
||||||
buttonAddCat.TabIndex=0;
|
buttonAddCat.TabIndex=0;
|
||||||
buttonAddCat.Text="Добавить катамаран";
|
buttonAddCat.Text="Добавить катамаран";
|
||||||
buttonAddCat.UseVisualStyleBackColor=true;
|
buttonAddCat.UseVisualStyleBackColor=true;
|
||||||
@ -661,5 +685,7 @@
|
|||||||
private ToolStripMenuItem файлToolStripMenuItem;
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
private ToolStripMenuItem сохранитьToolStripMenuItem2;
|
private ToolStripMenuItem сохранитьToolStripMenuItem2;
|
||||||
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
private ToolStripMenuItem загрузитьToolStripMenuItem;
|
||||||
|
private Button buttonSortByType;
|
||||||
|
private Button buttonSortByColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,7 +31,7 @@ namespace Catamaran
|
|||||||
SetslistBox.Items.Clear();
|
SetslistBox.Items.Clear();
|
||||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
{
|
{
|
||||||
SetslistBox.Items.Add(_storage.Keys[i]);
|
SetslistBox.Items.Add(_storage.Keys[i].Name);
|
||||||
}
|
}
|
||||||
if (SetslistBox.Items.Count > 0 && (index == -1 || index
|
if (SetslistBox.Items.Count > 0 && (index == -1 || index
|
||||||
>= SetslistBox.Items.Count))
|
>= SetslistBox.Items.Count))
|
||||||
@ -43,11 +43,11 @@ namespace Catamaran
|
|||||||
{
|
{
|
||||||
SetslistBox.SelectedIndex = index;
|
SetslistBox.SelectedIndex = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void ButtonAddStorage_Click(object sender, EventArgs e)
|
private void ButtonAddStorage_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string storname = setAddBox.Text;
|
if (string.IsNullOrEmpty(setAddBox.Text))
|
||||||
if (string.IsNullOrEmpty(setAddBox.Text) || _storage.Keys.Contains(storname))
|
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
@ -55,6 +55,7 @@ namespace Catamaran
|
|||||||
}
|
}
|
||||||
_storage.AddSet(setAddBox.Text);
|
_storage.AddSet(setAddBox.Text);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
Log.Information($"Добавлен набор: {setAddBox.Text}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
@ -71,9 +72,11 @@ namespace Catamaran
|
|||||||
}
|
}
|
||||||
if (MessageBox.Show($"Удалить набор {SetslistBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show($"Удалить набор {SetslistBox.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_storage.DelSet(SetslistBox.SelectedItem.ToString()
|
string name = SetslistBox.SelectedItem.ToString()
|
||||||
?? string.Empty);
|
?? string.Empty;
|
||||||
|
_storage.DelSet(name);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
Log.Information($"Удален набор: {name}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,9 +109,13 @@ namespace Catamaran
|
|||||||
Log.Warning($"Коллекция {SetslistBox.SelectedItem.ToString() ?? string.Empty} переполнена");
|
Log.Warning($"Коллекция {SetslistBox.SelectedItem.ToString() ?? string.Empty} переполнена");
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
}
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
Log.Warning($"Добавляемый объект уже существует в коллекции {SetslistBox.SelectedItem.ToString() ?? string.Empty}");
|
||||||
|
MessageBox.Show("Добавляемый объект уже сущесвует в коллекции");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
form.AddEvent(catamaranDelegate);
|
form.AddEvent(catamaranDelegate);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonRemoveCatamaran_Click(object sender, EventArgs e)
|
private void ButtonRemoveCatamaran_Click(object sender, EventArgs e)
|
||||||
@ -141,7 +148,7 @@ namespace Catamaran
|
|||||||
Log.Warning($"Не получилось удалить объект из коллекции {SetslistBox.SelectedItem.ToString() ?? string.Empty}");
|
Log.Warning($"Не получилось удалить объект из коллекции {SetslistBox.SelectedItem.ToString() ?? string.Empty}");
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
}
|
}
|
||||||
catch (FormatException ex)
|
catch (FormatException)
|
||||||
{
|
{
|
||||||
Log.Warning($"Было введено не число");
|
Log.Warning($"Было введено не число");
|
||||||
MessageBox.Show("Введите число");
|
MessageBox.Show("Введите число");
|
||||||
@ -177,7 +184,6 @@ namespace Catamaran
|
|||||||
{
|
{
|
||||||
Log.Warning("Не удалось сохранить");
|
Log.Warning("Не удалось сохранить");
|
||||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,10 +206,29 @@ namespace Catamaran
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Warning("Не удалось загрузить");
|
Log.Warning("Не удалось загрузить");
|
||||||
MessageBox.Show($"Не загрузилось: {ex.Message}","Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareCatamarans(new CatamaranCompareByType());
|
||||||
|
|
||||||
|
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareCatamarans(new CatamaranCompareByColor());
|
||||||
|
|
||||||
|
private void CompareCatamarans(IComparer<DrawningCatamaran?> comparer)
|
||||||
|
{
|
||||||
|
if (SetslistBox.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[SetslistBox.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
obj.Sort(comparer);
|
||||||
|
pictureBoxCollection.Image = obj.ShowCats();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,21 +18,27 @@ namespace Catamaran
|
|||||||
_maxCount = count;
|
_maxCount = count;
|
||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
|
|
||||||
public bool Insert(T catamaran)
|
public bool Insert(T catamaran, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (_places.Count == _maxCount)
|
if (_places.Count == _maxCount)
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
Insert(catamaran, 0);
|
Insert(catamaran, 0, equal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Insert(T catamaran, int position)
|
public bool Insert(T catamaran, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
if (!(position >= 0 && position <= Count))
|
if (!(position >= 0 && position <= Count))
|
||||||
return false;
|
return false;
|
||||||
|
if (equal != null)
|
||||||
|
{
|
||||||
|
if (_places.Contains(catamaran, equal))
|
||||||
|
throw new ArgumentException(nameof(catamaran));
|
||||||
|
}
|
||||||
_places.Insert(position, catamaran);
|
_places.Insert(position, catamaran);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user
Нет проверки, что other не равен null