Исправление ошибок
This commit is contained in:
parent
3b2f788d4f
commit
b3513987ac
@ -62,13 +62,13 @@ namespace Sailboat.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(BoatsGenericCollection<T, U> collect, T? obj)
|
public static bool operator +(BoatsGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect._collection.Insert(obj, new DrawingBoatEqutables());
|
return (bool)collect?._collection.Insert(obj, new DrawingBoatEqutables());
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
|
@ -129,39 +129,50 @@ namespace Sailboat.Generics
|
|||||||
{
|
{
|
||||||
throw new FileNotFoundException("Файл не найден");
|
throw new FileNotFoundException("Файл не найден");
|
||||||
}
|
}
|
||||||
using (StreamReader sr = new(filename))
|
|
||||||
{
|
using (StreamReader reader = new StreamReader(filename))
|
||||||
string str = sr.ReadLine();
|
|
||||||
if (str == null || str.Length == 0)
|
|
||||||
{
|
{
|
||||||
|
string checker = reader.ReadLine();
|
||||||
|
if (checker == null)
|
||||||
throw new NullReferenceException("Нет данных для загрузки");
|
throw new NullReferenceException("Нет данных для загрузки");
|
||||||
}
|
if (!checker.StartsWith("BoatStorage"))
|
||||||
if (!str.StartsWith("BoatStorage"))
|
|
||||||
{
|
{
|
||||||
throw new InvalidDataException("Неверный формат данных");
|
//если нет такой записи, то это не те данные
|
||||||
|
throw new FormatException("Неверный формат данных");
|
||||||
}
|
}
|
||||||
|
|
||||||
_boatStorages.Clear();
|
_boatStorages.Clear();
|
||||||
while ((str = sr.ReadLine()) != null)
|
string strs;
|
||||||
|
bool firstinit = true;
|
||||||
|
while ((strs = reader.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
if (strs == null && firstinit)
|
||||||
if (record.Length != 2)
|
throw new NullReferenceException("Нет данных для загрузки");
|
||||||
{
|
if (strs == null)
|
||||||
continue;
|
break;
|
||||||
}
|
firstinit = false;
|
||||||
|
string name = strs.Split('|')[0];
|
||||||
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
||||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
foreach (string data in strs.Split('|')[1].Split(';'))
|
||||||
foreach (string elem in set.Reverse())
|
|
||||||
{
|
{
|
||||||
DrawingBoat? truck = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
DrawingBoat? vehicle = data?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
if (truck != null)
|
if (vehicle != null)
|
||||||
{
|
{
|
||||||
if (collection + truck == -1)
|
try
|
||||||
{
|
{
|
||||||
throw new ApplicationException("Ошибка добавления в коллекцию");
|
_ = collection + vehicle;
|
||||||
|
}
|
||||||
|
catch (BoatNotFoundException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
catch (StorageOverflowException e)
|
||||||
|
{
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_boatStorages.Add(new BoatsCollectionInfo(record[0], string.Empty), collection);
|
_boatStorages.Add(new BoatsCollectionInfo(name, string.Empty), collection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
89
Sailboat/Sailboat/FormBoatCollection.Designer.cs
generated
89
Sailboat/Sailboat/FormBoatCollection.Designer.cs
generated
@ -29,29 +29,31 @@ namespace Sailboat
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
pictureBoxCollection = new PictureBox();
|
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||||
panelTools = new Panel();
|
this.panelTools = new System.Windows.Forms.Panel();
|
||||||
panelCollection = new Panel();
|
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||||
buttonDelObject = new Button();
|
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||||
listBoxStorages = new ListBox();
|
this.panelCollection = new System.Windows.Forms.Panel();
|
||||||
buttonAddObject = new Button();
|
this.buttonDelObject = new System.Windows.Forms.Button();
|
||||||
textBoxStorageName = new TextBox();
|
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
this.buttonAddObject = new System.Windows.Forms.Button();
|
||||||
buttonRefreshCollection = new Button();
|
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||||
buttonRemoveBoat = new Button();
|
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||||
buttonAddBoat = new Button();
|
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||||
menuStrip = new MenuStrip();
|
this.buttonRemoveBoat = new System.Windows.Forms.Button();
|
||||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
this.buttonAddBoat = new System.Windows.Forms.Button();
|
||||||
ToolStripMenuItem = new ToolStripMenuItem();
|
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
openFileDialog = new OpenFileDialog();
|
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
saveFileDialog = new SaveFileDialog();
|
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
panelTools.SuspendLayout();
|
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||||
panelCollection.SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||||
menuStrip.SuspendLayout();
|
this.panelTools.SuspendLayout();
|
||||||
SuspendLayout();
|
this.panelCollection.SuspendLayout();
|
||||||
|
this.menuStrip.SuspendLayout();
|
||||||
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
@ -77,7 +79,26 @@ namespace Sailboat
|
|||||||
panelTools.Name = "panelTools";
|
panelTools.Name = "panelTools";
|
||||||
panelTools.Size = new Size(183, 542);
|
panelTools.Size = new Size(183, 542);
|
||||||
panelTools.TabIndex = 1;
|
panelTools.TabIndex = 1;
|
||||||
this.panelTools.TabIndex = 1;
|
//
|
||||||
|
// buttonSortByColor
|
||||||
|
//
|
||||||
|
buttonSortByColor.Location = new System.Drawing.Point(20, 479);
|
||||||
|
buttonSortByColor.Name = "buttonSortByColor";
|
||||||
|
buttonSortByColor.Size = new System.Drawing.Size(180, 34);
|
||||||
|
buttonSortByColor.TabIndex = 7;
|
||||||
|
buttonSortByColor.Text = "Сортировать по цвету";
|
||||||
|
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||||
|
//
|
||||||
|
// buttonSortByType
|
||||||
|
//
|
||||||
|
buttonSortByType.Location = new System.Drawing.Point(20, 439);
|
||||||
|
buttonSortByType.Name = "buttonSortByType";
|
||||||
|
buttonSortByType.Size = new System.Drawing.Size(180, 34);
|
||||||
|
buttonSortByType.TabIndex = 6;
|
||||||
|
buttonSortByType.Text = "Сортировать по типу";
|
||||||
|
buttonSortByType.UseVisualStyleBackColor = true;
|
||||||
|
buttonSortByType.Click += buttonSortByType_Click;
|
||||||
//
|
//
|
||||||
// panelCollection
|
// panelCollection
|
||||||
//
|
//
|
||||||
@ -220,26 +241,6 @@ namespace Sailboat
|
|||||||
//
|
//
|
||||||
saveFileDialog.Filter = "txt file | *.txt";
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
//
|
//
|
||||||
// buttonSortByType
|
|
||||||
//
|
|
||||||
buttonSortByType.Location = new System.Drawing.Point(20, 348);
|
|
||||||
buttonSortByType.Name = "buttonSortByType";
|
|
||||||
buttonSortByType.Size = new System.Drawing.Size(180, 34);
|
|
||||||
buttonSortByType.TabIndex = 6;
|
|
||||||
buttonSortByType.Text = "Сортировать по типу";
|
|
||||||
buttonSortByType.UseVisualStyleBackColor = true;
|
|
||||||
buttonSortByType.Click += new System.EventHandler(this.buttonSortByType_Click);
|
|
||||||
//
|
|
||||||
// buttonSortByColor
|
|
||||||
//
|
|
||||||
buttonSortByColor.Location = new System.Drawing.Point(20, 488);
|
|
||||||
buttonSortByColor.Name = "buttonSortByColor";
|
|
||||||
buttonSortByColor.Size = new System.Drawing.Size(180, 34);
|
|
||||||
buttonSortByColor.TabIndex = 7;
|
|
||||||
buttonSortByColor.Text = "Сортировать по цвету";
|
|
||||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
|
||||||
buttonSortByColor.Click += new System.EventHandler(this.buttonSortByColor_Click);
|
|
||||||
//
|
|
||||||
// FormBoatCollection
|
// FormBoatCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
@ -77,16 +77,23 @@ namespace Sailboat
|
|||||||
_logger.LogWarning("Добавление пустого объекта");
|
_logger.LogWarning("Добавление пустого объекта");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (obj + drawingBoat != -1)
|
try
|
||||||
|
{
|
||||||
|
if (obj + drawingBoat)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = obj.ShowBoats();
|
pictureBoxCollection.Image = obj.ShowBoats();
|
||||||
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
catch (StorageOverflowException ex)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show(ex.Message);
|
||||||
_logger.LogInformation($"Не удалось добавить объект");
|
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
|
||||||
|
}
|
||||||
|
catch (ArgumentException ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +135,6 @@ namespace Sailboat
|
|||||||
_logger.LogWarning($"{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}");
|
_logger.LogWarning($"{ex.Message} из набора {listBoxStorages.SelectedItem.ToString()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
|
1
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
1
Sailboat/Sailboat/FormSailboat.Designer.cs
generated
@ -162,6 +162,7 @@
|
|||||||
buttonSelectBoat.TabIndex = 9;
|
buttonSelectBoat.TabIndex = 9;
|
||||||
buttonSelectBoat.Text = "Выбрать лодку";
|
buttonSelectBoat.Text = "Выбрать лодку";
|
||||||
buttonSelectBoat.UseVisualStyleBackColor = true;
|
buttonSelectBoat.UseVisualStyleBackColor = true;
|
||||||
|
buttonSelectBoat.Click += buttonSelectBoat_Click;
|
||||||
//
|
//
|
||||||
// FormSailboat
|
// FormSailboat
|
||||||
//
|
//
|
||||||
|
@ -23,7 +23,6 @@ namespace Sailboat.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _maxCount;
|
private readonly int _maxCount;
|
||||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -38,7 +37,7 @@ namespace Sailboat.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="boat">Добавляемая лодка</param>
|
/// <param name="boat">Добавляемая лодка</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T boat, IEqualityComparer<T?>? equal = null)
|
public bool Insert(T boat, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
return Insert(boat, 0, equal);
|
return Insert(boat, 0, equal);
|
||||||
}
|
}
|
||||||
@ -48,19 +47,18 @@ namespace Sailboat.Generics
|
|||||||
/// <param name="boat">Добавляемая лодка</param>
|
/// <param name="boat">Добавляемая лодка</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
|
public bool Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (position < 0 || position > Count)
|
if (position < 0 || position >= _maxCount)
|
||||||
throw new BoatNotFoundException(position);
|
throw new BoatNotFoundException(position);
|
||||||
|
|
||||||
if (Count >= _maxCount)
|
if (Count >= _maxCount)
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
if (equal != null && _places.Contains(boat, equal))
|
|
||||||
{
|
|
||||||
|
|
||||||
return -1;
|
if (equal != null && _places.Contains(boat, equal))
|
||||||
}
|
throw new ArgumentException("Данный объект уже есть в коллекции");
|
||||||
_places.Insert(position, boat);
|
_places.Insert(0, boat);
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
|
Loading…
Reference in New Issue
Block a user