From b676330c29858979828ef1d6260200f3d27f893c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=B8=D1=8F=20=D0=9A=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Sun, 21 Apr 2024 17:15:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=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=20=E2=84=966?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 2 +- .../ICollectionGenericObjects.cs | 12 +- .../ListGenericObjects.cs | 29 +++- .../MassiveGenericObjects.cs | 21 ++- .../StorageCollection.cs | 148 +++++++++++++++++- .../Drawings/DrawingExcavator.cs | 27 ++-- .../Drawings/DrawingExcavatorEmpty.cs | 17 +- .../ExtentionDrawningExcavatorEmpty.cs | 46 ++++++ .../Entity/EntityExcavator.cs | 26 +++ .../Entity/EntityExcavatorEmpty.cs | 26 ++- .../FormExcavatorCollection.Designer.cs | 81 ++++++++-- .../FormExcavatorCollection.cs | 54 ++++++- .../FormExcavatorCollection.resx | 12 ++ .../FormExcavatorConfig.Designer.cs | 2 +- 14 files changed, 460 insertions(+), 43 deletions(-) create mode 100644 WinFormsAppExcavator/WinFormsAppExcavator/Drawings/ExtentionDrawningExcavatorEmpty.cs diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs index 2d66485..582fdac 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/AbstractCompany.cs @@ -45,7 +45,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs index dc9e69e..ade57f2 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -15,7 +15,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -45,4 +45,14 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + /// + /// получение типа коллекции + /// + CollectionType GetCollectionType { get; } + /// + /// получение объектов коллекции по одному + /// + /// + IEnumerable GetItems(); + } diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs index 1f360bd..6692272 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/ListGenericObjects.cs @@ -1,4 +1,5 @@ -namespace WinFormsAppExcavator.CollectionGenericObjects; + +namespace WinFormsAppExcavator.CollectionGenericObjects; public class ListGenericObjects : ICollectionGenericObjects where T : class @@ -12,7 +13,23 @@ public class ListGenericObjects : ICollectionGenericObjects /// private int _maxCount; 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 CollectionType GetCollectionType => CollectionType.List; + /// /// Конструктор /// @@ -53,4 +70,12 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.RemoveAt(position); return obj; } + + public IEnumerable GetItems() + { + for (int i=0; i /// параметризованный набор объектов /// @@ -12,8 +13,12 @@ public class MassiveGenericObjects : ICollectionGenericObjects private T?[] _collection; public int Count => _collection.Length; - public int SetMaxCount - { + public int MaxCount + { get + { + return _collection.Length; + } + set { if (value > 0) @@ -30,6 +35,8 @@ public class MassiveGenericObjects : ICollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -110,4 +117,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]; + } + } } diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs index c78be6f..798a4c5 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/CollectionGenericObjects/StorageCollection.cs @@ -1,10 +1,13 @@ -namespace WinFormsAppExcavator.CollectionGenericObjects; +using System.Text; +using WinFormsAppExcavator.Drawings; + +namespace WinFormsAppExcavator.CollectionGenericObjects; /// /// класс-хранилище /// /// public class StorageCollection - where T : class + where T : DrawingExcavatorEmpty { /// /// Словарь (хранилище) с коллекциями @@ -61,7 +64,148 @@ public class StorageCollection // TODO Продумать логику получения объекта if (_storages.ContainsKey(name)) return _storages[name]; + return null; + } } + + + + + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при + ///сохранении данных + public bool SaveData(string filename) + { + if (_storages.Count == 0) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter writer = new StreamWriter(filename)) + { + writer.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) + { + StringBuilder sb = new(); + 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); + } + writer.Write(sb); + } + + } + return true; + } + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла/// true - загрузка прошла успешно, false - ошибка при загрузке + ///данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + using (StreamReader fs = File.OpenText(filename)) + { + string str = fs.ReadLine(); + if (str == null || str.Length == 0) + { + return false; + } + if (!str.StartsWith(_collectionKey)) + { + return false; + } + _storages.Clear(); + string strs = ""; + while ((strs = fs.ReadLine()) != null) + { + //по идее этого произойти не должно + //if (strs == null) + //{ + // return false; + //} + string[] record = strs.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?.CreateDrawningExcavatorEmpty() is T ship) + { + if (collection.Insert(ship) == -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/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavator.cs b/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavator.cs index 1b598b2..6240180 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavator.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavator.cs @@ -7,22 +7,29 @@ namespace WinFormsAppExcavator.Drawings; /// public class DrawingExcavator : DrawingExcavatorEmpty { + + /// - /// Конструктор - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы - public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool support, bool bulldozerDump) : base (100, 90) + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool support, bool bulldozerDump) : base (100, 90) { EntityExcavatorEmpty = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, support, bulldozerDump); } + public DrawingExcavator(EntityExcavator excavator) : base(100,90) + { + EntityExcavatorEmpty = new EntityExcavator(excavator.Speed, excavator.Weight, excavator.BodyColor, excavator.AdditionalColor, excavator.Bucket, excavator.Support, excavator.BulldozerDump); + } + public override void DrawTransport(Graphics g) { if (EntityExcavatorEmpty == null || EntityExcavatorEmpty is not EntityExcavator entityExcavator || !_startPosX.HasValue || !_startPosY.HasValue) diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavatorEmpty.cs b/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavatorEmpty.cs index c7c05eb..daef09c 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavatorEmpty.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/DrawingExcavatorEmpty.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using WinFormsAppExcavator.Entity; +using WinFormsAppExcavator.Entity; namespace WinFormsAppExcavator.Drawings; public class DrawingExcavatorEmpty { - /// /// Класс-сущность /// @@ -35,6 +29,8 @@ public class DrawingExcavatorEmpty /// protected int? _startPosY; + + /// /// Ширина прорисовки экскаватора /// @@ -99,6 +95,13 @@ public class DrawingExcavatorEmpty } + + public DrawingExcavatorEmpty(EntityExcavatorEmpty excavator) : this() + { + EntityExcavatorEmpty = new EntityExcavatorEmpty(excavator.Speed, excavator.Weight, excavator.BodyColor); + } + + /// /// Установка границ поля /// diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/ExtentionDrawningExcavatorEmpty.cs b/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/ExtentionDrawningExcavatorEmpty.cs new file mode 100644 index 0000000..e2c5adf --- /dev/null +++ b/WinFormsAppExcavator/WinFormsAppExcavator/Drawings/ExtentionDrawningExcavatorEmpty.cs @@ -0,0 +1,46 @@ +using WinFormsAppExcavator.Entity; +namespace WinFormsAppExcavator.Drawings; +/// +/// расширение для класса EntityExcavator +/// +public static class ExtentionDrawningExcavatorEmpty +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawingExcavatorEmpty? CreateDrawningExcavatorEmpty(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityExcavatorEmpty? excavator = EntityExcavator.CreateEntityExcavator(strs); + if (excavator != null) + { + return new DrawingExcavator((EntityExcavator)excavator); + } + excavator = EntityExcavatorEmpty.CreateEntityExcavatorEmpty(strs); + if (excavator != null) + { + return new DrawingExcavatorEmpty(excavator); + } + return null; + } + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawingExcavatorEmpty drawningExcavatorEmpty) + { + string[]? array = drawningExcavatorEmpty?.EntityExcavatorEmpty?.GetStringRepresentation(); + if (array == null) + { + return string.Empty; + } + return string.Join(_separatorForObject, array); + } +} diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavator.cs b/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavator.cs index 38c37ce..96169f2 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavator.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavator.cs @@ -52,6 +52,32 @@ public class EntityExcavator : EntityExcavatorEmpty BulldozerDump = bulldozerDump; } + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityExcavator), Speed.ToString(), Weight.ToString(), BodyColor.Name, + AdditionalColor.Name, Bucket.ToString(), Support.ToString(), BulldozerDump.ToString()}; + } + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityExcavator? CreateEntityExcavator(string[] strs) + { + if (strs.Length != 8 || strs[0] != nameof(EntityExcavator)) + { + return null; + } + return new EntityExcavator(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])); + } + } diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavatorEmpty.cs b/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavatorEmpty.cs index d7f2a7b..bd82827 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavatorEmpty.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/Entity/EntityExcavatorEmpty.cs @@ -48,4 +48,28 @@ public class EntityExcavatorEmpty Weight = weight; BodyColor = bodyColor; } -} \ No newline at end of file + + + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityExcavatorEmpty), Speed.ToString(),Weight.ToString(), BodyColor.Name }; + } + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityExcavatorEmpty? CreateEntityExcavatorEmpty(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityExcavatorEmpty)) + { + return null; + } + return new EntityExcavatorEmpty(Convert.ToInt32(strs[1]),Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } + +} \ No newline at end of file diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs index 4622a81..ed185db 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.Designer.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.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,9 +66,9 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(722, 0); + groupBoxTools.Location = new Point(722, 28); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(220, 555); + groupBoxTools.Size = new Size(220, 527); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -75,14 +82,14 @@ panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 324); + panelCompanyTools.Location = new Point(3, 327); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(214, 228); + panelCompanyTools.Size = new Size(214, 197); panelCompanyTools.TabIndex = 9; // // maskedTextBox // - maskedTextBox.Location = new Point(3, 96); + maskedTextBox.Location = new Point(0, 62); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(208, 27); @@ -92,7 +99,7 @@ // buttonAddExcavatorEmpty // buttonAddExcavatorEmpty.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddExcavatorEmpty.Location = new Point(5, 0); + buttonAddExcavatorEmpty.Location = new Point(3, 3); buttonAddExcavatorEmpty.Name = "buttonAddExcavatorEmpty"; buttonAddExcavatorEmpty.Size = new Size(209, 53); buttonAddExcavatorEmpty.TabIndex = 1; @@ -103,7 +110,7 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(5, 163); + buttonGoToCheck.Location = new Point(3, 131); buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Size = new Size(206, 29); buttonGoToCheck.TabIndex = 5; @@ -114,7 +121,7 @@ // buttonRemoveExcavator // buttonRemoveExcavator.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveExcavator.Location = new Point(5, 127); + buttonRemoveExcavator.Location = new Point(5, 95); buttonRemoveExcavator.Name = "buttonRemoveExcavator"; buttonRemoveExcavator.Size = new Size(206, 30); buttonRemoveExcavator.TabIndex = 4; @@ -125,7 +132,7 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(5, 198); + buttonRefresh.Location = new Point(3, 166); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(206, 27); buttonRefresh.TabIndex = 6; @@ -239,12 +246,53 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 28); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(722, 555); + pictureBox.Size = new Size(722, 527); pictureBox.TabIndex = 1; pictureBox.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(942, 28); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip"; + // + // файлToolStripMenuItem + // + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); + файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + файлToolStripMenuItem.Size = new Size(59, 24); + файлToolStripMenuItem.Text = "Файл"; + // + // saveToolStripMenuItem + // + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + saveToolStripMenuItem.Size = new Size(227, 26); + saveToolStripMenuItem.Text = "Сохранение"; + saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; + // + // loadToolStripMenuItem + // + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(227, 26); + loadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Click += loadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; + // // FormExcavatorCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -252,6 +300,8 @@ ClientSize = new Size(942, 555); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormExcavatorCollection"; Text = "Коллекция экскаваторов"; groupBoxTools.ResumeLayout(false); @@ -260,7 +310,10 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -283,5 +336,11 @@ private Button buttonCollectionDel; private ListBox listBoxCollection; 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/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs index c4f7caf..b42e105 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.cs @@ -1,4 +1,5 @@ -using WinFormsAppExcavator.CollectionGenericObjects; +using System.Windows.Forms; +using WinFormsAppExcavator.CollectionGenericObjects; using WinFormsAppExcavator.Drawings; namespace WinFormsAppExcavator; @@ -40,9 +41,9 @@ public partial class FormExcavatorCollection : Form /// private void ButtonAddExcavatorEmpty_Click(object sender, EventArgs e) { - FormExcavatorConfig form= new (); + FormExcavatorConfig form = new(); // TODO передать метод - + form.Show(); form.AddEvent(SetExcavator); @@ -172,7 +173,7 @@ public partial class FormExcavatorCollection : Form _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); RerfreshListBoxItems(); } - + /// /// обновление элементов /// @@ -237,5 +238,50 @@ public partial class FormExcavatorCollection : 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/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.resx b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.resx index af32865..0d57ea8 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.resx +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorCollection.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 145, 17 + + + 310, 17 + + + 61 + \ No newline at end of file diff --git a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorConfig.Designer.cs b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorConfig.Designer.cs index 1e2e62f..c016799 100644 --- a/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorConfig.Designer.cs +++ b/WinFormsAppExcavator/WinFormsAppExcavator/FormExcavatorConfig.Designer.cs @@ -170,7 +170,7 @@ // // panelGreen // - panelGreen.BackColor = Color.FromArgb(0, 192, 0); + panelGreen.BackColor = Color.Green; panelGreen.Location = new Point(74, 36); panelGreen.Name = "panelGreen"; panelGreen.Size = new Size(35, 33);