Morozov V.S LabWork07 #8

Closed
VoldemarProger wants to merge 3 commits from LabWork07 into LabWork06
4 changed files with 76 additions and 23 deletions
Showing only changes of commit 3f9f13fd89 - Show all commits

View File

@ -120,15 +120,24 @@ namespace AirPlaneWithRadar
}
if (maskedTextBoxPosition.Text == null)
return;
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null)
try
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}catch(PlainNotFoundException ex)
{
MessageBox.Show("Не удалось удалить объект");
MessageBox.Show("Wrong id");
}catch(Exception ex)
{
MessageBox.Show("Error of delete");
}
}
private void ButtonShowStorage_Click(object sender, EventArgs e)
@ -175,16 +184,18 @@ namespace AirPlaneWithRadar
}
private void SaveToolStrip_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.SaveData(saveFileDialog.FileName))
try
{
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
_mapsCollection.SaveData(saveFileDialog.FileName);
}
else
{
catch(Exception ex) {
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
@ -192,17 +203,20 @@ namespace AirPlaneWithRadar
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.LoadData(openFileDialog.FileName) && _mapsCollection.Count != 0)
try
{
_mapsCollection.LoadData(openFileDialog.FileName);
}
catch (Exception ex)
{
MessageBox.Show("Не удалось загрузить", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось загрузить", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}

View File

@ -54,7 +54,7 @@ namespace AirPlaneWithRadar
return _mapStorages[ind];
}
}
public bool SaveData(string filename)
public void SaveData(string filename)
{
if (File.Exists(filename))
{
@ -69,22 +69,22 @@ namespace AirPlaneWithRadar
}
}
return true;
}
public bool LoadData(string filename)
public void LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
throw new Exception("File not found");
}
using (StreamReader sr = new StreamReader(filename))
{
if (!sr.ReadLine().Equals("MapsCollection"))
{
return false;
throw new Exception("Wrong file");
}
_mapStorages.Clear();
string line = sr.ReadLine();
@ -109,7 +109,7 @@ namespace AirPlaneWithRadar
line = sr.ReadLine();
}
}
return true;
}
}

View 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 AirPlaneWithRadar
{
[Serializable]
internal class PlainNotFoundException : ApplicationException
{
public PlainNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
public PlainNotFoundException() : base() { }
public PlainNotFoundException(string message) : base(message) { }
public PlainNotFoundException(string message, Exception exception) : base(message, exception) { }
protected PlainNotFoundException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}

View 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 AirPlaneWithRadar
{
[Serializable]
internal class StorageOverFullException : ApplicationException
{
public StorageOverFullException(int count) : base($"В наборе превышено допустимое количество: {count}") { }
public StorageOverFullException() : base() { }
public StorageOverFullException(string message) : base(message) { }
public StorageOverFullException(string message, Exception exception) : base(message, exception) { }
protected StorageOverFullException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
}
}