Лабораторная работа №6

This commit is contained in:
Esenia12 2024-04-14 17:00:02 +04:00
parent 08bcdc0bdf
commit 7a4911bf31
14 changed files with 537 additions and 84 deletions

View File

@ -44,7 +44,7 @@ public abstract class AbstractCompany
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
_collection.SetMaxCount = GetMaxCount;
_collection.MaxCount = GetMaxCount;
}
/// <summary>

View File

@ -17,7 +17,7 @@ public interface ICollectionGenericObjects<T>
/// <summary>
/// Установка максимального количества элементов
/// </summary>
int SetMaxCount { set; }
int MaxCount { set; get; }
/// <summary>
/// Добавление объекта в коллекцию
@ -47,4 +47,15 @@ public interface ICollectionGenericObjects<T>
/// <param name="position">Позиция</param>
/// <returns>Объект</returns>
T? Get(int position);
/// <summary>
/// Получение типа коллекции
/// </summary>
CollectionType GetCollectionType { get; }
/// <summary>
/// Получение объектов коллекции по одному
/// </summary>
/// <returns>Поэлементый вывод элементов коллекции</returns>
IEnumerable<T?> GetItems();
}

View File

@ -19,12 +19,27 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
public int Count => _collection.Count;
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
public int MaxCount
{
get
{
return Count;
}
set
{
if (value > 0)
{
_maxCount = value;
}
}
}
/// <summary>
/// Конструктор
/// </summary>
public ListGenericObjects()
public CollectionType GetCollectionType => CollectionType.List;
/// <summary>
/// Конструктор
/// </summary>
public ListGenericObjects()
{
_collection = new();
}
@ -65,5 +80,13 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
_collection.RemoveAt(position);
return obj;
}
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < Count; ++i)
{
yield return _collection[i];
}
}
}

View File

@ -11,8 +11,12 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
public int Count => _collection.Length;
public int SetMaxCount
public int MaxCount
{
get
{
return _collection.Length;
}
set
{
if (value > 0)
@ -29,6 +33,8 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
}
}
public CollectionType GetCollectionType => CollectionType.Massive;
/// <summary>
/// Конструктор
/// </summary>
@ -105,6 +111,14 @@ internal class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
_collection[position] = null;
return removeObj;
}
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < _collection.Length; ++i)
{
yield return _collection[i];
}
}
}

View File

@ -1,4 +1,6 @@

using ProjectDumpTrack.Drawnings;
using System.Text;
namespace ProjectDumpTruck.CollectionGenericObjects;
/// <summary>
@ -6,7 +8,7 @@ namespace ProjectDumpTruck.CollectionGenericObjects;
/// </summary>
/// <typeparam name="T"></typeparam>
public class StorageCollection<T>
where T : class
where T : DrawningTrack
{
/// <summary>
/// Словарь (хранилище) с коллекциями
@ -18,6 +20,22 @@ public class StorageCollection<T>
/// </summary>
public List<string> Keys => _storages.Keys.ToList();
/// <summary>
/// Ключевое слово, с которого должен начинаться файл
/// </summary>
private readonly string _collectionKey = "CollectionsStorage";
/// <summary>
/// Разделитель для записи ключа и значения элемента словаря
/// </summary>
private readonly string _separatorForKeyValue = "|";
/// <summary>
/// Разделитель для записей коллекции данных в файл
/// </summary>
private readonly string _separatorItems = ";";
/// <summary>
/// Конструктор
/// </summary>
@ -69,5 +87,146 @@ public class StorageCollection<T>
return null;
}
}
/// <summary>
/// Сохранение информации по автомобилям в хранилище в файл
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename)
{
if (_storages.Count == 0)
{
return false;
}
if (File.Exists(filename))
{
File.Delete(filename);
}
StringBuilder sb = new();
sb.Append(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
sb.Append(Environment.NewLine);
// не сохраняем пустые коллекции
if (value.Value.Count == 0)
{
continue;
}
sb.Append(value.Key);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems())
{
string data = item?.GetDataForSave() ?? string.Empty;
if (string.IsNullOrEmpty(data))
{
continue;
}
sb.Append(data);
sb.Append(_separatorItems);
}
}
using FileStream fs = new(filename, FileMode.Create);
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
fs.Write(info, 0, info.Length);
return true;
}
/// <summary>
/// Загрузка информации по грузовикам в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
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);
}
}
string[] strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);
if (strs == null || strs.Length == 0)
{
return false;
}
if (!strs[0].Equals(_collectionKey))
{
//если нет такой записи, то это не те данные
return false;
}
_storages.Clear();
foreach (string data in strs)
{
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4)
{
continue;
}
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
if (collection == null)
{
return false;
}
collection.MaxCount = Convert.ToInt32(record[2]);
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set)
{
if (elem?.CreateDrawningTrack() is T track)
{
if (collection.Insert(track)==-1)
{
return false;
}
}
}
_storages.Add(record[0], collection);
}
return true;
}
/// <summary>
/// Создание коллекции по типу
/// </summary>
/// <param name="collectionType"></param>
/// <returns></returns>
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
{
return collectionType switch
{
CollectionType.Massive => new MassiveGenericObjects<T>(),
CollectionType.List => new ListGenericObjects<T>(),
_ => null,
};
}
}

View File

@ -6,9 +6,6 @@ namespace ProjectDumpTrack.Drawnings;
/// </summary>
public class DrawningDumpTrack : DrawningTrack
{
//}
/// <summary>
/// Конструктор
@ -17,13 +14,19 @@ public class DrawningDumpTrack : DrawningTrack
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// <param name="additionalAwningColor">Дополнительный цвет</param>
/// <param name="bodywork">Признак наличия кузова</param>
/// <param name="awning">Признак наличия тента</param>
public DrawningDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additional2Color, bool bodywork, bool awning) : base(130, 100)
public DrawningDumpTrack(int speed, double weight, Color bodyColor, Color additionalColor, Color additionalAwningColor, bool bodywork, bool awning) : base(130, 100)
{
EntityTrack = new EntityDumpTrack(speed, weight, bodyColor, additionalColor, additional2Color, bodywork, awning);
EntityTrack = new EntityDumpTrack(speed, weight, bodyColor, additionalColor, additionalAwningColor, bodywork, awning);
}
public DrawningDumpTrack(EntityDumpTrack track) : base(130, 100)
{
EntityTrack = new EntityDumpTrack(track.Speed, track.Weight, track.BodyColor, track.AdditionalColor, track.AdditionalAwningColor, track.Bodywork, track.Awning);
}
public override void DrawTransport(Graphics g)

View File

@ -102,7 +102,10 @@ public class DrawningTrack
}
public DrawningTrack(EntityTrack track) : this()
{
EntityTrack = new EntityTrack(track.Speed, track.Weight, track.BodyColor);
}
/// <summary>
/// Установка границ поля

View File

@ -0,0 +1,56 @@

using ProjectDumpTrack.Entities;
namespace ProjectDumpTrack.Drawnings;
/// <summary>
/// Расширение для класса EntityCar
/// </summary>
public static class ExtentionDrawningTrack
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <returns>Объект</returns>
public static DrawningTrack? CreateDrawningTrack(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityTrack? track = EntityDumpTrack.CreateEntityDumpTrack(strs);
if (track != null)
{
return new DrawningDumpTrack((EntityDumpTrack)track);
}
track = EntityTrack.CreateEntityTrack(strs);
if (track != null)
{
return new DrawningTrack(track);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="drawningCar">Сохраняемый объект</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawningTrack drawningTrack)
{
string[]? array = drawningTrack?.EntityTrack?.GetStringRepresentation();
if (array == null)
{
return string.Empty;
}
return string.Join(_separatorForObject, array);
}
}

View File

@ -42,7 +42,7 @@ public class EntityDumpTrack : EntityTrack
/// <param name="weight">Вес</param>
/// <param name="bodyColor">Основной цвет</param>
/// <param name="additionalColor">Дополнительный цвет</param>
/// /// <param name="additional2Color">Дополнительный цвет</param>
/// <param name="additionalAwningColor">Дополнительный цвет</param>
/// <param name="bodywork">Признак наличия кузова</param>
/// <param name="awning">Признак наличия тента</param>
@ -54,7 +54,29 @@ public class EntityDumpTrack : EntityTrack
Awning = awning;
}
/// <summary>
/// Получение строк со значениями свойств продвинутого объекта класса-сущности
/// </summary>
/// <returns></returns>
public override string[] GetStringRepresentation()
{
return new[] { nameof(EntityDumpTrack), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name,
AdditionalAwningColor.Name, Bodywork.ToString(), Awning.ToString()};
}
/// <summary>
/// Создание продвинутого объекта из массива строк
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityDumpTrack? CreateEntityDumpTrack(string[] strs)
{
if (strs.Length != 8 || strs[0] != nameof(EntityDumpTrack))
{
return null;
}
return new EntityDumpTrack(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]),
Color.FromName(strs[4]), Color.FromName(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7]));
}
}

View File

@ -43,7 +43,30 @@ public class EntityTrack
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
}
/// <summary>
/// Получение строк со значениями свойств объекта класса-сущности
/// </summary>
/// <returns></returns>
public virtual string[] GetStringRepresentation()
{
return new[] { nameof(EntityTrack), Speed.ToString(), Weight.ToString(), BodyColor.Name };
}
/// <summary>
/// Создание объекта из массива строк
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityTrack? CreateEntityTrack(string[] strs)
{
if (strs.Length != 4 || strs[0] != nameof(EntityTrack))
{
return null;
}
return new EntityTrack(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
}
}

View File

@ -46,10 +46,17 @@
labelCollectionName = new Label();
comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox();
menuStrip = new MenuStrip();
файлToolStripMenuItem = new ToolStripMenuItem();
saveToolStripMenuItem = new ToolStripMenuItem();
loadToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog();
openFileDialog = new OpenFileDialog();
groupBoxTools.SuspendLayout();
panelCompanyTools.SuspendLayout();
panelStorage.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
menuStrip.SuspendLayout();
SuspendLayout();
//
// groupBoxTools
@ -59,11 +66,9 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(903, 0);
groupBoxTools.Margin = new Padding(3, 4, 3, 4);
groupBoxTools.Location = new Point(790, 24);
groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Padding = new Padding(3, 4, 3, 4);
groupBoxTools.Size = new Size(247, 784);
groupBoxTools.Size = new Size(216, 538);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
@ -75,18 +80,16 @@
panelCompanyTools.Controls.Add(maskedTextBox);
panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Controls.Add(buttonDelTrack);
panelCompanyTools.Location = new Point(3, 472);
panelCompanyTools.Margin = new Padding(3, 4, 3, 4);
panelCompanyTools.Location = new Point(3, 354);
panelCompanyTools.Name = "panelCompanyTools";
panelCompanyTools.Size = new Size(240, 308);
panelCompanyTools.Size = new Size(210, 231);
panelCompanyTools.TabIndex = 9;
//
// buttonAddTrack
//
buttonAddTrack.Location = new Point(10, 18);
buttonAddTrack.Margin = new Padding(3, 4, 3, 4);
buttonAddTrack.Location = new Point(9, 14);
buttonAddTrack.Name = "buttonAddTrack";
buttonAddTrack.Size = new Size(219, 40);
buttonAddTrack.Size = new Size(192, 30);
buttonAddTrack.TabIndex = 1;
buttonAddTrack.Text = "Добавление грузовика";
buttonAddTrack.UseVisualStyleBackColor = true;
@ -94,10 +97,9 @@
//
// buttonRefresh
//
buttonRefresh.Location = new Point(10, 263);
buttonRefresh.Margin = new Padding(3, 4, 3, 4);
buttonRefresh.Location = new Point(9, 197);
buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(219, 33);
buttonRefresh.Size = new Size(192, 25);
buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true;
@ -105,20 +107,18 @@
//
// maskedTextBox
//
maskedTextBox.Location = new Point(10, 117);
maskedTextBox.Margin = new Padding(3, 4, 3, 4);
maskedTextBox.Location = new Point(9, 88);
maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(219, 27);
maskedTextBox.Size = new Size(192, 23);
maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int);
//
// buttonGoToCheck
//
buttonGoToCheck.Location = new Point(10, 216);
buttonGoToCheck.Margin = new Padding(3, 4, 3, 4);
buttonGoToCheck.Location = new Point(9, 162);
buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(219, 39);
buttonGoToCheck.Size = new Size(192, 29);
buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true;
@ -126,10 +126,9 @@
//
// buttonDelTrack
//
buttonDelTrack.Location = new Point(10, 156);
buttonDelTrack.Margin = new Padding(3, 4, 3, 4);
buttonDelTrack.Location = new Point(9, 117);
buttonDelTrack.Name = "buttonDelTrack";
buttonDelTrack.Size = new Size(219, 39);
buttonDelTrack.Size = new Size(192, 29);
buttonDelTrack.TabIndex = 4;
buttonDelTrack.Text = "Удалить грузовик";
buttonDelTrack.UseVisualStyleBackColor = true;
@ -137,10 +136,9 @@
//
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(14, 433);
buttonCreateCompany.Margin = new Padding(3, 4, 3, 4);
buttonCreateCompany.Location = new Point(12, 325);
buttonCreateCompany.Name = "buttonCreateCompany";
buttonCreateCompany.Size = new Size(219, 31);
buttonCreateCompany.Size = new Size(192, 23);
buttonCreateCompany.TabIndex = 8;
buttonCreateCompany.Text = "Создать компанию";
buttonCreateCompany.UseVisualStyleBackColor = true;
@ -156,18 +154,16 @@
panelStorage.Controls.Add(textBoxCollectionName);
panelStorage.Controls.Add(labelCollectionName);
panelStorage.Dock = DockStyle.Top;
panelStorage.Location = new Point(3, 24);
panelStorage.Margin = new Padding(3, 4, 3, 4);
panelStorage.Location = new Point(3, 19);
panelStorage.Name = "panelStorage";
panelStorage.Size = new Size(241, 361);
panelStorage.Size = new Size(210, 271);
panelStorage.TabIndex = 7;
//
// buttonCollectionDel
//
buttonCollectionDel.Location = new Point(10, 311);
buttonCollectionDel.Margin = new Padding(3, 4, 3, 4);
buttonCollectionDel.Location = new Point(9, 233);
buttonCollectionDel.Name = "buttonCollectionDel";
buttonCollectionDel.Size = new Size(219, 31);
buttonCollectionDel.Size = new Size(192, 23);
buttonCollectionDel.TabIndex = 6;
buttonCollectionDel.Text = "Удалить коллекцию";
buttonCollectionDel.UseVisualStyleBackColor = true;
@ -176,19 +172,17 @@
// listBoxCollection
//
listBoxCollection.FormattingEnabled = true;
listBoxCollection.ItemHeight = 20;
listBoxCollection.Location = new Point(10, 149);
listBoxCollection.Margin = new Padding(3, 4, 3, 4);
listBoxCollection.ItemHeight = 15;
listBoxCollection.Location = new Point(9, 112);
listBoxCollection.Name = "listBoxCollection";
listBoxCollection.Size = new Size(219, 144);
listBoxCollection.Size = new Size(192, 109);
listBoxCollection.TabIndex = 5;
//
// buttonCollectionAdd
//
buttonCollectionAdd.Location = new Point(10, 111);
buttonCollectionAdd.Margin = new Padding(3, 4, 3, 4);
buttonCollectionAdd.Location = new Point(9, 83);
buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonCollectionAdd.Size = new Size(219, 31);
buttonCollectionAdd.Size = new Size(192, 23);
buttonCollectionAdd.TabIndex = 4;
buttonCollectionAdd.Text = "Добавить коллекцию";
buttonCollectionAdd.UseVisualStyleBackColor = true;
@ -197,10 +191,9 @@
// radioButtonList
//
radioButtonList.AutoSize = true;
radioButtonList.Location = new Point(144, 76);
radioButtonList.Margin = new Padding(3, 4, 3, 4);
radioButtonList.Location = new Point(126, 57);
radioButtonList.Name = "radioButtonList";
radioButtonList.Size = new Size(80, 24);
radioButtonList.Size = new Size(66, 19);
radioButtonList.TabIndex = 3;
radioButtonList.TabStop = true;
radioButtonList.Text = "Список";
@ -209,10 +202,9 @@
// radioButtonMassive
//
radioButtonMassive.AutoSize = true;
radioButtonMassive.Location = new Point(33, 76);
radioButtonMassive.Margin = new Padding(3, 4, 3, 4);
radioButtonMassive.Location = new Point(29, 57);
radioButtonMassive.Name = "radioButtonMassive";
radioButtonMassive.Size = new Size(82, 24);
radioButtonMassive.Size = new Size(67, 19);
radioButtonMassive.TabIndex = 2;
radioButtonMassive.TabStop = true;
radioButtonMassive.Text = "Массив";
@ -220,18 +212,17 @@
//
// textBoxCollectionName
//
textBoxCollectionName.Location = new Point(10, 37);
textBoxCollectionName.Margin = new Padding(3, 4, 3, 4);
textBoxCollectionName.Location = new Point(9, 28);
textBoxCollectionName.Name = "textBoxCollectionName";
textBoxCollectionName.Size = new Size(219, 27);
textBoxCollectionName.Size = new Size(192, 23);
textBoxCollectionName.TabIndex = 1;
//
// labelCollectionName
//
labelCollectionName.AutoSize = true;
labelCollectionName.Location = new Point(54, 13);
labelCollectionName.Location = new Point(47, 10);
labelCollectionName.Name = "labelCollectionName";
labelCollectionName.Size = new Size(162, 20);
labelCollectionName.Size = new Size(128, 15);
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции :";
//
@ -240,10 +231,9 @@
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectorCompany.Location = new Point(14, 395);
comboBoxSelectorCompany.Margin = new Padding(3, 4, 3, 4);
comboBoxSelectorCompany.Location = new Point(12, 296);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(219, 28);
comboBoxSelectorCompany.Size = new Size(192, 23);
comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
//
@ -251,32 +241,73 @@
//
pictureBox.Dock = DockStyle.Fill;
pictureBox.Enabled = false;
pictureBox.Location = new Point(0, 0);
pictureBox.Margin = new Padding(3, 4, 3, 4);
pictureBox.Location = new Point(0, 24);
pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(903, 784);
pictureBox.Size = new Size(790, 538);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
pictureBox.Click += pictureBox_Click;
//
// menuStrip
//
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip";
menuStrip.Size = new Size(1006, 24);
menuStrip.TabIndex = 2;
menuStrip.Text = "menuStrip1";
//
// файлToolStripMenuItem
//
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
файлToolStripMenuItem.Name = айлToolStripMenuItem";
файлToolStripMenuItem.Size = new Size(48, 20);
файлToolStripMenuItem.Text = "Файл";
//
// saveToolStripMenuItem
//
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
saveToolStripMenuItem.Size = new Size(181, 22);
saveToolStripMenuItem.Text = "Сохранение";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// loadToolStripMenuItem
//
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
loadToolStripMenuItem.Size = new Size(181, 22);
loadToolStripMenuItem.Text = "Загрузка";
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
// saveFileDialog
//
saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
openFileDialog.Filter = "txt file | *.txt";
//
// FormTrackCollection
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1150, 784);
ClientSize = new Size(1006, 562);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Margin = new Padding(3, 4, 3, 4);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormTrackCollection";
Text = "Коллекция самосвалов";
Load += FormTrackCollection_Load;
groupBoxTools.ResumeLayout(false);
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
@ -299,5 +330,11 @@
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
private Panel panelCompanyTools;
private MenuStrip menuStrip;
private ToolStripMenuItem файлToolStripMenuItem;
private ToolStripMenuItem saveToolStripMenuItem;
private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog;
}
}

View File

@ -1,6 +1,7 @@

using ProjectDumpTruck.CollectionGenericObjects;
using ProjectDumpTrack.Drawnings;
using System.Windows.Forms;
namespace ProjectDumpTruck;
@ -285,15 +286,44 @@ public partial class FormTrackCollection : Form
RerfreshListBoxItems();
}
private void pictureBox_Click(object sender, EventArgs e)
/// <summary>
/// Обработка нажатия "Сохранение"
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.SaveData(saveFileDialog.FileName))
{
MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void FormTrackCollection_Load(object sender, EventArgs e)
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
{
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (_storageCollection.LoadData(openFileDialog.FileName))
{
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems();
}
else
{
MessageBox.Show("Не сохранилось", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

View File

@ -1,4 +1,64 @@
<root>
<?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
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<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
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
mimetype set.
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
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
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
: 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
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
@ -57,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="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>126, 17</value>
</metadata>
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>261, 17</value>
</metadata>
</root>

View File

@ -0,0 +1,3 @@
CollectionsStorage
v|Massive|32|EntityTrack:100:100:Aqua;EntityDumpTrack:5:45:White:Black:Red:True:True;EntityTrack:100:100:Aqua;EntityTrack:100:100:Aqua;
c|List|1|EntityTrack:100:100:Gray;