From 07a9d93c1794ec70192f7b190ff17209ac6c567d Mon Sep 17 00:00:00 2001 From: Tonb73 Date: Sat, 11 May 2024 09:26:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=8E=D1=82?= =?UTF-8?q?...=20=D0=A1=D0=9D=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 13 +- .../ListGenericObjects.cs | 73 ++++---- .../LocomotiveDepo.cs | 45 +++-- .../MassiveGenericObjects.cs | 105 ++++++------ .../StorageCollection.cs | 97 ++++++----- .../Exceptions/CollectionOverflowException.cs | 16 ++ .../Exceptions/ObjectNotFoundException.cs | 21 +++ .../PositionOutOfCollectionException.cs | 24 +++ .../FormLocomotiveCollection.cs | 160 ++++++++++-------- .../ProjectElectricLocomotive.csproj | 4 + 10 files changed, 342 insertions(+), 216 deletions(-) create mode 100644 ProjectElectricLocomotive/Exceptions/CollectionOverflowException.cs create mode 100644 ProjectElectricLocomotive/Exceptions/ObjectNotFoundException.cs create mode 100644 ProjectElectricLocomotive/Exceptions/PositionOutOfCollectionException.cs diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs b/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs index 603c506..83adb1f 100644 --- a/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs @@ -93,16 +93,15 @@ public abstract class AbstractCompany Bitmap bitmap = new(_pictureWidth, _pictureHeight); Graphics graphics = Graphics.FromImage(bitmap); DrawBackgound(graphics); - SetObjectsPosition(_collection); + SetObjectsPosition(); for (int i = 0; i < (_collection?.Count ?? 0); ++i) { - - DrawningLocomotive? obj = _collection?.Get(i); - if (obj != null) + try { - obj.SetPictureSize(_pictureWidth, _pictureWidth); + DrawningLocomotive obj = _collection?.Get(i); + obj?.DrawTransport(graphics); } - obj?.DrawTransport(graphics); + catch (Exception) { } } return bitmap; } @@ -115,6 +114,6 @@ public abstract class AbstractCompany /// /// Расстановка объектов /// - protected abstract void SetObjectsPosition(ICollectionGenericObjects collection); + protected abstract void SetObjectsPosition(); } diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs b/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs index 4bca8bc..0e4148e 100644 --- a/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectElectricLocomotive/CollectionGenericObjects/ListGenericObjects.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ProjectElectricLocomotive.Exceptions; namespace ProjectElectricLocomotive.CollectionGenericObjects { @@ -47,48 +48,48 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects } public T? Get(int position) { - if(position >= 0 && position < Count) - { - return _collection[position]; - } - // TODO проверка позиции - return null; + // проверка позиции + // выброс ошибки, если выход за границы массива + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); + + return _collection[position]; + } - public int Insert(T obj) + public int Insert(T obj) { - if(Count <= _maxCount) - { - _collection.Add(obj); - return Count; - } - // TODO проверка, что не превышено максимальное количество элементов - // TODO вставка в конец набора - return -1; + // выброс ошибки если переполнение + if (Count == _maxCount) throw new CollectionOverflowException(Count); + _collection.Add(obj); + return Count; + } public int Insert(T obj, int position) { - if(Count <= _maxCount) - { - _collection.Insert(position, obj); - return position; - } - // TODO проверка, что не превышено максимальное количество элементов - // TODO проверка позиции - // TODO вставка по позиции - return -1; - } - public T Remove(int position) - { - if(position >= 0 && position <= _maxCount) - { - T ret = _collection[position]; - _collection.RemoveAt(position); - return ret; - } - // TODO проверка позиции - // TODO удаление объекта из списка - return null; + // проверка, что не превышено максимальное количество элементов + // проверка позиции + // вставка по позиции + // выброс ошибки, если переполнение + // выброс ошибки если выход за границу + + if (Count == _maxCount) throw new CollectionOverflowException(Count); + + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); + + _collection.Insert(position, obj); + return position; + } + public T Remove(int position) + { + // проверка позиции + // удаление объекта из списка + //выброс ошибки, если выход за границы массива + + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); + T obj = _collection[position]; + _collection.RemoveAt(position); + return obj; + } public IEnumerable GetItems() { diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs b/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs index 9751592..fe3e2ee 100644 --- a/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs +++ b/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs @@ -31,22 +31,43 @@ public class LocomotiveDepo : AbstractCompany //g.DrawRectangle(steel, 0, _pictureHeight - 40, _pictureWidth, 1000); } - - protected override void SetObjectsPosition(ICollectionGenericObjects collection) + + protected override void SetObjectsPosition() { - int index = 0; - for(int i = _pictureHeight - _placeSizeHeight; i >= 0; i-= _placeSizeHeight) - { - for(int j = 0; j <= _pictureWidth - _placeSizeWidth; j += _placeSizeWidth) + + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + int positionWidth = 0; + int positionHeight = height; + + if (_collection?.Count != null) { - if (collection.Get(index) != null) + for (int i = 0; i < (_collection.Count); i++) { - collection.Get(index).SetPosition(j + 10, i + 10); - index++; + try + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * positionWidth + 25, positionHeight * _placeSizeHeight + 10); + } + catch (Exception) { } + + if (positionWidth < width - 1) + { + positionWidth++; + } + + else + { + positionWidth = 0; + positionHeight--; + } + if (positionHeight < 0) + { + return; + } } } - } - - } + + } } diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs index 211f9d6..44925ab 100644 --- a/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,4 +1,5 @@ -using System; +using ProjectElectricLocomotive.Exceptions; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -46,78 +47,78 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects { _collection = Array.Empty(); } - public T? Get(int position) + public T Get(int position) { - //TODO проверка позиции - if(position < 0) - { - return null; - } - return _collection[position]; + // проверка позиции + // выброс ошибки, если выход за границы массива + //выброс ошибки, если объект пустой + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); + if (_collection[position] == null) throw new ObjectNotFoundException(position); + return _collection[position]; } public int Insert(T obj) { - if(obj == null){ return -1; } - for(int i = 0; i < _collection.Length; i++) + // вставка в свободное место набора + // выброс ошибки, если переполнение + //выброс ошибки, если выход за границы массива + for (int i = 0; i < Count; i++) { if (_collection[i] == null) { _collection[i] = obj; - return i; } } - return -1; + throw new CollectionOverflowException(Count); } public int Insert(T obj, int position) { - if(obj == null || position < 0) - { - return -1; - } - if (_collection[position] != null) - { - for(int i = position; i < _collection.Length; i++) - { - if (_collection[i] == null) - { - _collection[i] = obj; - return position; - } - } - for(int i = position; i > 0; i--) - { - if (_collection[i] == null) - { - _collection[i] = obj; - return position; - } - } - } - + // проверка позиции + // проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда, если нет после, ищем до + // вставка + //выброс ошибки, если переполнение + //выброс ошибки, если выход за границы массива + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); - // TODO проверка позиции - // TODO проверка, что элемент массива по этой позиции пустой, если нет, то - // ищется свободное место после этой позиции и идет вставка туда - // если нет после, ищем до - // TODO вставка - return -1; - } - public T Remove(int position) - { - - if(position < 0) + if (_collection[position] == null) { - return null; + _collection[position] = obj; + return position; } else { - _collection[position] = null; + for (int i = 1; i < Count; ++i) + { + if (_collection[position + i] == null) + { + _collection[position + i] = obj; + return position + i; + } + for (i = position - 1; i >= 0; i--) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + } } - // TODO проверка позиции - // TODO удаление объекта из массива, присвоив элементу массива значение null - return Get(position); + throw new CollectionOverflowException(Count); + } + public T Remove(int position) + { + //// проверка позиции + //// удаление объекта из массива, присвоив элементу массива значение null + // выброс ошибки, если выход за границы массива + // выброс ошибки, если объект пустой + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); + if (_collection[position] == null) throw new ObjectNotFoundException(position); + T temp = _collection[position]; + _collection[position] = null; + return temp; } public IEnumerable GetItems() diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs b/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs index eb6c409..e0a0baa 100644 --- a/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectElectricLocomotive/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ using ProjectElectricLocomotive.Drawnings; +using ProjectElectricLocomotive.Exceptions; using System; using System.Collections.Generic; using System.Linq; @@ -100,49 +101,51 @@ where T : DrawningLocomotive /// /// Путь и имя файла /// true - сохранение прошло успешно, false - ошибка при сохранении данных - public bool SaveData(string filename) + public void SaveData(string filename) { - if (_storages.Count == 0) { - return false; - } - if (File.Exists(filename)) - { - File.Delete(filename); - } - using (StreamWriter writer = new StreamWriter(filename)) - { - writer.Write(_collectionKey); - foreach (KeyValuePair> value in _storages) + if (_storages.Count == 0) { - StringBuilder sb = new(); // построитель строк - sb.Append(Environment.NewLine); - // не сохраняем пустые коллекции - if (value.Value.Count == 0) + throw new Exception("В хранилище отсутствуют коллекции для сохранения"); + + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter writer = new StreamWriter(filename)) + { + writer.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) { - continue; - } - sb.Append(value.Key); - sb.Append(_separatorForKeyValue); - sb.Append(value.Value.GetCollectionType); - sb.Append(_separatorForKeyValue); - sb.Append(value.Value.MaxCount); - sb.Append(_separatorForKeyValue); - foreach (T? item in value.Value.GetItems()) - { - string data = item?.GetDataForSave() ?? string.Empty; - if (string.IsNullOrEmpty(data)) + StringBuilder sb = new(); // построитель строк + sb.Append(Environment.NewLine); + // не сохраняем пустые коллекции + if (value.Value.Count == 0) { continue; } - sb.Append(data); - sb.Append(_separatorItems); + sb.Append(value.Key); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.MaxCount); + sb.Append(_separatorForKeyValue); + foreach (T? item in value.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + { + continue; + } + sb.Append(data); + sb.Append(_separatorItems); + } + writer.Write(sb); } - writer.Write(sb); - } + } } - return true; } /// @@ -150,22 +153,24 @@ where T : DrawningLocomotive // /// // /// Путь и имя файла // /// true - загрузка прошла успешно, false - ошибка при загрузке данных - public bool LoadData(string filename) + public void LoadData(string filename) { + if (!File.Exists(filename)) { - return false; + throw new Exception("Файл не существует"); } using (StreamReader fs = File.OpenText(filename)) { string str = fs.ReadLine(); if (str == null || str.Length == 0) { - return false; + throw new Exception("В файле нет данных"); + } if (!str.StartsWith(_collectionKey)) { - return false; + throw new Exception("В файле неверные данные"); } _storages.Clear(); string strs = ""; @@ -180,23 +185,31 @@ where T : DrawningLocomotive ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); if (collection == null) { - return false; + throw new Exception("Не удалось создать коллекцию"); + } collection.MaxCount = Convert.ToInt32(record[2]); string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { - if (elem?.CreateDrawningLocomotive() is T locomotive) + if (elem?.CreateDrawningLocomotive() is T truck) { - if (collection.Insert(locomotive) == -1) + try { - return false; + if (collection.Insert(truck) == -1) + { + throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]); + } + } + catch (CollectionOverflowException ex) + { + throw new Exception("Коллекция переполнена", ex); + } } } _storages.Add(record[0], collection); } - return true; } } diff --git a/ProjectElectricLocomotive/Exceptions/CollectionOverflowException.cs b/ProjectElectricLocomotive/Exceptions/CollectionOverflowException.cs new file mode 100644 index 0000000..8d280e4 --- /dev/null +++ b/ProjectElectricLocomotive/Exceptions/CollectionOverflowException.cs @@ -0,0 +1,16 @@ +using System.Runtime.Serialization; +namespace ProjectElectricLocomotive.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) { } +} diff --git a/ProjectElectricLocomotive/Exceptions/ObjectNotFoundException.cs b/ProjectElectricLocomotive/Exceptions/ObjectNotFoundException.cs new file mode 100644 index 0000000..45cbe7f --- /dev/null +++ b/ProjectElectricLocomotive/Exceptions/ObjectNotFoundException.cs @@ -0,0 +1,21 @@ +using System; +using System.Runtime.Serialization; +namespace ProjectElectricLocomotive.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/ProjectElectricLocomotive/Exceptions/PositionOutOfCollectionException.cs b/ProjectElectricLocomotive/Exceptions/PositionOutOfCollectionException.cs new file mode 100644 index 0000000..46eee21 --- /dev/null +++ b/ProjectElectricLocomotive/Exceptions/PositionOutOfCollectionException.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive.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) { } +} + diff --git a/ProjectElectricLocomotive/FormLocomotiveCollection.cs b/ProjectElectricLocomotive/FormLocomotiveCollection.cs index dcb5922..c63a65e 100644 --- a/ProjectElectricLocomotive/FormLocomotiveCollection.cs +++ b/ProjectElectricLocomotive/FormLocomotiveCollection.cs @@ -1,5 +1,7 @@ -using ProjectElectricLocomotive.CollectionGenericObjects; +using Microsoft.Extensions.Logging; +using ProjectElectricLocomotive.CollectionGenericObjects; using ProjectElectricLocomotive.Drawnings; +using ProjectElectricLocomotive.Exceptions; using System; using System.Collections.Generic; using System.ComponentModel; @@ -10,6 +12,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; + namespace ProjectElectricLocomotive; @@ -24,6 +27,12 @@ public partial class FormLocomotiveCollection : Form /// private readonly StorageCollection _storageCollection; + + /// + /// Логер + /// + private readonly ILogger _logger; + /// /// Компания /// @@ -31,10 +40,12 @@ public partial class FormLocomotiveCollection : Form /// /// Конструктор /// - public FormLocomotiveCollection() + public FormLocomotiveCollection(ILogger logger) { InitializeComponent(); _storageCollection = new(); + _logger = logger; + _logger.LogInformation("Форма загрузилась"); } @@ -72,20 +83,24 @@ public partial class FormLocomotiveCollection : Form /// private void SetLocomotive(DrawningLocomotive? locomotive) { - if (_company == null || locomotive == null) + try { - return; + if (_company == null || locomotive == null) + { + return; + } + if (_company + locomotive != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + _logger.LogInformation("Добавлен объект: " + locomotive.GetDataForSave()); + } } - - if (_company + locomotive != -1) - { - pictureBox.Image = _company.Show(); - MessageBox.Show("Обьект добавлен"); - pictureBox.Image = _company.Show(); - } - else + catch (ObjectNotFoundException) { } + catch (CollectionOverflowException ex) { MessageBox.Show("Не удалось добавить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); } } @@ -96,30 +111,29 @@ public partial class FormLocomotiveCollection : Form /// private void buttonDelLocomotive_Click(object sender, EventArgs e) { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) { - if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == - null) + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + try + { + if (_company - pos != null) { - return; - } - else - { - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - pictureBox.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось удалить объект"); - } + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + _logger.LogInformation("Удален объект по позиции " + pos); } } + catch (Exception ex) + { + MessageBox.Show("Не удалось удалить объект"); + _logger.LogError("Ошибка: {Message}", ex.Message); + } } @@ -134,27 +148,29 @@ public partial class FormLocomotiveCollection : Form { return; } - DrawningLocomotive? locomotive = null; int counter = 100; - while (locomotive == null) + try { - locomotive = _company.GetRandomObject(); - counter--; - if (counter <= 0) + while (locomotive == null) { - break; + locomotive = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } } + FormlectricLocomotive form = new() + { + SetLocomotive = locomotive + }; + form.ShowDialog(); } - if (locomotive == null) + catch (Exception ex) { - return; + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } - FormlectricLocomotive form = new() - { - SetLocomotive = locomotive - }; - form.ShowDialog(); } /// @@ -233,16 +249,20 @@ public partial class FormLocomotiveCollection : Form MessageBox.Show("Коллекция не выбрана"); return; } - if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + try { - return; + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + _logger.LogInformation("Коллекция: " + listBoxCollection.SelectedItem.ToString() + " удалена"); + } + catch (Exception ex) + { + _logger.LogError("Ошибка: {Message}", ex.Message); } - _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); - RerfreshListBoxItems(); - // TODO прописать логику удаления элемента из коллекции - // нужно убедиться, что есть выбранная коллекция - // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись - // удалить и обновить ListBox } /// @@ -254,22 +274,28 @@ public partial class FormLocomotiveCollection : Form { if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) { - MessageBox.Show("Не все данные заполнены", "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - CollectionType collectionType = CollectionType.None; - if (radioButtonMassive.Checked) + try { - collectionType = CollectionType.Massive; + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + RerfreshListBoxItems(); + _logger.LogInformation("Коллекция добавлена " + textBoxCollectionName.Text); } - else if (radioButtonList.Checked) + catch (Exception ex) { - collectionType = CollectionType.List; + _logger.LogError("Ошибка: {Message}", ex.Message); } - _storageCollection.AddCollection(textBoxCollectionName.Text, - collectionType); - RerfreshListBoxItems(); } /// @@ -282,11 +308,11 @@ public partial class FormLocomotiveCollection : Form { if (saveFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.SaveData(saveFileDialog.FileName)) + // if (_storageCollection.SaveData(saveFileDialog.FileName)) { MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } - else + //else { MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } @@ -304,13 +330,13 @@ public partial class FormLocomotiveCollection : Form { if (openFileDialog.ShowDialog() == DialogResult.OK) { - if (_storageCollection.LoadData(openFileDialog.FileName)) + // if (_storageCollection.LoadData(openFileDialog.FileName)) { MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); RerfreshListBoxItems(); } - else + // else { MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj b/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj index 244387d..d11a7da 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive.csproj @@ -8,6 +8,10 @@ enable + + + + True