Lab6
This commit is contained in:
parent
3bd218f664
commit
9b61350dbf
@ -5,7 +5,6 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ProjectTrolleybus.DrawingObjects;
|
using ProjectTrolleybus.DrawingObjects;
|
||||||
using ProjectTrolleybus.Generics;
|
|
||||||
|
|
||||||
namespace ProjectTrolleybus.Generics
|
namespace ProjectTrolleybus.Generics
|
||||||
{
|
{
|
||||||
@ -130,5 +129,6 @@ namespace ProjectTrolleybus.Generics
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public IEnumerable<T?> GetBuses => _collection.GetBuses();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,6 +27,19 @@ namespace ProjectTrolleybus.Generics
|
|||||||
/// Высота окна отрисовки
|
/// Высота окна отрисовки
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly int _pictureHeight;
|
private readonly int _pictureHeight;
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForKeyValue = '|';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly char _separatorRecords = ';';
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly char _separatorForObject = ':';
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -73,5 +86,89 @@ namespace ProjectTrolleybus.Generics
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по автомобилям в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
public bool SaveData(string filename)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
File.Delete(filename);
|
||||||
|
}
|
||||||
|
StringBuilder data = new();
|
||||||
|
foreach (KeyValuePair<string,
|
||||||
|
BusesGenericCollection<DrawingBus, DrawingObjectBus>> record in _busStorages)
|
||||||
|
{
|
||||||
|
StringBuilder records = new();
|
||||||
|
foreach (DrawingBus? elem in record.Value.GetBuses)
|
||||||
|
{
|
||||||
|
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||||
|
}
|
||||||
|
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||||
|
}
|
||||||
|
if (data.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
using (StreamWriter streamWriter = new(filename))
|
||||||
|
{
|
||||||
|
streamWriter.WriteLine($"BusStorages{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 streanReader = new(filename))
|
||||||
|
{
|
||||||
|
string str = streanReader.ReadLine();
|
||||||
|
var strings = str.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (strings == null || strings.Length == 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!strings[0].StartsWith("BusStorages"))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_busStorages.Clear();
|
||||||
|
do
|
||||||
|
{
|
||||||
|
string[] record = str.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (record.Length != 2)
|
||||||
|
{
|
||||||
|
str = streanReader.ReadLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
BusesGenericCollection<DrawingBus, DrawingObjectBus> collection = new(_pictureWidth, _pictureHeight);
|
||||||
|
string[] set = record[1].Split(_separatorRecords,
|
||||||
|
StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
foreach (string elem in set)
|
||||||
|
{
|
||||||
|
DrawingBus? bus = elem?.CreateDrawingBus(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||||
|
if (bus != null)
|
||||||
|
{
|
||||||
|
if (!(collection + bus))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_busStorages.Add(record[0], collection);
|
||||||
|
str = streanReader.ReadLine();
|
||||||
|
} while (str != null);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
Trolleybus/Trolleybus/ExtentionDrawingBus.cs
Normal file
49
Trolleybus/Trolleybus/ExtentionDrawingBus.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectTrolleybus.Entities;
|
||||||
|
|
||||||
|
namespace ProjectTrolleybus.DrawingObjects
|
||||||
|
{
|
||||||
|
public static class ExtentionDrawingBus
|
||||||
|
{
|
||||||
|
public static DrawingBus? CreateDrawingBus(this string info, char separatorForObject, int width, int height)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(separatorForObject);
|
||||||
|
if (strs.Length == 3)
|
||||||
|
{
|
||||||
|
return new DrawingBus(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]), Color.FromName(strs[2]), width, height);
|
||||||
|
}
|
||||||
|
if (strs.Length == 6)
|
||||||
|
{
|
||||||
|
return new DrawingTrolleybus(Convert.ToInt32(strs[0]),
|
||||||
|
Convert.ToInt32(strs[1]),
|
||||||
|
Color.FromName(strs[2]),
|
||||||
|
Color.FromName(strs[3]),
|
||||||
|
Convert.ToBoolean(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]),
|
||||||
|
width, height);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static string GetDataForSave(this DrawingBus drawingBus, char separatorForObject)
|
||||||
|
{
|
||||||
|
var bus = drawingBus.EntityBus;
|
||||||
|
if (bus == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
var str = $"{bus.Speed}{separatorForObject}{bus.Weight}{separatorForObject}{bus.BodyColor.Name}";
|
||||||
|
if (bus is not EntityTrolleybus trolleybus)
|
||||||
|
{
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return $"{str}{separatorForObject}{trolleybus.AdditionalColor.Name}{separatorForObject}{trolleybus.Roga}{separatorForObject}{trolleybus.Battery}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
123
Trolleybus/Trolleybus/FormBusCollection.Designer.cs
generated
123
Trolleybus/Trolleybus/FormBusCollection.Designer.cs
generated
@ -39,9 +39,16 @@
|
|||||||
maskedTextBoxNumber = new MaskedTextBox();
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
buttonAddBus = new Button();
|
buttonAddBus = new Button();
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
файлToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
SaveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
LoadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
groupBoxTrolleybus.SuspendLayout();
|
groupBoxTrolleybus.SuspendLayout();
|
||||||
groupBoxSets.SuspendLayout();
|
groupBoxSets.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTrolleybus
|
// groupBoxTrolleybus
|
||||||
@ -51,9 +58,11 @@
|
|||||||
groupBoxTrolleybus.Controls.Add(buttonDeleteBus);
|
groupBoxTrolleybus.Controls.Add(buttonDeleteBus);
|
||||||
groupBoxTrolleybus.Controls.Add(maskedTextBoxNumber);
|
groupBoxTrolleybus.Controls.Add(maskedTextBoxNumber);
|
||||||
groupBoxTrolleybus.Controls.Add(buttonAddBus);
|
groupBoxTrolleybus.Controls.Add(buttonAddBus);
|
||||||
groupBoxTrolleybus.Location = new Point(538, 2);
|
groupBoxTrolleybus.Location = new Point(615, 32);
|
||||||
|
groupBoxTrolleybus.Margin = new Padding(3, 4, 3, 4);
|
||||||
groupBoxTrolleybus.Name = "groupBoxTrolleybus";
|
groupBoxTrolleybus.Name = "groupBoxTrolleybus";
|
||||||
groupBoxTrolleybus.Size = new Size(262, 448);
|
groupBoxTrolleybus.Padding = new Padding(3, 4, 3, 4);
|
||||||
|
groupBoxTrolleybus.Size = new Size(299, 568);
|
||||||
groupBoxTrolleybus.TabIndex = 0;
|
groupBoxTrolleybus.TabIndex = 0;
|
||||||
groupBoxTrolleybus.TabStop = false;
|
groupBoxTrolleybus.TabStop = false;
|
||||||
groupBoxTrolleybus.Text = "Инструменты";
|
groupBoxTrolleybus.Text = "Инструменты";
|
||||||
@ -65,25 +74,29 @@
|
|||||||
groupBoxSets.Controls.Add(buttonDelObject);
|
groupBoxSets.Controls.Add(buttonDelObject);
|
||||||
groupBoxSets.Controls.Add(listBoxStorages);
|
groupBoxSets.Controls.Add(listBoxStorages);
|
||||||
groupBoxSets.Controls.Add(buttonAddObject);
|
groupBoxSets.Controls.Add(buttonAddObject);
|
||||||
groupBoxSets.Location = new Point(6, 22);
|
groupBoxSets.Location = new Point(11, 28);
|
||||||
|
groupBoxSets.Margin = new Padding(3, 4, 3, 4);
|
||||||
groupBoxSets.Name = "groupBoxSets";
|
groupBoxSets.Name = "groupBoxSets";
|
||||||
groupBoxSets.Size = new Size(245, 234);
|
groupBoxSets.Padding = new Padding(3, 4, 3, 4);
|
||||||
|
groupBoxSets.Size = new Size(280, 312);
|
||||||
groupBoxSets.TabIndex = 4;
|
groupBoxSets.TabIndex = 4;
|
||||||
groupBoxSets.TabStop = false;
|
groupBoxSets.TabStop = false;
|
||||||
groupBoxSets.Text = "Наборы";
|
groupBoxSets.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// textBoxStorageName
|
// textBoxStorageName
|
||||||
//
|
//
|
||||||
textBoxStorageName.Location = new Point(6, 22);
|
textBoxStorageName.Location = new Point(7, 29);
|
||||||
|
textBoxStorageName.Margin = new Padding(3, 4, 3, 4);
|
||||||
textBoxStorageName.Name = "textBoxStorageName";
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
textBoxStorageName.Size = new Size(233, 23);
|
textBoxStorageName.Size = new Size(266, 27);
|
||||||
textBoxStorageName.TabIndex = 4;
|
textBoxStorageName.TabIndex = 4;
|
||||||
//
|
//
|
||||||
// buttonDelObject
|
// buttonDelObject
|
||||||
//
|
//
|
||||||
buttonDelObject.Location = new Point(6, 194);
|
buttonDelObject.Location = new Point(7, 259);
|
||||||
|
buttonDelObject.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonDelObject.Name = "buttonDelObject";
|
buttonDelObject.Name = "buttonDelObject";
|
||||||
buttonDelObject.Size = new Size(233, 30);
|
buttonDelObject.Size = new Size(266, 40);
|
||||||
buttonDelObject.TabIndex = 3;
|
buttonDelObject.TabIndex = 3;
|
||||||
buttonDelObject.Text = "Удалить набор";
|
buttonDelObject.Text = "Удалить набор";
|
||||||
buttonDelObject.UseVisualStyleBackColor = true;
|
buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
@ -92,19 +105,21 @@
|
|||||||
// listBoxStorages
|
// listBoxStorages
|
||||||
//
|
//
|
||||||
listBoxStorages.FormattingEnabled = true;
|
listBoxStorages.FormattingEnabled = true;
|
||||||
listBoxStorages.ItemHeight = 15;
|
listBoxStorages.ItemHeight = 20;
|
||||||
listBoxStorages.Location = new Point(6, 94);
|
listBoxStorages.Location = new Point(7, 125);
|
||||||
|
listBoxStorages.Margin = new Padding(3, 4, 3, 4);
|
||||||
listBoxStorages.Name = "listBoxStorages";
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
listBoxStorages.Size = new Size(233, 94);
|
listBoxStorages.Size = new Size(266, 124);
|
||||||
listBoxStorages.TabIndex = 2;
|
listBoxStorages.TabIndex = 2;
|
||||||
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// buttonAddObject
|
// buttonAddObject
|
||||||
//
|
//
|
||||||
buttonAddObject.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
buttonAddObject.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonAddObject.Location = new Point(6, 62);
|
buttonAddObject.Location = new Point(7, 83);
|
||||||
|
buttonAddObject.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonAddObject.Name = "buttonAddObject";
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
buttonAddObject.Size = new Size(233, 26);
|
buttonAddObject.Size = new Size(266, 35);
|
||||||
buttonAddObject.TabIndex = 1;
|
buttonAddObject.TabIndex = 1;
|
||||||
buttonAddObject.Text = "Добавить набор";
|
buttonAddObject.Text = "Добавить набор";
|
||||||
buttonAddObject.UseVisualStyleBackColor = true;
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
@ -112,9 +127,10 @@
|
|||||||
//
|
//
|
||||||
// buttonUpdateCollection
|
// buttonUpdateCollection
|
||||||
//
|
//
|
||||||
buttonUpdateCollection.Location = new Point(10, 408);
|
buttonUpdateCollection.Location = new Point(11, 499);
|
||||||
|
buttonUpdateCollection.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonUpdateCollection.Name = "buttonUpdateCollection";
|
buttonUpdateCollection.Name = "buttonUpdateCollection";
|
||||||
buttonUpdateCollection.Size = new Size(241, 28);
|
buttonUpdateCollection.Size = new Size(275, 37);
|
||||||
buttonUpdateCollection.TabIndex = 3;
|
buttonUpdateCollection.TabIndex = 3;
|
||||||
buttonUpdateCollection.Text = "Обновить коллекцию";
|
buttonUpdateCollection.Text = "Обновить коллекцию";
|
||||||
buttonUpdateCollection.UseVisualStyleBackColor = true;
|
buttonUpdateCollection.UseVisualStyleBackColor = true;
|
||||||
@ -122,9 +138,10 @@
|
|||||||
//
|
//
|
||||||
// buttonDeleteBus
|
// buttonDeleteBus
|
||||||
//
|
//
|
||||||
buttonDeleteBus.Location = new Point(10, 343);
|
buttonDeleteBus.Location = new Point(11, 439);
|
||||||
|
buttonDeleteBus.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonDeleteBus.Name = "buttonDeleteBus";
|
buttonDeleteBus.Name = "buttonDeleteBus";
|
||||||
buttonDeleteBus.Size = new Size(241, 29);
|
buttonDeleteBus.Size = new Size(275, 39);
|
||||||
buttonDeleteBus.TabIndex = 2;
|
buttonDeleteBus.TabIndex = 2;
|
||||||
buttonDeleteBus.Text = "Удалить автобус";
|
buttonDeleteBus.Text = "Удалить автобус";
|
||||||
buttonDeleteBus.UseVisualStyleBackColor = true;
|
buttonDeleteBus.UseVisualStyleBackColor = true;
|
||||||
@ -132,17 +149,19 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(70, 305);
|
maskedTextBoxNumber.Location = new Point(74, 404);
|
||||||
|
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(115, 23);
|
maskedTextBoxNumber.Size = new Size(131, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 1;
|
maskedTextBoxNumber.TabIndex = 1;
|
||||||
//
|
//
|
||||||
// buttonAddBus
|
// buttonAddBus
|
||||||
//
|
//
|
||||||
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||||
buttonAddBus.Location = new Point(10, 262);
|
buttonAddBus.Location = new Point(11, 348);
|
||||||
|
buttonAddBus.Margin = new Padding(3, 4, 3, 4);
|
||||||
buttonAddBus.Name = "buttonAddBus";
|
buttonAddBus.Name = "buttonAddBus";
|
||||||
buttonAddBus.Size = new Size(241, 28);
|
buttonAddBus.Size = new Size(275, 37);
|
||||||
buttonAddBus.TabIndex = 0;
|
buttonAddBus.TabIndex = 0;
|
||||||
buttonAddBus.Text = "Добавить автобус";
|
buttonAddBus.Text = "Добавить автобус";
|
||||||
buttonAddBus.UseVisualStyleBackColor = true;
|
buttonAddBus.UseVisualStyleBackColor = true;
|
||||||
@ -151,19 +170,64 @@
|
|||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
pictureBoxCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||||
pictureBoxCollection.Location = new Point(0, 2);
|
pictureBoxCollection.Location = new Point(0, 32);
|
||||||
|
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(537, 448);
|
pictureBoxCollection.Size = new Size(616, 568);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(920, 28);
|
||||||
|
menuStrip.TabIndex = 2;
|
||||||
|
menuStrip.Text = "menuStrip1";
|
||||||
|
//
|
||||||
|
// файлToolStripMenuItem
|
||||||
|
//
|
||||||
|
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||||
|
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||||
|
файлToolStripMenuItem.Size = new Size(59, 24);
|
||||||
|
файлToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// SaveToolStripMenuItem
|
||||||
|
//
|
||||||
|
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||||
|
SaveToolStripMenuItem.Size = new Size(166, 26);
|
||||||
|
SaveToolStripMenuItem.Text = "Сохранить";
|
||||||
|
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// LoadToolStripMenuItem
|
||||||
|
//
|
||||||
|
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||||
|
LoadToolStripMenuItem.Size = new Size(166, 26);
|
||||||
|
LoadToolStripMenuItem.Text = "Загрузить";
|
||||||
|
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.FileName = "openFileDialog1";
|
||||||
|
openFileDialog.Filter = "«txt file | *.txt";
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.FileName = "busStorages";
|
||||||
|
saveFileDialog.Filter = "«txt file | *.txt";
|
||||||
|
//
|
||||||
// FormBusCollection
|
// FormBusCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(805, 450);
|
ClientSize = new Size(920, 600);
|
||||||
Controls.Add(groupBoxTrolleybus);
|
Controls.Add(groupBoxTrolleybus);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
Name = "FormBusCollection";
|
Name = "FormBusCollection";
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Text = "Набор автобусов";
|
Text = "Набор автобусов";
|
||||||
@ -172,7 +236,10 @@
|
|||||||
groupBoxSets.ResumeLayout(false);
|
groupBoxSets.ResumeLayout(false);
|
||||||
groupBoxSets.PerformLayout();
|
groupBoxSets.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -188,5 +255,11 @@
|
|||||||
private ListBox listBoxStorages;
|
private ListBox listBoxStorages;
|
||||||
private Button buttonAddObject;
|
private Button buttonAddObject;
|
||||||
private TextBox textBoxStorageName;
|
private TextBox textBoxStorageName;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -81,7 +81,8 @@ namespace ProjectTrolleybus
|
|||||||
}
|
}
|
||||||
FormBusConfig form = new FormBusConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
FormBusConfig form = new FormBusConfig(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
form.Show();
|
form.Show();
|
||||||
Action<DrawingBus>? busDelegate = new((bus) => {
|
Action<DrawingBus>? busDelegate = new((bus) =>
|
||||||
|
{
|
||||||
if (obj + bus)
|
if (obj + bus)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
@ -134,6 +135,41 @@ namespace ProjectTrolleybus
|
|||||||
}
|
}
|
||||||
pictureBoxCollection.Image = obj.ShowBuses();
|
pictureBoxCollection.Image = obj.ShowBuses();
|
||||||
}
|
}
|
||||||
|
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("Загрузка прошла успешно",
|
||||||
|
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
foreach (var collection in _storage.Keys)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(collection);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не загрузилось", "Результат",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,4 +117,13 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>153, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>315, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
Loading…
x
Reference in New Issue
Block a user