From 65cbde716fed579cd13ad322ec915d9d4ece00b6 Mon Sep 17 00:00:00 2001 From: SVETLANA_8 Date: Thu, 11 Apr 2024 20:17:24 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 6 +- .../ICollectionGenericObjects.cs | 14 +- .../ListGenericObjects.cs | 32 +++- .../MassiveGenericObjects.cs | 32 ++-- .../StorageCollection.cs | 161 +++++++++++++++++- .../Drawnings/DrawningByldozer.cs | 17 ++ .../Drawnings/DrawningTrackedCar.cs | 13 +- .../Drawnings/ExtensionDrawningTrackedCar.cs | 56 ++++++ .../Entities/EntityByldozer.cs | 24 +++ .../Entities/EntityTrackedCar.cs | 25 +++ .../FormCarCollection.Designer.cs | 82 +++++++-- .../ProjectByldozer/FormCarCollection.cs | 39 ++++- .../ProjectByldozer/FormCarCollection.resx | 12 ++ 13 files changed, 475 insertions(+), 38 deletions(-) create mode 100644 ProjectByldozer/ProjectByldozer/Drawnings/ExtensionDrawningTrackedCar.cs diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs index 5d711bf..eca0f45 100644 --- a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/AbstractCompany.cs @@ -51,7 +51,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// @@ -60,9 +60,9 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningTrackedCar TrackedCar) + public static bool operator +(AbstractCompany company, DrawningTrackedCar trackedCar) { - return company._collection.Insert(TrackedCar); + return company._collection?.Insert(trackedCar) ?? false; } /// diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs index 884e418..d4360a4 100644 --- a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -14,14 +14,14 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj); + bool Insert(T obj); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -44,4 +44,14 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); } diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ListGenericObjects.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ListGenericObjects.cs index 4c6afab..f22284a 100644 --- a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/ListGenericObjects.cs @@ -21,7 +21,18 @@ public class ListGenericObjects: ICollectionGenericObjects public int Count => _collection.Count; - public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + public int MaxCount + { + get => _maxCount; + set + { + if (value > 0) + { + _maxCount = value; + } + } + } + public CollectionType GetCollectionType => CollectionType.List; /// /// Конструктор @@ -38,13 +49,16 @@ public class ListGenericObjects: ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) + public bool Insert(T obj) { // TODO проверка, что не превышено максимальное количество элементов // TODO вставка в конец набора - if (Count == _maxCount) return -1; - _collection.Add(obj); - return Count; + if (Count != _maxCount) + { + _collection.Add(obj); + return true; + } + return false; } public int Insert(T obj, int position) @@ -70,5 +84,13 @@ public class ListGenericObjects: ICollectionGenericObjects } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } } diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs index 8a8fd2e..47b5b7d 100644 --- a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/MassiveGenericObjects.cs @@ -13,8 +13,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects public int Count => _collection.Length; - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -31,6 +35,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -47,21 +53,17 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) + public bool Insert(T obj) { - // TODO вставка в свободное место набора - int index = 0; - while (index < _collection.Length) + for (int i = 0; i < _collection.Length; i++) { - if (_collection[index] == null) + if (_collection[i] == null) { - _collection[index] = obj; - return index; + _collection[i] = obj; + return true; } - - index++; } - return -1; + return false; } public int Insert(T obj, int position) @@ -111,4 +113,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects _collection[position] = null; return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; ++i) + { + yield return _collection[i]; + } + } } \ No newline at end of file diff --git a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/StorageCollection.cs b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/StorageCollection.cs index 155878c..5c96cff 100644 --- a/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectByldozer/ProjectByldozer/CollectionGenericObjects/StorageCollection.cs @@ -1,12 +1,15 @@  +using ProjectByldozer.Drawnings; +using System.Text; + namespace ProjectByldozer.CollectionGenericObjects; // Класс-хранилище коллекций /// /// public class StorageCollection - where T : class + where T : DrawningTrackedCar { /// /// Словарь (хранилище) с коллекциями @@ -17,7 +20,20 @@ public class StorageCollection /// Возвращение списка названий коллекций /// public List Keys => _storages.Keys.ToList(); + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; /// /// Конструктор /// @@ -71,4 +87,147 @@ 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?.CreateDrawningTrackedCar() is T car) + { + if (!collection.Insert(car)) + { + 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/ProjectByldozer/ProjectByldozer/Drawnings/DrawningByldozer.cs b/ProjectByldozer/ProjectByldozer/Drawnings/DrawningByldozer.cs index 6aae20d..8b77ac6 100644 --- a/ProjectByldozer/ProjectByldozer/Drawnings/DrawningByldozer.cs +++ b/ProjectByldozer/ProjectByldozer/Drawnings/DrawningByldozer.cs @@ -22,6 +22,23 @@ public class DrawningByldozer : DrawningTrackedCar { EntityTrackedCar = new EntityByldozer(speed, weight, bodyColor, additionalColor, dump, bakingpowder, pipe); } + /// + /// Конструктор для + /// + /// + /// + /// + /// + /// + /// + /// + public DrawningByldozer(EntityTrackedCar entityTrackedCar) + { + if (entityTrackedCar != null) + { + EntityTrackedCar = entityTrackedCar; + } + } public override void DrawTransport(Graphics g) { diff --git a/ProjectByldozer/ProjectByldozer/Drawnings/DrawningTrackedCar.cs b/ProjectByldozer/ProjectByldozer/Drawnings/DrawningTrackedCar.cs index 92a92d2..703b8df 100644 --- a/ProjectByldozer/ProjectByldozer/Drawnings/DrawningTrackedCar.cs +++ b/ProjectByldozer/ProjectByldozer/Drawnings/DrawningTrackedCar.cs @@ -67,7 +67,7 @@ public class DrawningTrackedCar /// Высота объекта /// public int GetHeight => _drawningTrackedCarHeight; - private DrawningTrackedCar() + public DrawningTrackedCar() { _pictureWidth = null; _pictureHeight = null; @@ -95,7 +95,16 @@ public class DrawningTrackedCar this._drawningTrackedCarWidth = _drawningShipWidth; this._drawningTrackedCarHeight = _drawnShipHeight; } - + /// + /// Конструктор для Drawning + /// + /// + /// + /// + public DrawningTrackedCar(EntityTrackedCar entityTrackedCar) + { + EntityTrackedCar = entityTrackedCar; + } /// /// Установка границ поля /// diff --git a/ProjectByldozer/ProjectByldozer/Drawnings/ExtensionDrawningTrackedCar.cs b/ProjectByldozer/ProjectByldozer/Drawnings/ExtensionDrawningTrackedCar.cs new file mode 100644 index 0000000..fb8ccc3 --- /dev/null +++ b/ProjectByldozer/ProjectByldozer/Drawnings/ExtensionDrawningTrackedCar.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectByldozer.Entities; + +namespace ProjectByldozer.Drawnings; + +public static class ExtensionDrawningTrackedCar +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningTrackedCar? CreateDrawningTrackedCar(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityTrackedCar? Trackedcar = EntityByldozer.CreateEntityByldozer(strs); + if (Trackedcar != null) + { + return new DrawningByldozer(Trackedcar); + } + + Trackedcar = EntityTrackedCar.CreateEntityTrackedCar(strs); + if (Trackedcar != null) + { + return new DrawningTrackedCar(Trackedcar); + } + + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningTrackedCar drawningTrackedCar) + { + string[]? array = drawningTrackedCar?.EntityTrackedCar?.GetStringRepresentation(); + + if (array == null) + { + return string.Empty; + } + + return string.Join(_separatorForObject, array); + } +} diff --git a/ProjectByldozer/ProjectByldozer/Entities/EntityByldozer.cs b/ProjectByldozer/ProjectByldozer/Entities/EntityByldozer.cs index 9ad5ecd..b4cc0f4 100644 --- a/ProjectByldozer/ProjectByldozer/Entities/EntityByldozer.cs +++ b/ProjectByldozer/ProjectByldozer/Entities/EntityByldozer.cs @@ -52,4 +52,28 @@ public class EntityByldozer : EntityTrackedCar Bakingpowder = bakingpowder; Pipe = pipe; } + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityByldozer), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, + Dump.ToString(), Bakingpowder.ToString(), Pipe.ToString() }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityByldozer? CreateEntityByldozer(string[] strs) + { + if (strs.Length != 8 || strs[0] != nameof(EntityByldozer)) + { + return null; + } + return new EntityByldozer(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), + Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7])); + } } \ No newline at end of file diff --git a/ProjectByldozer/ProjectByldozer/Entities/EntityTrackedCar.cs b/ProjectByldozer/ProjectByldozer/Entities/EntityTrackedCar.cs index 381c0c4..576cad9 100644 --- a/ProjectByldozer/ProjectByldozer/Entities/EntityTrackedCar.cs +++ b/ProjectByldozer/ProjectByldozer/Entities/EntityTrackedCar.cs @@ -43,5 +43,30 @@ public class EntityTrackedCar BodyColor = bodyColor; } + //TODO Прописать метод + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityTrackedCar), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityTrackedCar? CreateEntityTrackedCar(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityTrackedCar)) + { + return null; + } + + return new EntityTrackedCar(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } } diff --git a/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs b/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs index 38a80e5..c2185c6 100644 --- a/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs +++ b/ProjectByldozer/ProjectByldozer/FormCarCollection.Designer.cs @@ -46,21 +46,29 @@ buttonAddTrackedCar = new Button(); pictureBox = new PictureBox(); panelCompanyTools = new Panel(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + openFileDialog = new OpenFileDialog(); + saveFileDialog = new SaveFileDialog(); groupBoxTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); panelCompanyTools.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // // groupBoxTools // + groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Controls.Add(comboBoxSelectionCompany); groupBoxTools.Controls.Add(buttonCreateCompany); groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(778, 0); + groupBoxTools.Location = new Point(778, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(209, 501); + groupBoxTools.Size = new Size(209, 472); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -172,7 +180,7 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(3, 181); + buttonRefresh.Location = new Point(2, 144); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(208, 25); buttonRefresh.TabIndex = 6; @@ -183,7 +191,7 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(3, 149); + buttonGoToCheck.Location = new Point(3, 112); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(205, 26); buttonGoToCheck.TabIndex = 5; @@ -194,7 +202,7 @@ // buttonDelCar // buttonDelCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelCar.Location = new Point(3, 120); + buttonDelCar.Location = new Point(3, 83); buttonDelCar.Name = "buttonDelCar"; buttonDelCar.Size = new Size(205, 23); buttonDelCar.TabIndex = 4; @@ -204,7 +212,7 @@ // // maskedTextBox // - maskedTextBox.Location = new Point(3, 91); + maskedTextBox.Location = new Point(6, 54); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(205, 23); @@ -225,9 +233,9 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(778, 501); + pictureBox.Size = new Size(778, 472); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -239,19 +247,60 @@ panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Controls.Add(buttonDelCar); panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(776, 293); + panelCompanyTools.Location = new Point(3, 293); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(208, 208); + panelCompanyTools.Size = new Size(208, 176); panelCompanyTools.TabIndex = 9; // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(987, 24); + menuStrip.TabIndex = 10; + menuStrip.Text = "menuStrip"; + // + // файл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; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; + // + // saveFileDialog + // + saveFileDialog.FileName = "txt file | *.txt"; + // // FormCarCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(987, 501); - Controls.Add(panelCompanyTools); + ClientSize = new Size(987, 496); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormCarCollection"; Text = "коллекция бульдозеров"; groupBoxTools.ResumeLayout(false); @@ -260,7 +309,10 @@ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); panelCompanyTools.ResumeLayout(false); panelCompanyTools.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -283,5 +335,11 @@ private Button buttonCreateCompany; private Button buttonCollectionDel; private Panel panelCompanyTools; + private MenuStrip menuStrip; + private ToolStripMenuItem файлToolStripMenuItem; + private ToolStripMenuItem saveToolStripMenuItem; + private ToolStripMenuItem loadToolStripMenuItem; + private OpenFileDialog openFileDialog; + private SaveFileDialog saveFileDialog; } } \ No newline at end of file diff --git a/ProjectByldozer/ProjectByldozer/FormCarCollection.cs b/ProjectByldozer/ProjectByldozer/FormCarCollection.cs index ec41aaf..c2c1cb4 100644 --- a/ProjectByldozer/ProjectByldozer/FormCarCollection.cs +++ b/ProjectByldozer/ProjectByldozer/FormCarCollection.cs @@ -41,6 +41,7 @@ public partial class FormCarCollection : Form /// private void ButtonAddTrackedCar_Click(object sender, EventArgs e) { + FormCarConfig form = new(); // TODO передать метод @@ -60,17 +61,19 @@ public partial class FormCarCollection : Form return; } - if (_company + Trackedcar != -1) + if (_company + Trackedcar) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); + } else { - MessageBox.Show("Не удалось добавить объект"); + MessageBox.Show("не удалось добавить объект"); } } + private void ButtonDelCar_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) @@ -222,5 +225,37 @@ public partial class FormCarCollection : Form RerfreshListBoxItems(); } + 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 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/ProjectByldozer/ProjectByldozer/FormCarCollection.resx b/ProjectByldozer/ProjectByldozer/FormCarCollection.resx index a395bff..f31a8b6 100644 --- a/ProjectByldozer/ProjectByldozer/FormCarCollection.resx +++ b/ProjectByldozer/ProjectByldozer/FormCarCollection.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 3 + + + 125, 3 + + + 265, 3 + + + 25 + \ No newline at end of file