diff --git a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.Designer.cs b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.Designer.cs
index dfd50d6..e345f77 100644
--- a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.Designer.cs
+++ b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.Designer.cs
@@ -45,9 +45,16 @@
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddTrolleybus = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.menuStrip1 = new System.Windows.Forms.MenuStrip();
+ this.FiletoolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.downloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
+ this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
@@ -63,11 +70,11 @@
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddTrolleybus);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBox1.Location = new System.Drawing.Point(900, 0);
+ this.groupBox1.Location = new System.Drawing.Point(900, 33);
this.groupBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.groupBox1.Size = new System.Drawing.Size(300, 997);
+ this.groupBox1.Size = new System.Drawing.Size(300, 964);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
@@ -245,13 +252,56 @@
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Location = new System.Drawing.Point(0, 33);
this.pictureBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(900, 997);
+ this.pictureBox.Size = new System.Drawing.Size(900, 964);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
+ // menuStrip1
+ //
+ this.menuStrip1.GripMargin = new System.Windows.Forms.Padding(2, 2, 0, 2);
+ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
+ this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.FiletoolStripMenuItem});
+ this.menuStrip1.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip1.Name = "menuStrip1";
+ this.menuStrip1.Size = new System.Drawing.Size(1200, 33);
+ this.menuStrip1.TabIndex = 2;
+ this.menuStrip1.Text = "menuStrip1";
+ //
+ // FiletoolStripMenuItem
+ //
+ this.FiletoolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.saveToolStripMenuItem,
+ this.downloadToolStripMenuItem});
+ this.FiletoolStripMenuItem.Name = "FiletoolStripMenuItem";
+ this.FiletoolStripMenuItem.Size = new System.Drawing.Size(54, 29);
+ this.FiletoolStripMenuItem.Text = "File";
+ //
+ // saveToolStripMenuItem
+ //
+ this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
+ this.saveToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
+ this.saveToolStripMenuItem.Text = "Save";
+ this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
+ //
+ // downloadToolStripMenuItem
+ //
+ this.downloadToolStripMenuItem.Name = "downloadToolStripMenuItem";
+ this.downloadToolStripMenuItem.Size = new System.Drawing.Size(270, 34);
+ this.downloadToolStripMenuItem.Text = "Download";
+ this.downloadToolStripMenuItem.Click += new System.EventHandler(this.downloadToolStripMenuItem_Click);
+ //
+ // openFileDialog
+ //
+ this.openFileDialog.Filter = "txt file | *.txt";
+ //
+ // saveFileDialog
+ //
+ this.saveFileDialog.Filter = "txt file | *.txt";
+ //
// FormMapWithSetTrolleybus
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
@@ -259,6 +309,8 @@
this.ClientSize = new System.Drawing.Size(1200, 997);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
+ this.Controls.Add(this.menuStrip1);
+ this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "FormMapWithSetTrolleybus";
this.Text = "FormMapWithSetTrolleybus";
@@ -267,7 +319,10 @@
this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.menuStrip1.ResumeLayout(false);
+ this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -290,5 +345,11 @@
private System.Windows.Forms.ListBox listBoxMaps;
private System.Windows.Forms.Button buttonAddMap;
private System.Windows.Forms.TextBox textBoxNewMapName;
+ private System.Windows.Forms.MenuStrip menuStrip1;
+ private System.Windows.Forms.ToolStripMenuItem FiletoolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem downloadToolStripMenuItem;
+ private System.Windows.Forms.OpenFileDialog openFileDialog;
+ private System.Windows.Forms.SaveFileDialog saveFileDialog;
}
}
\ No newline at end of file
diff --git a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
index 091f483..a5fc4fb 100644
--- a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
+++ b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.cs
@@ -230,5 +230,38 @@ namespace Trolleybus
}
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
+
+ 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 downloadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ try
+ {
+ _mapsCollection.LoadData(openFileDialog.FileName);
+ ReloadMaps();
+ MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("Не получилось загрузить файл", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ }
}
}
diff --git a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.resx b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.resx
index 1af7de1..ef1ab9d 100644
--- a/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.resx
+++ b/Trolleybus/Trolleybus/FormMapWithSetTrolleybus.resx
@@ -117,4 +117,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 173, 17
+
+
+ 357, 17
+
\ No newline at end of file
diff --git a/Trolleybus/Trolleybus/MapsCollection.cs b/Trolleybus/Trolleybus/MapsCollection.cs
index 1425ada..7824eda 100644
--- a/Trolleybus/Trolleybus/MapsCollection.cs
+++ b/Trolleybus/Trolleybus/MapsCollection.cs
@@ -76,21 +76,20 @@ namespace Trolleybus
return true;
}
- public bool LoadData(string filename)
+ public void LoadData(string filename)
{
if (!File.Exists(filename))
{
- return false;
+ throw new FileNotFoundException("Файл не найден");
}
using (StreamReader sr = new(filename))
{
- string str = "";
- if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection"))
+ string str = sr.ReadLine();
+ if (!str.Contains("MapsCollection"))
{
//если нет такой записи, то это не те данные
- return false;
+ throw new FileFormatException("Формат данных в файле не правильный");
}
- //очищаем записи
_mapStorages.Clear();
while ((str = sr.ReadLine()) != null)
{
@@ -109,7 +108,6 @@ namespace Trolleybus
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, (char)StringSplitOptions.RemoveEmptyEntries));
}
}
- return true;
}
}
}
diff --git a/Trolleybus/Trolleybus/Trolleybus.csproj b/Trolleybus/Trolleybus/Trolleybus.csproj
index b682ca1..9ded4bf 100644
--- a/Trolleybus/Trolleybus/Trolleybus.csproj
+++ b/Trolleybus/Trolleybus/Trolleybus.csproj
@@ -45,6 +45,7 @@
+