Load
This commit is contained in:
parent
f2a405c743
commit
7a9c7c16a2
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>173, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>357, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WindowsBase" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AbstractMap.cs" />
|
||||
|
Loading…
Reference in New Issue
Block a user