Lab6 Done+

This commit is contained in:
Yunusov_Niyaz 2023-12-06 17:18:36 +04:00
parent 9b61350dbf
commit a96cb7156e
3 changed files with 19 additions and 23 deletions

View File

@ -39,7 +39,6 @@ namespace ProjectTrolleybus.Generics
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly char _separatorForObject = ':';
/// <summary>
/// Конструктор
/// </summary>
@ -47,8 +46,7 @@ namespace ProjectTrolleybus.Generics
/// <param name="pictureHeight"></param>
public BusesGenericStorage(int pictureWidth, int pictureHeight)
{
_busStorages = new Dictionary<string,
BusesGenericCollection<DrawingBus, DrawingObjectBus>>();
_busStorages = new Dictionary<string, BusesGenericCollection<DrawingBus, DrawingObjectBus>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@ -76,8 +74,7 @@ namespace ProjectTrolleybus.Generics
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public BusesGenericCollection<DrawingBus, DrawingObjectBus>?
this[string ind]
public BusesGenericCollection<DrawingBus, DrawingObjectBus>? this[string ind]
{
get
{
@ -129,9 +126,9 @@ namespace ProjectTrolleybus.Generics
{
return false;
}
using (StreamReader streanReader = new(filename))
using (StreamReader streamReader = new(filename))
{
string str = streanReader.ReadLine();
string str = streamReader.ReadLine();
var strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strings == null || strings.Length == 0)
{
@ -147,12 +144,11 @@ namespace ProjectTrolleybus.Generics
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 2)
{
str = streanReader.ReadLine();
str = streamReader.ReadLine();
continue;
}
BusesGenericCollection<DrawingBus, DrawingObjectBus> collection = new(_pictureWidth, _pictureHeight);
string[] set = record[1].Split(_separatorRecords,
StringSplitOptions.RemoveEmptyEntries);
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
DrawingBus? bus = elem?.CreateDrawingBus(_separatorForObject, _pictureWidth, _pictureHeight);
@ -165,7 +161,7 @@ namespace ProjectTrolleybus.Generics
}
}
_busStorages.Add(record[0], collection);
str = streanReader.ReadLine();
str = streamReader.ReadLine();
} while (str != null);
}
return true;

View File

@ -11,20 +11,20 @@ namespace ProjectTrolleybus.DrawingObjects
{
public static DrawingBus? CreateDrawingBus(this string info, char separatorForObject, int width, int height)
{
string[] strs = info.Split(separatorForObject);
if (strs.Length == 3)
string[] strings = info.Split(separatorForObject);
if (strings.Length == 3)
{
return new DrawingBus(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
return new DrawingBus(Convert.ToInt32(strings[0]),
Convert.ToInt32(strings[1]), Color.FromName(strings[2]), width, height);
}
if (strs.Length == 6)
if (strings.Length == 6)
{
return new DrawingTrolleybus(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]),
Color.FromName(strs[2]),
Color.FromName(strs[3]),
Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]),
return new DrawingTrolleybus(Convert.ToInt32(strings[0]),
Convert.ToInt32(strings[1]),
Color.FromName(strings[2]),
Color.FromName(strings[3]),
Convert.ToBoolean(strings[4]),
Convert.ToBoolean(strings[5]),
width, height);
}
return null;

View File

@ -210,7 +210,7 @@
//
// openFileDialog
//
openFileDialog.FileName = "openFileDialog1";
openFileDialog.FileName = "busStorages";
openFileDialog.Filter = "«txt file | *.txt";
//
// saveFileDialog