Люто натрайкетчил
This commit is contained in:
parent
ac523a95a4
commit
cb5c91f884
@ -1,4 +1,5 @@
|
||||
using Monorail.DrawningObjects;
|
||||
using Monorail.Exceptions;
|
||||
using Monorail.Generics;
|
||||
using Monorail.MovementStrategy;
|
||||
using System;
|
||||
@ -63,16 +64,16 @@ namespace Monorail
|
||||
form.Show();
|
||||
Action<DrawningMonorail>? monorailDelegate = new((m) =>
|
||||
{
|
||||
bool q = (obj + m);
|
||||
if (q)
|
||||
try
|
||||
{
|
||||
bool q = obj + m;
|
||||
MessageBox.Show("Объект добавлен");
|
||||
m.ChangePictureBoxSize(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||
}
|
||||
else
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
});
|
||||
form.AddEvent(monorailDelegate);
|
||||
@ -96,14 +97,15 @@ namespace Monorail
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (obj - pos != null)
|
||||
try
|
||||
{
|
||||
var q = obj - pos;
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = obj.ShowMonorails();
|
||||
}
|
||||
else
|
||||
catch (MonorailNotFoundException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,15 +163,17 @@ MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.SaveData(saveFileDialog.FileName))
|
||||
try
|
||||
{
|
||||
_storage.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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -179,8 +183,8 @@ MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
try {
|
||||
_storage.LoadData(openFileDialog.FileName);
|
||||
MessageBox.Show("Загрузка прошла успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
foreach(var collection in _storage.Keys)
|
||||
@ -188,10 +192,11 @@ MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
listBoxStorages.Items.Add(collection);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show($"Не загрузилось: {ex.Message}",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,7 @@ namespace Monorail.Generics
|
||||
pos)
|
||||
{
|
||||
T? obj = collect._collection[pos];
|
||||
if (obj != null)
|
||||
collect._collection.Remove(pos);
|
||||
collect._collection.Remove(pos);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ MonorailGenericCollection<DrawningMonorail, DrawningObjectMonorail>> record in _
|
||||
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||
}
|
||||
string toWrite = $"MonorailStorage{Environment.NewLine}{data}";
|
||||
var strs = toWrite.Split(new char[] { '\n', '\r' },
|
||||
@ -70,7 +70,7 @@ StringSplitOptions.RemoveEmptyEntries);
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Файл не найден");
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
@ -79,11 +79,11 @@ StringSplitOptions.RemoveEmptyEntries);
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
if (strs == null || strs.Length == 0)
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Нет данных для загрузки");
|
||||
}
|
||||
if (!strs[0].StartsWith("MonorailStorage"))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Неверный формат данных");
|
||||
}
|
||||
_monorailStorages.Clear();
|
||||
do
|
||||
@ -107,7 +107,7 @@ StringSplitOptions.RemoveEmptyEntries);
|
||||
{
|
||||
if (!(collection + monorail))
|
||||
{
|
||||
return false;
|
||||
throw new Exception("Ошибка добавления в коллекцию");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
20
Monorail/Monorail/MonorailNotFoundException.cs
Normal file
20
Monorail/Monorail/MonorailNotFoundException.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
|
||||
namespace Monorail.Exceptions
|
||||
{
|
||||
[Serializable]
|
||||
internal class MonorailNotFoundException : ApplicationException
|
||||
{
|
||||
public MonorailNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||
public MonorailNotFoundException() : base () { }
|
||||
public MonorailNotFoundException(string message) : base(message) { }
|
||||
public MonorailNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||
protected MonorailNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||
}
|
||||
}
|
@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using Monorail.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Monorail.Generics
|
||||
{
|
||||
@ -23,7 +25,7 @@ namespace Monorail.Generics
|
||||
public bool Insert(T monorail)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
return false;
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
Insert(monorail, 0);
|
||||
return true;
|
||||
|
||||
@ -31,7 +33,9 @@ namespace Monorail.Generics
|
||||
|
||||
public bool Insert(T monorail, int position)
|
||||
{
|
||||
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||
if (_places.Count == _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
if (!(position >= 0 && position <= Count))
|
||||
return false;
|
||||
_places.Insert(position, monorail);
|
||||
return true;
|
||||
@ -39,7 +43,7 @@ namespace Monorail.Generics
|
||||
public bool Remove(int position)
|
||||
{
|
||||
if (!(position >= 0 && position < Count))
|
||||
return false;
|
||||
throw new MonorailNotFoundException(position);
|
||||
_places.RemoveAt(position);
|
||||
return true;
|
||||
}
|
||||
|
19
Monorail/Monorail/StorageOverflowException.cs
Normal file
19
Monorail/Monorail/StorageOverflowException.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace Monorail.Exceptions
|
||||
{
|
||||
[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 context) : base(info, context) { }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user