Коллекции работают... СНова

This commit is contained in:
Tonb73 2024-05-11 09:26:13 +03:00
parent e69b946506
commit 07a9d93c17
10 changed files with 342 additions and 216 deletions

View File

@ -93,16 +93,15 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight); Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap); Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics); DrawBackgound(graphics);
SetObjectsPosition(_collection); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{ {
try
DrawningLocomotive? obj = _collection?.Get(i);
if (obj != null)
{ {
obj.SetPictureSize(_pictureWidth, _pictureWidth); DrawningLocomotive obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
} }
obj?.DrawTransport(graphics); catch (Exception) { }
} }
return bitmap; return bitmap;
} }
@ -115,6 +114,6 @@ public abstract class AbstractCompany
/// <summary> /// <summary>
/// Расстановка объектов /// Расстановка объектов
/// </summary> /// </summary>
protected abstract void SetObjectsPosition(ICollectionGenericObjects<DrawningLocomotive> collection); protected abstract void SetObjectsPosition();
} }

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ProjectElectricLocomotive.Exceptions;
namespace ProjectElectricLocomotive.CollectionGenericObjects namespace ProjectElectricLocomotive.CollectionGenericObjects
{ {
@ -47,48 +48,48 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
} }
public T? Get(int position) public T? Get(int position)
{ {
if(position >= 0 && position < Count) // проверка позиции
{ // выброс ошибки, если выход за границы массива
return _collection[position]; if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
}
// TODO проверка позиции return _collection[position];
return null;
} }
public int Insert(T obj) public int Insert(T obj)
{ {
if(Count <= _maxCount) // выброс ошибки если переполнение
{ if (Count == _maxCount) throw new CollectionOverflowException(Count);
_collection.Add(obj); _collection.Add(obj);
return Count; return Count;
}
// TODO проверка, что не превышено максимальное количество элементов
// TODO вставка в конец набора
return -1;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if(Count <= _maxCount) // проверка, что не превышено максимальное количество элементов
{ // проверка позиции
_collection.Insert(position, obj); // вставка по позиции
return position; // выброс ошибки, если переполнение
} // выброс ошибки если выход за границу
// TODO проверка, что не превышено максимальное количество элементов
// TODO проверка позиции if (Count == _maxCount) throw new CollectionOverflowException(Count);
// TODO вставка по позиции
return -1; if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
}
public T Remove(int position) _collection.Insert(position, obj);
{ return position;
if(position >= 0 && position <= _maxCount)
{
T ret = _collection[position];
_collection.RemoveAt(position);
return ret;
}
// TODO проверка позиции
// TODO удаление объекта из списка
return null;
} }
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<T?> GetItems() public IEnumerable<T?> GetItems()
{ {

View File

@ -31,22 +31,43 @@ public class LocomotiveDepo : AbstractCompany
//g.DrawRectangle(steel, 0, _pictureHeight - 40, _pictureWidth, 1000); //g.DrawRectangle(steel, 0, _pictureHeight - 40, _pictureWidth, 1000);
} }
protected override void SetObjectsPosition(ICollectionGenericObjects<DrawningLocomotive> collection) protected override void SetObjectsPosition()
{ {
int index = 0;
for(int i = _pictureHeight - _placeSizeHeight; i >= 0; i-= _placeSizeHeight) int width = _pictureWidth / _placeSizeWidth;
{ int height = _pictureHeight / _placeSizeHeight;
for(int j = 0; j <= _pictureWidth - _placeSizeWidth; j += _placeSizeWidth) 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); try
index++; {
_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;
}
} }
} }
}
}
}
} }

View File

@ -1,4 +1,5 @@
using System; using ProjectElectricLocomotive.Exceptions;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -46,78 +47,78 @@ namespace ProjectElectricLocomotive.CollectionGenericObjects
{ {
_collection = Array.Empty<T?>(); _collection = Array.Empty<T?>();
} }
public T? Get(int position) public T Get(int position)
{ {
//TODO проверка позиции // проверка позиции
if(position < 0) // выброс ошибки, если выход за границы массива
{ //выброс ошибки, если объект пустой
return null; if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
} if (_collection[position] == null) throw new ObjectNotFoundException(position);
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) 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) if (_collection[i] == null)
{ {
_collection[i] = obj; _collection[i] = obj;
return i; return i;
} }
} }
return -1; throw new CollectionOverflowException(Count);
} }
public int Insert(T obj, int position) 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 (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
{
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;
}
}
}
// TODO проверка позиции if (_collection[position] == null)
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
// TODO вставка
return -1;
}
public T Remove(int position)
{
if(position < 0)
{ {
return null; _collection[position] = obj;
return position;
} }
else 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 проверка позиции throw new CollectionOverflowException(Count);
// TODO удаление объекта из массива, присвоив элементу массива значение null }
return Get(position); 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<T?> GetItems() public IEnumerable<T?> GetItems()

View File

@ -1,4 +1,5 @@
using ProjectElectricLocomotive.Drawnings; using ProjectElectricLocomotive.Drawnings;
using ProjectElectricLocomotive.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -100,49 +101,51 @@ where T : DrawningLocomotive
/// </summary> /// </summary>
/// <param name="filename">Путь и имя файла</param> /// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns> /// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename) public void SaveData(string filename)
{ {
if (_storages.Count == 0)
{ {
return false; if (_storages.Count == 0)
}
if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{ {
StringBuilder sb = new(); // построитель строк throw new Exception("В хранилище отсутствуют коллекции для сохранения");
sb.Append(Environment.NewLine);
// не сохраняем пустые коллекции }
if (value.Value.Count == 0) if (File.Exists(filename))
{
File.Delete(filename);
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{ {
continue; StringBuilder sb = new(); // построитель строк
} sb.Append(Environment.NewLine);
sb.Append(value.Key); // не сохраняем пустые коллекции
sb.Append(_separatorForKeyValue); if (value.Value.Count == 0)
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; continue;
} }
sb.Append(data); sb.Append(value.Key);
sb.Append(_separatorItems); 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;
} }
/// <summary> /// <summary>
@ -150,22 +153,24 @@ where T : DrawningLocomotive
// /// </summary> // /// </summary>
// /// <param name="filename">Путь и имя файла</param> // /// <param name="filename">Путь и имя файла</param>
// /// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns> // /// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename) public void LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
return false; throw new Exception("Файл не существует");
} }
using (StreamReader fs = File.OpenText(filename)) using (StreamReader fs = File.OpenText(filename))
{ {
string str = fs.ReadLine(); string str = fs.ReadLine();
if (str == null || str.Length == 0) if (str == null || str.Length == 0)
{ {
return false; throw new Exception("В файле нет данных");
} }
if (!str.StartsWith(_collectionKey)) if (!str.StartsWith(_collectionKey))
{ {
return false; throw new Exception("В файле неверные данные");
} }
_storages.Clear(); _storages.Clear();
string strs = ""; string strs = "";
@ -180,23 +185,31 @@ where T : DrawningLocomotive
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType); ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null) if (collection == null)
{ {
return false; throw new Exception("Не удалось создать коллекцию");
} }
collection.MaxCount = Convert.ToInt32(record[2]); collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set) 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); _storages.Add(record[0], collection);
} }
return true;
} }
} }

View File

@ -0,0 +1,16 @@
using System.Runtime.Serialization;
namespace ProjectElectricLocomotive.Exceptions;
/// <summary>
/// Класс, описывающий ошибку переполнения коллекции
/// </summary>
[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) { }
}

View File

@ -0,0 +1,21 @@
using System;
using System.Runtime.Serialization;
namespace ProjectElectricLocomotive.Exceptions;
/// <summary>
/// Класс, описывающий ошибку, что по указанной позиции нет элемента
/// </summary>
[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) { }
}

View File

@ -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;
/// <summary>
/// Класс, описывающий ошибку выхода за границы коллекции
/// </summary>
[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) { }
}

View File

@ -1,5 +1,7 @@
using ProjectElectricLocomotive.CollectionGenericObjects; using Microsoft.Extensions.Logging;
using ProjectElectricLocomotive.CollectionGenericObjects;
using ProjectElectricLocomotive.Drawnings; using ProjectElectricLocomotive.Drawnings;
using ProjectElectricLocomotive.Exceptions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -10,6 +12,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace ProjectElectricLocomotive; namespace ProjectElectricLocomotive;
@ -24,6 +27,12 @@ public partial class FormLocomotiveCollection : Form
/// </summary> /// </summary>
private readonly StorageCollection<DrawningLocomotive> _storageCollection; private readonly StorageCollection<DrawningLocomotive> _storageCollection;
/// <summary>
/// Логер
/// </summary>
private readonly ILogger _logger;
/// <summary> /// <summary>
/// Компания /// Компания
/// </summary> /// </summary>
@ -31,10 +40,12 @@ public partial class FormLocomotiveCollection : Form
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormLocomotiveCollection() public FormLocomotiveCollection(ILogger<FormLocomotiveCollection> logger)
{ {
InitializeComponent(); InitializeComponent();
_storageCollection = new(); _storageCollection = new();
_logger = logger;
_logger.LogInformation("Форма загрузилась");
} }
@ -72,20 +83,24 @@ public partial class FormLocomotiveCollection : Form
/// <param name="locomotive"></param> /// <param name="locomotive"></param>
private void SetLocomotive(DrawningLocomotive? locomotive) 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());
}
} }
catch (ObjectNotFoundException) { }
if (_company + locomotive != -1) catch (CollectionOverflowException ex)
{
pictureBox.Image = _company.Show();
MessageBox.Show("Обьект добавлен");
pictureBox.Image = _company.Show();
}
else
{ {
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
} }
} }
@ -96,30 +111,29 @@ public partial class FormLocomotiveCollection : Form
/// <param name="e"></param> /// <param name="e"></param>
private void buttonDelLocomotive_Click(object sender, EventArgs e) private void buttonDelLocomotive_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
{ {
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == return;
null) }
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
try
{
if (_company - pos != null)
{ {
return; MessageBox.Show("Объект удален");
} pictureBox.Image = _company.Show();
else _logger.LogInformation("Удален объект по позиции " + pos);
{
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("Не удалось удалить объект");
}
} }
} }
catch (Exception ex)
{
MessageBox.Show("Не удалось удалить объект");
_logger.LogError("Ошибка: {Message}", ex.Message);
}
} }
@ -134,27 +148,29 @@ public partial class FormLocomotiveCollection : Form
{ {
return; return;
} }
DrawningLocomotive? locomotive = null; DrawningLocomotive? locomotive = null;
int counter = 100; int counter = 100;
while (locomotive == null) try
{ {
locomotive = _company.GetRandomObject(); while (locomotive == null)
counter--;
if (counter <= 0)
{ {
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();
} }
/// <summary> /// <summary>
@ -233,16 +249,20 @@ public partial class FormLocomotiveCollection : Form
MessageBox.Show("Коллекция не выбрана"); MessageBox.Show("Коллекция не выбрана");
return; 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
} }
/// <summary> /// <summary>
@ -254,22 +274,28 @@ public partial class FormLocomotiveCollection : Form
{ {
if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked))
{ {
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
CollectionType collectionType = CollectionType.None; try
if (radioButtonMassive.Checked)
{ {
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();
} }
/// <summary> /// <summary>
@ -282,11 +308,11 @@ public partial class FormLocomotiveCollection : Form
{ {
if (saveFileDialog.ShowDialog() == DialogResult.OK) if (saveFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_storageCollection.SaveData(saveFileDialog.FileName)) // if (_storageCollection.SaveData(saveFileDialog.FileName))
{ {
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
} }
else //else
{ {
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
@ -304,13 +330,13 @@ public partial class FormLocomotiveCollection : Form
{ {
if (openFileDialog.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_storageCollection.LoadData(openFileDialog.FileName)) // if (_storageCollection.LoadData(openFileDialog.FileName))
{ {
MessageBox.Show("Загрузка прошла успешно", MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
else // else
{ {
MessageBox.Show("Не сохранилось", "Результат", MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBoxButtons.OK, MessageBoxIcon.Error);

View File

@ -8,6 +8,10 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>