зафиксировать
This commit is contained in:
parent
c41e547bab
commit
7c4cf25b53
@ -43,6 +43,8 @@
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
ButtonSortByType = new Button();
|
||||
ButtonSortByColor = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
@ -59,16 +61,16 @@
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 25;
|
||||
listBoxStorages.Location = new Point(935, 146);
|
||||
listBoxStorages.Location = new Point(935, 130);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(231, 129);
|
||||
listBoxStorages.Size = new Size(231, 79);
|
||||
listBoxStorages.TabIndex = 1;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
ButtonAddObject.BackColor = SystemColors.ButtonHighlight;
|
||||
ButtonAddObject.Location = new Point(935, 102);
|
||||
ButtonAddObject.Location = new Point(935, 86);
|
||||
ButtonAddObject.Name = "ButtonAddObject";
|
||||
ButtonAddObject.Size = new Size(231, 38);
|
||||
ButtonAddObject.TabIndex = 2;
|
||||
@ -78,7 +80,7 @@
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(935, 65);
|
||||
textBoxStorageName.Location = new Point(935, 49);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(231, 31);
|
||||
textBoxStorageName.TabIndex = 3;
|
||||
@ -86,7 +88,7 @@
|
||||
// ButtonDelObject
|
||||
//
|
||||
ButtonDelObject.BackColor = SystemColors.ButtonHighlight;
|
||||
ButtonDelObject.Location = new Point(935, 281);
|
||||
ButtonDelObject.Location = new Point(935, 215);
|
||||
ButtonDelObject.Name = "ButtonDelObject";
|
||||
ButtonDelObject.Size = new Size(231, 34);
|
||||
ButtonDelObject.TabIndex = 4;
|
||||
@ -154,14 +156,14 @@
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(270, 34);
|
||||
SaveToolStripMenuItem.Size = new Size(212, 34);
|
||||
SaveToolStripMenuItem.Text = "Сохранение";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenu_Click;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(270, 34);
|
||||
LoadToolStripMenuItem.Size = new Size(212, 34);
|
||||
LoadToolStripMenuItem.Text = "Загрузка";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenu_Click;
|
||||
//
|
||||
@ -174,11 +176,35 @@
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
ButtonSortByType.BackColor = SystemColors.ButtonHighlight;
|
||||
ButtonSortByType.Location = new Point(935, 284);
|
||||
ButtonSortByType.Name = "ButtonSortByType";
|
||||
ButtonSortByType.Size = new Size(231, 34);
|
||||
ButtonSortByType.TabIndex = 10;
|
||||
ButtonSortByType.Text = "Сортировать по типу";
|
||||
ButtonSortByType.UseVisualStyleBackColor = false;
|
||||
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
ButtonSortByColor.BackColor = SystemColors.ButtonHighlight;
|
||||
ButtonSortByColor.Location = new Point(935, 329);
|
||||
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
ButtonSortByColor.Size = new Size(231, 34);
|
||||
ButtonSortByColor.TabIndex = 11;
|
||||
ButtonSortByColor.Text = "Сортировать по цвету";
|
||||
ButtonSortByColor.UseVisualStyleBackColor = false;
|
||||
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1178, 644);
|
||||
Controls.Add(ButtonSortByColor);
|
||||
Controls.Add(ButtonSortByType);
|
||||
Controls.Add(menuStrip1);
|
||||
Controls.Add(textBoxBoat);
|
||||
Controls.Add(ButtonRefreshCollection);
|
||||
@ -216,5 +242,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button ButtonSortByType;
|
||||
private Button ButtonSortByColor;
|
||||
}
|
||||
}
|
@ -15,6 +15,7 @@ using ProjectBoat_bae.Generics;
|
||||
using ProjectBoat_bae.Exceptions;
|
||||
using ProjectBoat_bae.MovementStrategy;
|
||||
using NLog;
|
||||
using System.Numerics;
|
||||
|
||||
namespace ProjectBoat_bae
|
||||
{
|
||||
@ -24,7 +25,7 @@ namespace ProjectBoat_bae
|
||||
private readonly BoatsGenericStorage _storage;
|
||||
|
||||
// Логер
|
||||
private readonly
|
||||
private readonly
|
||||
Microsoft.Extensions.Logging.ILogger? _logger;
|
||||
|
||||
public FormBoatCollection(ILogger<FormBoatCollection> logger)
|
||||
@ -59,13 +60,21 @@ namespace ProjectBoat_bae
|
||||
private void ButtonAddObject_Click_1(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
//if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
//{
|
||||
// MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
// MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// return;
|
||||
//}
|
||||
//_storage.AddSet(textBoxStorageName.Text);
|
||||
//ReloadObjects();
|
||||
//_logger.LogInformation($"Added set: {textBoxStorageName.Text}");
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Input not complete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
_storage.AddSet(textBoxStorageName.Text.ToString());
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Added set: {textBoxStorageName.Text}");
|
||||
}
|
||||
@ -73,57 +82,52 @@ namespace ProjectBoat_bae
|
||||
// Удаление набора
|
||||
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||
{
|
||||
//if (listBoxStorages.SelectedIndex == -1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
//if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
//{
|
||||
// MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
// _logger.LogWarning("Неудачная попытка. Коллекция не добавлена, не все данные заполнены");
|
||||
// return;
|
||||
//}
|
||||
//_storage.AddSet(textBoxStorageName.Text);
|
||||
//ReloadObjects();
|
||||
|
||||
//_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||
if (MessageBox.Show($"Delete Object {name}?", "Deleting",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogWarning("Неудачная попытка. Коллекция не добавлена, не все данные заполнены");
|
||||
return;
|
||||
_storage.DelSet(name);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Deleted set: {name}");
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
|
||||
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||
}
|
||||
|
||||
// Добавление объекта в набор
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
//if (listBoxStorages.SelectedIndex == -1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
//if (obj == null)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
FormBoatConfig formPlaneConfig = new FormBoatConfig();
|
||||
formPlaneConfig.AddEvent(AddBoat);
|
||||
formPlaneConfig.Show();
|
||||
}
|
||||
//FormBoatConfig formPlaneConfig = new FormBoatConfig();
|
||||
//formPlaneConfig.AddEvent(AddBoat);
|
||||
//formPlaneConfig.Show();
|
||||
|
||||
private void AddBoat(Drawningboat boat)
|
||||
{
|
||||
boat._pictureWidth = pictureBoxCollection.Width;
|
||||
boat._pictureHeight = pictureBoxCollection.Height;
|
||||
if (listBoxStorages.SelectedIndex == -1) return;
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null) return;
|
||||
|
||||
if (obj + boat)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
_logger.LogInformation($"Добавлен объект {obj}");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//удаление объекта
|
||||
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
@ -133,7 +137,108 @@ namespace ProjectBoat_bae
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удалить", MessageBoxButtons.YesNo,
|
||||
FormBoatConfig formPlaneConfig = new FormBoatConfig();
|
||||
formPlaneConfig.AddEvent(AddBoat);
|
||||
formPlaneConfig.Show();
|
||||
}
|
||||
|
||||
private void AddBoat(Drawningboat boat)
|
||||
{
|
||||
//boat._pictureWidth = pictureBoxCollection.Width;
|
||||
//boat._pictureHeight = pictureBoxCollection.Height;
|
||||
//if (listBoxStorages.SelectedIndex == -1) return;
|
||||
//var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
//if (obj == null) return;
|
||||
|
||||
//if (obj + boat)
|
||||
//{
|
||||
// MessageBox.Show("Объект добавлен");
|
||||
// pictureBoxCollection.Image = obj.ShowBoats();
|
||||
// _logger.LogInformation($"Добавлен объект {obj}");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("Не удалось добавить объект");
|
||||
//}
|
||||
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_ = obj + boat;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
_logger.LogInformation($"plane added in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"plane not added in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//удаление объекта
|
||||
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
//if (listBoxStorages.SelectedIndex == -1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
//if (obj == null)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//if (MessageBox.Show("Удалить объект?", "Удалить", MessageBoxButtons.YesNo,
|
||||
// MessageBoxIcon.Question) == DialogResult.No)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//try
|
||||
//{
|
||||
// int pos = Convert.ToInt32(textBoxBoat.Text);
|
||||
// if (obj - pos != null)
|
||||
// {
|
||||
// MessageBox.Show("Объект удален");
|
||||
// pictureBoxCollection.Image = obj.ShowBoats();
|
||||
// _logger.LogInformation($"лодка удалена из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// MessageBox.Show("Объект не удален");
|
||||
// _logger.LogWarning($"лодка не удалена из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
// }
|
||||
//}
|
||||
//catch (BoatNotFoundException ex)
|
||||
//{
|
||||
// MessageBox.Show(ex.Message);
|
||||
// _logger.LogWarning($"BoatNotFound: {ex.Message} in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
//}
|
||||
//catch (Exception ex)
|
||||
//{
|
||||
// MessageBox.Show("Объекта нет");
|
||||
// _logger.LogWarning("Not input");
|
||||
//}
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Delete Object?", "Delete", MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
@ -143,24 +248,24 @@ namespace ProjectBoat_bae
|
||||
int pos = Convert.ToInt32(textBoxBoat.Text);
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
MessageBox.Show("Object deleted");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
_logger.LogInformation($"лодка удалена из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
_logger.LogInformation($"plane deleted in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Объект не удален");
|
||||
_logger.LogWarning($"лодка не удалена из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
MessageBox.Show("Object not deleted");
|
||||
_logger.LogWarning($"plane not deleted in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
catch (BoatNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"BoatNotFound: {ex.Message} in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
_logger.LogWarning($"PlaneNotFound: {ex.Message} in set {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Объекта нет");
|
||||
MessageBox.Show("Not input");
|
||||
_logger.LogWarning("Not input");
|
||||
}
|
||||
}
|
||||
@ -168,12 +273,23 @@ namespace ProjectBoat_bae
|
||||
// Обновление
|
||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||
{
|
||||
//if (listBoxStorages.SelectedIndex == -1)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
//string.Empty];
|
||||
//if (obj == null)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
//pictureBoxCollection.Image = obj.ShowBoats();
|
||||
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
|
||||
string.Empty];
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
@ -184,6 +300,8 @@ namespace ProjectBoat_bae
|
||||
//Выбор набора
|
||||
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
//pictureBoxCollection.Image =
|
||||
//_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats();
|
||||
pictureBoxCollection.Image =
|
||||
_storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowBoats();
|
||||
}
|
||||
@ -191,7 +309,7 @@ namespace ProjectBoat_bae
|
||||
//сохранение
|
||||
private void SaveToolStripMenu_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
@ -213,7 +331,7 @@ namespace ProjectBoat_bae
|
||||
private void LoadToolStripMenu_Click(object sender, EventArgs args)
|
||||
{
|
||||
|
||||
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
@ -229,5 +347,21 @@ namespace ProjectBoat_bae
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareBoats(new BoatCompareByType());
|
||||
|
||||
public void CompareBoats(IComparer<Drawningboat?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1) return;
|
||||
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null) return;
|
||||
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareBoats(new BoatCompareByColor());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ProjectBoat_bae.DrawningObjects;
|
||||
using ProjectBoat_bae.Entities;
|
||||
|
||||
namespace ProjectBoat_bae.Generics
|
||||
{
|
||||
internal class BoatCompareByColor : IComparer<Drawningboat?>
|
||||
{
|
||||
public int Compare(Drawningboat? x, Drawningboat? y)
|
||||
{
|
||||
|
||||
if (x == null || x.EntityBoat == null)
|
||||
throw new NotImplementedException(nameof(x));
|
||||
|
||||
if (y == null || y.EntityBoat == null)
|
||||
throw new NotImplementedException(nameof(y));
|
||||
|
||||
var bodyColor = x.EntityBoat.BodyColor.Name.CompareTo(y.EntityBoat.BodyColor.Name);
|
||||
|
||||
if (bodyColor != 0) return bodyColor;
|
||||
|
||||
if (x.EntityBoat is EntityMotorBoat &&
|
||||
y.EntityBoat is EntityMotorBoat)
|
||||
{
|
||||
var addcolor = (x.EntityBoat as EntityMotorBoat).AdditionalColor.Name.CompareTo((y.EntityBoat
|
||||
as EntityMotorBoat).AdditionalColor.Name);
|
||||
if (addcolor != 0) return addcolor;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ProjectBoat_bae.DrawningObjects;
|
||||
namespace ProjectBoat_bae.Generics
|
||||
{
|
||||
internal class BoatCompareByType : IComparer<Drawningboat?>
|
||||
{
|
||||
public int Compare(Drawningboat? x, Drawningboat? 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);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectBoat_bae.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)
|
||||
{
|
||||
if (Name != other?.Name)
|
||||
throw new NotImplementedException(nameof(Name));
|
||||
return true;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Name;
|
||||
}
|
||||
}
|
||||
}
|
@ -45,10 +45,11 @@ namespace ProjectBoat_bae.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (bool)collect._collection.Insert(obj);
|
||||
//return (bool)collect._collection.Insert(obj);
|
||||
return collect._collection.Insert(obj, new DrawingBoatEqutables());
|
||||
}
|
||||
|
||||
// Перегрузка оператора вычитания
|
||||
// Перегрузка оператора вычитанияreturn collect._collection.Insert(obj, new DrawingPlaneEqutables());
|
||||
public static T? operator -(BoatsGenericCollection<T, U> collect, int
|
||||
pos)
|
||||
{
|
||||
@ -111,5 +112,6 @@ namespace ProjectBoat_bae.Generics
|
||||
|
||||
// Получение объектов коллекции
|
||||
public IEnumerable<T?> GetBoats => _collection.GetBoats();
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,9 @@ namespace ProjectBoat_bae.Generics
|
||||
{
|
||||
internal class BoatsGenericStorage
|
||||
{
|
||||
//readonly Dictionary<string, BoatsGenericCollection<Drawningboat, DrawningObjectBoat>> _boatStorages;
|
||||
readonly Dictionary<string, BoatsGenericCollection<Drawningboat, DrawningObjectBoat>> _boatStorages;
|
||||
// public List<string> Keys => _boatStorages.Keys.ToList();
|
||||
public List<string> Keys => _boatStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
@ -27,6 +29,8 @@ namespace ProjectBoat_bae.Generics
|
||||
}
|
||||
public void AddSet(string name)
|
||||
{
|
||||
//if (_boatStorages.ContainsKey(name)) return;
|
||||
//_boatStorages[name] = new BoatsGenericCollection<Drawningboat, DrawningObjectBoat>(_pictureWidth, _pictureHeight);
|
||||
if (_boatStorages.ContainsKey(name)) return;
|
||||
_boatStorages[name] = new BoatsGenericCollection<Drawningboat, DrawningObjectBoat>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectBoat_bae.DrawningObjects;
|
||||
using ProjectBoat_bae.Entities;
|
||||
|
||||
namespace ProjectBoat_bae.Generics
|
||||
{
|
||||
internal class DrawingBoatEqutables : IEqualityComparer<Drawningboat?>
|
||||
{
|
||||
public bool Equals(Drawningboat? x, Drawningboat? 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.BodyColor != y.EntityBoat.BodyColor)
|
||||
return false;
|
||||
// to do logic for "сравнения" additional parameters :)
|
||||
if (x is DrawningMotorBoat && y is DrawningMotorBoat)
|
||||
{
|
||||
if ((x.EntityBoat as EntityMotorBoat).AdditionalColor != (y.EntityBoat as EntityMotorBoat).AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityBoat as EntityMotorBoat).Body != (y.EntityBoat as EntityMotorBoat).Body)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x.EntityBoat as EntityMotorBoat).Wing != (y.EntityBoat as EntityMotorBoat).Wing)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] Drawningboat obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,8 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ProjectBoat_bae.Exceptions;
|
||||
|
||||
namespace ProjectBoat_bae.Generics
|
||||
{
|
||||
internal class SetGeneric<T> where T : class
|
||||
@ -14,6 +16,8 @@ namespace ProjectBoat_bae.Generics
|
||||
// Максимальное количество объектов в списке
|
||||
private readonly int _maxCount;
|
||||
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
|
||||
// Конструктор
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
@ -21,27 +25,86 @@ namespace ProjectBoat_bae.Generics
|
||||
_places = new List<T?>(_maxCount);
|
||||
}
|
||||
|
||||
public bool Insert(T boat)
|
||||
//public bool Insert(T boat)
|
||||
//{
|
||||
// return Insert(boat, 0);
|
||||
//}
|
||||
//public bool Insert(T boat, int position)
|
||||
//{
|
||||
// if (position < 0 || position >= _maxCount)
|
||||
// return false;
|
||||
|
||||
// if (Count >= _maxCount)
|
||||
// return false;
|
||||
// _places.Insert(0, boat);
|
||||
// return true;
|
||||
//}
|
||||
public bool Insert(T boat, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var secondBoat in _places)
|
||||
{
|
||||
if (equal.Equals(boat, secondBoat))
|
||||
{
|
||||
throw new Exception("Такой объект уже есть в коллекции");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Insert(boat, 0);
|
||||
}
|
||||
public bool Insert(T boat, int position)
|
||||
public bool Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
return false;
|
||||
throw new StorageOverflowException("Impossible to insert");
|
||||
|
||||
if (Count >= _maxCount)
|
||||
return false;
|
||||
_places.Insert(0, boat);
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var secondBoat in _places)
|
||||
{
|
||||
if (equal.Equals(boat, secondBoat))
|
||||
{
|
||||
throw new ApplicationException("Такой объект уже есть в коллекции");
|
||||
}
|
||||
}
|
||||
}
|
||||
_places.Insert(position, boat);
|
||||
return true;
|
||||
}
|
||||
|
||||
//public bool Remove(int position)
|
||||
//{
|
||||
// if (position < 0 || position > _maxCount)
|
||||
// return false;
|
||||
// if (position >= Count)
|
||||
// return false;
|
||||
// _places.RemoveAt(position);
|
||||
// return true;
|
||||
//}
|
||||
//public T? this[int position]
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (position < 0 || position > _maxCount)
|
||||
// return null;
|
||||
// return _places[position];
|
||||
// }
|
||||
// set
|
||||
// {
|
||||
// if (position < 0 || position > _maxCount)
|
||||
// return;
|
||||
// _places[position] = value;
|
||||
// }
|
||||
//}
|
||||
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
return false;
|
||||
if (position >= Count)
|
||||
return false;
|
||||
if (position >= Count || position < 0)
|
||||
throw new BoatNotFoundException("Invalid operation");
|
||||
if (_places[position] == null)
|
||||
throw new BoatNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user