lab_6_done
This commit is contained in:
parent
a8323ce73c
commit
a6bdc22ffe
@ -21,7 +21,7 @@ namespace ProjectExcavator.Generic
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T?> GetCars => _collection.GetExcavators();
|
||||
public IEnumerable<T?> 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;
|
||||
|
@ -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<string,
|
||||
ExcavatorGenericCollection<DrawningExcavator, DrawningObjectExcavator>> 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;
|
||||
}
|
||||
/// <summary>
|
||||
@ -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<DrawningExcavator,DrawningObjectExcavator> 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<DrawningExcavator, DrawningObjectExcavator> 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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
/// <summary>
|
||||
/// Добавление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_excavatorStorages.ContainsKey(name))
|
||||
|
@ -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();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user