че то не хочет
This commit is contained in:
parent
cf00e1bcc2
commit
4148c28d17
@ -33,8 +33,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
|||||||
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
|
public static bool operator -(AirplanesGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection[pos];
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null && collect != null)
|
collect._collection.Remove(pos);
|
||||||
return collect._collection.Remove(pos);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
|
@ -43,7 +43,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
|||||||
}
|
}
|
||||||
if (data.Length == 0)
|
if (data.Length == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new Exception("Невалиданя операция, нет данных для сохранения");
|
||||||
}
|
}
|
||||||
string toWrite = $"AirplanesStorage{Environment.NewLine}{data}";
|
string toWrite = $"AirplanesStorage{Environment.NewLine}{data}";
|
||||||
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
var strs = toWrite.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
@ -60,7 +60,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
|||||||
{
|
{
|
||||||
if (!File.Exists(filename))
|
if (!File.Exists(filename))
|
||||||
{
|
{
|
||||||
return false;
|
throw new IOException("Файл не найден");
|
||||||
}
|
}
|
||||||
using (StreamReader sr = new(filename))
|
using (StreamReader sr = new(filename))
|
||||||
{
|
{
|
||||||
@ -68,12 +68,11 @@ namespace ProjectAirplaneWithRadar.Generics
|
|||||||
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
var strs = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
if (strs == null || strs.Length == 0)
|
if (strs == null || strs.Length == 0)
|
||||||
{
|
{
|
||||||
return false;
|
throw new IOException("Нет данных для загрузки");
|
||||||
}
|
}
|
||||||
if (!strs[0].StartsWith("AirplanesStorage"))
|
if (!strs[0].StartsWith("AirplanesStorage"))
|
||||||
{
|
{
|
||||||
//если нет такой записи, то это не те данные
|
throw new IOException("Неверный формат данных");
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
_airplanesStorages.Clear();
|
_airplanesStorages.Clear();
|
||||||
do
|
do
|
||||||
|
@ -18,6 +18,7 @@ namespace ProjectAirplaneWithRadar.DrawningObjects
|
|||||||
protected int _startPosY;
|
protected int _startPosY;
|
||||||
protected readonly int _airplaneWidth = 200;
|
protected readonly int _airplaneWidth = 200;
|
||||||
protected readonly int _airplaneHeight = 78;
|
protected readonly int _airplaneHeight = 78;
|
||||||
|
char separator = '|';
|
||||||
public int GetPosX => _startPosX;
|
public int GetPosX => _startPosX;
|
||||||
public int GetPosY => _startPosY;
|
public int GetPosY => _startPosY;
|
||||||
public int GetWidth => _airplaneWidth;
|
public int GetWidth => _airplaneWidth;
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Runtime.Serialization;
|
||||||
|
|
||||||
|
namespace ProjectAirplaneWithRadar.Exceptions
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class AirplaneNotFoundException :ApplicationException
|
||||||
|
{
|
||||||
|
public AirplaneNotFoundException(int i) : base($"Не найден объект по позиции {i}") { }
|
||||||
|
public AirplaneNotFoundException() : base() { }
|
||||||
|
public AirplaneNotFoundException(string message) : base(message) { }
|
||||||
|
public AirplaneNotFoundException(string message, Exception exception) : base(message, exception) { }
|
||||||
|
protected AirplaneNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) { }
|
||||||
|
}
|
||||||
|
}
|
@ -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 ProjectAirplaneWithRadar.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) { }
|
||||||
|
}
|
||||||
|
}
|
@ -5,6 +5,8 @@ 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 System.ComponentModel;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar
|
||||||
{
|
{
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
using ProjectAirplaneWithRadar.DrawningObjects;
|
using ProjectAirplaneWithRadar.DrawningObjects;
|
||||||
using ProjectAirplaneWithRadar.MovementStrategy;
|
using ProjectAirplaneWithRadar.MovementStrategy;
|
||||||
using ProjectAirplaneWithRadar.Generics;
|
using ProjectAirplaneWithRadar.Generics;
|
||||||
|
using ProjectAirplaneWithRadar.Exceptions;
|
||||||
using System.Diagnostics.Metrics;
|
using System.Diagnostics.Metrics;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
using Serilog;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar
|
||||||
{
|
{
|
||||||
@ -50,15 +55,17 @@ namespace ProjectAirplaneWithRadar
|
|||||||
form.Show();
|
form.Show();
|
||||||
Action<DrawningAirplane>? airplaneDelegate = new((m) =>
|
Action<DrawningAirplane>? airplaneDelegate = new((m) =>
|
||||||
{
|
{
|
||||||
bool q = (obj + m);
|
try
|
||||||
if (q)
|
|
||||||
{
|
{
|
||||||
|
bool q = obj + m;
|
||||||
MessageBox.Show("Îáúåêò äîáàâëåí");
|
MessageBox.Show("Îáúåêò äîáàâëåí");
|
||||||
|
Log.Information($"Äîáàâëåí îáúåêò â êîëëåêöèþ {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||||
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||||
}
|
}
|
||||||
else
|
catch(StorageOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Íå óäàëîñü äîáàâèòü îáúåêò");
|
Log.Warning($"Êîëëåêöèÿ {listBoxStorages.SelectedItem.ToString() ?? string.Empty} ïåðåïîëíåíà");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
form.AddEvent(airplaneDelegate);
|
form.AddEvent(airplaneDelegate);
|
||||||
@ -81,14 +88,25 @@ namespace ProjectAirplaneWithRadar
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (obj - pos != null)
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
|
var q = obj - pos;
|
||||||
MessageBox.Show("Îáúåêò óäàëåí");
|
MessageBox.Show("Îáúåêò óäàëåí");
|
||||||
|
Log.Information($"Óäàëåí îáúåêò èç êîëëåêöèè {listBoxStorages.SelectedItem.ToString() ?? string.Empty} ïî íîìåðó {pos}");
|
||||||
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
pictureBoxAirplanesCollection.Image = obj.ShowAirplanes();
|
||||||
}
|
}
|
||||||
else
|
catch (AirplaneNotFoundException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Íå óäàëîñü óäàëèòü îáúåêò");
|
MessageBox.Show("Íå óäàëîñü óäàëèòü îáúåêò");
|
||||||
|
Log.Warning($"Íå ïîëó÷èëîñü óäàëèòü îáúåêò èç êîëëåêöèè {listBoxStorages.SelectedItem.ToString() ?? string.Empty}");
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
|
}
|
||||||
|
catch (FormatException ex)
|
||||||
|
{
|
||||||
|
Log.Warning($"Áûëî ââåäåíî íå ÷èñëî");
|
||||||
|
MessageBox.Show("Ââåäèòå ÷èñëî");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void buttonUpdateCollection_Click(object sender, EventArgs e)
|
private void buttonUpdateCollection_Click(object sender, EventArgs e)
|
||||||
@ -115,7 +133,7 @@ namespace ProjectAirplaneWithRadar
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_storage.AddSet(textBoxStorageName.Text);
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
ReloadObjects();
|
ReloadObjects(); Log.Information($"Äîáàâëåí íàáîð: {textBoxStorageName.Text}");
|
||||||
}
|
}
|
||||||
private void buttonRemoveObject_Click(object sender, EventArgs e)
|
private void buttonRemoveObject_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
@ -125,9 +143,10 @@ namespace ProjectAirplaneWithRadar
|
|||||||
}
|
}
|
||||||
if (MessageBox.Show($"Óäàëèòü îáúåêò {listBoxStorages.SelectedItem}?", "Óäàëåíèå", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
if (MessageBox.Show($"Óäàëèòü îáúåêò {listBoxStorages.SelectedItem}?", "Óäàëåíèå", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
{
|
{
|
||||||
_storage.DelSet(listBoxStorages.SelectedItem.ToString()
|
string name = listBoxStorages.SelectedItem.ToString() ?? string.Empty;
|
||||||
?? string.Empty);
|
_storage.DelSet(name);
|
||||||
ReloadObjects();
|
ReloadObjects();
|
||||||
|
Log.Information($"Óäàëåí íàáîð: {name}");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -144,15 +163,17 @@ namespace ProjectAirplaneWithRadar
|
|||||||
{
|
{
|
||||||
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
if (saveFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storage.SaveData(saveFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_storage.SaveData(saveFileDialog.FileName);
|
||||||
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî",
|
MessageBox.Show("Ñîõðàíåíèå ïðîøëî óñïåøíî",
|
||||||
"Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
"Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
Log.Information($"Ôàéë {saveFileDialog.FileName} óñïåøíî ñîõðàíåí");
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Íå ñîõðàíèëîñü", "Ðåçóëüòàò",
|
Log.Warning("Íå óäàëîñü ñîõðàíèòü");
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show($"Íå ñîõðàíèëîñü: {ex.Message}","Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,19 +181,22 @@ namespace ProjectAirplaneWithRadar
|
|||||||
{
|
{
|
||||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_storage.LoadData(openFileDialog.FileName))
|
try
|
||||||
{
|
{
|
||||||
|
_storage.LoadData(openFileDialog.FileName);
|
||||||
MessageBox.Show("Çàãðóçêà ïðîøëà óñïåøíî",
|
MessageBox.Show("Çàãðóçêà ïðîøëà óñïåøíî",
|
||||||
"Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
"Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
Log.Information($"Ôàéë {openFileDialog.FileName} óñïåøíî çàãðóæåí");
|
||||||
foreach (var collection in _storage.Keys)
|
foreach (var collection in _storage.Keys)
|
||||||
{
|
{
|
||||||
listBoxStorages.Items.Add(collection);
|
listBoxStorages.Items.Add(collection);
|
||||||
}
|
}
|
||||||
|
ReloadObjects();
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Íå çàãðóçèëîñü", "Ðåçóëüòàò",
|
Log.Warning("Íå óäàëîñü çàãðóçèòü");
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show($"Íå çàãðóçèëîñü: {ex.Message}","Ðåçóëüòàò", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,18 @@
|
|||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using NLog.Extensions.Logging;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using Serilog;
|
||||||
|
using Serilog.Events;
|
||||||
|
using Serilog.Formatting.Json;
|
||||||
|
using Microsoft.VisualBasic.Logging;
|
||||||
|
|
||||||
namespace ProjectAirplaneWithRadar
|
namespace ProjectAirplaneWithRadar
|
||||||
{
|
{
|
||||||
internal static class Program
|
internal static class Program
|
||||||
@ -8,6 +23,10 @@ namespace ProjectAirplaneWithRadar
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
|
Log.Logger = new LoggerConfiguration()
|
||||||
|
.WriteTo.File("log.txt")
|
||||||
|
.MinimumLevel.Debug()
|
||||||
|
.CreateLogger();
|
||||||
// To customize application configuration such as set high DPI settings or default font,
|
// To customize application configuration such as set high DPI settings or default font,
|
||||||
// see https://aka.ms/applicationconfiguration.
|
// see https://aka.ms/applicationconfiguration.
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
using System.CodeDom;
|
using ProjectAirplaneWithRadar.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.CodeDom;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Windows.Forms.VisualStyles;
|
using System.Windows.Forms.VisualStyles;
|
||||||
@ -19,13 +22,15 @@ namespace ProjectAirplaneWithRadar.Generics
|
|||||||
public bool Insert(T airplane)
|
public bool Insert(T airplane)
|
||||||
{
|
{
|
||||||
if (_places.Count == _maxCount)
|
if (_places.Count == _maxCount)
|
||||||
return false;
|
throw new StorageOverflowException(_maxCount);
|
||||||
Insert(airplane, 0);
|
Insert(airplane, 0);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public bool Insert(T airplane, int position)
|
public bool Insert(T airplane, 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;
|
return false;
|
||||||
_places.Insert(position, airplane);
|
_places.Insert(position, airplane);
|
||||||
return true;
|
return true;
|
||||||
@ -33,7 +38,7 @@ namespace ProjectAirplaneWithRadar.Generics
|
|||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
if (!(position >= 0 && position < Count))
|
if (!(position >= 0 && position < Count))
|
||||||
return false;
|
throw new AirplaneNotFoundException(position);
|
||||||
_places.RemoveAt(position);
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user