This commit is contained in:
Sergey Kozyrev 2023-11-15 11:34:08 +04:00
parent 8079e18f75
commit 3fb85c16dd
3 changed files with 39 additions and 44 deletions

View File

@ -68,40 +68,31 @@ namespace Lab.Generics
{
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);
using (StreamWriter writer = new StreamWriter(filename))
{
writer.WriteLine("CarStorage");
writer.Write(data.ToString());
return true;
}
}
public bool LoadData(string filename)
{
if (!File.Exists(filename))
{
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0)
{
bufferTextFromFile += temp.GetString(b);
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
using (StreamReader reader = new StreamReader(filename))
{
string checker = reader.ReadLine();
if (checker == null)
return false;
}
if (!strs[0].StartsWith("CarStorage"))
{
string strs = reader.ReadLine();
if (!checker.StartsWith("CarStorage"))
return false;
}
_carStorages.Clear();
foreach (string data in strs)
foreach (string data in strs.Split(';'))
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
@ -126,7 +117,7 @@ namespace Lab.Generics
}
return true;
}
}
}
}

View File

@ -38,12 +38,12 @@ namespace Lab
{
return string.Empty;
}
var str = $"{Tanker.Speed}{separatorForObject}{Tanker.Weight}{separatorForObject}{Tanker.BodyColor.Name}";
var str = $"{Tanker.Speed}{separatorForObject}{Tanker.Weight}{separatorForObject}{Tanker.BodyColor}";
if (Tanker is not GasolineTanker gasTanker)
{
return str;
}
return $"{str}{separatorForObject}{gasTanker.AdditionalColor.Name}{separatorForObject}{gasTanker.BodyKit}{separatorForObject}{gasTanker.Wing}{separatorForObject}{gasTanker.SportLine}";
return $"{str}{separatorForObject}{gasTanker.AdditionalColor}{separatorForObject}{gasTanker.BodyKit}{separatorForObject}{gasTanker.Wing}{separatorForObject}{gasTanker.SportLine}";
}
}

View File

@ -49,12 +49,16 @@ namespace Lab.Generics
{
if (position < 0 || position > _maxCount)
return null;
if (_places.Count <= position)
return null;
return _places[position];
}
set
{
if (position < 0 || position > _maxCount)
return;
if (_places.Count <= position)
return;
_places[position] = value;
}
}