diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs index bbba0f7..ca1c40a 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/AbstractCompany.cs @@ -44,7 +44,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs index 9a30125..ee3833f 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -17,7 +17,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { set; get; } /// /// Добавление объекта в коллекцию @@ -47,4 +47,15 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); } diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs index a97b5a8..6f79745 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/ListGenericObjects.cs @@ -19,12 +19,27 @@ public class ListGenericObjects : ICollectionGenericObjects 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; + } + } + } - /// - /// Конструктор - /// - public ListGenericObjects() + public CollectionType GetCollectionType => CollectionType.List; + + /// + /// Конструктор + /// + public ListGenericObjects() { _collection = new(); } @@ -65,5 +80,13 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.RemoveAt(position); return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < Count; ++i) + { + yield return _collection[i]; + } + } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs index 495535c..8a9c762 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/MassiveGenericObjects.cs @@ -11,8 +11,12 @@ internal class MassiveGenericObjects : ICollectionGenericObjects 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 : ICollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -105,6 +111,14 @@ internal class MassiveGenericObjects : ICollectionGenericObjects _collection[position] = null; return removeObj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs index ea0ea17..9c2b4bf 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,6 @@ - +using ProjectDumpTrack.Drawnings; +using System.Text; + namespace ProjectDumpTruck.CollectionGenericObjects; /// @@ -6,7 +8,7 @@ namespace ProjectDumpTruck.CollectionGenericObjects; /// /// public class StorageCollection - where T : class + where T : DrawningTrack { /// /// Словарь (хранилище) с коллекциями @@ -18,6 +20,22 @@ public class StorageCollection /// public List Keys => _storages.Keys.ToList(); + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + + /// /// Конструктор /// @@ -69,5 +87,146 @@ public class StorageCollection return null; } } - + + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + 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> 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; + } + + /// + /// Загрузка информации по грузовикам в хранилище из файла + /// + /// Путь и имя файла + /// 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); + } + } + + 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? collection = StorageCollection.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; + } + + /// + /// Создание коллекции по типу + /// + /// + /// + private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) + { + return collectionType switch + { + CollectionType.Massive => new MassiveGenericObjects(), + CollectionType.List => new ListGenericObjects(), + _ => null, + }; + } + } diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs index e653c70..6c467c4 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningDumpTrack.cs @@ -6,9 +6,6 @@ namespace ProjectDumpTrack.Drawnings; /// public class DrawningDumpTrack : DrawningTrack { - - - //} /// /// Конструктор @@ -17,13 +14,19 @@ public class DrawningDumpTrack : DrawningTrack /// Вес /// Основной цвет /// Дополнительный цвет + /// Дополнительный цвет /// Признак наличия кузова /// Признак наличия тента - 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) diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs index 827c74d..3e80d2b 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/DrawningTrack.cs @@ -102,7 +102,10 @@ public class DrawningTrack } - + public DrawningTrack(EntityTrack track) : this() + { + EntityTrack = new EntityTrack(track.Speed, track.Weight, track.BodyColor); + } /// /// Установка границ поля diff --git a/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTrack.cs new file mode 100644 index 0000000..8fa7fce --- /dev/null +++ b/ProjectDumpTruck/ProjectDumpTruck/Drawnings/ExtentionDrawningTrack.cs @@ -0,0 +1,56 @@ + +using ProjectDumpTrack.Entities; + +namespace ProjectDumpTrack.Drawnings; +/// +/// Расширение для класса EntityCar +/// + +public static class ExtentionDrawningTrack +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + 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; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningTrack drawningTrack) + { + string[]? array = drawningTrack?.EntityTrack?.GetStringRepresentation(); + + if (array == null) + { + return string.Empty; + } + + return string.Join(_separatorForObject, array); + } +} + diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs index 67b9019..ba856ad 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityDumpTrack.cs @@ -42,7 +42,7 @@ public class EntityDumpTrack : EntityTrack /// Вес /// Основной цвет /// Дополнительный цвет - /// /// Дополнительный цвет + /// Дополнительный цвет /// Признак наличия кузова /// Признак наличия тента @@ -54,7 +54,29 @@ public class EntityDumpTrack : EntityTrack Awning = awning; } - + /// + /// Получение строк со значениями свойств продвинутого объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityDumpTrack), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, + AdditionalAwningColor.Name, Bodywork.ToString(), Awning.ToString()}; + } + /// + /// Создание продвинутого объекта из массива строк + /// + /// + /// + 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])); + } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTrack.cs b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTrack.cs index cc7cd46..f239953 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTrack.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/Entities/EntityTrack.cs @@ -43,7 +43,30 @@ public class EntityTrack Speed = speed; Weight = weight; BodyColor = bodyColor; + } + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityTrack), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + 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])); } } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs index bbd951e..edf11c2 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs index 4cf09e9..7a44ddc 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.cs @@ -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) + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + 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); + } + } } + } diff --git a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx index f298a7b..8b1dfa1 100644 --- a/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx +++ b/ProjectDumpTruck/ProjectDumpTruck/FormTrackCollection.resx @@ -1,4 +1,64 @@ - + + + @@ -57,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 126, 17 + + + 261, 17 + \ No newline at end of file diff --git a/Файл с данными.txt b/Файл с данными.txt new file mode 100644 index 0000000..5f8f2e5 --- /dev/null +++ b/Файл с данными.txt @@ -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; \ No newline at end of file