From d533dd8a04319c2e75441d3d5d7aa1e6a29c42c4 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Fri, 11 Nov 2022 20:54:58 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20ExtentionLocomotive,=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=86=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D0=B0=20=D0=B2=20FormLocomotiveConfig=20=D1=80?= =?UTF-8?q?=D0=B5=D1=88=D0=B5=D0=BD=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectLocomotive/ExtentionLocomotive.cs | 48 +++++++++++++++++++ .../FormLocomotiveConfig.Designer.cs | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs diff --git a/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs new file mode 100644 index 0000000..7f4d18b --- /dev/null +++ b/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectLocomotive +{ + internal static class ExtentionLocomotive + { + private static readonly char _separatorForObject = ':'; + public static string getDataForSave(this DrawningLocomotive drawningLocomotive) + { + var locomotive = drawningLocomotive.Locomotivе; + var str = $"{locomotive.Speed}{_separatorForObject}{locomotive.Weight}{_separatorForObject}{locomotive.BodyColor.Name}"; + if (locomotive is not EntityElectricLocomotive warmlyLocomotive) + { + return str; + } + return $"{str}{_separatorForObject}{warmlyLocomotive.DopColor.Name}{_separatorForObject}{warmlyLocomotive.ElectroLines}{_separatorForObject}{warmlyLocomotive.ElectroBattery}"; + } + + public static DrawningLocomotive createDrawningLocomotive(this string info) + { + string[] strs = info.Split(_separatorForObject); + if (strs.Length == 3) + { + return new DrawningLocomotive( + Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]) + ); + } + if (strs.Length == 6) + { + return new DrawningElectroLocomotive( + 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; + } + } +} diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs index 9057d41..9314077 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs @@ -172,7 +172,7 @@ // // panelGreen // - this.panelGreen.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(192)))), ((int)(((byte)(0))))); + this.panelGreen.BackColor = System.Drawing.Color.Green; this.panelGreen.Location = new System.Drawing.Point(90, 39); this.panelGreen.Margin = new System.Windows.Forms.Padding(4); this.panelGreen.Name = "panelGreen"; -- 2.25.1 From 0c626b2cb3671f67792c6fa0cfc5f6c73853076d Mon Sep 17 00:00:00 2001 From: Sem730 Date: Fri, 11 Nov 2022 21:06:11 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20DrawninObject=20=D0=B8=20IDrawningObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectLocomotive/ProjectLocomotive/DrawningObject.cs | 3 +++ ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs b/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs index e4b3d99..087b5fc 100644 --- a/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs +++ b/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs @@ -31,5 +31,8 @@ namespace ProjectLocomotive // TODO _loc.DrawTransport(g); } + public string getInfo() => _loc?.getDataForSave(); + + public static IDrawningObject Create(string data) => new DrawningObject(data.createDrawningLocomotive()); } } diff --git a/ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs b/ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs index 26a219f..50c50b6 100644 --- a/ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs +++ b/ProjectLocomotive/ProjectLocomotive/IDrawningObject.cs @@ -39,6 +39,8 @@ namespace ProjectLocomotive /// /// (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + // Получение информации по объекту + string getInfo(); } } -- 2.25.1 From 4b59366b429dc8402fcbf698e34235d0f19fd941 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Fri, 11 Nov 2022 21:12:49 +0300 Subject: [PATCH 3/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20MapWithSetLocomotiveGeneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetLocomotivesGeneric.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs b/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs index c32bdd1..4ac3618 100644 --- a/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs +++ b/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs @@ -147,5 +147,23 @@ namespace ProjectLocomotive } } } + /// Получение данных в виде строки + public string GetData(char separatorType, char separatorData) + { + string data = $"{_map.GetType().Name}{separatorType}"; + foreach (var locomotive in _setLocomotives.GetLocomotives()) + { + data += $"{locomotive.getInfo()}{separatorData}"; + } + return data; + } + /// Загрузка списка из массива строк + public void LoadData(string[] records) + { + foreach (var rec in records) + { + _setLocomotives.Insert(DrawningObject.Create(rec) as T); + } + } } } -- 2.25.1 From ae6e1074b8f88202c3c5dcab93244c3abfbbf467 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Fri, 11 Nov 2022 21:26:44 +0300 Subject: [PATCH 4/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20MapsCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectLocomotive/MapsCollection.cs | 81 ++++++++++++++++++- 1 file changed, 77 insertions(+), 4 deletions(-) diff --git a/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs b/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs index 92b798c..24a2457 100644 --- a/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs +++ b/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs @@ -10,7 +10,7 @@ namespace Locomotive internal class MapsCollection { /// Словарь (хранилище) с картами - readonly Dictionary> _mapStorages; /// Возвращение списка названий карт public List Keys => _mapStorages.Keys.ToList(); @@ -18,11 +18,14 @@ namespace Locomotive 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>(); + MapWithSetLocomotivesGeneric>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -30,7 +33,7 @@ namespace Locomotive public void AddMap(string name, AbstractMap map) { // Логика для добавления - if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); + if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); } /// Удаление карты public void DelMap(string name) @@ -39,7 +42,7 @@ namespace Locomotive if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name); } /// Доступ к парковке - public MapWithSetLocomotivesGeneric this[string ind] + public MapWithSetLocomotivesGeneric this[string ind] { get { @@ -48,5 +51,75 @@ namespace Locomotive return null; } } + /// Метод записи информации в файл + 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 (FileStream fs = new(filename, FileMode.Create)) + { + WriteToFile($"MapsCollection{Environment.NewLine}", fs); + foreach (var storage in _mapStorages) + { + + WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs); + } + } + return true; + } + /// Загрузка информации по локомотивам на парковках из файла + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + string bufferTextFromFile = ""; + using (FileStream fs = new(filename, FileMode.Open)) + { + byte[] b = new byte[fs.Length]; + UTF8Encoding temp = new(true); + while (fs.Read(b, 0, b.Length) > 0) + { + bufferTextFromFile += temp.GetString(b); + } + } + var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); + if (!strs[0].Contains("MapsCollection")) + { + //если нет такой записи, то это не те данные + return false; + } + //очищаем записи + _mapStorages.Clear(); + for (int i = 1; i < strs.Length; ++i) + { + var elem = strs[i].Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) + { + case "Simple Map": + map = new SimpleMap(); + break; + case "Spike Map": + map = new SpikeMap(); + break; + case "Rail Map": + map = new RailroadMap(); + break; + } + _mapStorages.Add(elem[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + } + return true; + } } } \ No newline at end of file -- 2.25.1 From b4e17fa1f7c4514243b32875f63d3324e34dd673 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Sun, 20 Nov 2022 09:54:54 +0300 Subject: [PATCH 5/7] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0=206=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectLocomotive/DrawningObject.cs | 1 - .../FormMapWithSetLocomotives.Designer.cs | 69 +++++++++++++++-- .../FormMapWithSetLocomotives.cs | 33 ++++++++- .../MapWithSetLocomotivesGeneric.cs | 2 +- .../ProjectLocomotive/MapsCollection.cs | 74 +++++++++---------- 5 files changed, 129 insertions(+), 50 deletions(-) diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs b/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs index 087b5fc..2fb578b 100644 --- a/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs +++ b/ProjectLocomotive/ProjectLocomotive/DrawningObject.cs @@ -32,7 +32,6 @@ namespace ProjectLocomotive _loc.DrawTransport(g); } public string getInfo() => _loc?.getDataForSave(); - public static IDrawningObject Create(string data) => new DrawningObject(data.createDrawningLocomotive()); } } diff --git a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs index bb232b1..ecd2001 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs @@ -44,9 +44,16 @@ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddLocomotive = 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.loadFileDialog = new System.Windows.Forms.OpenFileDialog(); + this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.groupBoxTools.SuspendLayout(); this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); + this.menuStrip.SuspendLayout(); this.SuspendLayout(); // // groupBoxTools @@ -62,11 +69,11 @@ this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonAddLocomotive); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(794, 0); + this.groupBoxTools.Location = new System.Drawing.Point(580, 28); this.groupBoxTools.Margin = new System.Windows.Forms.Padding(4); this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxTools.Size = new System.Drawing.Size(220, 654); + this.groupBoxTools.Size = new System.Drawing.Size(220, 540); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -238,20 +245,63 @@ // 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(4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(794, 654); + this.pictureBox.Size = new System.Drawing.Size(580, 540); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; + // menuStrip + // + this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + 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(800, 28); + this.menuStrip.TabIndex = 2; + // + // 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(46, 24); + this.fileToolStripMenuItem.Text = "File"; + // + // saveToolStripMenuItem + // + this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + this.saveToolStripMenuItem.Size = new System.Drawing.Size(224, 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(224, 26); + this.loadToolStripMenuItem.Text = "Load"; + this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click); + // + // loadFileDialog + // + this.loadFileDialog.Filter = "txt file | *.txt"; + // + // saveFileDialog + // + this.saveFileDialog.Filter = "txt file | *.txt"; + // // // FormMapWithSetLocomotives // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1014, 654); + this.ClientSize = new System.Drawing.Size(800, 568); 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(4); this.Name = "FormMapWithSetLocomotives"; this.Text = "Карта с набором объектов"; @@ -260,7 +310,10 @@ 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(); } #endregion private GroupBox groupBoxTools; @@ -280,5 +333,11 @@ private Button buttonAddMap; private Button buttonDeleteMap; private ListBox listBoxMaps; + private MenuStrip menuStrip; + private ToolStripMenuItem fileToolStripMenuItem; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripMenuItem loadToolStripMenuItem; + private OpenFileDialog loadFileDialog; + private SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs index 5385cb3..39e2ecb 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs @@ -65,7 +65,6 @@ namespace ProjectLocomotive { return; } - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + new DrawningObject(locomotive) != -1) { MessageBox.Show("Объект добавлен"); @@ -75,7 +74,6 @@ namespace ProjectLocomotive { MessageBox.Show("Ошибка при добавлении объекта"); } - } /// Удаление объекта private void buttonRemoveLocomotive_Click(object sender, EventArgs e) @@ -184,5 +182,36 @@ namespace ProjectLocomotive _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); ReloadMaps(); } + private void saveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_mapsCollection.SaveData(saveFileDialog.FileName)) + { + MessageBox.Show("Saved successfully", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Saving failed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void loadToolStripMenuItem_Click(object sender, EventArgs e) + { + if (loadFileDialog.ShowDialog() == DialogResult.OK) + { + if (_mapsCollection.LoadData(loadFileDialog.FileName)) + { + MessageBox.Show("Loaded successfully", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Loading failed", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + ReloadMaps(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + } } } diff --git a/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs b/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs index 4ac3618..a6aa393 100644 --- a/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs +++ b/ProjectLocomotive/ProjectLocomotive/MapWithSetLocomotivesGeneric.cs @@ -137,7 +137,7 @@ namespace ProjectLocomotive int curHeight = 0; foreach (var locomotive in _setLocomotives.GetLocomotives()) { - locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 560, _pictureWidth, _pictureHeight); + locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 380, _pictureWidth, _pictureHeight); locomotive?.DrawningObject(g); if (curWidth < width) curWidth++; else diff --git a/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs b/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs index 24a2457..31fe400 100644 --- a/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs +++ b/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs @@ -41,7 +41,7 @@ namespace Locomotive // Логика для удаления if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name); } - /// Доступ к парковке + /// Доступ к депо public MapWithSetLocomotivesGeneric this[string ind] { get @@ -51,12 +51,6 @@ namespace Locomotive return null; } } - /// Метод записи информации в файл - 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) { @@ -65,61 +59,59 @@ namespace Locomotive File.Delete(filename); } using (FileStream fs = new(filename, FileMode.Create)) + using (StreamWriter sw = new StreamWriter(fs, Encoding.UTF8)) { - WriteToFile($"MapsCollection{Environment.NewLine}", fs); + sw.WriteLine("MapsCollection"); foreach (var storage in _mapStorages) { - WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs); + sw.WriteLine( + $"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" + ); } } return true; } - /// Загрузка информации по локомотивам на парковках из файла + /// Загрузка информации по локомотивам в депо из файла public bool LoadData(string filename) { if (!File.Exists(filename)) { return false; } - string bufferTextFromFile = ""; using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader sr = new StreamReader(fs, Encoding.UTF8)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + string curLine = sr.ReadLine(); + + if (!curLine.Contains("MapsCollection")) { - bufferTextFromFile += temp.GetString(b); + return false; } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - if (!strs[0].Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - return false; - } - //очищаем записи - _mapStorages.Clear(); - for (int i = 1; i < strs.Length; ++i) - { - var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) + _mapStorages.Clear(); + while ((curLine = sr.ReadLine()) != null) { - case "Simple Map": - map = new SimpleMap(); - break; - case "Spike Map": - map = new SpikeMap(); - break; - case "Rail Map": - map = new RailroadMap(); - break; + var elems = curLine.Split(separatorDict); + AbstractMap map = null; + + switch (elems[1]) + { + case "Simple Map": + map = new SimpleMap(); + break; + case "Spike Map": + map = new SpikeMap(); + break; + case "Rail Map": + map = new RailroadMap(); + break; + } + + _mapStorages.Add(elems[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elems[0]].LoadData(elems[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } - _mapStorages.Add(elem[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + return true; } - return true; } } } \ No newline at end of file -- 2.25.1 From 5510ce31d0ce55ba36b898f5e0dd791a73a6aa85 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Sun, 20 Nov 2022 11:57:53 +0300 Subject: [PATCH 6/7] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?=20=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B1=D0=B5=D0=BB=D1=8B.=20=D0=9B=D0=B0=D0=B1=D0=B0=D1=80?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectLocomotive/DrawningElectroLocomotive.cs | 1 - ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs | 1 - ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs | 2 -- .../ProjectLocomotive/FormLocomotiveConfig.Designer.cs | 1 - .../ProjectLocomotive/FormMapWithSetLocomotives.cs | 1 - ProjectLocomotive/ProjectLocomotive/MapsCollection.cs | 1 - 6 files changed, 7 deletions(-) diff --git a/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs index db8f44f..89e6053 100644 --- a/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/DrawningElectroLocomotive.cs @@ -40,7 +40,6 @@ namespace ProjectLocomotive return; } Pen pen = new(Color.Black); - if (elLocc.ElectroLines) { g.DrawLine(pen, _startPosX + 20, _startPosY, _startPosX + 5, _startPosY - 12); diff --git a/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs b/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs index 7f4d18b..d880093 100644 --- a/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs +++ b/ProjectLocomotive/ProjectLocomotive/ExtentionLocomotive.cs @@ -19,7 +19,6 @@ namespace ProjectLocomotive } return $"{str}{_separatorForObject}{warmlyLocomotive.DopColor.Name}{_separatorForObject}{warmlyLocomotive.ElectroLines}{_separatorForObject}{warmlyLocomotive.ElectroBattery}"; } - public static DrawningLocomotive createDrawningLocomotive(this string info) { string[] strs = info.Split(_separatorForObject); diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs index bd67b24..3f0412e 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotive.Designer.cs @@ -19,9 +19,7 @@ } base.Dispose(disposing); } - #region Windows Form Designer generated code - /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. diff --git a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs index 9314077..21246c9 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormLocomotiveConfig.Designer.cs @@ -360,7 +360,6 @@ this.panelObject.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxObject)).EndInit(); this.ResumeLayout(false); - } #endregion private GroupBox groupBoxConfig; diff --git a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs index 39e2ecb..0cbe158 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.cs @@ -196,7 +196,6 @@ namespace ProjectLocomotive } } } - private void loadToolStripMenuItem_Click(object sender, EventArgs e) { if (loadFileDialog.ShowDialog() == DialogResult.OK) diff --git a/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs b/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs index 31fe400..c11a9eb 100644 --- a/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs +++ b/ProjectLocomotive/ProjectLocomotive/MapsCollection.cs @@ -64,7 +64,6 @@ namespace Locomotive sw.WriteLine("MapsCollection"); foreach (var storage in _mapStorages) { - sw.WriteLine( $"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}" ); -- 2.25.1 From 665230d38555d07a8e2c6760f7eb9ab7d20328b1 Mon Sep 17 00:00:00 2001 From: Sem730 Date: Tue, 22 Nov 2022 11:48:54 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D1=8B=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=20=D0=B0=D0=BD=D0=B3=D0=BB=D0=B8=D0=B9=D1=81=D0=BA=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=BD=D0=B0=20=D1=80=D1=83=D1=81=D1=81=D0=BA?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetLocomotives.Designer.cs | 27 ++++++++++--------- .../FormMapWithSetLocomotives.resx | 9 +++++++ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs index ecd2001..78944f7 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.Designer.cs @@ -69,11 +69,11 @@ this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonAddLocomotive); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(580, 28); + this.groupBoxTools.Location = new System.Drawing.Point(580, 33); this.groupBoxTools.Margin = new System.Windows.Forms.Padding(4); this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Padding = new System.Windows.Forms.Padding(4); - this.groupBoxTools.Size = new System.Drawing.Size(220, 540); + this.groupBoxTools.Size = new System.Drawing.Size(220, 535); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; @@ -90,7 +90,7 @@ this.groupBox1.Size = new System.Drawing.Size(208, 250); this.groupBox1.TabIndex = 8; this.groupBox1.TabStop = false; - this.groupBox1.Text = "Maps"; + this.groupBox1.Text = "Карты"; // // buttonDeleteMap // @@ -245,12 +245,13 @@ // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBox.Location = new System.Drawing.Point(0, 28); + this.pictureBox.Location = new System.Drawing.Point(0, 33); this.pictureBox.Margin = new System.Windows.Forms.Padding(4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(580, 540); + this.pictureBox.Size = new System.Drawing.Size(580, 535); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; + // // menuStrip // this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); @@ -258,7 +259,7 @@ this.fileToolStripMenuItem}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; - this.menuStrip.Size = new System.Drawing.Size(800, 28); + this.menuStrip.Size = new System.Drawing.Size(800, 33); this.menuStrip.TabIndex = 2; // // fileToolStripMenuItem @@ -267,21 +268,21 @@ this.saveToolStripMenuItem, this.loadToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; - this.fileToolStripMenuItem.Size = new System.Drawing.Size(46, 24); - this.fileToolStripMenuItem.Text = "File"; + this.fileToolStripMenuItem.Size = new System.Drawing.Size(69, 29); + this.fileToolStripMenuItem.Text = "Файл"; // // saveToolStripMenuItem // this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; - this.saveToolStripMenuItem.Size = new System.Drawing.Size(224, 26); - this.saveToolStripMenuItem.Text = "Save"; + this.saveToolStripMenuItem.Size = new System.Drawing.Size(200, 34); + 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 = "Load"; + this.loadToolStripMenuItem.Size = new System.Drawing.Size(200, 34); + this.loadToolStripMenuItem.Text = "Загрузить"; this.loadToolStripMenuItem.Click += new System.EventHandler(this.loadToolStripMenuItem_Click); // // loadFileDialog @@ -292,7 +293,6 @@ // this.saveFileDialog.Filter = "txt file | *.txt"; // - // // FormMapWithSetLocomotives // this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); @@ -314,6 +314,7 @@ this.menuStrip.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); + } #endregion private GroupBox groupBoxTools; diff --git a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.resx b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.resx index f298a7b..ac9a930 100644 --- a/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.resx +++ b/ProjectLocomotive/ProjectLocomotive/FormMapWithSetLocomotives.resx @@ -57,4 +57,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 163, 17 + + + 341, 17 + \ No newline at end of file -- 2.25.1