diff --git a/111.txt b/111.txt new file mode 100644 index 0000000..6f7540f --- /dev/null +++ b/111.txt @@ -0,0 +1,3 @@ +CollectionsStorage +1|Massive|45|EntityMilitaryAircraft:100:100:Yellow;EntityMilitaryAircraft:100:100:Red; +2|Massive|45|EntityMilitaryAircraft:100:100:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet;EntityMilitaryAircraft:100:100:BlueViolet; \ No newline at end of file diff --git a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs index a3c69d7..d8f62c5 100644 --- a/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs +++ b/AirFighter/AirFighter/CollectionGenericObjects/StorageCollection.cs @@ -40,7 +40,7 @@ public class StorageCollection /// public StorageCollection() { - _storages = new Dictionary>(); + _storages = new Dictionary>(); } /// @@ -90,12 +90,12 @@ public class StorageCollection } /// - /// Сохранение информации по автомобилям в хранилище в файл - /// - /// Путь и имя файла - /// true - сохранение прошло успешно, false - ошибка при сохранении данных - - public bool SaveData(string filename) + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + + public bool SaveData(string filename) { if (_storages.Count == 0) { @@ -110,12 +110,13 @@ public class StorageCollection using (StreamWriter writer = new StreamWriter(filename)) { writer.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) { StringBuilder sb = new(); sb.Append(Environment.NewLine); - // не сохраняем пустые коллекции + if (value.Value.Count == 0) { continue; @@ -127,9 +128,11 @@ public class StorageCollection sb.Append(_separatorForKeyValue); sb.Append(value.Value.MaxCount); sb.Append(_separatorForKeyValue); + foreach (T? item in value.Value.GetItems()) { string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) { continue; @@ -159,7 +162,7 @@ public class StorageCollection return false; } using (StreamReader fs = File.OpenText(filename)) - { + { string str = fs.ReadLine(); if (str == null || str.Length == 0) @@ -173,7 +176,7 @@ public class StorageCollection } _storages.Clear(); - + string strs = ""; while ((strs = fs.ReadLine()) != null) diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs index 4916ec0..b23df18 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.Designer.cs @@ -277,7 +277,7 @@ saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; saveToolStripMenuItem.Size = new Size(227, 26); saveToolStripMenuItem.Text = "Сохранение"; - saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; + saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // // loadToolStripMenuItem // @@ -285,7 +285,7 @@ loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; loadToolStripMenuItem.Size = new Size(227, 26); loadToolStripMenuItem.Text = "Загрузка"; - loadToolStripMenuItem.Click += loadToolStripMenuItem_Click; + loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; // // openFileDialog // diff --git a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs index 760c7b2..d9f4b35 100644 --- a/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs +++ b/AirFighter/AirFighter/FormMilitaryAircraftCollection.cs @@ -232,7 +232,7 @@ public partial class FormMilitaryAircraftCollection : Form /// /// /// - private void saveToolStripMenuItem_Click(object sender, EventArgs e) + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) { if (saveFileDialog.ShowDialog() == DialogResult.OK) { @@ -252,18 +252,18 @@ public partial class FormMilitaryAircraftCollection : Form /// /// /// - private void loadToolStripMenuItem_Click(object sender, EventArgs e) + private void LoadToolStripMenuItem_Click(object sender, EventArgs e) { if (openFileDialog.ShowDialog() == DialogResult.OK) { if (_storageCollection.LoadData(openFileDialog.FileName)) { MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - RerfreshListBoxItems(); + RerfreshListBoxItems(); } else { - MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/AirFighter/AirFighter/MilitaryAircraftDelegate.cs b/AirFighter/AirFighter/MilitaryAircraftDelegate.cs deleted file mode 100644 index bc7be90..0000000 --- a/AirFighter/AirFighter/MilitaryAircraftDelegate.cs +++ /dev/null @@ -1,9 +0,0 @@ -using ProjectAirFighter.Drawnings; - -namespace ProjectAirFighter; - -/// -/// Делегат передачи объекта класса-прорисовки -/// -/// -public delegate void MilitaryAircraftDelegate(DrawningMilitaryAircraft militaryAircraft);