This commit is contained in:
shadowik 2022-11-24 21:54:29 +04:00
parent 03128c8559
commit 0c5960afb2
9 changed files with 296 additions and 48 deletions

View File

@ -22,6 +22,11 @@ namespace DoubleDeckerBus
return _bus?.GetCurrentPosition() ?? default; return _bus?.GetCurrentPosition() ?? default;
} }
public string GetInfo()
{
return _bus?.GetDataForSave();
}
public void MoveObject(Direction direction) public void MoveObject(Direction direction)
{ {
_bus?.MoveTransport(direction); _bus?.MoveTransport(direction);
@ -36,5 +41,10 @@ namespace DoubleDeckerBus
{ {
_bus.DrawTransport(g); _bus.DrawTransport(g);
} }
public static IDrawingObject Create(string data)
{
return new DrawingObjectBus(data.CreateDrawningCar());
}
} }
} }

View File

@ -19,5 +19,11 @@ namespace DoubleDeckerBus
Weight = (weight <= 0) ? rnd.Next(50, 70) : weight; Weight = (weight <= 0) ? rnd.Next(50, 70) : weight;
BodyColor = bodyColor; BodyColor = bodyColor;
} }
public static EntityBus Creator(string data) {
string[] strs = data.Split(':');
return new EntityBus(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
} }
} }

View File

@ -0,0 +1,35 @@
namespace DoubleDeckerBus
{
internal static class ExtentionBus
{
private static readonly char _separatorForObject = ':';
public static DrawingBus CreateDrawningCar(this string info)
{
string[] strs = info.Split(_separatorForObject);
if (strs.Length == 3)
{
return new DrawingBus(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
}
if (strs.Length == 6)
{
return new DrawingDDB(Convert.ToInt32(strs[0]),
Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
Convert.ToBoolean(strs[5]));
}
return null;
}
public static string GetDataForSave(this DrawingBus drawingBus)
{
var bus = drawingBus.Bus;
var str = $"{bus.Speed}{_separatorForObject}{bus.Weight}{_separatorForObject}{bus.BodyColor.Name}";
if (bus is not EntityDDB sportCar)
{
return str;
}
return $"{str}{_separatorForObject}{sportCar.ExtraColor.Name}{_separatorForObject}{sportCar.SecondStage}{_separatorForObject}{sportCar.Ledder}";
}
}
}

View File

@ -45,9 +45,16 @@
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddBus = new System.Windows.Forms.Button(); this.buttonAddBus = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox(); 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.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBoxSettings.SuspendLayout(); this.groupBoxSettings.SuspendLayout();
this.groupBox1.SuspendLayout(); this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxSettings // groupBoxSettings
@ -63,9 +70,11 @@
this.groupBoxSettings.Controls.Add(this.maskedTextBoxPosition); this.groupBoxSettings.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxSettings.Controls.Add(this.buttonAddBus); this.groupBoxSettings.Controls.Add(this.buttonAddBus);
this.groupBoxSettings.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxSettings.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxSettings.Location = new System.Drawing.Point(645, 0); this.groupBoxSettings.Location = new System.Drawing.Point(737, 28);
this.groupBoxSettings.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxSettings.Name = "groupBoxSettings"; this.groupBoxSettings.Name = "groupBoxSettings";
this.groupBoxSettings.Size = new System.Drawing.Size(200, 643); this.groupBoxSettings.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxSettings.Size = new System.Drawing.Size(229, 829);
this.groupBoxSettings.TabIndex = 0; this.groupBoxSettings.TabIndex = 0;
this.groupBoxSettings.TabStop = false; this.groupBoxSettings.TabStop = false;
this.groupBoxSettings.Text = "Инструменты"; this.groupBoxSettings.Text = "Инструменты";
@ -77,9 +86,11 @@
this.groupBox1.Controls.Add(this.ButtonAddMap); this.groupBox1.Controls.Add(this.ButtonAddMap);
this.groupBox1.Controls.Add(this.textBoxNewMapName); this.groupBox1.Controls.Add(this.textBoxNewMapName);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap); this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Location = new System.Drawing.Point(0, 22); this.groupBox1.Location = new System.Drawing.Point(0, 29);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(200, 339); this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Size = new System.Drawing.Size(229, 452);
this.groupBox1.TabIndex = 11; this.groupBox1.TabIndex = 11;
this.groupBox1.TabStop = false; this.groupBox1.TabStop = false;
this.groupBox1.Text = "Карты"; this.groupBox1.Text = "Карты";
@ -87,18 +98,20 @@
// listBoxMaps // listBoxMaps
// //
this.listBoxMaps.FormattingEnabled = true; this.listBoxMaps.FormattingEnabled = true;
this.listBoxMaps.ItemHeight = 15; this.listBoxMaps.ItemHeight = 20;
this.listBoxMaps.Location = new System.Drawing.Point(6, 150); this.listBoxMaps.Location = new System.Drawing.Point(7, 200);
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.listBoxMaps.Name = "listBoxMaps"; this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(188, 124); this.listBoxMaps.Size = new System.Drawing.Size(214, 164);
this.listBoxMaps.TabIndex = 4; this.listBoxMaps.TabIndex = 4;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged); this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
// //
// ButtonDeleteMap // ButtonDeleteMap
// //
this.ButtonDeleteMap.Location = new System.Drawing.Point(6, 280); this.ButtonDeleteMap.Location = new System.Drawing.Point(7, 373);
this.ButtonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonDeleteMap.Name = "ButtonDeleteMap"; this.ButtonDeleteMap.Name = "ButtonDeleteMap";
this.ButtonDeleteMap.Size = new System.Drawing.Size(194, 53); this.ButtonDeleteMap.Size = new System.Drawing.Size(222, 71);
this.ButtonDeleteMap.TabIndex = 3; this.ButtonDeleteMap.TabIndex = 3;
this.ButtonDeleteMap.Text = "Удалить карту"; this.ButtonDeleteMap.Text = "Удалить карту";
this.ButtonDeleteMap.UseVisualStyleBackColor = true; this.ButtonDeleteMap.UseVisualStyleBackColor = true;
@ -106,9 +119,10 @@
// //
// ButtonAddMap // ButtonAddMap
// //
this.ButtonAddMap.Location = new System.Drawing.Point(6, 84); this.ButtonAddMap.Location = new System.Drawing.Point(7, 112);
this.ButtonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ButtonAddMap.Name = "ButtonAddMap"; this.ButtonAddMap.Name = "ButtonAddMap";
this.ButtonAddMap.Size = new System.Drawing.Size(194, 53); this.ButtonAddMap.Size = new System.Drawing.Size(222, 71);
this.ButtonAddMap.TabIndex = 2; this.ButtonAddMap.TabIndex = 2;
this.ButtonAddMap.Text = "Добавить карту"; this.ButtonAddMap.Text = "Добавить карту";
this.ButtonAddMap.UseVisualStyleBackColor = true; this.ButtonAddMap.UseVisualStyleBackColor = true;
@ -116,17 +130,19 @@
// //
// textBoxNewMapName // textBoxNewMapName
// //
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 22); this.textBoxNewMapName.Location = new System.Drawing.Point(7, 29);
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxNewMapName.Name = "textBoxNewMapName"; this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(188, 23); this.textBoxNewMapName.Size = new System.Drawing.Size(214, 27);
this.textBoxNewMapName.TabIndex = 1; this.textBoxNewMapName.TabIndex = 1;
// //
// comboBoxSelectorMap // comboBoxSelectorMap
// //
this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 55); this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 73);
this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28);
this.comboBoxSelectorMap.TabIndex = 0; this.comboBoxSelectorMap.TabIndex = 0;
// //
// buttonRight // buttonRight
@ -134,10 +150,9 @@
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::DoubleDeckerBus.Properties.Resources.RightArrow; this.buttonRight.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.RightArrow;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(109, 591); this.buttonRight.Location = new System.Drawing.Point(125, 760);
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(26, 22); this.buttonRight.Size = new System.Drawing.Size(30, 29);
this.buttonRight.TabIndex = 10; this.buttonRight.TabIndex = 10;
this.buttonRight.Text = " "; this.buttonRight.Text = " ";
this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.UseVisualStyleBackColor = true;
@ -148,10 +163,9 @@
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::DoubleDeckerBus.Properties.Resources.DownArrow; this.buttonDown.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.DownArrow;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(86, 610); this.buttonDown.Location = new System.Drawing.Point(98, 785);
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(26, 22); this.buttonDown.Size = new System.Drawing.Size(30, 29);
this.buttonDown.TabIndex = 9; this.buttonDown.TabIndex = 9;
this.buttonDown.Text = " "; this.buttonDown.Text = " ";
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
@ -162,10 +176,9 @@
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::DoubleDeckerBus.Properties.Resources.LeftArrow; this.buttonLeft.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.LeftArrow;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(63, 591); this.buttonLeft.Location = new System.Drawing.Point(72, 760);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(26, 22); this.buttonLeft.Size = new System.Drawing.Size(30, 29);
this.buttonLeft.TabIndex = 8; this.buttonLeft.TabIndex = 8;
this.buttonLeft.Text = " "; this.buttonLeft.Text = " ";
this.buttonLeft.UseVisualStyleBackColor = true; this.buttonLeft.UseVisualStyleBackColor = true;
@ -176,10 +189,9 @@
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::DoubleDeckerBus.Properties.Resources.UpArrow; this.buttonUp.BackgroundImage = global::DoubleDeckerBus.Properties.Resources.UpArrow;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(85, 572); this.buttonUp.Location = new System.Drawing.Point(97, 735);
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(26, 22); this.buttonUp.Size = new System.Drawing.Size(30, 29);
this.buttonUp.TabIndex = 7; this.buttonUp.TabIndex = 7;
this.buttonUp.Text = " "; this.buttonUp.Text = " ";
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
@ -187,9 +199,10 @@
// //
// button1 // button1
// //
this.button1.Location = new System.Drawing.Point(6, 521); this.button1.Location = new System.Drawing.Point(7, 695);
this.button1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(182, 35); this.button1.Size = new System.Drawing.Size(208, 47);
this.button1.TabIndex = 5; this.button1.TabIndex = 5;
this.button1.Text = "Посмотреть карту"; this.button1.Text = "Посмотреть карту";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
@ -197,9 +210,10 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(6, 480); this.buttonShowStorage.Location = new System.Drawing.Point(7, 640);
this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(182, 35); this.buttonShowStorage.Size = new System.Drawing.Size(208, 47);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Посмотреть хранилище"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -207,9 +221,10 @@
// //
// buttonDeleteBus // buttonDeleteBus
// //
this.buttonDeleteBus.Location = new System.Drawing.Point(6, 438); this.buttonDeleteBus.Location = new System.Drawing.Point(7, 584);
this.buttonDeleteBus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDeleteBus.Name = "buttonDeleteBus"; this.buttonDeleteBus.Name = "buttonDeleteBus";
this.buttonDeleteBus.Size = new System.Drawing.Size(188, 36); this.buttonDeleteBus.Size = new System.Drawing.Size(215, 48);
this.buttonDeleteBus.TabIndex = 3; this.buttonDeleteBus.TabIndex = 3;
this.buttonDeleteBus.Text = "Удалить автобус"; this.buttonDeleteBus.Text = "Удалить автобус";
this.buttonDeleteBus.UseVisualStyleBackColor = true; this.buttonDeleteBus.UseVisualStyleBackColor = true;
@ -217,17 +232,19 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 409); this.maskedTextBoxPosition.Location = new System.Drawing.Point(7, 545);
this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(188, 23); this.maskedTextBoxPosition.Size = new System.Drawing.Size(214, 27);
this.maskedTextBoxPosition.TabIndex = 2; this.maskedTextBoxPosition.TabIndex = 2;
// //
// buttonAddBus // buttonAddBus
// //
this.buttonAddBus.Location = new System.Drawing.Point(6, 367); this.buttonAddBus.Location = new System.Drawing.Point(7, 489);
this.buttonAddBus.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddBus.Name = "buttonAddBus"; this.buttonAddBus.Name = "buttonAddBus";
this.buttonAddBus.Size = new System.Drawing.Size(188, 36); this.buttonAddBus.Size = new System.Drawing.Size(215, 48);
this.buttonAddBus.TabIndex = 1; this.buttonAddBus.TabIndex = 1;
this.buttonAddBus.Text = "Добавить автобус"; this.buttonAddBus.Text = "Добавить автобус";
this.buttonAddBus.UseVisualStyleBackColor = true; this.buttonAddBus.UseVisualStyleBackColor = true;
@ -236,19 +253,66 @@
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; 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, 28);
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(645, 643); this.pictureBox.Size = new System.Drawing.Size(737, 829);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
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(966, 28);
this.menuStrip1.TabIndex = 2;
this.menuStrip1.Text = "menuStrip1";
//
// FileToolStripMenuItem
//
this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SaveToolStripMenuItem,
this.LoadToolStripMenuItem});
this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
this.FileToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
this.FileToolStripMenuItem.Text = "Файл";
//
// SaveToolStripMenuItem
//
this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
this.SaveToolStripMenuItem.Text = "Сохранение";
this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
// LoadToolStripMenuItem
//
this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
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";
//
// FormMapWithSetBuses // FormMapWithSetBuses
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); 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(845, 643); this.ClientSize = new System.Drawing.Size(966, 857);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxSettings); this.Controls.Add(this.groupBoxSettings);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormMapWithSetBuses"; this.Name = "FormMapWithSetBuses";
this.Text = "Карты с набором объектов"; this.Text = "Карты с набором объектов";
this.groupBoxSettings.ResumeLayout(false); this.groupBoxSettings.ResumeLayout(false);
@ -256,7 +320,10 @@
this.groupBox1.ResumeLayout(false); this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout(); this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@ -279,5 +346,11 @@
private Button ButtonDeleteMap; private Button ButtonDeleteMap;
private Button ButtonAddMap; private Button ButtonAddMap;
private ListBox listBoxMaps; private ListBox listBoxMaps;
private MenuStrip menuStrip1;
private ToolStripMenuItem FileToolStripMenuItem;
private ToolStripMenuItem SaveToolStripMenuItem;
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
} }
} }

View File

@ -54,7 +54,6 @@ namespace DoubleDeckerBus
private void ButtonAddBus_Click(object sender, EventArgs e) private void ButtonAddBus_Click(object sender, EventArgs e)
{ {
var formBusConfig = new FormBusConfig(); var formBusConfig = new FormBusConfig();
// TODO Call method AddEvent from fromBusConfig
formBusConfig.AddEvent(AddBus); formBusConfig.AddEvent(AddBus);
formBusConfig.Show(); formBusConfig.Show();
@ -179,6 +178,36 @@ namespace DoubleDeckerBus
ReloadMaps(); 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)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_mapsCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
ReloadMaps();
}
else {
MessageBox.Show("Ошибка при загрузке", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }
} }

View File

@ -57,4 +57,13 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </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>152, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>319, 17</value>
</metadata>
</root> </root>

View File

@ -18,5 +18,6 @@ namespace DoubleDeckerBus
(float Left, float Right, float Top, float Bottom) GetCurrentPosition(); (float Left, float Right, float Top, float Bottom) GetCurrentPosition();
string GetInfo();
} }
} }

View File

@ -140,5 +140,23 @@ namespace DoubleDeckerBus
if (currentHeight > height) return; if (currentHeight > height) return;
} }
} }
public string GetData(char separatorType, char separatorData)
{
string data = $"{_map.GetType().Name}{separatorType}";
foreach (var bus in _setBuses.GetBuses())
{
data += $"{bus.GetInfo()}{separatorData}";
}
return data;
}
public void LoadData(string[] records)
{
foreach (var rec in records)
{
_setBuses.Insert(DrawingObjectBus.Create(rec) as T);
}
}
} }
} }

View File

@ -1,21 +1,26 @@
using DoubleDeckerBus; using DoubleDeckerBus;
using System.Text;
namespace DoubleDeckerBus namespace DoubleDeckerBus
{ {
internal class MapsCollection internal class MapsCollection
{ {
readonly Dictionary<string, MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>> _mapStorages; readonly Dictionary<string, MapWithSetBusesGeneric<IDrawingObject, AbstractMap>> _mapStorages;
public List<string> Keys => _mapStorages.Keys.ToList(); public List<string> Keys => _mapStorages.Keys.ToList();
private readonly int _pictureWidth; private readonly int _pictureWidth;
private readonly int _pictureHeight; private readonly int _pictureHeight;
private readonly char separatorDict = '|';
private readonly char separatorData = ';';
public MapsCollection(int pictureWidth, int pictureHeight) public MapsCollection(int pictureWidth, int pictureHeight)
{ {
_mapStorages = new Dictionary<string, MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>>(); _mapStorages = new Dictionary<string, MapWithSetBusesGeneric<IDrawingObject, AbstractMap>>();
_pictureWidth = pictureWidth; _pictureWidth = pictureWidth;
_pictureHeight = pictureHeight; _pictureHeight = pictureHeight;
} }
@ -23,7 +28,7 @@ namespace DoubleDeckerBus
public void AddMap(string name, AbstractMap map) public void AddMap(string name, AbstractMap map)
{ {
if (Keys.Contains(name)) return; if (Keys.Contains(name)) return;
_mapStorages.Add(name, new MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap>(_pictureWidth, _pictureHeight, map)); _mapStorages.Add(name, new MapWithSetBusesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
} }
public void DelMap(string name) public void DelMap(string name)
@ -31,7 +36,7 @@ namespace DoubleDeckerBus
_mapStorages.Remove(name); _mapStorages.Remove(name);
} }
public MapWithSetBusesGeneric<DrawingObjectBus, AbstractMap> this[string ind] public MapWithSetBusesGeneric<IDrawingObject, AbstractMap> this[string ind]
{ {
get get
{ {
@ -39,5 +44,67 @@ namespace DoubleDeckerBus
return result; return result;
} }
} }
private static void WriteToFile(string text, FileStream stream)
{
byte[] info = new UTF8Encoding(true).GetBytes(text);
stream.Write(info, 0, info.Length);
}
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;
}
string line;
using (StreamReader sw = new(filename))
{
line = sw.ReadLine();
if (line == null || !line.Contains("MapsCollection"))
{
return false;
}
_mapStorages.Clear();
line = sw.ReadLine();
while (line != null)
{
var elem = line.Split(separatorDict);
AbstractMap map = null;
switch (elem[1])
{
case "SimpleMap":
map = new SimpleMap();
break;
case "WaterMap":
map = new WaterMap();
break;
}
_mapStorages.Add(elem[0], new MapWithSetBusesGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
_mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
line = sw.ReadLine();
}
return true;
}
}
} }
} }