Доработка загрузки сохранённых файлов.

This commit is contained in:
Programmist73 2022-11-08 09:53:18 +04:00
parent 8561691deb
commit 69386aab84
8 changed files with 69 additions and 67 deletions

View File

@ -45,7 +45,5 @@ namespace Airbus
g.DrawEllipse(pen, _startPosX + 24, _startPosY + 22, 10, 5);
}
}
}
}

View File

@ -25,7 +25,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]),
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.Location = new System.Drawing.Point(843, 28);
this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(250, 694);
this.groupBoxTools.Size = new System.Drawing.Size(250, 769);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты";
@ -145,7 +145,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::Airbus.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(158, 629);
this.buttonRight.Location = new System.Drawing.Point(158, 704);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(45, 45);
this.buttonRight.TabIndex = 9;
@ -157,7 +157,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::Airbus.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(107, 629);
this.buttonDown.Location = new System.Drawing.Point(107, 704);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(45, 45);
this.buttonDown.TabIndex = 8;
@ -169,7 +169,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::Airbus.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(56, 629);
this.buttonLeft.Location = new System.Drawing.Point(56, 704);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(45, 45);
this.buttonLeft.TabIndex = 7;
@ -181,7 +181,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::Airbus.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(107, 578);
this.buttonUp.Location = new System.Drawing.Point(107, 653);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(45, 45);
this.buttonUp.TabIndex = 6;
@ -241,7 +241,7 @@
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 28);
this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(843, 694);
this.pictureBox.Size = new System.Drawing.Size(843, 769);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@ -291,7 +291,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1093, 722);
this.ClientSize = new System.Drawing.Size(1093, 797);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip);

View File

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

View File

@ -66,4 +66,7 @@
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>311, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>

View File

@ -146,7 +146,7 @@
//
// panelPurple
//
this.panelPurple.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(0)))), ((int)(((byte)(192)))));
this.panelPurple.BackColor = System.Drawing.Color.DeepPink;
this.panelPurple.Location = new System.Drawing.Point(192, 79);
this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(40, 40);

View File

@ -38,22 +38,19 @@ namespace Airbus
//добавление карты
public void AddMap(string name, AbstractMap map)
{
var NewElem = new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(
_pictureWidth, _pictureHeight, map);
_mapStorage.Add(name, NewElem);
if (!_mapStorage.ContainsKey(name))
{
_mapStorage.Add(name, new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
}
}
//удаление карты
public void DelMap(string 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);
if (_mapStorage.ContainsKey(name))
{
_mapStorage.Remove(name);
}
}
//сохранение информации по самолётам в ангарах в файл
@ -64,14 +61,15 @@ namespace Airbus
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)
{
WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" +
$"{Environment.NewLine}", fs);
sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" +
$"{Environment.NewLine}");
}
}
@ -86,52 +84,41 @@ namespace Airbus
return false;
}
string bufferTextFromFile = "";
using (FileStream fs = new(filename, FileMode.Open))
using (StreamReader sr = new(filename))
{
byte[] b = new byte[fs.Length];
UTF8Encoding temp = new(true);
string str = sr.ReadLine();
while (fs.Read(b, 0, b.Length) > 0)
//если не содержит такую запись
if (!str.Contains("MapsCollection"))
{
bufferTextFromFile += temp.GetString(b);
}
}
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 "DesertStormMap":
map = new DesertStormMap();
break;
case "StarWarsMap":
map = new StarWarsMap();
break;
return false;
}
_mapStorage.Add(elem[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight,
_mapStorage.Clear();
while ((str = sr.ReadLine()) != null)
{
var element = str.Split(separatorDict);
AbstractMap map = null;
switch (element[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "DesertStormMap":
map = new DesertStormMap();
break;
case "StarWarsMap":
map = new StarWarsMap();
break;
}
_mapStorage.Add(element[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight,
map));
_mapStorage[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
_mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
}
return true;
@ -143,7 +130,17 @@ namespace Airbus
{
get
{
return _mapStorage[ind];
if(ind != String.Empty)
{
MapWithSetPlanesGeneric<IDrawningObject, AbstractMap> value;
if(_mapStorage.TryGetValue(ind, out value))
{
return value;
}
}
return null;
}
}
}

View File

@ -0,0 +1,3 @@
MapsCollection
123|StarWarsMap|1000:750:Yellow;1000:750:Lime:Red:True:True;
456|DesertStormMap|1000:750:Red;1000:750:Blue;1000:750:DeepPink:Lime:True:True;