DozorovaA.A_SeventhLabWork #10
@ -165,14 +165,25 @@ namespace ArmoredVehicle
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxImage.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (MachineNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show($"Ошибка удаления: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show($"Неизестная ошибка: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,13 +255,14 @@ namespace ArmoredVehicle
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_mapsCollection.SaveData(saveFileDialog.FileName);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не сохранилось: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -263,17 +275,18 @@ namespace ArmoredVehicle
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_mapsCollection.LoadData(openFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
_mapsCollection.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
ReloadMaps();
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Загрузка не удалась", "Результат",
|
||||
MessageBox.Show($"Загрузка не удалась {ex.Message}", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
ArmoredVehicle/MachineNotFoundException.cs
Normal file
14
ArmoredVehicle/MachineNotFoundException.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ArmoredVehicle
|
||||
{
|
||||
[Serializable]
|
||||
internal class MachineNotFoundException : ApplicationException
|
||||
{
|
||||
public MachineNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public MachineNotFoundException() : base() { }
|
||||
public MachineNotFoundException(string message) : base(message) { }
|
||||
public MachineNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected MachineNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
||||
}
|
@ -115,7 +115,7 @@ namespace ArmoredVehicle
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns></returns>
|
||||
public bool SaveData(string filename)
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
@ -129,7 +129,7 @@ namespace ArmoredVehicle
|
||||
fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -137,11 +137,11 @@ namespace ArmoredVehicle
|
||||
/// </summary>
|
||||
/// <param name="filename"></param>
|
||||
/// <returns></returns>
|
||||
public bool LoadData(string filename)
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Файл не найден");
|
||||
}
|
||||
string bufferTextFromFile = "";
|
||||
using (StreamReader sr = new(filename))
|
||||
@ -149,7 +149,7 @@ namespace ArmoredVehicle
|
||||
string checkMap = sr.ReadLine();
|
||||
if (!checkMap.Contains("MapsCollection"))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Неверный формат данных");
|
||||
}
|
||||
bufferTextFromFile = sr.ReadLine();
|
||||
_mapStorages.Clear();
|
||||
@ -175,7 +175,6 @@ namespace ArmoredVehicle
|
||||
bufferTextFromFile = sr.ReadLine();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,10 +45,11 @@
|
||||
/// <returns></returns>
|
||||
public int Insert(T machine, int position)
|
||||
{
|
||||
if (position >= _maxCount && position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
//if (position >= _maxCount && position < 0)
|
||||
//{
|
||||
// return -1;
|
||||
//}
|
||||
if(position >= _maxCount) throw new StorageOverflowException(_maxCount);
|
||||
|
||||
_places.Insert(position, machine);
|
||||
|
||||
@ -71,9 +72,9 @@
|
||||
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
else throw new MachineNotFoundException(position);
|
||||
}
|
||||
return null;
|
||||
else throw new MachineNotFoundException(position);
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение объекта из набора по позиции
|
||||
|
19
ArmoredVehicle/StorageOverflowException.cs
Normal file
19
ArmoredVehicle/StorageOverflowException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ArmoredVehicle
|
||||
{
|
||||
[Serializable]
|
||||
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) { }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user