laba6 Кувшинов Тимур ПИбд-21 Простая #9
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
|
61
Laba1Loco/Laba1Loco/ExtentionDrawingTrain.cs
Normal file
61
Laba1Loco/Laba1Loco/ExtentionDrawingTrain.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal static class ExtentionDrawingTrain
|
||||
{
|
||||
/// <summary>
|
||||
/// Создание объекта из строки
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <param name="width">Ширина</param>
|
||||
/// <param name="height">Высота</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawingTrain CreateDrawingTrain(this string info, char separatorForObject, int width, int height)
|
||||
{
|
||||
string[] strs = info.Split(separatorForObject);
|
||||
if (strs.Length == 3)
|
||||
{
|
||||
return new DrawingTrain(Convert.ToInt32(strs[0]),
|
||||
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||
}
|
||||
if (strs.Length == 7)
|
||||
{
|
||||
return new DrawingLoco(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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение данных для сохранения в файл
|
||||
/// </summary>
|
||||
/// <param name="drawningtrain">Сохраняемый объект</param>
|
||||
/// <param name="separatorForObject">Разделитель даннных</param>
|
||||
/// <returns>Строка с данными по объекту</returns>
|
||||
public static string GetDataForSave(this DrawingTrain drawningTrain, char separatorForObject)
|
||||
{
|
||||
var train = drawningTrain.EntityTrain;
|
||||
if (train == null)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
var str = $"{train.Speed}{separatorForObject}{train.Weight}{separatorForObject}{train.BodyColor.Name}";
|
||||
if (!(train is EntityLoco))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
return $"{str}{separatorForObject}{(train as EntityLoco).AdditionalColor.Name}{separatorForObject}{(train as EntityLoco).Tube}{separatorForObject}{(train as EntityLoco).FuelTank}{separatorForObject}{(train as EntityLoco).LocoLine}";
|
||||
}
|
||||
}
|
||||
}
|
319
Laba1Loco/Laba1Loco/FormTrainCollection.Designer.cs
generated
319
Laba1Loco/Laba1Loco/FormTrainCollection.Designer.cs
generated
@ -28,146 +28,209 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
this.ButtonAddTrain = new System.Windows.Forms.Button();
|
||||
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
this.ButtonRemoveTrain = new System.Windows.Forms.Button();
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
this.textBoxSetName = new System.Windows.Forms.TextBox();
|
||||
this.buttonAddSet = new System.Windows.Forms.Button();
|
||||
this.listBoxStorage = new System.Windows.Forms.ListBox();
|
||||
this.buttonRemoveSet = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
|
||||
this.panel1.SuspendLayout();
|
||||
this.panel2.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
pictureBoxCollection = new System.Windows.Forms.PictureBox();
|
||||
panel1 = new System.Windows.Forms.Panel();
|
||||
panel2 = new System.Windows.Forms.Panel();
|
||||
buttonRemoveSet = new System.Windows.Forms.Button();
|
||||
listBoxStorage = new System.Windows.Forms.ListBox();
|
||||
buttonAddSet = new System.Windows.Forms.Button();
|
||||
textBoxSetName = new System.Windows.Forms.TextBox();
|
||||
maskedTextBoxNumber = new System.Windows.Forms.TextBox();
|
||||
ButtonAddTrain = new System.Windows.Forms.Button();
|
||||
ButtonRefreshCollection = new System.Windows.Forms.Button();
|
||||
ButtonRemoveTrain = new System.Windows.Forms.Button();
|
||||
menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
filesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
loadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||
saveFileDialog = new System.Windows.Forms.SaveFileDialog();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
panel1.SuspendLayout();
|
||||
panel2.SuspendLayout();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
this.pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
this.pictureBoxCollection.Size = new System.Drawing.Size(633, 473);
|
||||
this.pictureBoxCollection.TabIndex = 0;
|
||||
this.pictureBoxCollection.TabStop = false;
|
||||
pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
|
||||
pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
|
||||
pictureBoxCollection.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new System.Drawing.Size(738, 546);
|
||||
pictureBoxCollection.TabIndex = 0;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.AccessibleName = "";
|
||||
this.panel1.Controls.Add(this.panel2);
|
||||
this.panel1.Controls.Add(this.maskedTextBoxNumber);
|
||||
this.panel1.Controls.Add(this.ButtonAddTrain);
|
||||
this.panel1.Controls.Add(this.ButtonRefreshCollection);
|
||||
this.panel1.Controls.Add(this.ButtonRemoveTrain);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.panel1.Location = new System.Drawing.Point(639, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(166, 473);
|
||||
this.panel1.TabIndex = 1;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
this.maskedTextBoxNumber.Location = new System.Drawing.Point(33, 365);
|
||||
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 20);
|
||||
this.maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// ButtonAddTrain
|
||||
//
|
||||
this.ButtonAddTrain.Location = new System.Drawing.Point(43, 327);
|
||||
this.ButtonAddTrain.Name = "ButtonAddTrain";
|
||||
this.ButtonAddTrain.Size = new System.Drawing.Size(75, 23);
|
||||
this.ButtonAddTrain.TabIndex = 3;
|
||||
this.ButtonAddTrain.Text = "Add Train";
|
||||
this.ButtonAddTrain.UseVisualStyleBackColor = true;
|
||||
this.ButtonAddTrain.Click += new System.EventHandler(this.ButtonAddTrain_Click);
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
this.ButtonRefreshCollection.Location = new System.Drawing.Point(21, 438);
|
||||
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
this.ButtonRefreshCollection.Size = new System.Drawing.Size(121, 23);
|
||||
this.ButtonRefreshCollection.TabIndex = 2;
|
||||
this.ButtonRefreshCollection.Text = "Refresh Collection";
|
||||
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
|
||||
//
|
||||
// ButtonRemoveTrain
|
||||
//
|
||||
this.ButtonRemoveTrain.Location = new System.Drawing.Point(33, 400);
|
||||
this.ButtonRemoveTrain.Name = "ButtonRemoveTrain";
|
||||
this.ButtonRemoveTrain.Size = new System.Drawing.Size(100, 23);
|
||||
this.ButtonRemoveTrain.TabIndex = 0;
|
||||
this.ButtonRemoveTrain.Text = "Remove Train";
|
||||
this.ButtonRemoveTrain.UseVisualStyleBackColor = true;
|
||||
this.ButtonRemoveTrain.Click += new System.EventHandler(this.ButtonRemoveTrain_Click);
|
||||
panel1.AccessibleName = "";
|
||||
panel1.Controls.Add(panel2);
|
||||
panel1.Controls.Add(maskedTextBoxNumber);
|
||||
panel1.Controls.Add(ButtonAddTrain);
|
||||
panel1.Controls.Add(ButtonRefreshCollection);
|
||||
panel1.Controls.Add(ButtonRemoveTrain);
|
||||
panel1.Controls.Add(menuStrip1);
|
||||
panel1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
panel1.Location = new System.Drawing.Point(745, 0);
|
||||
panel1.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new System.Drawing.Size(194, 546);
|
||||
panel1.TabIndex = 1;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
this.panel2.AccessibleName = "";
|
||||
this.panel2.Controls.Add(this.buttonRemoveSet);
|
||||
this.panel2.Controls.Add(this.listBoxStorage);
|
||||
this.panel2.Controls.Add(this.buttonAddSet);
|
||||
this.panel2.Controls.Add(this.textBoxSetName);
|
||||
this.panel2.Location = new System.Drawing.Point(14, 12);
|
||||
this.panel2.Name = "panel2";
|
||||
this.panel2.Size = new System.Drawing.Size(140, 208);
|
||||
this.panel2.TabIndex = 5;
|
||||
//
|
||||
// textBoxSetName
|
||||
//
|
||||
this.textBoxSetName.Location = new System.Drawing.Point(8, 12);
|
||||
this.textBoxSetName.Name = "textBoxSetName";
|
||||
this.textBoxSetName.Size = new System.Drawing.Size(120, 20);
|
||||
this.textBoxSetName.TabIndex = 0;
|
||||
//
|
||||
// buttonAddSet
|
||||
//
|
||||
this.buttonAddSet.Location = new System.Drawing.Point(8, 38);
|
||||
this.buttonAddSet.Name = "buttonAddSet";
|
||||
this.buttonAddSet.Size = new System.Drawing.Size(120, 23);
|
||||
this.buttonAddSet.TabIndex = 1;
|
||||
this.buttonAddSet.Text = "Add set";
|
||||
this.buttonAddSet.UseVisualStyleBackColor = true;
|
||||
this.buttonAddSet.Click += new System.EventHandler(this.buttonAddSet_Click);
|
||||
//
|
||||
// listBoxStorage
|
||||
//
|
||||
this.listBoxStorage.FormattingEnabled = true;
|
||||
this.listBoxStorage.Location = new System.Drawing.Point(8, 67);
|
||||
this.listBoxStorage.Name = "listBoxStorage";
|
||||
this.listBoxStorage.Size = new System.Drawing.Size(120, 95);
|
||||
this.listBoxStorage.TabIndex = 2;
|
||||
this.listBoxStorage.SelectedIndexChanged += new System.EventHandler(this.listBoxStorage_SelectedIndexChanged);
|
||||
panel2.AccessibleName = "";
|
||||
panel2.Controls.Add(buttonRemoveSet);
|
||||
panel2.Controls.Add(listBoxStorage);
|
||||
panel2.Controls.Add(buttonAddSet);
|
||||
panel2.Controls.Add(textBoxSetName);
|
||||
panel2.Location = new System.Drawing.Point(18, 98);
|
||||
panel2.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
panel2.Name = "panel2";
|
||||
panel2.Size = new System.Drawing.Size(163, 240);
|
||||
panel2.TabIndex = 5;
|
||||
//
|
||||
// buttonRemoveSet
|
||||
//
|
||||
this.buttonRemoveSet.Location = new System.Drawing.Point(8, 168);
|
||||
this.buttonRemoveSet.Name = "buttonRemoveSet";
|
||||
this.buttonRemoveSet.Size = new System.Drawing.Size(120, 23);
|
||||
this.buttonRemoveSet.TabIndex = 3;
|
||||
this.buttonRemoveSet.Text = "Remove set";
|
||||
this.buttonRemoveSet.UseVisualStyleBackColor = true;
|
||||
this.buttonRemoveSet.Click += new System.EventHandler(this.buttonRemoveSet_Click);
|
||||
buttonRemoveSet.Location = new System.Drawing.Point(9, 194);
|
||||
buttonRemoveSet.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
buttonRemoveSet.Name = "buttonRemoveSet";
|
||||
buttonRemoveSet.Size = new System.Drawing.Size(140, 27);
|
||||
buttonRemoveSet.TabIndex = 3;
|
||||
buttonRemoveSet.Text = "Remove set";
|
||||
buttonRemoveSet.UseVisualStyleBackColor = true;
|
||||
buttonRemoveSet.Click += buttonRemoveSet_Click;
|
||||
//
|
||||
// listBoxStorage
|
||||
//
|
||||
listBoxStorage.FormattingEnabled = true;
|
||||
listBoxStorage.ItemHeight = 15;
|
||||
listBoxStorage.Location = new System.Drawing.Point(9, 77);
|
||||
listBoxStorage.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
listBoxStorage.Name = "listBoxStorage";
|
||||
listBoxStorage.Size = new System.Drawing.Size(139, 109);
|
||||
listBoxStorage.TabIndex = 2;
|
||||
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddSet
|
||||
//
|
||||
buttonAddSet.Location = new System.Drawing.Point(9, 44);
|
||||
buttonAddSet.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
buttonAddSet.Name = "buttonAddSet";
|
||||
buttonAddSet.Size = new System.Drawing.Size(140, 27);
|
||||
buttonAddSet.TabIndex = 1;
|
||||
buttonAddSet.Text = "Add set";
|
||||
buttonAddSet.UseVisualStyleBackColor = true;
|
||||
buttonAddSet.Click += buttonAddSet_Click;
|
||||
//
|
||||
// textBoxSetName
|
||||
//
|
||||
textBoxSetName.Location = new System.Drawing.Point(9, 14);
|
||||
textBoxSetName.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
textBoxSetName.Name = "textBoxSetName";
|
||||
textBoxSetName.Size = new System.Drawing.Size(139, 23);
|
||||
textBoxSetName.TabIndex = 0;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new System.Drawing.Point(38, 421);
|
||||
maskedTextBoxNumber.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new System.Drawing.Size(116, 23);
|
||||
maskedTextBoxNumber.TabIndex = 4;
|
||||
//
|
||||
// ButtonAddTrain
|
||||
//
|
||||
ButtonAddTrain.Location = new System.Drawing.Point(50, 377);
|
||||
ButtonAddTrain.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ButtonAddTrain.Name = "ButtonAddTrain";
|
||||
ButtonAddTrain.Size = new System.Drawing.Size(88, 27);
|
||||
ButtonAddTrain.TabIndex = 3;
|
||||
ButtonAddTrain.Text = "Add Train";
|
||||
ButtonAddTrain.UseVisualStyleBackColor = true;
|
||||
ButtonAddTrain.Click += ButtonAddTrain_Click;
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new System.Drawing.Point(24, 505);
|
||||
ButtonRefreshCollection.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new System.Drawing.Size(141, 27);
|
||||
ButtonRefreshCollection.TabIndex = 2;
|
||||
ButtonRefreshCollection.Text = "Refresh Collection";
|
||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
||||
//
|
||||
// ButtonRemoveTrain
|
||||
//
|
||||
ButtonRemoveTrain.Location = new System.Drawing.Point(38, 462);
|
||||
ButtonRemoveTrain.Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
ButtonRemoveTrain.Name = "ButtonRemoveTrain";
|
||||
ButtonRemoveTrain.Size = new System.Drawing.Size(117, 27);
|
||||
ButtonRemoveTrain.TabIndex = 0;
|
||||
ButtonRemoveTrain.Text = "Remove Train";
|
||||
ButtonRemoveTrain.UseVisualStyleBackColor = true;
|
||||
ButtonRemoveTrain.Click += ButtonRemoveTrain_Click;
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { filesToolStripMenuItem });
|
||||
menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new System.Drawing.Size(194, 24);
|
||||
menuStrip1.TabIndex = 6;
|
||||
menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// filesToolStripMenuItem
|
||||
//
|
||||
filesToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||
filesToolStripMenuItem.Name = "filesToolStripMenuItem";
|
||||
filesToolStripMenuItem.Size = new System.Drawing.Size(42, 20);
|
||||
filesToolStripMenuItem.Text = "Files";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
saveToolStripMenuItem.Text = "Save";
|
||||
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
// loadToolStripMenuItem
|
||||
//
|
||||
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
loadToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
loadToolStripMenuItem.Text = "Load";
|
||||
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
// openFileDialog
|
||||
//
|
||||
openFileDialog.FileName = "TrainSave.txt";
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// saveFileDialog
|
||||
//
|
||||
saveFileDialog.FileName = "TrainSave.txt";
|
||||
saveFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// FormTrainCollection
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(805, 473);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.pictureBoxCollection);
|
||||
this.Name = "FormTrainCollection";
|
||||
this.Text = "FormTrainCollection";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel1.PerformLayout();
|
||||
this.panel2.ResumeLayout(false);
|
||||
this.panel2.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
ClientSize = new System.Drawing.Size(939, 546);
|
||||
Controls.Add(panel1);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
MainMenuStrip = menuStrip1;
|
||||
Margin = new System.Windows.Forms.Padding(4, 3, 4, 3);
|
||||
Name = "FormTrainCollection";
|
||||
Text = "FormTrainCollection";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
panel1.ResumeLayout(false);
|
||||
panel1.PerformLayout();
|
||||
panel2.ResumeLayout(false);
|
||||
panel2.PerformLayout();
|
||||
menuStrip1.ResumeLayout(false);
|
||||
menuStrip1.PerformLayout();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -183,5 +246,11 @@
|
||||
private System.Windows.Forms.ListBox listBoxStorage;
|
||||
private System.Windows.Forms.Button buttonAddSet;
|
||||
private System.Windows.Forms.TextBox textBoxSetName;
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem filesToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem saveToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem loadToolStripMenuItem;
|
||||
private System.Windows.Forms.OpenFileDialog openFileDialog;
|
||||
private System.Windows.Forms.SaveFileDialog saveFileDialog;
|
||||
}
|
||||
}
|
@ -189,5 +189,50 @@ namespace Laba1Loco
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Сохранение"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Загрузка"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_storage.LoadData(openFileDialog.FileName))
|
||||
{
|
||||
MessageBox.Show("Загрузка прошла успешно",
|
||||
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не загрузилось", "Результат",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
ReloadObjects();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
|
||||
Example:
|
||||
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
@ -26,36 +26,36 @@
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
@ -117,4 +117,13 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>132, 17</value>
|
||||
</metadata>
|
||||
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>271, 17</value>
|
||||
</metadata>
|
||||
</root>
|
@ -11,6 +11,10 @@ namespace Laba1Loco
|
||||
where T : DrawingTrain
|
||||
where U : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение объектов коллекции
|
||||
/// </summary>
|
||||
public IEnumerable<T> GetTrains => _collection.GetTrains();
|
||||
/// <summary>
|
||||
/// Ширина окна прорисовки
|
||||
/// </summary>
|
||||
|
@ -1,13 +1,105 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace Laba1Loco
|
||||
{
|
||||
internal class TrainsGenericStorage
|
||||
{
|
||||
/// <summary>
|
||||
/// Разделитель для записи ключа и значения элемента словаря
|
||||
/// </summary>
|
||||
private static readonly char _separatorForKeyValue = '|';
|
||||
/// <summary>
|
||||
/// Разделитель для записей коллекции данных в файл
|
||||
/// </summary>
|
||||
private readonly char _separatorRecords = ';';
|
||||
/// <summary>
|
||||
/// Разделитель для записи информации по объекту в файл
|
||||
/// </summary>
|
||||
private static readonly char _separatorForObject = ':';
|
||||
|
||||
/// <summary>
|
||||
/// Сохранение информации по поездам в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - сохранение прошло успешно, false - ошибка при cохранении данных</returns>
|
||||
public bool SaveData(string filename)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new StringBuilder();
|
||||
foreach (KeyValuePair<string, TrainsGenericCollection<DrawingTrain, DrawningObjectTrain>> record in _trainStorages)
|
||||
{
|
||||
StringBuilder records = new StringBuilder();
|
||||
foreach (DrawingTrain elem in record.Value.GetTrains)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
}
|
||||
if (data.Length == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamWriter sr = new StreamWriter(filename))
|
||||
{
|
||||
sr.Write($"TrainStorage{Environment.NewLine}{data}");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по поездам в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
/// <returns>true - загрузка прошла успешно, false - ошибка призагрузке данных</returns>
|
||||
public bool LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
using (StreamReader sr = new(filename))
|
||||
{
|
||||
string s = sr.ReadLine();
|
||||
if (s == null || s.Length == 0)
|
||||
return false;
|
||||
if (!s.StartsWith("TrainStorage"))//если нет такой записи, то это не те данные
|
||||
return false;
|
||||
_trainStorages.Clear();
|
||||
s = sr.ReadLine();
|
||||
while (s != null && s.Length != 0)
|
||||
{
|
||||
string[] record = s.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
s = sr.ReadLine();
|
||||
if (record.Length != 2)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TrainsGenericCollection<DrawingTrain, DrawningObjectTrain> collection = new(_pictureWidth, _pictureHeight);
|
||||
string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set.Reverse())
|
||||
{
|
||||
DrawingTrain train = elem?.CreateDrawingTrain(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (train != null)
|
||||
{
|
||||
if (collection + train == -1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
_trainStorages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user