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

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); 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]), 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(843, 28); this.groupBoxTools.Location = new System.Drawing.Point(843, 28);
this.groupBoxTools.Name = "groupBoxTools"; 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.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; 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.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.BackgroundImage = global::Airbus.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(45, 45); this.buttonRight.Size = new System.Drawing.Size(45, 45);
this.buttonRight.TabIndex = 9; 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.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.BackgroundImage = global::Airbus.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(45, 45); this.buttonDown.Size = new System.Drawing.Size(45, 45);
this.buttonDown.TabIndex = 8; 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.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.BackgroundImage = global::Airbus.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(45, 45); this.buttonLeft.Size = new System.Drawing.Size(45, 45);
this.buttonLeft.TabIndex = 7; 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.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.BackgroundImage = global::Airbus.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; 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.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(45, 45); this.buttonUp.Size = new System.Drawing.Size(45, 45);
this.buttonUp.TabIndex = 6; this.buttonUp.TabIndex = 6;
@ -241,7 +241,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, 28); this.pictureBox.Location = new System.Drawing.Point(0, 28);
this.pictureBox.Name = "pictureBox"; 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.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -291,7 +291,7 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 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.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Controls.Add(this.menuStrip); this.Controls.Add(this.menuStrip);

View File

@ -230,10 +230,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

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

View File

@ -146,7 +146,7 @@
// //
// panelPurple // 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.Location = new System.Drawing.Point(192, 79);
this.panelPurple.Name = "panelPurple"; this.panelPurple.Name = "panelPurple";
this.panelPurple.Size = new System.Drawing.Size(40, 40); this.panelPurple.Size = new System.Drawing.Size(40, 40);

View File

@ -38,22 +38,19 @@ 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)
{
if (_mapStorage.ContainsKey(name))
{ {
_mapStorage.Remove(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);
} }
//сохранение информации по самолётам в ангарах в файл //сохранение информации по самолётам в ангарах в файл
@ -64,14 +61,15 @@ 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}");
} }
} }
@ -86,36 +84,24 @@ 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 = sr.ReadLine();
UTF8Encoding temp = new(true);
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; return false;
} }
//очищаем записи
_mapStorage.Clear(); _mapStorage.Clear();
for (int i = 1; i < strs.Length; ++i) while ((str = sr.ReadLine()) != null)
{ {
var elem = strs[i].Split(separatorDict); var element = str.Split(separatorDict);
AbstractMap map = null; AbstractMap map = null;
switch (elem[1]) switch (element[1])
{ {
case "SimpleMap": case "SimpleMap":
map = new SimpleMap(); map = new SimpleMap();
@ -128,10 +114,11 @@ namespace Airbus
break; break;
} }
_mapStorage.Add(elem[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, _mapStorage.Add(element[0], new MapWithSetPlanesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight,
map)); map));
_mapStorage[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); _mapStorage[element[0]].LoadData(element[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
}
} }
return true; return true;
@ -143,7 +130,17 @@ namespace Airbus
{ {
get 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;