Мелкие правки.

This commit is contained in:
Nikolaeva_Y.A 2022-12-06 08:43:56 +04:00
parent 801a55a24c
commit 14708bf7c6
4 changed files with 62 additions and 62 deletions

View File

@ -24,7 +24,7 @@ namespace Airbus
} }
//если аэробус //если аэробус
if (strs.Length == 5) if (strs.Length == 6)
{ {
return new DrawningSuperAirbus(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), return new DrawningSuperAirbus(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5])); Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), Convert.ToBoolean(strs[5]));

View File

@ -72,7 +72,7 @@
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(627, 24); this.groupBoxTools.Location = new System.Drawing.Point(627, 24);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(200, 510); this.groupBoxTools.Size = new System.Drawing.Size(200, 547);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
@ -238,7 +238,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 24); this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(627, 510); this.pictureBox.Size = new System.Drawing.Size(627, 547);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -266,12 +266,14 @@
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.SaveToolStripMenuItem.Text = "Сохранение"; this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
// //
// LoadToolStripMenuItem // LoadToolStripMenuItem
// //
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.LoadToolStripMenuItem.Text = "Загрузка"; this.LoadToolStripMenuItem.Text = "Загрузка";
this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
// //
// openFileDialog // openFileDialog
// //
@ -286,7 +288,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(827, 534); this.ClientSize = new System.Drawing.Size(827, 571);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip1); this.Controls.Add(this.menuStrip1);

View File

@ -227,10 +227,11 @@ namespace Airbus
//обработка нажатия загрузки //обработка нажатия загрузки
private void LoadToolStripMenuItem_Click(object sender, EventArgs e) private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{ {
if (saveFileDialog.ShowDialog() == DialogResult.OK) if (openFileDialog.ShowDialog() == DialogResult.OK)
{ {
if (_mapsCollection.LoadData(openFileDialog.FileName)) if (_mapsCollection.LoadData(openFileDialog.FileName))
{ {
ReloadMaps();
MessageBox.Show("Загрузка данных прошла успешно", "Результат", MessageBox.Show("Загрузка данных прошла успешно", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBoxButtons.OK, MessageBoxIcon.Information);
} }

View File

@ -38,24 +38,22 @@ namespace Airbus
//добавление карты //добавление карты
public void AddMap(string name, AbstractMap map) public void AddMap(string name, AbstractMap map)
{ {
var NewElem = new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>( if (!_mapStorage.ContainsKey(name))
_pictureWidth, _pictureHeight, map); {
_mapStorage.Add(name, NewElem); _mapStorage.Add(name, new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
} }
//удаление карты //удаление карты
public void DelMap(string name) public void DelMap(string name)
{ {
_mapStorage.Remove(name); if (_mapStorage.ContainsKey(name))
} {
// Метод записи информации в файл _mapStorage.Remove(name);
private static void WriteToFile(string text, FileStream stream) }
{
byte[] info = new UTF8Encoding(true).GetBytes(text);
stream.Write(info, 0, info.Length);
} }
// Сохранение информации по автомобилям в хранилище в файл // сохранение информации по автомобилям в хранилище в файл
public bool SaveData(string filename) public bool SaveData(string filename)
{ {
if (File.Exists(filename)) if (File.Exists(filename))
@ -63,21 +61,21 @@ namespace Airbus
File.Delete(filename); File.Delete(filename);
} }
using (FileStream fs = new(filename, FileMode.Create)) using (StreamWriter sw = new(filename))
{ {
WriteToFile($"MapsCollection{Environment.NewLine}", fs); sw.Write($"MapsCollection{Environment.NewLine}");
foreach (var storage in _mapStorage) foreach (var storage in _mapStorage)
{ {
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" +
$"{Environment.NewLine}", fs); $"{Environment.NewLine}");
} }
} }
return true; return true;
} }
// Загрузка нформации по автомобилям на парковках из файла // загрузка информации по автомобилям на парковках из файла
public bool LoadData(string filename) public bool LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
@ -85,61 +83,60 @@ namespace Airbus
return false; return false;
} }
string bufferTextFromFile = ""; using (StreamReader sr = new(filename))
using (FileStream fs = new(filename, FileMode.Open))
{ {
byte[] b = new byte[fs.Length]; string str = "";
UTF8Encoding temp = new(true);
while (fs.Read(b, 0, b.Length) > 0) //если не содержит такую запись или пустой файл
if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
{ {
bufferTextFromFile += temp.GetString(b); return false;
}
}
var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (!strs[0].Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
return false;
}
//очищаем записи
_mapStorage.Clear();
for (int i = 1; i < strs.Length; ++i)
{
var elem = strs[i].Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "DesertMap":
map = new DesertMap();
break;
case "SpaceMap":
map = new SpaceMap();
break;
} }
_mapStorage.Add(elem[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map)); _mapStorage.Clear();
_mapStorage[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
while ((str = sr.ReadLine()) != null)
{
var element = str.Split(separatorDict);
AbstractMap map = null;
switch (element[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "DesertMap":
map = new DesertMap();
break;
case "SpaceMap":
map = new SpaceMap();
break;
}
_mapStorage.Add(element[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
} }
return true; return true;
} }
//Доступ к аэродрому //доступ к аэродрому
public MapWithSetPlanesGeneric<IDrawningObject, AbstractMap> this[string ind] public MapWithSetPlanesGeneric<IDrawningObject, AbstractMap> this[string ind]
{ {
get get
{ {
return _mapStorage[ind]; if (ind != string.Empty)
{
MapWithSetPlanesGeneric<IDrawningObject, AbstractMap> value;
if (_mapStorage.TryGetValue(ind, out value))
{
return value;
}
}
return null;
} }
} }
} }