исправление
This commit is contained in:
parent
1dd50a48f4
commit
b4ed17d723
@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
||||
namespace HoistingCrane
|
||||
{
|
||||
internal class DrawingObjectHoistingCrane : IDrawingObject
|
||||
@ -24,7 +19,7 @@ namespace HoistingCrane
|
||||
}
|
||||
public void SetObject(int x, int y, int width, int height)
|
||||
{
|
||||
_hoistingCrane.SetPosition(x, y, width, height);
|
||||
_hoistingCrane?.SetPosition(x, y, width, height);
|
||||
}
|
||||
public void DrawingObject(Graphics g)
|
||||
{
|
||||
@ -32,5 +27,6 @@ namespace HoistingCrane
|
||||
}
|
||||
public string GetInfo() => _hoistingCrane?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectHoistingCrane(data.CreateDrawingHoistingCrane());
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -48,9 +48,16 @@
|
||||
this.buttonShowOnMap = new System.Windows.Forms.Button();
|
||||
this.buttonAddHoistingCrane = new System.Windows.Forms.Button();
|
||||
this.pictureBox = new System.Windows.Forms.PictureBox();
|
||||
this.menuStrip = 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.groupBoxMaps.SuspendLayout();
|
||||
this.groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
|
||||
this.menuStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// groupBoxMaps
|
||||
@ -115,7 +122,6 @@
|
||||
this.comboBoxSelectorMap.Size = new System.Drawing.Size(200, 28);
|
||||
this.comboBoxSelectorMap.TabIndex = 0;
|
||||
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
|
||||
|
||||
//
|
||||
// textBoxNewMapName
|
||||
//
|
||||
@ -138,11 +144,11 @@
|
||||
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
|
||||
this.groupBoxTools.Controls.Add(this.buttonAddHoistingCrane);
|
||||
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(927, 0);
|
||||
this.groupBoxTools.Location = new System.Drawing.Point(927, 28);
|
||||
this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxTools.Name = "groupBoxTools";
|
||||
this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 782);
|
||||
this.groupBoxTools.Size = new System.Drawing.Size(233, 754);
|
||||
this.groupBoxTools.TabIndex = 0;
|
||||
this.groupBoxTools.TabStop = false;
|
||||
this.groupBoxTools.Text = "Инструменты";
|
||||
@ -184,7 +190,7 @@
|
||||
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonDown.BackgroundImage = global::HoistingCrane.Properties.Resources.down;
|
||||
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonDown.Location = new System.Drawing.Point(104, 715);
|
||||
this.buttonDown.Location = new System.Drawing.Point(104, 687);
|
||||
this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonDown.Name = "buttonDown";
|
||||
this.buttonDown.Size = new System.Drawing.Size(34, 40);
|
||||
@ -197,7 +203,7 @@
|
||||
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonRight.BackgroundImage = global::HoistingCrane.Properties.Resources.right;
|
||||
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonRight.Location = new System.Drawing.Point(145, 715);
|
||||
this.buttonRight.Location = new System.Drawing.Point(145, 687);
|
||||
this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonRight.Name = "buttonRight";
|
||||
this.buttonRight.Size = new System.Drawing.Size(34, 40);
|
||||
@ -210,7 +216,7 @@
|
||||
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonLeft.BackgroundImage = global::HoistingCrane.Properties.Resources.left;
|
||||
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonLeft.Location = new System.Drawing.Point(63, 715);
|
||||
this.buttonLeft.Location = new System.Drawing.Point(63, 687);
|
||||
this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonLeft.Name = "buttonLeft";
|
||||
this.buttonLeft.Size = new System.Drawing.Size(34, 40);
|
||||
@ -223,7 +229,7 @@
|
||||
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
this.buttonUp.BackgroundImage = global::HoistingCrane.Properties.Resources.up;
|
||||
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
|
||||
this.buttonUp.Location = new System.Drawing.Point(104, 667);
|
||||
this.buttonUp.Location = new System.Drawing.Point(104, 639);
|
||||
this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.buttonUp.Name = "buttonUp";
|
||||
this.buttonUp.Size = new System.Drawing.Size(34, 40);
|
||||
@ -256,13 +262,51 @@
|
||||
// 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, 28);
|
||||
this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.pictureBox.Name = "pictureBox";
|
||||
this.pictureBox.Size = new System.Drawing.Size(927, 782);
|
||||
this.pictureBox.Size = new System.Drawing.Size(927, 754);
|
||||
this.pictureBox.TabIndex = 1;
|
||||
this.pictureBox.TabStop = false;
|
||||
//
|
||||
// menuStrip
|
||||
//
|
||||
this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
|
||||
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.fileToolStripMenuItem});
|
||||
this.menuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip.Name = "menuStrip";
|
||||
this.menuStrip.Size = new System.Drawing.Size(1160, 28);
|
||||
this.menuStrip.TabIndex = 2;
|
||||
this.menuStrip.Text = "menuStrip";
|
||||
//
|
||||
// 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(54, 29);
|
||||
this.fileToolStripMenuItem.Text = "File";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
this.saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
this.saveToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
|
||||
this.saveToolStripMenuItem.Text = "Save";
|
||||
this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
this.loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
this.loadToolStripMenuItem.Size = new System.Drawing.Size(125, 26);
|
||||
this.loadToolStripMenuItem.Text = "Load";
|
||||
this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click);
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
this.openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormMapWithSetHoistingCrane
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
@ -270,6 +314,8 @@
|
||||
this.ClientSize = new System.Drawing.Size(1160, 782);
|
||||
this.Controls.Add(this.pictureBox);
|
||||
this.Controls.Add(this.groupBoxTools);
|
||||
this.Controls.Add(this.menuStrip);
|
||||
this.MainMenuStrip = this.menuStrip;
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormMapWithSetHoistingCrane";
|
||||
this.Text = "Карта с набором объектов";
|
||||
@ -278,7 +324,10 @@
|
||||
this.groupBoxTools.ResumeLayout(false);
|
||||
this.groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
|
||||
this.menuStrip.ResumeLayout(false);
|
||||
this.menuStrip.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
@ -301,5 +350,11 @@
|
||||
private Button buttonDeleteMap;
|
||||
private ListBox listBoxMaps;
|
||||
private Button buttonAddMap;
|
||||
private System.Windows.Forms.MenuStrip menuStrip;
|
||||
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
@ -206,5 +206,39 @@ namespace HoistingCrane
|
||||
}
|
||||
pictureBox.Image = _mapHoistingCraneCollectionGeneric.MoveObject(enums);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip.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>144, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>303, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace HoistingCrane
|
||||
{
|
||||
@ -11,7 +9,7 @@ namespace HoistingCrane
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap>> _mapStorages;
|
||||
readonly Dictionary<string, MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
@ -29,9 +27,12 @@ namespace HoistingCrane
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
/// private readonly char separatorDict = '|';
|
||||
private readonly char separatorData = ';';
|
||||
private readonly char separatorDict = '|';
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap>>();
|
||||
_mapStorages = new Dictionary<string, MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
@ -61,13 +62,13 @@ namespace HoistingCrane
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> this[string ind]
|
||||
public MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ind != String.Empty)
|
||||
{
|
||||
MapWithSetHoistingCraneGeneric<DrawingObjectHoistingCrane, AbstractMap> value;
|
||||
MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap> value;
|
||||
if (_mapStorages.TryGetValue(ind, out value))
|
||||
{
|
||||
return value;
|
||||
@ -76,5 +77,69 @@ namespace HoistingCrane
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сохранение информации про лодки м в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Create))
|
||||
using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8))
|
||||
{
|
||||
sw.WriteLine("MapsCollection");
|
||||
foreach (var storage in _mapStorages)
|
||||
{
|
||||
|
||||
sw.WriteLine(
|
||||
$"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}"
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Загрузка информации по локомотивам в депо из файла
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (FileStream fs = new(filename, FileMode.Open))
|
||||
using (StreamReader sr = new StreamReader(fs, Encoding.UTF8))
|
||||
{
|
||||
string curLine = sr.ReadLine();
|
||||
|
||||
if (!curLine.Contains("MapsCollection"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_mapStorages.Clear();
|
||||
while ((curLine = sr.ReadLine()) != null)
|
||||
{
|
||||
var elems = curLine.Split(separatorDict);
|
||||
AbstractMap map = null;
|
||||
|
||||
switch (elems[1])
|
||||
{
|
||||
case "SimpleMap":
|
||||
map = new SimpleMap();
|
||||
break;
|
||||
case "SecondMap":
|
||||
map = new SecondMap();
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
_mapStorages.Add(elems[0], new MapWithSetHoistingCraneGeneric<IDrawingObject, AbstractMap>(_pictureWidth, _pictureHeight, map));
|
||||
_mapStorages[elems[0]].LoadData(elems[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user