From db78391b7f9cc2d81457b0ee846c7d9313c1b8ea Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 26 Nov 2023 23:07:12 +0400 Subject: [PATCH 1/8] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20ExtentionLocomo?= =?UTF-8?q?tive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/ExtentionLocomotive.cs | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs diff --git a/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs new file mode 100644 index 0000000..aed65f9 --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectElectricLocomotive.Entities; + +namespace ProjectElectricLocomotive.DrawingObjects +{ + public static class ExtentionLocomotive + { + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Разделитель даннных + /// Ширина + /// Высота + /// Объект + public static DrawingLocomotive? CreateDrawningCar(this string info, char + separatorForObject, int width, int height) + { + string[] strs = info.Split(separatorForObject); + if (strs.Length == 3) + { + return new DrawingLocomotive(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + } + if (strs.Length == 7) + { + return new DrawningSportCar(Convert.ToInt32(strs[0]), + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), + Color.FromName(strs[3]), + Convert.ToBoolean(strs[4]), + Convert.ToBoolean(strs[5]), + Convert.ToBoolean(strs[6]), width, height); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Разделитель даннных + /// Строка с данными по объекту + public static string GetDataForSave(this DrawingLocomotive drawningCar, + char separatorForObject) + { + var loco = drawningCar.EntityLocomotive; + if (loco == null) + { + return string.Empty; + } + var str = + $"{loco.Speed}{separatorForObject}{loco.Weight}{separatorForObject}{loco.BodyColor.Name}"; + if (loco is not EntityElectricLocomotive electricLocomotive) + { + return str; + } + return + $"{str}{separatorForObject}{electricLocomotive.AdditionalColor.Name}{separatorForObject}{electricLocomotive.Pantograph}{separatorForObject}{electricLocomotive.Compartment}"; + } + + } +} -- 2.25.1 From 127a678e28faf68bff0f747bf3770b574822665b Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 26 Nov 2023 23:12:10 +0400 Subject: [PATCH 2/8] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81-=D0=BA=D0=BE=D0=BB?= =?UTF-8?q?=D0=BB=D0=B5=D0=BA=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/ExtentionLocomotive.cs | 14 ++++++-------- .../LocomotivesGenericCollection.cs | 4 ++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs index aed65f9..fd063a4 100644 --- a/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs @@ -24,17 +24,17 @@ namespace ProjectElectricLocomotive.DrawingObjects if (strs.Length == 3) { return new DrawingLocomotive(Convert.ToInt32(strs[0]), - Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height); + Convert.ToInt32(strs[1]), + Color.FromName(strs[2]), width, height); } - if (strs.Length == 7) + if (strs.Length == 6) { - return new DrawningSportCar(Convert.ToInt32(strs[0]), + return new DrawingElectricLocomotive(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), Color.FromName(strs[3]), Convert.ToBoolean(strs[4]), - Convert.ToBoolean(strs[5]), - Convert.ToBoolean(strs[6]), width, height); + Convert.ToBoolean(strs[5]), width, height); } return null; } @@ -44,8 +44,7 @@ namespace ProjectElectricLocomotive.DrawingObjects /// Сохраняемый объект /// Разделитель даннных /// Строка с данными по объекту - public static string GetDataForSave(this DrawingLocomotive drawningCar, - char separatorForObject) + public static string GetDataForSave(this DrawingLocomotive drawningCar, char separatorForObject) { var loco = drawningCar.EntityLocomotive; if (loco == null) @@ -61,6 +60,5 @@ namespace ProjectElectricLocomotive.DrawingObjects return $"{str}{separatorForObject}{electricLocomotive.AdditionalColor.Name}{separatorForObject}{electricLocomotive.Pantograph}{separatorForObject}{electricLocomotive.Compartment}"; } - } } diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index 51de520..4ff16df 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -87,5 +87,9 @@ namespace ProjectElectricLocomotive.Generics } } } + /// + /// Получение объектов коллекции + /// + public IEnumerable GetLocomotives => _collection.GetLocomotives(); } } -- 2.25.1 From 18d078a97ed55dafd48ca6829c2e2944926b6465 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 26 Nov 2023 23:57:23 +0400 Subject: [PATCH 3/8] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=B0=206=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.Designer.cs | 79 +++++++++++-- .../FormLocomotiveCollection.cs | 43 +++++++ .../FormLocomotiveCollection.resx | 33 ++++++ .../LocomotivesGenericStorage.cs | 106 ++++++++++++++++++ 4 files changed, 253 insertions(+), 8 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index 1b467de..3620ab3 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -28,6 +28,7 @@ /// private void InitializeComponent() { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLocomotiveCollection)); panelLocomotiveCollection = new Panel(); groupBoxSets = new GroupBox(); textBoxSetName = new TextBox(); @@ -40,9 +41,16 @@ ButtonRemoveLocomotive = new Button(); ButtonAddLocomotive = new Button(); pictureBoxCollection = new PictureBox(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + LoadToolStripMenuItem = new ToolStripMenuItem(); + SaveToolStripMenuItem = new ToolStripMenuItem(); + saveFileDialog = new SaveFileDialog(); + openFileDialog = new OpenFileDialog(); panelLocomotiveCollection.SuspendLayout(); groupBoxSets.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + menuStrip.SuspendLayout(); SuspendLayout(); // // panelLocomotiveCollection @@ -56,9 +64,9 @@ panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive); panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive); panelLocomotiveCollection.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - panelLocomotiveCollection.Location = new Point(660, 2); + panelLocomotiveCollection.Location = new Point(660, 27); panelLocomotiveCollection.Name = "panelLocomotiveCollection"; - panelLocomotiveCollection.Size = new Size(248, 584); + panelLocomotiveCollection.Size = new Size(248, 559); panelLocomotiveCollection.TabIndex = 0; panelLocomotiveCollection.Tag = "Инструменты"; // @@ -68,9 +76,9 @@ groupBoxSets.Controls.Add(buttonDeleteSet); groupBoxSets.Controls.Add(listBoxStorages); groupBoxSets.Controls.Add(buttonAddSet); - groupBoxSets.Location = new Point(3, 15); + groupBoxSets.Location = new Point(3, 25); groupBoxSets.Name = "groupBoxSets"; - groupBoxSets.Size = new Size(242, 324); + groupBoxSets.Size = new Size(242, 314); groupBoxSets.TabIndex = 5; groupBoxSets.TabStop = false; groupBoxSets.Text = "Наборы"; @@ -130,7 +138,7 @@ // // ButtonRefreshCollection // - ButtonRefreshCollection.Location = new Point(3, 530); + ButtonRefreshCollection.Location = new Point(3, 505); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; ButtonRefreshCollection.Size = new Size(242, 43); ButtonRefreshCollection.TabIndex = 2; @@ -160,19 +168,65 @@ // // pictureBoxCollection // - pictureBoxCollection.Location = new Point(2, 2); + pictureBoxCollection.Location = new Point(2, 27); pictureBoxCollection.Name = "pictureBoxCollection"; - pictureBoxCollection.Size = new Size(655, 584); + pictureBoxCollection.Size = new Size(655, 560); + pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize; pictureBoxCollection.TabIndex = 1; pictureBoxCollection.TabStop = false; // + // menuStrip + // + menuStrip.GripStyle = ToolStripGripStyle.Visible; + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(909, 24); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip1"; + // + // файлToolStripMenuItem + // + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { LoadToolStripMenuItem, SaveToolStripMenuItem }); + файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + файлToolStripMenuItem.Size = new Size(48, 20); + файлToolStripMenuItem.Text = "&Файл"; + // + // LoadToolStripMenuItem + // + LoadToolStripMenuItem.Image = (Image)resources.GetObject("LoadToolStripMenuItem.Image"); + LoadToolStripMenuItem.ImageTransparentColor = Color.Magenta; + LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; + LoadToolStripMenuItem.Size = new Size(180, 22); + LoadToolStripMenuItem.Text = "Загрузка"; + LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + // + // SaveToolStripMenuItem + // + SaveToolStripMenuItem.Image = (Image)resources.GetObject("SaveToolStripMenuItem.Image"); + SaveToolStripMenuItem.ImageTransparentColor = Color.Magenta; + SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; + SaveToolStripMenuItem.Size = new Size(180, 22); + SaveToolStripMenuItem.Text = "Сохранение"; + SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.FileName = "openFileDialog1"; + // // FormLocomotiveCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(909, 587); - Controls.Add(pictureBoxCollection); + Controls.Add(menuStrip); Controls.Add(panelLocomotiveCollection); + Controls.Add(pictureBoxCollection); + MainMenuStrip = menuStrip; Name = "FormLocomotiveCollection"; Text = "Набор локомотивов"; panelLocomotiveCollection.ResumeLayout(false); @@ -180,7 +234,10 @@ groupBoxSets.ResumeLayout(false); groupBoxSets.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -196,5 +253,11 @@ private ListBox listBoxStorages; private Button buttonAddSet; private TextBox textBoxSetName; + private MenuStrip menuStrip; + private SaveFileDialog saveFileDialog; + private OpenFileDialog openFileDialog; + private ToolStripMenuItem файлToolStripMenuItem; + private ToolStripMenuItem LoadToolStripMenuItem; + private ToolStripMenuItem SaveToolStripMenuItem; } } \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 9f5fe1d..922c807 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -132,5 +132,48 @@ namespace ProjectElectricLocomotive ReloadObjects(); } } + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + private void SaveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (saveFileDialog.ShowDialog() == DialogResult.OK) + { + if (_storage.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 (_storage.LoadData(openFileDialog.FileName)) + { + MessageBox.Show("Load is done!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadObjects(); + } + else + { + MessageBox.Show("Load is fail!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); + + } + } + } } } + diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx index af32865..514a67a 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx @@ -117,4 +117,37 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 19, 13 + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAFUSURBVDhPlZK9SgNBFIXnCcQnkLyA4CPkHayFdBY22mqj + paVlxCKCoBaClUQLESNRC4OE4EKQrAbcYBKy62Z/ynHOzUwcMzuyDhzYGc795tw7y2ZXFEVLSZI8p2la + kkf5lywO1vZr/MH54LkhwlgQKsZxvC4AfHHjjM+tHOaDiKIKiqDqk0s6rbUJoCDCsy3t5kJh+bJFZrZ8 + YGhh9ZjgSIeUUgVZPgHot2HfGwbTNu4aTf75UuW+50wVhSMAKwRwugO6aevokYohfQbDzj1/vdj8pffb + PfJREpUAEPSOvXoFBdSFBIDgmxIgTr3lEkRPYZMOwDwYDtzrXToATPVp06B9QwB8o4YAipjVr02dqx0T + gOHMGm3qNc8nL6EAX33XMP2l8cj7mQEOvMaJYbKpWy/zMAzf6BVE9ADF6CnLnCXMCn8mAUSMEiCYwX/k + +/48Y4x9AwxhsnXBwZZBAAAAAElFTkSuQmCC + + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAABzSURBVDhPY/j69WvDt2/f/pODQXoZQIyYCfv+MwTPIQmD + 9ID0gg3ApoAYjGHAh/cficLD2QBS8SA1AJufkTGyWtoagM5HFwdhmAEfkPMCukJkzcjiIAw24MuXLwbI + hqArRNaMLA7CYANAAGYISIA0/O0/AID67ECmnhNDAAAAAElFTkSuQmCC + + + + 134, 11 + + + 269, 13 + + + 62 + \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs index f29cdff..44fde5e 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs @@ -20,6 +20,18 @@ namespace ProjectElectricLocomotive /// Возвращение списка названий наборов /// public List Keys => _locomotivesStorage.Keys.ToList(); + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private static readonly char _separatorForKeyValue = '|'; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly char _separatorRecords = ';'; + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly char _separatorForObject = ':'; private readonly int _pictureWidth; @@ -79,5 +91,99 @@ namespace ProjectElectricLocomotive return null; } } + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (File.Exists(filename)) + { + File.Delete(filename); + } + StringBuilder data = new(); + foreach (KeyValuePair> record in _locomotivesStorage) + { + StringBuilder records = new(); + foreach (DrawingLocomotive? elem in record.Value.GetLocomotives) + { + records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}"); + } + data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}"); + } + if (data.Length == 0) + { + return false; + } + using FileStream fs = new(filename, FileMode.Create); + byte[] info = new + UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}"); + fs.Write(info, 0, info.Length); + return true; + } + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + 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 == null || strs.Length == 0) + { + return false; + } + if (!strs[0].StartsWith("CarStorage")) + { + //если нет такой записи, то это не те данные + return false; + } + _locomotivesStorage.Clear(); + foreach (string data in strs) + { + string[] record = data.Split(_separatorForKeyValue, + StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) + { + continue; + } + LocomotivesGenericCollection + collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, + StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + DrawingLocomotive? loco = elem?.CreateDrawningCar(_separatorForObject, _pictureWidth, _pictureHeight); + if (loco != null) + { + if (collection + loco == -1) + { + return false; + } + } + } + _locomotivesStorage.Add(record[0], collection); + } + return true; + } } } + + -- 2.25.1 From 7d265f9eb0e4cc4ba8e68053d8d956750f338567 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 26 Nov 2023 23:59:46 +0400 Subject: [PATCH 4/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/FormLocomotiveCollection.Designer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index 3620ab3..71fd457 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -177,7 +177,7 @@ // // menuStrip // - menuStrip.GripStyle = ToolStripGripStyle.Visible; + menuStrip.BackColor = SystemColors.ButtonFace; menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; -- 2.25.1 From 94a7a2f2bc2543c25c90dd09ebf5c43bf02f6d9d Mon Sep 17 00:00:00 2001 From: tellsense Date: Mon, 27 Nov 2023 00:03:43 +0400 Subject: [PATCH 5/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=E2=84=962.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.Designer.cs | 82 ++++++++----------- .../FormLocomotiveCollection.resx | 2 +- 2 files changed, 36 insertions(+), 48 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index 71fd457..9a18fb5 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -29,13 +29,11 @@ private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormLocomotiveCollection)); - panelLocomotiveCollection = new Panel(); groupBoxSets = new GroupBox(); textBoxSetName = new TextBox(); buttonDeleteSet = new Button(); listBoxStorages = new ListBox(); buttonAddSet = new Button(); - LabelOnPanel = new Label(); maskedTextBoxNumber = new MaskedTextBox(); ButtonRefreshCollection = new Button(); ButtonRemoveLocomotive = new Button(); @@ -47,36 +45,21 @@ SaveToolStripMenuItem = new ToolStripMenuItem(); saveFileDialog = new SaveFileDialog(); openFileDialog = new OpenFileDialog(); - panelLocomotiveCollection.SuspendLayout(); + groupBoxMenu = new GroupBox(); groupBoxSets.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); menuStrip.SuspendLayout(); + groupBoxMenu.SuspendLayout(); SuspendLayout(); // - // panelLocomotiveCollection - // - panelLocomotiveCollection.AccessibleDescription = ""; - panelLocomotiveCollection.AccessibleName = ""; - panelLocomotiveCollection.Controls.Add(groupBoxSets); - panelLocomotiveCollection.Controls.Add(LabelOnPanel); - panelLocomotiveCollection.Controls.Add(maskedTextBoxNumber); - panelLocomotiveCollection.Controls.Add(ButtonRefreshCollection); - panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive); - panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive); - panelLocomotiveCollection.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point); - panelLocomotiveCollection.Location = new Point(660, 27); - panelLocomotiveCollection.Name = "panelLocomotiveCollection"; - panelLocomotiveCollection.Size = new Size(248, 559); - panelLocomotiveCollection.TabIndex = 0; - panelLocomotiveCollection.Tag = "Инструменты"; - // // groupBoxSets // groupBoxSets.Controls.Add(textBoxSetName); groupBoxSets.Controls.Add(buttonDeleteSet); groupBoxSets.Controls.Add(listBoxStorages); + groupBoxSets.Controls.Add(ButtonAddLocomotive); groupBoxSets.Controls.Add(buttonAddSet); - groupBoxSets.Location = new Point(3, 25); + groupBoxSets.Location = new Point(0, 22); groupBoxSets.Name = "groupBoxSets"; groupBoxSets.Size = new Size(242, 314); groupBoxSets.TabIndex = 5; @@ -120,27 +103,18 @@ buttonAddSet.UseVisualStyleBackColor = true; buttonAddSet.Click += buttonAddSet_Click; // - // LabelOnPanel - // - LabelOnPanel.AutoSize = true; - LabelOnPanel.Location = new Point(3, -3); - LabelOnPanel.Name = "LabelOnPanel"; - LabelOnPanel.Size = new Size(83, 15); - LabelOnPanel.TabIndex = 4; - LabelOnPanel.Text = "Инструменты"; - // // maskedTextBoxNumber // - maskedTextBoxNumber.Location = new Point(35, 408); + maskedTextBoxNumber.Location = new Point(6, 342); maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(176, 23); + maskedTextBoxNumber.Size = new Size(226, 23); maskedTextBoxNumber.TabIndex = 3; // // ButtonRefreshCollection // - ButtonRefreshCollection.Location = new Point(3, 505); + ButtonRefreshCollection.Location = new Point(6, 440); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; - ButtonRefreshCollection.Size = new Size(242, 43); + ButtonRefreshCollection.Size = new Size(230, 43); ButtonRefreshCollection.TabIndex = 2; ButtonRefreshCollection.Text = " Обновить коллекцию"; ButtonRefreshCollection.UseVisualStyleBackColor = true; @@ -148,9 +122,9 @@ // // ButtonRemoveLocomotive // - ButtonRemoveLocomotive.Location = new Point(3, 460); + ButtonRemoveLocomotive.Location = new Point(6, 388); ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive"; - ButtonRemoveLocomotive.Size = new Size(242, 39); + ButtonRemoveLocomotive.Size = new Size(230, 39); ButtonRemoveLocomotive.TabIndex = 1; ButtonRemoveLocomotive.Text = "Удалить локомотив"; ButtonRemoveLocomotive.UseVisualStyleBackColor = true; @@ -158,9 +132,9 @@ // // ButtonAddLocomotive // - ButtonAddLocomotive.Location = new Point(3, 345); + ButtonAddLocomotive.Location = new Point(6, 269); ButtonAddLocomotive.Name = "ButtonAddLocomotive"; - ButtonAddLocomotive.Size = new Size(242, 39); + ButtonAddLocomotive.Size = new Size(226, 39); ButtonAddLocomotive.TabIndex = 0; ButtonAddLocomotive.Text = "Добавить локомотив"; ButtonAddLocomotive.UseVisualStyleBackColor = true; @@ -168,7 +142,7 @@ // // pictureBoxCollection // - pictureBoxCollection.Location = new Point(2, 27); + pictureBoxCollection.Location = new Point(6, 24); pictureBoxCollection.Name = "pictureBoxCollection"; pictureBoxCollection.Size = new Size(655, 560); pictureBoxCollection.SizeMode = PictureBoxSizeMode.AutoSize; @@ -197,7 +171,7 @@ LoadToolStripMenuItem.Image = (Image)resources.GetObject("LoadToolStripMenuItem.Image"); LoadToolStripMenuItem.ImageTransparentColor = Color.Magenta; LoadToolStripMenuItem.Name = "LoadToolStripMenuItem"; - LoadToolStripMenuItem.Size = new Size(180, 22); + LoadToolStripMenuItem.Size = new Size(141, 22); LoadToolStripMenuItem.Text = "Загрузка"; LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; // @@ -206,7 +180,7 @@ SaveToolStripMenuItem.Image = (Image)resources.GetObject("SaveToolStripMenuItem.Image"); SaveToolStripMenuItem.ImageTransparentColor = Color.Magenta; SaveToolStripMenuItem.Name = "SaveToolStripMenuItem"; - SaveToolStripMenuItem.Size = new Size(180, 22); + SaveToolStripMenuItem.Size = new Size(141, 22); SaveToolStripMenuItem.Text = "Сохранение"; SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; // @@ -218,36 +192,49 @@ // openFileDialog.FileName = "openFileDialog1"; // + // groupBoxMenu + // + groupBoxMenu.AutoSize = true; + groupBoxMenu.Controls.Add(maskedTextBoxNumber); + groupBoxMenu.Controls.Add(groupBoxSets); + groupBoxMenu.Controls.Add(ButtonRemoveLocomotive); + groupBoxMenu.Controls.Add(ButtonRefreshCollection); + groupBoxMenu.Dock = DockStyle.Right; + groupBoxMenu.Location = new Point(661, 24); + groupBoxMenu.Name = "groupBoxMenu"; + groupBoxMenu.Size = new Size(248, 563); + groupBoxMenu.TabIndex = 6; + groupBoxMenu.TabStop = false; + groupBoxMenu.Text = "Инструменты"; + // // FormLocomotiveCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(909, 587); + Controls.Add(groupBoxMenu); Controls.Add(menuStrip); - Controls.Add(panelLocomotiveCollection); Controls.Add(pictureBoxCollection); MainMenuStrip = menuStrip; Name = "FormLocomotiveCollection"; Text = "Набор локомотивов"; - panelLocomotiveCollection.ResumeLayout(false); - panelLocomotiveCollection.PerformLayout(); groupBoxSets.ResumeLayout(false); groupBoxSets.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); + groupBoxMenu.ResumeLayout(false); + groupBoxMenu.PerformLayout(); ResumeLayout(false); PerformLayout(); } - #endregion - private Panel panelLocomotiveCollection; + #endregion private Button ButtonAddLocomotive; private Button ButtonRemoveLocomotive; private Button ButtonRefreshCollection; private PictureBox pictureBoxCollection; private MaskedTextBox maskedTextBoxNumber; - private Label LabelOnPanel; private GroupBox groupBoxSets; private Button buttonDeleteSet; private ListBox listBoxStorages; @@ -259,5 +246,6 @@ private ToolStripMenuItem файлToolStripMenuItem; private ToolStripMenuItem LoadToolStripMenuItem; private ToolStripMenuItem SaveToolStripMenuItem; + private GroupBox groupBoxMenu; } } \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx index 514a67a..2cb4710 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.resx @@ -148,6 +148,6 @@ 269, 13 - 62 + 25 \ No newline at end of file -- 2.25.1 From a1d6167007a2ccfaf229a28b67c53df1bd1fb9d5 Mon Sep 17 00:00:00 2001 From: tellsense Date: Mon, 27 Nov 2023 00:17:43 +0400 Subject: [PATCH 6/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=E2=84=963?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/FormLocomotiveCollection.cs | 8 ++++---- .../ElectricLocomotive/FormLocomotiveConfig.Designer.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 922c807..049c631 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -143,12 +143,12 @@ namespace ProjectElectricLocomotive { if (_storage.SaveData(saveFileDialog.FileName)) { - MessageBox.Show("Сохранение прошло успешно", + MessageBox.Show("Сохранение прошло успешно!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { - MessageBox.Show("Не сохранилось", "Результат", + MessageBox.Show("Ошибка сохранения!", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } @@ -164,12 +164,12 @@ namespace ProjectElectricLocomotive { if (_storage.LoadData(openFileDialog.FileName)) { - MessageBox.Show("Load is done!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Загрузка завершена!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadObjects(); } else { - MessageBox.Show("Load is fail!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Ошибка загрузки!", "Result", MessageBoxButtons.OK, MessageBoxIcon.Error); } } diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs index f851898..4fa6470 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveConfig.Designer.cs @@ -186,7 +186,7 @@ // panelColorGreen // panelColorGreen.AllowDrop = true; - panelColorGreen.BackColor = Color.FromArgb(0, 192, 0); + panelColorGreen.BackColor = Color.Green; panelColorGreen.Location = new Point(87, 28); panelColorGreen.Name = "panelColorGreen"; panelColorGreen.Size = new Size(50, 50); -- 2.25.1 From fb1f7abf5c22406668fb009bb8241f0f4b037ef1 Mon Sep 17 00:00:00 2001 From: tellsense Date: Mon, 27 Nov 2023 00:33:49 +0400 Subject: [PATCH 7/8] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=B2=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20LocomotivesGene?= =?UTF-8?q?ricStorage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocomotivesGenericStorage.cs | 95 ++++++++++--------- 1 file changed, 48 insertions(+), 47 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs index 44fde5e..68f1489 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs @@ -1,5 +1,4 @@ using ProjectElectricLocomotive.DrawingObjects; -using ProjectElectricLocomotive.Generics; using ProjectElectricLocomotive.MovementStrategy; using System; using System.Collections.Generic; @@ -7,7 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace ProjectElectricLocomotive +namespace ProjectElectricLocomotive.Generics { internal class LocomotivesGenericStorage { @@ -103,8 +102,7 @@ namespace ProjectElectricLocomotive File.Delete(filename); } StringBuilder data = new(); - foreach (KeyValuePair> record in _locomotivesStorage) + foreach (KeyValuePair> record in _locomotivesStorage) { StringBuilder records = new(); foreach (DrawingLocomotive? elem in record.Value.GetLocomotives) @@ -117,10 +115,11 @@ namespace ProjectElectricLocomotive { return false; } - using FileStream fs = new(filename, FileMode.Create); - byte[] info = new - UTF8Encoding(true).GetBytes($"CarStorage{Environment.NewLine}{data}"); - fs.Write(info, 0, info.Length); + using StreamWriter fs = new StreamWriter(filename); + { + fs.WriteLine($"LocomotiveStorage{Environment.NewLine}"); + fs.WriteLine(data); + } return true; } /// @@ -134,56 +133,58 @@ namespace ProjectElectricLocomotive { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + + using (StreamReader fs = File.OpenText(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + + string str = fs.ReadLine(); + + if (str == null || str.Length == 0) { - bufferTextFromFile += temp.GetString(b); + return false; } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, - StringSplitOptions.RemoveEmptyEntries); - if (strs == null || strs.Length == 0) - { - return false; - } - if (!strs[0].StartsWith("CarStorage")) - { - //если нет такой записи, то это не те данные - return false; - } - _locomotivesStorage.Clear(); - foreach (string data in strs) - { - string[] record = data.Split(_separatorForKeyValue, - StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 2) - { - continue; - } - LocomotivesGenericCollection - collection = new(_pictureWidth, _pictureHeight); - string[] set = record[1].Split(_separatorRecords, - StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + + if (!str.StartsWith("LocomotiveStorage")) { - DrawingLocomotive? loco = elem?.CreateDrawningCar(_separatorForObject, _pictureWidth, _pictureHeight); - if (loco != null) + //если нет такой записи, то это не те данные + return false; + } + + _locomotivesStorage.Clear(); + string strs = ""; + + + while ((strs = fs.ReadLine()) != null) + { + + if (strs == null) { - if (collection + loco == -1) + return false; + } + + string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 2) + { + continue; + } + LocomotivesGenericCollection collection = new(_pictureWidth, _pictureHeight); + string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); + foreach (string thing in set) + { + DrawingLocomotive? loco = thing?.CreateDrawingLocomotive(_separatorForObject, _pictureWidth, _pictureHeight); + if (loco != null) { - return false; + if ((collection + loco) == -1) + { + return false; + } } } + _locomotivesStorage.Add(record[0], collection); } - _locomotivesStorage.Add(record[0], collection); + return true; } - return true; } } } - -- 2.25.1 From c8545fdb07b982f38f4648588cce65b0715aabfa Mon Sep 17 00:00:00 2001 From: tellsense Date: Mon, 27 Nov 2023 00:36:05 +0400 Subject: [PATCH 8/8] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs | 2 +- .../ElectricLocomotive/LocomotivesGenericStorage.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs index fd063a4..5218aba 100644 --- a/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/ExtentionLocomotive.cs @@ -17,7 +17,7 @@ namespace ProjectElectricLocomotive.DrawingObjects /// Ширина /// Высота /// Объект - public static DrawingLocomotive? CreateDrawningCar(this string info, char + public static DrawingLocomotive? CreateDrawningLocomotive(this string info, char separatorForObject, int width, int height) { string[] strs = info.Split(separatorForObject); diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs index 68f1489..0c46d87 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs @@ -169,9 +169,9 @@ namespace ProjectElectricLocomotive.Generics } LocomotivesGenericCollection collection = new(_pictureWidth, _pictureHeight); string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - foreach (string thing in set) + foreach (string elem in set) { - DrawingLocomotive? loco = thing?.CreateDrawingLocomotive(_separatorForObject, _pictureWidth, _pictureHeight); + DrawingLocomotive? loco = elem?.CreateDrawningLocomotive(_separatorForObject, _pictureWidth, _pictureHeight); if (loco != null) { if ((collection + loco) == -1) -- 2.25.1