From 813efb47b7707aca4f96e23649a7193d847b1353 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Tue, 21 Nov 2023 17:27:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sailboat/Sailboat/BoatsGenericStorage.cs | 10 ++- Sailboat/Sailboat/ExtentionDrawingBoat.cs | 2 +- .../Sailboat/FormBoatCollection.Designer.cs | 2 + Sailboat/Sailboat/FormBoatCollection.cs | 63 ++++++++++--------- Sailboat/Sailboat/FormBoatCollection.resx | 3 - 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Sailboat/Sailboat/BoatsGenericStorage.cs b/Sailboat/Sailboat/BoatsGenericStorage.cs index 8b68b99..c282fdc 100644 --- a/Sailboat/Sailboat/BoatsGenericStorage.cs +++ b/Sailboat/Sailboat/BoatsGenericStorage.cs @@ -119,7 +119,7 @@ namespace Sailboat.Generics } using FileStream fs = new(filename, FileMode.Create); byte[] info = new - UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}"); + UTF8Encoding(true).GetBytes($"BoatStorage{Environment.NewLine}{data}"); fs.Write(info, 0, info.Length); return true; } @@ -150,7 +150,7 @@ namespace Sailboat.Generics { return false; } - if (!strs[0].StartsWith("CarStorage")) + if (!strs[0].StartsWith("BoatStorage")) { //если нет такой записи, то это не те данные return false; @@ -158,8 +158,7 @@ namespace Sailboat.Generics _boatStorages.Clear(); foreach (string data in strs) { - string[] record = data.Split(_separatorForKeyValue, - StringSplitOptions.RemoveEmptyEntries); + string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); if (record.Length != 2) { continue; @@ -170,8 +169,7 @@ namespace Sailboat.Generics StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { - DrawingBoat? boat = - elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight); + DrawingBoat? boat = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight); if (boat != null) { if (!(collection + boat)) diff --git a/Sailboat/Sailboat/ExtentionDrawingBoat.cs b/Sailboat/Sailboat/ExtentionDrawingBoat.cs index 190503f..07da6f2 100644 --- a/Sailboat/Sailboat/ExtentionDrawingBoat.cs +++ b/Sailboat/Sailboat/ExtentionDrawingBoat.cs @@ -26,7 +26,7 @@ namespace Sailboat.DrawingObjects return new DrawingBoat(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); } - if (strs.Length == 7) + if (strs.Length == 6) { return new DrawingSailboat(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), diff --git a/Sailboat/Sailboat/FormBoatCollection.Designer.cs b/Sailboat/Sailboat/FormBoatCollection.Designer.cs index 871bc2d..f18e0c1 100644 --- a/Sailboat/Sailboat/FormBoatCollection.Designer.cs +++ b/Sailboat/Sailboat/FormBoatCollection.Designer.cs @@ -191,12 +191,14 @@ this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.SaveToolStripMenuItem.Text = "Сохранение"; + this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click); // // LoadToolStripMenuItem // this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26); this.LoadToolStripMenuItem.Text = "Загрузка"; + this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click); // // openFileDialog // diff --git a/Sailboat/Sailboat/FormBoatCollection.cs b/Sailboat/Sailboat/FormBoatCollection.cs index 8ea390a..1aa637c 100644 --- a/Sailboat/Sailboat/FormBoatCollection.cs +++ b/Sailboat/Sailboat/FormBoatCollection.cs @@ -166,37 +166,40 @@ namespace Sailboat } } - ///// - ///// Обработка нажатия "Сохранение" - ///// - ///// - ///// - //private void SaveToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // if (saveFileDialog.ShowDialog() == DialogResult.OK) - // { - // if (_storage.SaveData(saveFileDialog.FileName)) - // { - // MessageBox.Show("Сохранение прошло успешно", - // "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - // } - // else - // { - // MessageBox.Show("Не сохранилось", "Результат", - // MessageBoxButtons.OK, MessageBoxIcon.Error); - // } - // } - //} + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.SaveData(saveFileDialog.FileName)) + { + MessageBox.Show("Сохранение прошло успешно", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не сохранилось", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - ///// - ///// Обработка нажатия "Загрузка" - ///// - ///// - ///// - //private void LoadToolStripMenuItem_Click(object sender, EventArgs e) - //{ - // // TODO продумать логику - //} + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) + { + if (openFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.LoadData(openFileDialog.FileName)) + { + MessageBox.Show("Загрузка прошла успешно", + "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + ReloadObjects(); + } } } diff --git a/Sailboat/Sailboat/FormBoatCollection.resx b/Sailboat/Sailboat/FormBoatCollection.resx index 66d62b4..3198a4b 100644 --- a/Sailboat/Sailboat/FormBoatCollection.resx +++ b/Sailboat/Sailboat/FormBoatCollection.resx @@ -60,9 +60,6 @@ 17, 17 - - 17, 17 - 144, 0