Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9908850f9 | ||
|
|
c7bd11dd18 | ||
|
|
5077f1ff45 | ||
|
|
12a157fa6d | ||
|
|
28ab4fd98f | ||
|
|
c010d1ece9 | ||
|
|
64dac95ddd | ||
|
|
f3fbf1e64f |
20
MotorBoat/MotorBoat/AppSetting.json
Normal file
20
MotorBoat/MotorBoat/AppSetting.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Serilog": {
|
||||
"Using": [ "Serilog.Sinks.File" ],
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss.fff}]{Level:u4}: {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
|
||||
"Properties": {
|
||||
"Application": "MotorBoat"
|
||||
}
|
||||
}
|
||||
}
|
||||
49
MotorBoat/MotorBoat/BoatCompareByColor.cs
Normal file
49
MotorBoat/MotorBoat/BoatCompareByColor.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.DrawningObjects;
|
||||
using MotorBoat.Entities;
|
||||
|
||||
namespace MotorBoat.Generics
|
||||
{
|
||||
internal class BoatCompareByColor : 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));
|
||||
}
|
||||
var bodyColorCompare = x.EntityBoat.BodyColor.Name.CompareTo(y.EntityBoat.BodyColor.Name);
|
||||
if (bodyColorCompare != 0)
|
||||
{
|
||||
return bodyColorCompare;
|
||||
}
|
||||
if (x.EntityBoat is EntityMotorBoat xEntityMotorBoat && y.EntityBoat is EntityMotorBoat yEntityMotorBoat)
|
||||
{
|
||||
var BodyColorCompare = xEntityMotorBoat.BodyColor.Name.CompareTo(yEntityMotorBoat.BodyColor.Name);
|
||||
if (BodyColorCompare != 0)
|
||||
{
|
||||
return BodyColorCompare;
|
||||
}
|
||||
var AdditionalColorCompare = xEntityMotorBoat.AdditionalColor.Name.CompareTo(yEntityMotorBoat.AdditionalColor.Name);
|
||||
if (AdditionalColorCompare != 0)
|
||||
{
|
||||
return AdditionalColorCompare;
|
||||
}
|
||||
}
|
||||
var speedCompare = x.EntityBoat.Speed.CompareTo(y.EntityBoat.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityBoat.Weight.CompareTo(y.EntityBoat.Weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
MotorBoat/MotorBoat/BoatCompareByType.cs
Normal file
34
MotorBoat/MotorBoat/BoatCompareByType.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.DrawningObjects;
|
||||
|
||||
namespace MotorBoat.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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MotorBoat.Generics
|
||||
{
|
||||
@@ -69,7 +71,8 @@ namespace MotorBoat.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (bool)collect?._collection.Insert(obj);
|
||||
return collect?._collection.Insert(obj, new DrawningBoatEqutables()) ?? false;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,14 +81,14 @@ namespace MotorBoat.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="pos"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator -(BoatsGenericCollection<T, U>? collect, int pos)
|
||||
public static T? operator -(BoatsGenericCollection<T, U>? collect, int pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
T? obj = collect?._collection[pos];
|
||||
if (obj != null && collect != null)
|
||||
{
|
||||
collect._collection.Remove(pos);
|
||||
}
|
||||
return false;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -148,5 +151,11 @@ namespace MotorBoat.Generics
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetBoats => _collection.GetBoats();
|
||||
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
|
||||
}
|
||||
}
|
||||
20
MotorBoat/MotorBoat/BoatNotFoundException.cs
Normal file
20
MotorBoat/MotorBoat/BoatNotFoundException.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.Exceptions
|
||||
{
|
||||
internal class BoatNotFoundException : ApplicationException
|
||||
{
|
||||
public BoatNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public BoatNotFoundException() : base() { }
|
||||
public BoatNotFoundException(string message) : base(message) { }
|
||||
public BoatNotFoundException(string message, Exception exception) : base(message, exception)
|
||||
{ }
|
||||
protected BoatNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
|
||||
}
|
||||
}
|
||||
30
MotorBoat/MotorBoat/BoatsCollectionInfo.cs
Normal file
30
MotorBoat/MotorBoat/BoatsCollectionInfo.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MotorBoat.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)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.DrawningObjects;
|
||||
using MotorBoat.MovementStrategy;
|
||||
using MotorBoat.Exceptions;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Numerics;
|
||||
|
||||
namespace MotorBoat.Generics
|
||||
{
|
||||
@@ -16,12 +19,27 @@ namespace MotorBoat.Generics
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, BoatsGenericCollection<DrawningBoat,DrawningObjectBoat>> _boatStorages;
|
||||
readonly Dictionary<BoatsCollectionInfo, BoatsGenericCollection<DrawningBoat,DrawningObjectBoat>> _boatStorages;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _boatStorages.Keys.ToList();
|
||||
public List<BoatsCollectionInfo> Keys => _boatStorages.Keys.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
@@ -40,7 +58,7 @@ namespace MotorBoat.Generics
|
||||
/// <param name="pictureHeight"></param>
|
||||
public BoatsGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_boatStorages = new Dictionary<string, BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>>();
|
||||
_boatStorages = new Dictionary<BoatsCollectionInfo, BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@@ -51,9 +69,9 @@ namespace MotorBoat.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_boatStorages.ContainsKey(name))
|
||||
return;
|
||||
_boatStorages[name] = new BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>(_pictureWidth, _pictureHeight);
|
||||
if (!_boatStorages.ContainsKey(new BoatsCollectionInfo(name, string.Empty)))
|
||||
_boatStorages.Add(new BoatsCollectionInfo(name, string.Empty),
|
||||
new BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -62,9 +80,8 @@ namespace MotorBoat.Generics
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_boatStorages.ContainsKey(name))
|
||||
return;
|
||||
_boatStorages.Remove(name);
|
||||
if (_boatStorages.ContainsKey(new BoatsCollectionInfo(name, string.Empty)))
|
||||
_boatStorages.Remove(new BoatsCollectionInfo(name, string.Empty));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -72,15 +89,114 @@ namespace MotorBoat.Generics
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>?
|
||||
this[string ind]
|
||||
public BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_boatStorages.ContainsKey(ind))
|
||||
return _boatStorages[ind];
|
||||
if (_boatStorages.ContainsKey(new BoatsCollectionInfo(ind, string.Empty)))
|
||||
return _boatStorages[new BoatsCollectionInfo(ind, string.Empty)];
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по лодкам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<BoatsCollectionInfo, BoatsGenericCollection<DrawningBoat, DrawningObjectBoat>> record in _boatStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningBoat? elem in record.Value.GetBoats)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
|
||||
if (data.Length == 0) {
|
||||
throw new InvalidOperationException("Невалидная операция, нет данных для сохранения");
|
||||
}
|
||||
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write($"BoatStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Загрузка информации по лодкам в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
throw new FileNotFoundException($"Файл {filename} не найден");
|
||||
}
|
||||
|
||||
using (StreamReader fs = File.OpenText(filename))
|
||||
{
|
||||
string str = fs.ReadLine();
|
||||
if (str == null || str.Length == 0)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
if (!str.StartsWith("BoatStorage"))
|
||||
{
|
||||
// если нет такой записи,то это не те данные
|
||||
throw new FormatException("Неверный формат данных");
|
||||
}
|
||||
|
||||
_boatStorages.Clear();
|
||||
string strs = "";
|
||||
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
if (strs == null)
|
||||
{
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
}
|
||||
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
BoatsGenericCollection<DrawningBoat, DrawningObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
DrawningBoat? boat = elem?.CreateDrawningBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (boat != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
_ = collection + boat;
|
||||
}
|
||||
catch (BoatNotFoundException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
|
||||
catch (StorageOverflowException e)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
_boatStorages.Add(new BoatsCollectionInfo(record[0], string.Empty), collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -210,5 +210,11 @@ namespace MotorBoat.DrawningObjects
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangePictureBoxSize(int pictureBoxWidth, int pictureBoxHeight)
|
||||
{
|
||||
_pictureWidth = pictureBoxWidth;
|
||||
_pictureHeight = pictureBoxHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
MotorBoat/MotorBoat/DrawningShipEqutables.cs
Normal file
60
MotorBoat/MotorBoat/DrawningShipEqutables.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.DrawningObjects;
|
||||
using MotorBoat.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace MotorBoat.Generics
|
||||
{
|
||||
internal class DrawningBoatEqutables : 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;
|
||||
}
|
||||
if (x is DrawningMotorBoat && y is DrawningMotorBoat)
|
||||
{
|
||||
EntityMotorBoat EntityX = (EntityMotorBoat)x.EntityBoat;
|
||||
EntityMotorBoat EntityY = (EntityMotorBoat)y.EntityBoat;
|
||||
|
||||
if (EntityX.Glass != EntityY.Glass)
|
||||
return false;
|
||||
if (EntityX.Engine != EntityY.Engine)
|
||||
return false;
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningBoat obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
67
MotorBoat/MotorBoat/ExtentionDrawningBoat.cs
Normal file
67
MotorBoat/MotorBoat/ExtentionDrawningBoat.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.Entities;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace MotorBoat.DrawningObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Расширение для класса EntityBoat
|
||||
/// </summary>
|
||||
public static class ExtentionDrawningBoat
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningBoat? CreateDrawningBoat(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawningBoat(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawningMotorBoat(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]),
|
||||
Color.FromName(strs[2]),
|
||||
Color.FromName(strs[3]),
|
||||
Convert.ToBoolean(strs[4]),
|
||||
Convert.ToBoolean(strs[5]), width, height);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningBoat">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawningBoat drawningBoat,
|
||||
char separatorForObject)
|
||||
{
|
||||
var boat = drawningBoat.EntityBoat;
|
||||
if (boat == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{boat.Speed}{separatorForObject}{boat.Weight}{separatorForObject}{boat.BodyColor.Name}";
|
||||
|
||||
if (boat is not EntityMotorBoat motorBoat)
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{motorBoat.AdditionalColor.Name}" +
|
||||
$"{separatorForObject}{motorBoat.Glass}{separatorForObject}{motorBoat.Engine}{separatorForObject}";
|
||||
}
|
||||
}
|
||||
}
|
||||
103
MotorBoat/MotorBoat/FormBoatCollection.Designer.cs
generated
103
MotorBoat/MotorBoat/FormBoatCollection.Designer.cs
generated
@@ -34,35 +34,44 @@
|
||||
ButtonRemoveBoat = new Button();
|
||||
ButtonRefreshCollection = new Button();
|
||||
groupBoxTools = new GroupBox();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
groupBoxCollections = new GroupBox();
|
||||
ButtonRemoveObject = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
ButtonAddObject = new Button();
|
||||
textBoxStorageName = new MaskedTextBox();
|
||||
menuStrip1 = new MenuStrip();
|
||||
FileToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
groupBoxTools.SuspendLayout();
|
||||
groupBoxCollections.SuspendLayout();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Dock = DockStyle.Left;
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Location = new Point(0, 24);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(578, 500);
|
||||
pictureBoxCollection.Size = new Size(578, 576);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(51, 371);
|
||||
maskedTextBoxNumber.Location = new Point(51, 454);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(100, 23);
|
||||
maskedTextBoxNumber.TabIndex = 0;
|
||||
//
|
||||
// ButtonAddBoat
|
||||
//
|
||||
ButtonAddBoat.Location = new Point(6, 325);
|
||||
ButtonAddBoat.Location = new Point(6, 408);
|
||||
ButtonAddBoat.Name = "ButtonAddBoat";
|
||||
ButtonAddBoat.Size = new Size(188, 40);
|
||||
ButtonAddBoat.TabIndex = 1;
|
||||
@@ -72,7 +81,7 @@
|
||||
//
|
||||
// ButtonRemoveBoat
|
||||
//
|
||||
ButtonRemoveBoat.Location = new Point(6, 407);
|
||||
ButtonRemoveBoat.Location = new Point(6, 490);
|
||||
ButtonRemoveBoat.Name = "ButtonRemoveBoat";
|
||||
ButtonRemoveBoat.Size = new Size(188, 41);
|
||||
ButtonRemoveBoat.TabIndex = 2;
|
||||
@@ -82,7 +91,7 @@
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(6, 454);
|
||||
ButtonRefreshCollection.Location = new Point(6, 537);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(188, 39);
|
||||
ButtonRefreshCollection.TabIndex = 3;
|
||||
@@ -92,19 +101,41 @@
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonSortByType);
|
||||
groupBoxTools.Controls.Add(buttonSortByColor);
|
||||
groupBoxTools.Controls.Add(groupBoxCollections);
|
||||
groupBoxTools.Controls.Add(ButtonRefreshCollection);
|
||||
groupBoxTools.Controls.Add(ButtonRemoveBoat);
|
||||
groupBoxTools.Controls.Add(ButtonAddBoat);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxNumber);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(584, 0);
|
||||
groupBoxTools.Location = new Point(584, 24);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(200, 500);
|
||||
groupBoxTools.Size = new Size(200, 576);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Location = new Point(12, 339);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(176, 29);
|
||||
buttonSortByType.TabIndex = 6;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Location = new Point(12, 304);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(176, 29);
|
||||
buttonSortByColor.TabIndex = 5;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||
//
|
||||
// groupBoxCollections
|
||||
//
|
||||
groupBoxCollections.Controls.Add(ButtonRemoveObject);
|
||||
@@ -136,7 +167,7 @@
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(176, 109);
|
||||
listBoxStorages.TabIndex = 2;
|
||||
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||
listBoxStorages.SelectedIndexChanged += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonAddObject
|
||||
//
|
||||
@@ -155,13 +186,54 @@
|
||||
textBoxStorageName.Size = new Size(176, 23);
|
||||
textBoxStorageName.TabIndex = 0;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(784, 24);
|
||||
menuStrip1.TabIndex = 2;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// FileToolStripMenuItem
|
||||
//
|
||||
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||
FileToolStripMenuItem.Size = new Size(48, 20);
|
||||
FileToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.Size = new Size(141, 22);
|
||||
SaveToolStripMenuItem.Text = "Сохранение";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// LoadToolStripMenuItem
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.Size = new Size(141, 22);
|
||||
LoadToolStripMenuItem.Text = "Загрузка";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "openFileDialog1";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormBoatCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(784, 500);
|
||||
ClientSize = new Size(784, 600);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(menuStrip1);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Name = "FormBoatCollection";
|
||||
Text = "Набор лодок";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
@@ -169,7 +241,10 @@
|
||||
groupBoxTools.PerformLayout();
|
||||
groupBoxCollections.ResumeLayout(false);
|
||||
groupBoxCollections.PerformLayout();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -185,5 +260,13 @@
|
||||
private ListBox listBoxStorages;
|
||||
private Button ButtonAddObject;
|
||||
private MaskedTextBox textBoxStorageName;
|
||||
private MenuStrip menuStrip1;
|
||||
private ToolStripMenuItem FileToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,9 @@ using System.Windows.Forms;
|
||||
using MotorBoat.DrawningObjects;
|
||||
using MotorBoat.Generics;
|
||||
using MotorBoat.MovementStrategy;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MotorBoat.Exceptions;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
@@ -23,13 +26,18 @@ namespace MotorBoat
|
||||
/// </summary>
|
||||
private readonly BoatsGenericStorage _storage;
|
||||
|
||||
/// Логер
|
||||
/// </summary>
|
||||
private readonly ILogger _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormBoatCollection()
|
||||
public FormBoatCollection(ILogger<FormBoatCollection> logger)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storage = new BoatsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -41,7 +49,7 @@ namespace MotorBoat
|
||||
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))
|
||||
{
|
||||
@@ -62,12 +70,12 @@ namespace MotorBoat
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||
{
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_storage.AddSet(textBoxStorageName.Text);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,13 +98,18 @@ namespace MotorBoat
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
string nameSet = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||
if (MessageBox.Show($"Удалить объект {nameSet}?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||
_storage.DelSet(nameSet);
|
||||
ReloadObjects();
|
||||
_logger.LogInformation($"Удален набор: {nameSet}");
|
||||
}
|
||||
_logger.LogWarning("Отмена удаления набора");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -107,7 +120,10 @@ namespace MotorBoat
|
||||
private void ButtonAddBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
|
||||
@@ -127,16 +143,30 @@ namespace MotorBoat
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
|
||||
if (obj == null)
|
||||
{
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
|
||||
if (obj + drawningBoat)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
else
|
||||
|
||||
try
|
||||
{
|
||||
if (obj + drawningBoat)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
||||
}
|
||||
}
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Не удалось добавить объект: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,27 +178,46 @@ namespace MotorBoat
|
||||
private void ButtonRemoveBoat_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
_logger.LogWarning("Удаление объекта из несуществующего набора");
|
||||
return;
|
||||
}
|
||||
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
|
||||
if (obj == null)
|
||||
return;
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
_logger.LogWarning("Отмена удаления объекта");
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||
if (obj - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
if (obj - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
_logger.LogInformation($"Удален объект из коллекции {listBoxStorages.SelectedItem.ToString() ?? string.Empty} по номеру {pos}");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
_logger.LogWarning($"Не удалось удалить объект из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (BoatNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show(ex.Message);
|
||||
_logger.LogWarning($"Нет объекта{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
_logger.LogWarning($"Было введено не число");
|
||||
MessageBox.Show("Введите число");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,5 +238,71 @@ namespace MotorBoat
|
||||
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Данные загружены в файл {saveFileDialog.FileName}");
|
||||
}
|
||||
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogWarning($"Не удалось сохранить информацию в файл: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
{
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogInformation($"Данные загружены из файла {openFileDialog.FileName}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_logger.LogWarning($"Не удалось загрузить информацию из файла: {ex.Message}");
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e) => CompareBoats(new BoatCompareByType());
|
||||
private void buttonSortByType_Click(object sender, EventArgs e) => CompareBoats(new BoatCompareByColor());
|
||||
private 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,16 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>272, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>39</value>
|
||||
</metadata>
|
||||
</root>
|
||||
8
MotorBoat/MotorBoat/FormBoatConfig.Designer.cs
generated
8
MotorBoat/MotorBoat/FormBoatConfig.Designer.cs
generated
@@ -218,9 +218,9 @@
|
||||
checkBoxEngine.AutoSize = true;
|
||||
checkBoxEngine.Location = new Point(11, 126);
|
||||
checkBoxEngine.Name = "checkBoxEngine";
|
||||
checkBoxEngine.Size = new Size(225, 19);
|
||||
checkBoxEngine.Size = new Size(180, 19);
|
||||
checkBoxEngine.TabIndex = 7;
|
||||
checkBoxEngine.Text = "Признак наличия защитного стекла";
|
||||
checkBoxEngine.Text = "Признак наличия двигателя";
|
||||
checkBoxEngine.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// checkBoxGlass
|
||||
@@ -228,9 +228,9 @@
|
||||
checkBoxGlass.AutoSize = true;
|
||||
checkBoxGlass.Location = new Point(11, 99);
|
||||
checkBoxGlass.Name = "checkBoxGlass";
|
||||
checkBoxGlass.Size = new Size(180, 19);
|
||||
checkBoxGlass.Size = new Size(225, 19);
|
||||
checkBoxGlass.TabIndex = 6;
|
||||
checkBoxGlass.Text = "Признак наличия двигателя";
|
||||
checkBoxGlass.Text = "Признак наличия защитного стекла";
|
||||
checkBoxGlass.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// label2
|
||||
|
||||
@@ -92,12 +92,12 @@ namespace MotorBoat
|
||||
{
|
||||
case "labelSimpleObject":
|
||||
_boat = new DrawningBoat((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
(int)numericUpDownWeight.Value, Color.White, 900, 500);
|
||||
break;
|
||||
case "labelModifiedObject":
|
||||
_boat = new DrawningMotorBoat((int)numericUpDownSpeed.Value,
|
||||
(int)numericUpDownWeight.Value, Color.White, Color.Black, checkBoxGlass.Checked,
|
||||
checkBoxEngine.Checked, pictureBoxObject.Width, pictureBoxObject.Height);
|
||||
checkBoxEngine.Checked, 900, 500);
|
||||
break;
|
||||
}
|
||||
DrawBoat();
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace MotorBoat
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public DrawningBoat? SelectedBoat { get; private set; }
|
||||
public DrawningBoat? SelectedBoat { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
@@ -8,6 +8,19 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.3.7" />
|
||||
<PackageReference Include="Serilog" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Properties\Resources.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace MotorBoat
|
||||
{
|
||||
internal static class Program
|
||||
@@ -11,7 +16,30 @@ namespace MotorBoat
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormBoatCollection());
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
using (ServiceProvider serviceProvider = services.BuildServiceProvider())
|
||||
{
|
||||
Application.Run(serviceProvider.GetRequiredService<FormBoatCollection>());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<FormBoatCollection>().AddLogging(option =>
|
||||
{
|
||||
string[] path = Directory.GetCurrentDirectory().Split('\\');
|
||||
string pathNeed = "";
|
||||
for (int i = 0; i < path.Length - 3; i++)
|
||||
{
|
||||
pathNeed += path[i] + "\\";
|
||||
}
|
||||
var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile(path: $"{pathNeed}appSetting.json", optional: false, reloadOnChange: true).Build();
|
||||
var logger = new LoggerConfiguration().ReadFrom.Configuration(configuration).CreateLogger();
|
||||
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddSerilog(logger);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MotorBoat.Exceptions;
|
||||
|
||||
namespace MotorBoat.Generics
|
||||
{
|
||||
@@ -32,10 +33,12 @@ namespace MotorBoat.Generics
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="count"></param>
|
||||
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
_places = new List<T?>(_maxCount);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -43,14 +46,9 @@ namespace MotorBoat.Generics
|
||||
/// </summary>
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat)
|
||||
public bool Insert(T boat, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Insert(boat, 0);
|
||||
return true;
|
||||
return Insert(boat, 0, equal);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@@ -58,13 +56,18 @@ namespace MotorBoat.Generics
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat, int position)
|
||||
public bool Insert(T boat, int position, IEqualityComparer<T>? equal = null)
|
||||
{
|
||||
if(!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_places.Insert(position, boat);
|
||||
if (position < 0 || position >= _maxCount)
|
||||
throw new BoatNotFoundException(position);
|
||||
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
if (equal != null && _places.Contains(boat, equal))
|
||||
throw new ArgumentException("Данный объект уже есть в коллекции");
|
||||
|
||||
_places.Insert(0, boat);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -75,7 +78,8 @@ namespace MotorBoat.Generics
|
||||
/// <returns></returns>
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (position < 0 || position >= Count) return false;
|
||||
if (position < 0 || position > _maxCount || position >= Count)
|
||||
throw new BoatNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
@@ -88,27 +92,26 @@ namespace MotorBoat.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (position < 0 || position > _maxCount)
|
||||
if (position < 0 || position >= Count)
|
||||
return null;
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||
if (position < 0 || position > _maxCount || Count == _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Insert(position, value);
|
||||
return;
|
||||
_places[position] = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <param name="maxShips"></param>
|
||||
/// <param name="maxBoats"></param>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> GetBoats(int? maxBoats = null)
|
||||
public IEnumerable<T> GetBoats(int? maxBoats = null)
|
||||
{
|
||||
for (int i = 0; i < _places.Count; ++i)
|
||||
{
|
||||
|
||||
18
MotorBoat/MotorBoat/StorageOverflowException.cs
Normal file
18
MotorBoat/MotorBoat/StorageOverflowException.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace MotorBoat.Exceptions
|
||||
{
|
||||
internal class StorageOverflowException : ApplicationException
|
||||
{
|
||||
public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { }
|
||||
public StorageOverflowException() : base() { }
|
||||
public StorageOverflowException(string message) : base(message) { }
|
||||
public StorageOverflowException(string message, Exception exception) : base(message, exception) { }
|
||||
protected StorageOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user