diff --git a/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs b/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
index a443262..323aecc 100644
--- a/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
+++ b/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
@@ -21,7 +21,7 @@ namespace ProjectExcavator.Generic
///
/// Получение объектов коллекции
///
- public IEnumerable GetCars => _collection.GetExcavators();
+ public IEnumerable GetExcavators => _collection.GetExcavators();
public ExcavatorGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
@@ -74,6 +74,7 @@ namespace ProjectExcavator.Generic
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
}
}
+
private void DrawObjects(Graphics g)
{
int i = 0;
diff --git a/ProjectExcavator/ProjectExcavator/ExcavatorsGenericStorage.cs b/ProjectExcavator/ProjectExcavator/ExcavatorsGenericStorage.cs
index 8f2b095..a35b5c7 100644
--- a/ProjectExcavator/ProjectExcavator/ExcavatorsGenericStorage.cs
+++ b/ProjectExcavator/ProjectExcavator/ExcavatorsGenericStorage.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.DirectoryServices.ActiveDirectory;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -63,25 +64,20 @@ namespace ProjectExcavator.Generic
{
File.Delete(filename);
}
- StringBuilder data = new();
- foreach (KeyValuePair> record in _excavatorStorages)
+ using (StreamWriter sw = File.CreateText(filename))
{
- StringBuilder records = new();
- foreach (DrawningExcavator? elem in record.Value.GetCars)
- {
- records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
+ sw.WriteLine($"ExcavatorStorage");
+ string storageString;
+ foreach (var storage in _excavatorStorages)
+ {
+ storageString = "";
+ foreach (var excavator in storage.Value.GetExcavators)
+ {
+ storageString += $"{excavator?.GetDataForSave(_separatorForObject)}{_separatorRecords}";
+ }
+ sw.WriteLine($"{storage.Key}{_separatorForKeyValue}{storageString}");
+ }
}
- data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
- }
- if (data.Length == 0)
- {
- return false;
- }
- using FileStream fs = new(filename, FileMode.Create);
- byte[] info = new
- UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}");
- fs.Write(info, 0, info.Length);
return true;
}
///
@@ -95,58 +91,45 @@ namespace ProjectExcavator.Generic
{
return false;
}
- string bufferTextFromFile = "";
- using (FileStream fs = new(filename, FileMode.Open))
+ using (StreamReader sr = new StreamReader(filename))
{
- byte[] b = new byte[fs.Length];
- UTF8Encoding temp = new(true);
- while (fs.Read(b, 0, b.Length) > 0)
+ string? currentLine = sr.ReadLine();
+ if (currentLine == null || !currentLine.Contains("ExcavatorStorage"))
{
- bufferTextFromFile += temp.GetString(b);
+ return false;
}
- }
- var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
- if (strs == null || strs.Length == 0)
- {
- return false;
- }
- if (!strs[0].StartsWith("ExcavatorStorage"))
- {
- //если нет такой записи, то это не те данные
- return false;
- }
- _excavatorStorages.Clear();
- foreach (string data in strs)
-
-
- {
- string[] record = data.Split(_separatorForKeyValue,
- StringSplitOptions.RemoveEmptyEntries);
- if (record.Length != 2)
+ _excavatorStorages.Clear();
+ currentLine = sr.ReadLine();
+ while (currentLine != null)
{
- continue;
- }
- ExcavatorGenericCollection collection = new(_pictureWidth,_pictureHeight);
- string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
- foreach(string elem in set)
- {
- DrawningExcavator? excavator = elem?.CreateDrawningExcavator(_separatorForObject, _pictureWidth, _pictureHeight);
- if(excavator != null)
+ string[] record = currentLine.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
+ if (record.Length != 2)
{
- if (collection + excavator == -1)
+ continue;
+ }
+ ExcavatorGenericCollection collection = new(_pictureWidth, _pictureHeight);
+ string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
+ foreach (string elem in set)
+ {
+ DrawningExcavator? excavator = elem?.CreateDrawningExcavator(_separatorForObject, _pictureWidth, _pictureHeight);
+ if (excavator != null)
{
- return false;
+ if (collection + excavator == -1)
+ {
+ return false;
+ }
}
}
+ _excavatorStorages.Add(record[0], collection);
+ currentLine = sr.ReadLine();
}
- _excavatorStorages.Add(record[0], collection);
+ return true;
}
- return true;
}
- ///
- /// Добавление набора
- ///
- /// Название набора
+ ///
+ /// Добавление набора
+ ///
+ /// Название набора
public void AddSet(string name)
{
if (_excavatorStorages.ContainsKey(name))
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
index e9b0ac0..695af45 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
@@ -150,9 +150,7 @@ pictureBoxCollection.Height);
MessageBox.Show("Не удалось удалить объект");
}
}
-
- private void buttonRefreshCollection_Click(object sender, EventArgs
-e)
+ private void RefreshCollection()
{
if (listBoxStorages.SelectedIndex == -1)
{
@@ -166,6 +164,11 @@ e)
}
pictureBoxCollection.Image = obj.ShowExcavator();
}
+
+ private void buttonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ RefreshCollection();
+ }
///
/// Обработка нажатия "Сохранение"
///
@@ -182,8 +185,7 @@ e)
}
else
{
- MessageBox.Show("Не сохранилось", "Результат",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Не сохранилось", "Результат",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
@@ -198,13 +200,13 @@ e)
{
if (_storage.LoadData(openFileDialog.FileName))
{
- MessageBox.Show("Загрузка прошла успешно",
- "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ ReloadObjects();
+ RefreshCollection();
+ MessageBox.Show("Загрузка прошла успешно","Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
- MessageBox.Show("Не загрузилось", "Результат",
- MessageBoxButtons.OK, MessageBoxIcon.Error);
+ MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
ReloadObjects();