From 8a3e041126ce48dba51abe9ef99cfceb0226e83f Mon Sep 17 00:00:00 2001 From: Pyro <732603@gmail.com> Date: Mon, 17 Jun 2024 00:15:50 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=966?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 12 +-- .../BoatHarborService.cs | 21 ++-- .../ICollectionGenericObjects.cs | 6 +- .../ListGenericObjects.cs | 47 ++++---- .../MassiveGenericObjects.cs | 47 ++++---- .../StorageCollection.cs | 50 +++++---- .../Exceptions/CollectionOverflowException.cs | 20 ---- .../Exceptions/ObjectNotFoundException.cs | 20 ---- .../PositionOutOfCollectionException.cs | 20 ---- .../FormBoatCollection.Designer.cs | 16 +-- .../ProjectMotorBoat/FormBoatCollection.cs | 102 ++++++------------ ProjectMotorBoat/ProjectMotorBoat/Program.cs | 29 +---- .../ProjectMotorBoat/ProjectMotorBoat.csproj | 10 -- ProjectMotorBoat/ProjectMotorBoat/save.txt | 2 - 14 files changed, 133 insertions(+), 269 deletions(-) delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs delete mode 100644 ProjectMotorBoat/ProjectMotorBoat/save.txt diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs index 524d736..5a87d1f 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/AbstractCompany.cs @@ -10,7 +10,7 @@ public abstract class AbstractCompany /// /// Размер места (ширина) /// - protected readonly int _placeSizeWidth = 126; + protected readonly int _placeSizeWidth = 120; /// /// Размер места (высота) @@ -35,7 +35,7 @@ public abstract class AbstractCompany /// /// Вычисление максимального количества элементов, который можно разместить в окне /// - private int GetMaxCount => (_pictureWidth * _pictureHeight) / (_placeSizeWidth * _placeSizeHeight); + private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); /// /// Конструктор @@ -96,12 +96,8 @@ public abstract class AbstractCompany SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { - try - { - DrawingBoat? obj = _collection?.Get(i); - obj?.DrawTransport(graphics); - } - catch (Exception) { } + DrawingBoat? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); } return bitmap; diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs index 58ee77b..0854001 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/BoatHarborService.cs @@ -1,6 +1,5 @@ using ProjectMotorBoat.Drawings; using ProjectMotorBoat.Entities; -using ProjectMotorBoat.Exceptions; using System.Drawing; namespace ProjectMotorBoat.CollectionGenericObjects; @@ -25,9 +24,9 @@ public class BoatHarborService : AbstractCompany { Pen pen = new(Color.BurlyWood, 4); - for (int startPosX = 0; (startPosX + _placeSizeWidth) < _pictureWidth; startPosX += _placeSizeWidth) + for (int startPosX = 5; (startPosX + _placeSizeWidth) < _pictureWidth; startPosX += _placeSizeWidth) { - for (int startPosY = 0; (startPosY + _placeSizeHeight) < _pictureHeight; startPosY += _placeSizeHeight) + for (int startPosY = 5; (startPosY + _placeSizeHeight) < _pictureHeight; startPosY += _placeSizeHeight) { Point[] points = { @@ -43,23 +42,19 @@ public class BoatHarborService : AbstractCompany protected override void SetObjectsPosition() { - int startPosX = 5; - int startPosY = 5; + int startPosX = 10; + int startPosY = 10; - for (int i = 0; i < (_collection?.Count ?? 0); i++) + for (int i = 0; _collection?.Get(i) != null; i++) { if (startPosX + _placeSizeWidth > _pictureWidth) { - startPosX = 5; + startPosX = 10; startPosY += _placeSizeHeight; } - try - { - _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); - _collection.Get(i).SetPosition(startPosX, startPosY); - } - catch (Exception) { } + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(startPosX, startPosY); startPosX += _placeSizeWidth; } diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs index 329018d..b405892 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -21,7 +21,7 @@ public interface ICollectionGenericObjects /// Добавление объекта в коллекцию /// /// Добавляемый объект - /// Count - вставка прошла удачно, -1 - вставка не удалась + /// true - вставка прошла удачно, false - вставка не удалась int Insert(T obj); /// @@ -29,14 +29,14 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// Позиция - /// Count - вставка прошла удачно, -1 - вставка не удалась + /// true - вставка прошла удачно, false - вставка не удалась int Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция - /// Объект + /// true - удаление прошло удачно, false - удаление не удалось T? Remove(int position); /// diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs index ff3e277..f815ab9 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/ListGenericObjects.cs @@ -1,6 +1,4 @@ -using ProjectMotorBoat.Exceptions; - -namespace ProjectMotorBoat.CollectionGenericObjects; +namespace ProjectMotorBoat.CollectionGenericObjects; /// /// Параметризованный набор объектов @@ -41,41 +39,46 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { - // выброс ошибки, если выход за границы массива - if (position < 0 || position > _collection.Count) throw new PositionOutOfCollectionException(position); - return _collection[position]; + if (position < Count && _collection[position] != null) + { + return _collection[position]; + } + return null; } public int Insert(T obj) { - // выброс ошибки, если переполнение - if (Count >= _maxCount) throw new CollectionOverflowException(Count); - _collection.Add(obj); - return _collection.Count; + if (Count < _maxCount) + { + _collection.Add(obj); + return _collection.Count; + } + return -1; } public int Insert(T obj, int position) { - // выброс ошибки, если переполнение - if (Count >= _maxCount) throw new CollectionOverflowException(); - - if (_collection[position] == null) + if (Count < _maxCount) { - _collection.Insert(position, obj); - return position; + if (_collection[position] == null) + { + _collection.Insert(position, obj); + return position; + } } return -1; } public T? Remove(int position) { - // выброс ошибки, если выход за границы массива - if (position < 0 || position > _collection.Count) throw new PositionOutOfCollectionException(position); - if (_collection[position] != null) + if (Count < _maxCount) { - T? obj = _collection[position]; - _collection.RemoveAt(position); - return obj; + if (_collection[position] != null) + { + T? obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } } return null; } diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs index a0ca361..27cc790 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,6 +1,4 @@ -using ProjectMotorBoat.Exceptions; - -namespace ProjectMotorBoat.CollectionGenericObjects; +namespace ProjectMotorBoat.CollectionGenericObjects; /// /// Параметризованный набор объектов @@ -50,12 +48,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - // выброс ошибки, если выход за границы массива - if (position >= Count) throw new PositionOutOfCollectionException(position); - // выброс ошибки, если объект пустой - if (_collection[position] == null) throw new ObjectNotFoundException(position); - - return _collection[position]; + // проверка позиции ✔ + if (_collection[position] != null && position < Count - 1) + { + return _collection[position]; + } + return null; } public int Insert(T obj) @@ -69,15 +67,16 @@ public class MassiveGenericObjects : ICollectionGenericObjects return Count; } } - // выброс ошибки, если переполнение - throw new CollectionOverflowException(Count); + return -1; } public int Insert(T obj, int position) { - // выброс ошибки, если выход за границы массива - if (position >= Count) throw new PositionOutOfCollectionException(position); - + // проверка позиции ✔ + // проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до ✔ + // вставка ✔ if (_collection[position] != null) { for (int i = position; i < Count; i++) @@ -98,20 +97,22 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } } - // выброс ошибки, если переполнение - throw new CollectionOverflowException(Count); + + return -1; } public T? Remove(int position) { - // выброс ошибки, если выход за границы массива - if (position >= Count) throw new PositionOutOfCollectionException(position); - // выброс ошибки, если объект пустой - if (_collection[position] == null) throw new ObjectNotFoundException(position); + // проверка позиции ✔ + // удаление объекта из массива, присвоив элементу массива значение null ✔ + if (_collection[position] != null) + { + T? obj = _collection[position]; + _collection[position] = null; + return obj; + } - T? obj = _collection[position]; - _collection[position] = null; - return obj; + return null; } public IEnumerable GetItems() diff --git a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs index 58cdd3e..8555feb 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/CollectionGenericObjects/StorageCollection.cs @@ -1,5 +1,4 @@ using ProjectMotorBoat.Drawings; -using ProjectMotorBoat.Exceptions; using ProjectMotorBoat.MovementStrategy; using System.Text; using System.Windows.Forms; @@ -108,7 +107,7 @@ public class StorageCollection { if (_storages.Count == 0) { - throw new Exception("В хранилище отсутствуют коллекции для сохранения"); + return false; } if (File.Exists(filename)) @@ -172,11 +171,16 @@ public class StorageCollection return false; } - if (!str.Equals(_collectionKey)) - { - // Если нет такой записи, то это не те данные - return false; - } + string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + if (strs == null || strs.Length == 0) + { + throw new Exception("В файле нет данных"); + } + + if (!strs[0].Equals(_collectionKey)) + { + throw new Exception("В файле неверные данные"); + } _storages.Clear(); string data = ""; @@ -188,31 +192,31 @@ public class StorageCollection continue; } - CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); - ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); - if (collection == null) - { - return false; - } + CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType) ?? + throw new Exception("Не удалось определить тип коллекции:" + record[1]); + collection.MaxCount = Convert.ToInt32(record[2]); - collection.MaxCount = Convert.ToInt32(record[2]); - - string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawingBoat() is T boat) { - if (elem?.CreateDrawingBoat() is T boat) + try { - if (collection.Insert(boat) == 0) + if (collection.Insert(boat) == -1) { - return false; + throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); } } + catch (CollectionOverflowException ex) + { + throw new Exception("Коллекция переполнена", ex); + } } - - _storages.Add(record[0], collection); } + _storages.Add(record[0], collection); } - return true; } /// diff --git a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs b/ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs deleted file mode 100644 index 25aa59b..0000000 --- a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/CollectionOverflowException.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Runtime.Serialization; - -namespace ProjectMotorBoat.Exceptions; - -/// -/// Класс, описывающий ошибку переполнения коллекции -/// -[Serializable] -internal class CollectionOverflowException : ApplicationException -{ - public CollectionOverflowException(int count) : base("В коллекции превышено допустимое количество: " + count) { } - - public CollectionOverflowException() : base() { } - - public CollectionOverflowException(string message) : base(message) { } - - public CollectionOverflowException(string message, Exception exception) : base(message, exception) { } - - protected CollectionOverflowException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } -} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs b/ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs deleted file mode 100644 index d4bdf6d..0000000 --- a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/ObjectNotFoundException.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Runtime.Serialization; - -namespace ProjectMotorBoat.Exceptions; - -/// -/// Класс, описывающий ошибку, что по указанной позиции нет элемента -/// -[Serializable] -internal class ObjectNotFoundException : ApplicationException -{ - public ObjectNotFoundException(int i) : base("Не найден объект по позиции " + i) { } - - public ObjectNotFoundException() : base() { } - - public ObjectNotFoundException(string message) : base(message) { } - - public ObjectNotFoundException(string message, Exception exception) : base(message, exception) { } - - protected ObjectNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } -} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs b/ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs deleted file mode 100644 index 7bbfa51..0000000 --- a/ProjectMotorBoat/ProjectMotorBoat/Exceptions/PositionOutOfCollectionException.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Runtime.Serialization; - -namespace ProjectMotorBoat.Exceptions; - -/// -/// Класс, описывающий ошибку выхода за границы коллекции -/// -[Serializable] -internal class PositionOutOfCollectionException : ApplicationException -{ - public PositionOutOfCollectionException(int i) : base("Выход за границы коллекции. Позиция " + i) { } - - public PositionOutOfCollectionException() : base() { } - - public PositionOutOfCollectionException(string message) : base(message) { } - - public PositionOutOfCollectionException(string message, Exception exception) : base(message, exception) { } - - protected PositionOutOfCollectionException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } -} \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs index f6297f9..fcf7995 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.Designer.cs @@ -66,9 +66,9 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(763, 24); + groupBoxTools.Location = new Point(777, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(201, 544); + groupBoxTools.Size = new Size(201, 561); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -82,15 +82,15 @@ panelCompanyTools.Controls.Add(buttonRemoveBoat); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 322); + panelCompanyTools.Location = new Point(3, 329); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(195, 219); + panelCompanyTools.Size = new Size(195, 229); panelCompanyTools.TabIndex = 8; // // buttonAddBoat // buttonAddBoat.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBoat.Location = new Point(3, 3); + buttonAddBoat.Location = new Point(3, 4); buttonAddBoat.Name = "buttonAddBoat"; buttonAddBoat.Size = new Size(184, 32); buttonAddBoat.TabIndex = 1; @@ -249,7 +249,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(763, 544); + pictureBox.Size = new Size(777, 561); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -258,7 +258,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(964, 24); + menuStrip.Size = new Size(978, 24); menuStrip.TabIndex = 2; menuStrip.Text = "menuStrip1"; // @@ -297,7 +297,7 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(964, 568); + ClientSize = new Size(978, 585); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); diff --git a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs index 525a334..a830c41 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/FormBoatCollection.cs @@ -1,5 +1,4 @@ -using Microsoft.Extensions.Logging; -using ProjectMotorBoat.CollectionGenericObjects; +using ProjectMotorBoat.CollectionGenericObjects; using ProjectMotorBoat.Drawings; namespace ProjectMotorBoat; @@ -19,19 +18,13 @@ public partial class FormBoatCollection : Form /// private AbstractCompany? _company = null; - /// - /// Логер - /// - private readonly ILogger _logger; - /// /// Конструктор /// - public FormBoatCollection(ILogger logger) + public FormBoatCollection() { InitializeComponent(); _storageCollection = new(); - _logger = logger; } /// @@ -68,19 +61,14 @@ public partial class FormBoatCollection : Form return; } - try + if (_company + boat >= 0) { - if (_company + boat >= 0) - { - MessageBox.Show("Объект добавлен"); - _logger.LogInformation("Добавлен объект: {boat}", boat.GetDataForSave()); - pictureBox.Image = _company.Show(); - } + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); } - catch (Exception ex) + else { - MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogError("Ошибка: {Message}", ex.Message); + MessageBox.Show("Не удалось добавить объект"); } } @@ -102,20 +90,14 @@ public partial class FormBoatCollection : Form } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - - try + if (_company - pos != null) { - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - _logger.LogInformation("Удалён объект по позиции: {pos}", pos); - pictureBox.Image = _company.Show(); - } + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); } - catch (Exception ex) + else { - MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogError("Ошибка: {Message}", ex.Message); + MessageBox.Show("Не удалось удалить объект"); } } @@ -133,33 +115,26 @@ public partial class FormBoatCollection : Form DrawingBoat? boat = null; int counter = 100; - try + while (boat == null) { - while (boat == null) + boat = _company.GetRandomObject(); + counter--; + if (counter <= 0) { - boat = _company.GetRandomObject(); - counter--; - if (counter <= 0) - { - break; - } + break; } - - if (boat == null) - { - return; - } - - FormMotorBoat form = new() - { - SetBoat = boat - }; - form.ShowDialog(); } - catch (Exception ex) + + if (boat == null) { - _logger.LogError("Ошибка: {Message}", ex.Message); + return; } + + FormMotorBoat form = new() + { + SetBoat = boat + }; + form.ShowDialog(); } /// @@ -201,7 +176,6 @@ public partial class FormBoatCollection : Form } _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); - _logger.LogInformation("Добавлена коллекция: {collection} Типа: {type}", textBoxCollectionName.Text, collectionType.ToString()); RerfreshListBoxItems(); } @@ -221,11 +195,8 @@ public partial class FormBoatCollection : Form return; } if (_storageCollection.Keys.Contains(listBoxCollection.SelectedItem.ToString() ?? string.Empty)) - { _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString() ?? string.Empty); - } - _logger.LogInformation("Удалена коллекция: {collection}", listBoxCollection.SelectedItem.ToString()); RerfreshListBoxItems(); } @@ -270,7 +241,6 @@ public partial class FormBoatCollection : Form { case "Хранилище": _company = new BoatHarborService(pictureBox.Width, pictureBox.Height, collection); - _logger.LogInformation("Создана компания на коллекции: {collection}", listBoxCollection.SelectedItem.ToString()); break; } @@ -287,16 +257,13 @@ public partial class FormBoatCollection : Form { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - try + if (_storageCollection.SaveData(saveFileDialog.FileName)) { - _storageCollection.SaveData(saveFileDialog.FileName); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogInformation("Сохранение в файл: {filename}", saveFileDialog.FileName); } - catch (Exception ex) + else { - MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogError("Ошибка: {Message}", ex.Message); + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } @@ -308,21 +275,18 @@ public partial class FormBoatCollection : Form /// private void LoadToolStripMenuItem_Click(object sender, EventArgs e) { + // TODO продумать логику if (openFileDialog.ShowDialog() == DialogResult.OK) { - try + if (_storageCollection.LoadData(openFileDialog.FileName)) { - _storageCollection.LoadData(openFileDialog.FileName); RerfreshListBoxItems(); MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - _logger.LogInformation("Загрузка из файла: {filename}", openFileDialog.FileName); } - catch (Exception ex) + else { - MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - _logger.LogError("Ошибка: {Message}", ex.Message); + MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } - } } } diff --git a/ProjectMotorBoat/ProjectMotorBoat/Program.cs b/ProjectMotorBoat/ProjectMotorBoat/Program.cs index 843a24c..bcbd11e 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/Program.cs +++ b/ProjectMotorBoat/ProjectMotorBoat/Program.cs @@ -1,7 +1,3 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Serilog; - namespace ProjectMotorBoat { internal static class Program @@ -15,30 +11,7 @@ namespace ProjectMotorBoat // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Information() - .WriteTo.File("boatlog-.log", rollingInterval: RollingInterval.Day) - .CreateLogger(); - - ServiceCollection services = new(); - ConfigureServices(services); - using ServiceProvider serviceProvider = services.BuildServiceProvider(); - Application.Run(serviceProvider.GetRequiredService()); - } - - /// - /// Конфигурация сервиса DI - /// - /// - private static void ConfigureServices(ServiceCollection services) - { - services.AddSingleton() - .AddLogging(option => - { - option.SetMinimumLevel(LogLevel.Information); - option.AddSerilog(Log.Logger); - }); + Application.Run(new FormBoatCollection()); } } } \ No newline at end of file diff --git a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj index fda71c6..13ee123 100644 --- a/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj +++ b/ProjectMotorBoat/ProjectMotorBoat/ProjectMotorBoat.csproj @@ -8,16 +8,6 @@ enable - - - - - - - - - - True diff --git a/ProjectMotorBoat/ProjectMotorBoat/save.txt b/ProjectMotorBoat/ProjectMotorBoat/save.txt deleted file mode 100644 index 36db68b..0000000 --- a/ProjectMotorBoat/ProjectMotorBoat/save.txt +++ /dev/null @@ -1,2 +0,0 @@ -CollectionsStorage -Коллекция|Massive|60|EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White;EntityBoat:100:100:White; \ No newline at end of file