шестая лаба

This commit is contained in:
ikswi 2024-05-02 11:12:20 +04:00
parent c3e7442abe
commit 94811d9785
5 changed files with 22 additions and 25 deletions

3
111.txt Normal file
View File

@ -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;

View File

@ -40,7 +40,7 @@ public class StorageCollection<T>
/// </summary>
public StorageCollection()
{
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
}
/// <summary>
@ -90,12 +90,12 @@ public class StorageCollection<T>
}
/// <summary>
/// Сохранение информации по автомобилям в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
/// Сохранение информации по автомобилям в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
{
if (_storages.Count == 0)
{
@ -110,12 +110,13 @@ public class StorageCollection<T>
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
StringBuilder sb = new();
sb.Append(Environment.NewLine);
// не сохраняем пустые коллекции
if (value.Value.Count == 0)
{
continue;
@ -127,9 +128,11 @@ public class StorageCollection<T>
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<T>
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<T>
}
_storages.Clear();
string strs = "";
while ((strs = fs.ReadLine()) != null)

View File

@ -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
//

View File

@ -232,7 +232,7 @@ public partial class FormMilitaryAircraftCollection : Form
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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);
}
}
}

View File

@ -1,9 +0,0 @@
using ProjectAirFighter.Drawnings;
namespace ProjectAirFighter;
/// <summary>
/// Делегат передачи объекта класса-прорисовки
/// </summary>
/// <param name="militaryAircraft"></param>
public delegate void MilitaryAircraftDelegate(DrawningMilitaryAircraft militaryAircraft);