diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningObjectAirplane.cs
index 4897fad..4b7c5a0 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawningObjectAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningObjectAirplane.cs
@@ -36,5 +36,7 @@ namespace AirplaneWithRadar
{
_airplane.DrawTransport(g);
}
+ public string GetInfo() => _airplane?.GetDataForSave();
+ public static IDrawningObject Create(string data) => new DrawningObjectAirplane(data.CreateDrawningAirplane());
}
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/ExtentionAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/ExtentionAirplane.cs
new file mode 100644
index 0000000..e15346a
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/ExtentionAirplane.cs
@@ -0,0 +1,53 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirplaneWithRadar
+{
+ internal static class ExtentionAirplane
+ {
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly char _separatorForObject = ':';
+ ///
+ /// Создание объекта из строки
+ ///
+ ///
+ ///
+ public static DrawningAirplane CreateDrawningAirplane(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ if (strs.Length == 3)
+ {
+ return new DrawningAirplane(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
+ }
+ if (strs.Length == 7)
+ {
+ return new DrawningAirplaneWithRadar(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
+ Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ ///
+ ///
+ public static string GetDataForSave(this DrawningAirplane drawningAirplane)
+ {
+ var airplane = drawningAirplane.Airplane;
+ var str = $"{airplane.Speed}{_separatorForObject}{airplane.Weight}{_separatorForObject}{airplane.BodyColor.Name}";
+ if (airplane is not EntityAirplaneWithRadar airplaneWithRadar)
+ {
+ return str;
+ }
+ return $"{str}{_separatorForObject}{airplaneWithRadar.DopColor.Name}{_separatorForObject}{airplaneWithRadar.Radar}{_separatorForObject}{airplaneWithRadar.Ladder}{_separatorForObject}{airplaneWithRadar.Window}";
+ }
+ }
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs
index 2f8b278..f2db7f6 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs
@@ -45,9 +45,16 @@
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.файлToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
+ this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBox.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// groupBox
@@ -63,11 +70,9 @@
this.groupBox.Controls.Add(this.buttonAddAirplane);
this.groupBox.Controls.Add(this.groupBox1);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBox.Location = new System.Drawing.Point(685, 0);
- this.groupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBox.Location = new System.Drawing.Point(600, 24);
this.groupBox.Name = "groupBox";
- this.groupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.groupBox.Size = new System.Drawing.Size(229, 653);
+ this.groupBox.Size = new System.Drawing.Size(200, 492);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
@@ -77,10 +82,9 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(98, 605);
- this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonDown.Location = new System.Drawing.Point(86, 456);
this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(34, 40);
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 9;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -90,10 +94,9 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(140, 605);
- this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRight.Location = new System.Drawing.Point(122, 456);
this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(34, 40);
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 8;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -103,10 +106,9 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(57, 605);
- this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonLeft.Location = new System.Drawing.Point(50, 456);
this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(34, 40);
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 7;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -116,10 +118,9 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(98, 557);
- this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonUp.Location = new System.Drawing.Point(86, 420);
this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(34, 40);
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 6;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
@@ -127,10 +128,9 @@
// buttonShowOnMap
//
this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonShowOnMap.Location = new System.Drawing.Point(22, 509);
- this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(19, 384);
this.buttonShowOnMap.Name = "buttonShowOnMap";
- this.buttonShowOnMap.Size = new System.Drawing.Size(193, 40);
+ this.buttonShowOnMap.Size = new System.Drawing.Size(169, 30);
this.buttonShowOnMap.TabIndex = 5;
this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonShowOnMap.UseVisualStyleBackColor = true;
@@ -139,10 +139,9 @@
// buttonShowStorage
//
this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonShowStorage.Location = new System.Drawing.Point(22, 461);
- this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowStorage.Location = new System.Drawing.Point(19, 348);
this.buttonShowStorage.Name = "buttonShowStorage";
- this.buttonShowStorage.Size = new System.Drawing.Size(193, 40);
+ this.buttonShowStorage.Size = new System.Drawing.Size(169, 30);
this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@@ -151,10 +150,9 @@
// buttonRemoveAirplane
//
this.buttonRemoveAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRemoveAirplane.Location = new System.Drawing.Point(22, 413);
- this.buttonRemoveAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRemoveAirplane.Location = new System.Drawing.Point(19, 312);
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
- this.buttonRemoveAirplane.Size = new System.Drawing.Size(193, 40);
+ this.buttonRemoveAirplane.Size = new System.Drawing.Size(169, 30);
this.buttonRemoveAirplane.TabIndex = 3;
this.buttonRemoveAirplane.Text = "Удалить самолет";
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
@@ -163,20 +161,18 @@
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 378);
- this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 286);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
- this.maskedTextBoxPosition.Size = new System.Drawing.Size(193, 27);
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23);
this.maskedTextBoxPosition.TabIndex = 2;
//
// buttonAddAirplane
//
this.buttonAddAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonAddAirplane.Location = new System.Drawing.Point(22, 330);
- this.buttonAddAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddAirplane.Location = new System.Drawing.Point(19, 250);
this.buttonAddAirplane.Name = "buttonAddAirplane";
- this.buttonAddAirplane.Size = new System.Drawing.Size(193, 40);
+ this.buttonAddAirplane.Size = new System.Drawing.Size(169, 30);
this.buttonAddAirplane.TabIndex = 1;
this.buttonAddAirplane.Text = "Добавить самолет";
this.buttonAddAirplane.UseVisualStyleBackColor = true;
@@ -189,18 +185,21 @@
this.groupBox1.Controls.Add(this.ButtonAddMap);
this.groupBox1.Controls.Add(this.textBoxNewMapName);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
- this.groupBox1.Location = new System.Drawing.Point(6, 26);
+ this.groupBox1.Location = new System.Drawing.Point(5, 20);
+ this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(250, 300);
+ this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
+ this.groupBox1.Size = new System.Drawing.Size(219, 225);
this.groupBox1.TabIndex = 18;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Карты";
//
// ButtonDeleteMap
//
- this.ButtonDeleteMap.Location = new System.Drawing.Point(10, 255);
+ this.ButtonDeleteMap.Location = new System.Drawing.Point(9, 191);
+ this.ButtonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonDeleteMap.Name = "ButtonDeleteMap";
- this.ButtonDeleteMap.Size = new System.Drawing.Size(207, 29);
+ this.ButtonDeleteMap.Size = new System.Drawing.Size(181, 22);
this.ButtonDeleteMap.TabIndex = 13;
this.ButtonDeleteMap.Text = "Удалить карту";
this.ButtonDeleteMap.UseVisualStyleBackColor = true;
@@ -209,18 +208,20 @@
// ListBoxMaps
//
this.ListBoxMaps.FormattingEnabled = true;
- this.ListBoxMaps.ItemHeight = 20;
- this.ListBoxMaps.Location = new System.Drawing.Point(10, 136);
+ this.ListBoxMaps.ItemHeight = 15;
+ this.ListBoxMaps.Location = new System.Drawing.Point(9, 102);
+ this.ListBoxMaps.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ListBoxMaps.Name = "ListBoxMaps";
- this.ListBoxMaps.Size = new System.Drawing.Size(207, 104);
+ this.ListBoxMaps.Size = new System.Drawing.Size(182, 79);
this.ListBoxMaps.TabIndex = 12;
this.ListBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// ButtonAddMap
//
- this.ButtonAddMap.Location = new System.Drawing.Point(10, 101);
+ this.ButtonAddMap.Location = new System.Drawing.Point(9, 76);
+ this.ButtonAddMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.ButtonAddMap.Name = "ButtonAddMap";
- this.ButtonAddMap.Size = new System.Drawing.Size(207, 29);
+ this.ButtonAddMap.Size = new System.Drawing.Size(181, 22);
this.ButtonAddMap.TabIndex = 11;
this.ButtonAddMap.Text = "Добавить карту";
this.ButtonAddMap.UseVisualStyleBackColor = true;
@@ -228,9 +229,10 @@
//
// textBoxNewMapName
//
- this.textBoxNewMapName.Location = new System.Drawing.Point(10, 34);
+ this.textBoxNewMapName.Location = new System.Drawing.Point(9, 26);
+ this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxNewMapName.Name = "textBoxNewMapName";
- this.textBoxNewMapName.Size = new System.Drawing.Size(207, 27);
+ this.textBoxNewMapName.Size = new System.Drawing.Size(182, 23);
this.textBoxNewMapName.TabIndex = 10;
//
// comboBoxSelectorMap
@@ -241,31 +243,74 @@
"Простая карта",
"Карта неба с облаками",
"Карта туманного неба с грозой"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(10, 67);
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(9, 50);
+ this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(207, 28);
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(182, 23);
this.comboBoxSelectorMap.TabIndex = 9;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBox.Location = new System.Drawing.Point(0, 0);
- this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.pictureBox.Location = new System.Drawing.Point(0, 24);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(685, 653);
+ this.pictureBox.Size = new System.Drawing.Size(600, 492);
this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
+ // menuStrip
+ //
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.файлToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(800, 24);
+ this.menuStrip.TabIndex = 2;
+ this.menuStrip.Text = "menuStrip1";
+ //
+ // файлToolStripMenuItem
+ //
+ this.файлToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.SaveToolStripMenuItem,
+ this.LoadToolStripMenuItem});
+ this.файлToolStripMenuItem.Name = "файлToolStripMenuItem";
+ this.файлToolStripMenuItem.Size = new System.Drawing.Size(48, 20);
+ this.файлToolStripMenuItem.Text = "Файл";
+ //
+ // SaveToolStripMenuItem
+ //
+ this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
+ this.SaveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.SaveToolStripMenuItem.Text = "Сохранение";
+ this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
+ //
+ // LoadToolStripMenuItem
+ //
+ this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
+ this.LoadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.LoadToolStripMenuItem.Text = "Загрузка";
+ this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
+ //
+ // openFileDialog
+ //
+ this.openFileDialog.FileName = "openFileDialog1";
+ this.openFileDialog.Filter = "txt file|*.txt";
+ //
+ // saveFileDialog
+ //
+ this.saveFileDialog.Filter = "txt file|*.txt";
+ //
// FormMapWithSetAirplane
//
- this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(914, 653);
+ this.ClientSize = new System.Drawing.Size(800, 516);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
- this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
this.Name = "FormMapWithSetAirplane";
this.Text = "FormMapWithSetAirplane";
this.groupBox.ResumeLayout(false);
@@ -273,6 +318,8 @@
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@@ -297,5 +344,11 @@
private ListBox ListBoxMaps;
private Button ButtonAddMap;
private TextBox textBoxNewMapName;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem файлToolStripMenuItem;
+ private ToolStripMenuItem SaveToolStripMenuItem;
+ private ToolStripMenuItem LoadToolStripMenuItem;
+ private OpenFileDialog openFileDialog;
+ private SaveFileDialog saveFileDialog;
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs
index ecd62b5..9da5e58 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs
@@ -211,6 +211,11 @@ namespace AirplaneWithRadar
MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
+ if (textBoxNewMapName.Text.Contains('|') || textBoxNewMapName.Text.Contains(':') || textBoxNewMapName.Text.Contains(';'))
+ {
+ MessageBox.Show("Присутствуют символы, недопустимые для имени карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
_mapsCollection.AddMap(textBoxNewMapName.Text, _mapDict[comboBoxSelectorMap.Text]);
ReloadMaps();
}
@@ -232,5 +237,45 @@ namespace AirplaneWithRadar
ReloadMaps();
}
}
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ ///
+ private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (saveFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.SaveData(saveFileDialog.FileName))
+ {
+ MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ ///
+ /// Обработка нажатия "Загрузка"
+ ///
+ ///
+ ///
+ private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ // TODO продумать логику
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.LoadData(openFileDialog.FileName))
+ {
+ ReloadMaps();
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ else
+ {
+ MessageBox.Show("Не получилось загрузить файл", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx
index f298a7b..934ed35 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx
@@ -57,4 +57,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 125, 17
+
+
+ 265, 17
+
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/IDrawningObject.cs b/AirplaneWithRadar/AirplaneWithRadar/IDrawningObject.cs
index 8e6aa9d..15ad11e 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/IDrawningObject.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/IDrawningObject.cs
@@ -36,5 +36,10 @@ namespace AirplaneWithRadar
///
///
(float Left, float Right, float Top, float Bottom) GetCurrentPosition();
- }
+ ///
+ /// Получение информации по объекту
+ ///
+ ///
+ string GetInfo();
+ }
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs
index cfcc925..ca34620 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs
@@ -65,6 +65,31 @@
}
return new(_pictureWidth, _pictureHeight);
}
+ ///
+ /// Получение данных в виде строки
+ ///
+ ///
+ ///
+ public string GetData(char separatorType, char separatorData)
+ {
+ string data = $"{_map.GetType().Name}{separatorType}";
+ foreach (var airplane in _setAirplane.GetAirplane())
+ {
+ data += $"{airplane.GetInfo()}{separatorData}";
+ }
+ return data;
+ }
+ ///
+ /// Загрузка списка из массива строк
+ ///
+ ///
+ public void LoadData(string[] records)
+ {
+ foreach (var rec in records)
+ {
+ _setAirplane.Insert(DrawningObjectAirplane.Create(rec) as T);
+ }
+ }
// "Взбалтываем" набор, чтобы все элементы оказались в начале
private void Shaking()
{
diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs b/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs
index 1994358..9cb12c8 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/MapsCollection.cs
@@ -9,13 +9,21 @@ namespace AirplaneWithRadar
{
internal class MapsCollection
{
- readonly Dictionary> _mapStorages;
+ readonly Dictionary> _mapStorages;
public List Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
+ ///
+ /// Разделитель для записи информации по элементу словаря в файл
+ ///
+ private readonly char separatorDict = '|';
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight)
{
- _mapStorages = new Dictionary>();
+ _mapStorages = new Dictionary>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@@ -23,14 +31,14 @@ namespace AirplaneWithRadar
{
if (!_mapStorages.ContainsKey(name))
{
- _mapStorages.Add(name, new MapWithSetAirplaneGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages.Add(name, new MapWithSetAirplaneGeneric(_pictureWidth, _pictureHeight, map));
}
}
public void DelMap(string name)
{
if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name);
}
- public MapWithSetAirplaneGeneric this[string ind]
+ public MapWithSetAirplaneGeneric this[string ind]
{
get
{
@@ -41,5 +49,80 @@ namespace AirplaneWithRadar
return null;
}
}
+ ///
+ /// Сохранение информации по локомотивам в хранилище в файл
+ ///
+ /// Путь и имя файла
+ ///
+ public bool SaveData(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ using (StreamWriter sw = new(filename))
+ {
+ sw.Write($"MapsCollection{Environment.NewLine}");
+ foreach (var storage in _mapStorages)
+ {
+ sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
+ }
+ }
+ return true;
+ }
+ ///
+ /// Загрузка информации по локомотивам в депо из файла
+ ///
+ ///
+ ///
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ using (StreamReader sr = new(filename))
+ {
+ bool isFirst = true;
+ string str;
+ while ((str = sr.ReadLine()) != null)
+ {
+ if (isFirst)
+ {
+ if (!str.Contains("MapsCollection"))
+ {
+ //если нет такой записи, то это не те данные
+ return false;
+ }
+ else
+ {
+ //очищаем записи
+ _mapStorages.Clear();
+ }
+ isFirst = false;
+ }
+ else
+ {
+ var elem = str.Split(separatorDict);
+ AbstractMap map = null;
+ switch (elem[1])
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Карта неба с облаками":
+ map = new SkyMap();
+ break;
+ case "Карта туманного неба с грозой":
+ map = new FoggySkyMap();
+ break;
+ }
+ _mapStorages.Add(elem[0], new MapWithSetAirplaneGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
+ }
+ }
+ }
+ return true;
+ }
}
}