Исправление ошибок
This commit is contained in:
parent
3b2f788d4f
commit
b3513987ac
@ -62,13 +62,13 @@ namespace Sailboat.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <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)
|
||||
{
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
return collect._collection.Insert(obj, new DrawingBoatEqutables());
|
||||
return (bool)collect?._collection.Insert(obj, new DrawingBoatEqutables());
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
|
@ -129,39 +129,50 @@ namespace Sailboat.Generics
|
||||
{
|
||||
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("Нет данных для загрузки");
|
||||
}
|
||||
if (!str.StartsWith("BoatStorage"))
|
||||
if (!checker.StartsWith("BoatStorage"))
|
||||
{
|
||||
throw new InvalidDataException("Неверный формат данных");
|
||||
//если нет такой записи, то это не те данные
|
||||
throw new FormatException("Неверный формат данных");
|
||||
}
|
||||
|
||||
_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 (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (strs == null && firstinit)
|
||||
throw new NullReferenceException("Нет данных для загрузки");
|
||||
if (strs == null)
|
||||
break;
|
||||
firstinit = false;
|
||||
string name = strs.Split('|')[0];
|
||||
BoatsGenericCollection<DrawingBoat, DrawingObjectBoat> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set.Reverse())
|
||||
foreach (string data in strs.Split('|')[1].Split(';'))
|
||||
{
|
||||
DrawingBoat? truck = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (truck != null)
|
||||
DrawingBoat? vehicle = data?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
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>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxCollection = new PictureBox();
|
||||
panelTools = new Panel();
|
||||
panelCollection = new Panel();
|
||||
buttonDelObject = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
buttonAddObject = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
buttonRefreshCollection = new Button();
|
||||
buttonRemoveBoat = new Button();
|
||||
buttonAddBoat = new Button();
|
||||
menuStrip = new MenuStrip();
|
||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||
ToolStripMenuItem = new ToolStripMenuItem();
|
||||
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panelTools.SuspendLayout();
|
||||
panelCollection.SuspendLayout();
|
||||
menuStrip.SuspendLayout();
|
||||
SuspendLayout();
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panelTools = new System.Windows.Forms.Panel();
|
||||
this.buttonSortByColor = new System.Windows.Forms.Button();
|
||||
this.buttonSortByType = new System.Windows.Forms.Button();
|
||||
this.panelCollection = new System.Windows.Forms.Panel();
|
||||
this.buttonDelObject = new System.Windows.Forms.Button();
|
||||
this.listBoxStorages = new System.Windows.Forms.ListBox();
|
||||
this.buttonAddObject = new System.Windows.Forms.Button();
|
||||
this.textBoxStorageName = new System.Windows.Forms.TextBox();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
|
||||
this.buttonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.buttonRemoveBoat = new System.Windows.Forms.Button();
|
||||
this.buttonAddBoat = new System.Windows.Forms.Button();
|
||||
this.menuStrip = new System.Windows.Forms.MenuStrip();
|
||||
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panelTools.SuspendLayout();
|
||||
this.panelCollection.SuspendLayout();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
@ -77,7 +79,26 @@ namespace Sailboat
|
||||
panelTools.Name = "panelTools";
|
||||
panelTools.Size = new Size(183, 542);
|
||||
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
|
||||
//
|
||||
@ -220,26 +241,6 @@ namespace Sailboat
|
||||
//
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
|
@ -77,16 +77,23 @@ namespace Sailboat
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
}
|
||||
if (obj + drawingBoat != -1)
|
||||
try
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
||||
if (obj + drawingBoat)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
_logger.LogInformation($"Объект {obj.GetType()} добавлен");
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (StorageOverflowException ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogInformation($"Не удалось добавить объект");
|
||||
MessageBox.Show(ex.Message);
|
||||
_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()}");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
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.Text = "Выбрать лодку";
|
||||
buttonSelectBoat.UseVisualStyleBackColor = true;
|
||||
buttonSelectBoat.Click += buttonSelectBoat_Click;
|
||||
//
|
||||
// FormSailboat
|
||||
//
|
||||
|
@ -23,7 +23,6 @@ namespace Sailboat.Generics
|
||||
/// </summary>
|
||||
private readonly int _maxCount;
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -38,7 +37,7 @@ namespace Sailboat.Generics
|
||||
/// </summary>
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <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);
|
||||
}
|
||||
@ -48,19 +47,18 @@ namespace Sailboat.Generics
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <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);
|
||||
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
if (equal != null && _places.Contains(boat, equal))
|
||||
{
|
||||
|
||||
return -1;
|
||||
}
|
||||
_places.Insert(position, boat);
|
||||
return position;
|
||||
throw new ArgumentException("Данный объект уже есть в коллекции");
|
||||
_places.Insert(0, boat);
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
|
Loading…
Reference in New Issue
Block a user