diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs index 7d13659..7e13652 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs @@ -48,7 +48,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs index b26b08d..2b24287 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -11,7 +11,7 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию @@ -41,4 +41,15 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// Поэлементый вывод элементов коллекции + IEnumerable GetItems(); } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs index 84bec82..7f14d87 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs @@ -7,7 +7,19 @@ 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 => _maxCount; + set + { + if (value > 0) + { + _maxCount = value; + } + } + } + + public CollectionType GetCollectionType => CollectionType.List; /// /// Конструктор @@ -55,4 +67,12 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.RemoveAt(position); return obj; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; ++i) + { + yield return _collection[i]; + } + } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs index 7c28554..917fcf0 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs @@ -8,10 +8,14 @@ where T : class /// private T?[] _collection; - public int Count => _collection.Length; + public int Count => _collection.Length; - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -28,6 +32,8 @@ where T : class } } + public CollectionType GetCollectionType => CollectionType.Massive; + /// /// Конструктор /// @@ -91,18 +97,22 @@ where T : class return -1; } - public T? Remove(int position) + public T Remove(int position) { - // проверка позиции if (position < 0 || position >= Count) { return null; } - - if (_collection[position] == null) return null; - - T? temp = _collection[position]; + T obj = _collection[position]; _collection[position] = null; - return temp; + 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/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs index 5590311..093a363 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs @@ -1,7 +1,9 @@ - +using ProjectGasolineTanker.Drawnings; +using System.Text; + namespace ProjectGasolineTanker.CollectionGenericObjects; public class StorageCollection - where T : class + where T : DrawningTanker { /// /// Словарь (хранилище) с коллекциями @@ -13,6 +15,21 @@ public class StorageCollection /// public List Keys => _storages.Keys.ToList(); + /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// @@ -74,4 +91,118 @@ 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(); + + using (StreamWriter sw = new StreamWriter(filename)) + { + sw.WriteLine(_collectionKey.ToString()); + foreach (KeyValuePair> kvpair in _storages) + { + // не сохраняем пустые коллекции + if (kvpair.Value.Count == 0) + continue; + sb.Append(kvpair.Key); + sb.Append(_separatorForKeyValue); + sb.Append(kvpair.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(kvpair.Value.MaxCount); + sb.Append(_separatorForKeyValue); + foreach (T? item in kvpair.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + continue; + sb.Append(data); + sb.Append(_separatorItems); + } + sw.WriteLine(sb.ToString()); + sb.Clear(); + } + } + return true; + } + + /// + /// Загрузка информации по автомобилям в хранилище из файла + /// + /// Путь и имя файла + /// true - загрузка прошла успешно, false - ошибка при загрузке данных + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + + using (StreamReader sr = new StreamReader(filename)) + { + string? str; + str = sr.ReadLine(); + if (str != _collectionKey.ToString()) + return false; + _storages.Clear(); + while ((str = sr.ReadLine()) != null) + { + string[] record = str.Split(_separatorForKeyValue); + 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?.CreateDrawningTanker() is T tanker) + { + if (collection.Insert(tanker) == -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, + }; + } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningGasolineTanker.cs index f45c91f..098e103 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningGasolineTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningGasolineTanker.cs @@ -17,6 +17,14 @@ public class DrawningGasolineTanker : DrawningTanker { EntityTanker = new EntityGasolineTanker(speed, weight, bodyColor, additionalColor, tank, signalbeacon); } + /// + /// Конструктор через сущность + /// + /// Объект класса-сущность + public DrawningGasolineTanker(EntityTanker entityTanker) : base() + { + EntityTanker = entityTanker; + } public override void DrawTransport(Graphics g) { diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTanker.cs index 71f3562..12da339 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/DrawningTanker.cs @@ -1,5 +1,5 @@ using ProjectGasolineTanker.Entities; -using System; +using ProjectGasolineTanker.Drawnings; using System.Collections.Generic; using System.Linq; using System.Text; @@ -67,7 +67,7 @@ public class DrawningTanker /// /// Пустой конструктор /// - private DrawningTanker() + protected DrawningTanker() { _pictureWidth = null; _pictureHeight = null; @@ -90,17 +90,27 @@ public class DrawningTanker /// /// Ширина прорисовки танка /// Высота прорисовки танка - protected DrawningTanker(int drawningCarWidth, int drawningCarHeight) : this() + public DrawningTanker(int drawningCarWidth, int drawningCarHeight) : this() { _drawningCarWidth = drawningCarWidth; _drawningCarHeight = drawningCarHeight; } /// + /// Конструктор через сущность + /// + /// Объект класса-сущность + public DrawningTanker(EntityTanker entityTanker) : base() + { + EntityTanker = entityTanker; + } + /// /// Установка границ поля /// /// Ширина поля /// Высота поля /// true - границы заданы, false - проверка не пройдена , нельзя разместить объект в этих размерах + + public bool SetPictureSize(int width, int height) { diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/ExtentionDrawningTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/ExtentionDrawningTanker.cs new file mode 100644 index 0000000..aaedc34 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawnings/ExtentionDrawningTanker.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectGasolineTanker.Entities; + +namespace ProjectGasolineTanker.Drawnings; +public static class ExtentionDrawningTanker +{ + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningTanker? CreateDrawningTanker(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityTanker? tanker = EntityGasolineTanker.CreateEntityGasolineTanker(strs); + if (tanker != null) + { + return new DrawningGasolineTanker(tanker); + } + + tanker = EntityTanker.CreateEntityCar(strs); + if (tanker != null) + { + return new DrawningTanker(tanker); + } + + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningTanker drawningTanker) + { + string[]? array = drawningTanker?.EntityTanker?.GetStringRepresentation(); + + if (array == null) + { + return string.Empty; + } + + return string.Join(_separatorForObject, array); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs index 44667d8..70e564d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityGasolineTanker.cs @@ -14,11 +14,11 @@ public class EntityGasolineTanker : EntityTanker /// /// Наличие безнобака /// - public bool Tank { get; private set; } + public bool Signalbeacon { get; private set; } /// /// Наличие радара /// - public bool Signalbeacon { get; private set; } + public bool Tank { get; private set; } /// /// Инициализация полей объекта-класса зенитной установки @@ -30,10 +30,33 @@ public class EntityGasolineTanker : EntityTanker /// Признак /// Признак - public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool tank, bool signalbeacon) : base(speed, weight, bodyColor) + public EntityGasolineTanker(int speed, double weight, Color bodyColor, Color additionalColor, bool signalbeacon, bool tank) : base(speed, weight, bodyColor) { Signalbeacon = signalbeacon; Tank = tank; AdditionalColor = additionalColor; } + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityGasolineTanker), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Signalbeacon.ToString(), Tank.ToString() }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityGasolineTanker? CreateEntityGasolineTanker(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityGasolineTanker)) + { + return null; + } + return new EntityGasolineTanker(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), + Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6])); + } } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs index cd43dea..32fe060 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Entities/EntityTanker.cs @@ -35,4 +35,27 @@ public class EntityTanker Weight = weight; BodyColor = bodyColor; } + /// + /// Получение строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityTanker), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityTanker? CreateEntityCar(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityTanker)) + { + return null; + } + + return new EntityTanker(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs index 6f8a810..59412ef 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs @@ -30,7 +30,13 @@ namespace ProjectGasolineTanker /// private void InitializeComponent() { - groupBoxTools = new GroupBox(); + Инструменты = new GroupBox(); + panelCompanyTools = new Panel(); + buttonAddTanker = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonGoToCheck = new Button(); + buttonRemoveTanker = new Button(); + buttonRefresh = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -40,40 +46,107 @@ namespace ProjectGasolineTanker radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToCheck = new Button(); - buttonRemoveTanker = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddTanker = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); - groupBoxTools.SuspendLayout(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + saveFileDialog = new SaveFileDialog(); + openFileDialog = new OpenFileDialog(); + Инструменты.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // - // groupBoxTools + // Инструменты // - groupBoxTools.Controls.Add(panelCompanyTools); - groupBoxTools.Controls.Add(buttonCreateCompany); - groupBoxTools.Controls.Add(panelStorage); - groupBoxTools.Controls.Add(comboBoxSelectorCompany); - groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(783, 0); - groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(179, 616); - groupBoxTools.TabIndex = 0; - groupBoxTools.TabStop = false; - groupBoxTools.Text = "Инструменты"; + Инструменты.Controls.Add(panelCompanyTools); + Инструменты.Controls.Add(buttonCreateCompany); + Инструменты.Controls.Add(panelStorage); + Инструменты.Controls.Add(comboBoxSelectorCompany); + Инструменты.Dock = DockStyle.Right; + Инструменты.Location = new Point(861, 24); + Инструменты.Name = "Инструменты"; + Инструменты.Size = new Size(225, 627); + Инструменты.TabIndex = 0; + Инструменты.TabStop = false; + Инструменты.Text = "Инструменты"; + // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddTanker); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonGoToCheck); + panelCompanyTools.Controls.Add(buttonRemoveTanker); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Location = new Point(3, 380); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(219, 244); + panelCompanyTools.TabIndex = 8; + // + // buttonAddTanker + // + buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTanker.Location = new Point(3, 21); + buttonAddTanker.Name = "buttonAddTanker"; + buttonAddTanker.Size = new Size(213, 37); + buttonAddTanker.TabIndex = 1; + buttonAddTanker.Text = "Добавление грузовика"; + buttonAddTanker.UseVisualStyleBackColor = true; + buttonAddTanker.Click += ButtonAddTanker_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(3, 86); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(213, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(3, 161); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(213, 40); + buttonGoToCheck.TabIndex = 6; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveTanker + // + buttonRemoveTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTanker.Location = new Point(3, 115); + buttonRemoveTanker.Name = "buttonRemoveTanker"; + buttonRemoveTanker.Size = new Size(213, 40); + buttonRemoveTanker.TabIndex = 4; + buttonRemoveTanker.Text = "Удаление автомобиль"; + buttonRemoveTanker.UseVisualStyleBackColor = true; + buttonRemoveTanker.Click += ButtonRemoveTanker_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(3, 207); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(213, 40); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(6, 320); + buttonCreateCompany.Location = new Point(6, 350); buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(167, 23); - buttonCreateCompany.TabIndex = 8; + buttonCreateCompany.Size = new Size(213, 24); + buttonCreateCompany.TabIndex = 7; buttonCreateCompany.Text = "Создать компанию"; buttonCreateCompany.UseVisualStyleBackColor = true; buttonCreateCompany.Click += ButtonCreateCompany_Click; @@ -90,14 +163,14 @@ namespace ProjectGasolineTanker panelStorage.Dock = DockStyle.Top; panelStorage.Location = new Point(3, 19); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(173, 266); + panelStorage.Size = new Size(219, 296); panelStorage.TabIndex = 7; // // buttonCollectionDel // - buttonCollectionDel.Location = new Point(3, 227); + buttonCollectionDel.Location = new Point(3, 267); buttonCollectionDel.Name = "buttonCollectionDel"; - buttonCollectionDel.Size = new Size(167, 23); + buttonCollectionDel.Size = new Size(213, 24); buttonCollectionDel.TabIndex = 6; buttonCollectionDel.Text = "Удалить коллекцию"; buttonCollectionDel.UseVisualStyleBackColor = true; @@ -107,16 +180,16 @@ namespace ProjectGasolineTanker // listBoxCollection.FormattingEnabled = true; listBoxCollection.ItemHeight = 15; - listBoxCollection.Location = new Point(3, 112); + listBoxCollection.Location = new Point(3, 122); listBoxCollection.Name = "listBoxCollection"; - listBoxCollection.Size = new Size(167, 109); + listBoxCollection.Size = new Size(213, 139); listBoxCollection.TabIndex = 5; // // buttonCollectionAdd // - buttonCollectionAdd.Location = new Point(3, 83); + buttonCollectionAdd.Location = new Point(3, 85); buttonCollectionAdd.Name = "buttonCollectionAdd"; - buttonCollectionAdd.Size = new Size(167, 23); + buttonCollectionAdd.Size = new Size(213, 24); buttonCollectionAdd.TabIndex = 4; buttonCollectionAdd.Text = "Добавить коллекцию"; buttonCollectionAdd.UseVisualStyleBackColor = true; @@ -125,7 +198,7 @@ namespace ProjectGasolineTanker // radioButtonList // radioButtonList.AutoSize = true; - radioButtonList.Location = new Point(98, 58); + radioButtonList.Location = new Point(139, 60); radioButtonList.Name = "radioButtonList"; radioButtonList.Size = new Size(66, 19); radioButtonList.TabIndex = 3; @@ -136,7 +209,7 @@ namespace ProjectGasolineTanker // radioButtonMassive // radioButtonMassive.AutoSize = true; - radioButtonMassive.Location = new Point(16, 58); + radioButtonMassive.Location = new Point(19, 60); radioButtonMassive.Name = "radioButtonMassive"; radioButtonMassive.Size = new Size(67, 19); radioButtonMassive.TabIndex = 2; @@ -146,130 +219,108 @@ namespace ProjectGasolineTanker // // textBoxCollectionName // - textBoxCollectionName.Location = new Point(3, 29); + textBoxCollectionName.Location = new Point(3, 31); textBoxCollectionName.Name = "textBoxCollectionName"; - textBoxCollectionName.Size = new Size(167, 23); + textBoxCollectionName.Size = new Size(213, 23); textBoxCollectionName.TabIndex = 1; // // labelCollectionName // labelCollectionName.AutoSize = true; - labelCollectionName.Location = new Point(26, 11); + labelCollectionName.Location = new Point(47, 13); labelCollectionName.Name = "labelCollectionName"; labelCollectionName.Size = new Size(125, 15); labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(3, 210); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(167, 40); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheck - // - buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(3, 170); - buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(167, 40); - buttonGoToCheck.TabIndex = 5; - buttonGoToCheck.Text = "Передать на тесты"; - buttonGoToCheck.UseVisualStyleBackColor = true; - buttonGoToCheck.Click += ButtonGoToCheck_Click; - // - // buttonRemoveTanker - // - buttonRemoveTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveTanker.Location = new Point(3, 124); - buttonRemoveTanker.Name = "buttonRemoveTanker"; - buttonRemoveTanker.Size = new Size(167, 40); - buttonRemoveTanker.TabIndex = 4; - buttonRemoveTanker.Text = "Удалить автомобиль"; - buttonRemoveTanker.UseVisualStyleBackColor = true; - buttonRemoveTanker.Click += ButtonRemoveTanker_Click; - - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Location = new Point(3, 95); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(167, 23); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddTanker - // - buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddTanker.Location = new Point(3, 3); - buttonAddTanker.Name = "buttonAddTanker"; - buttonAddTanker.Size = new Size(167, 40); - buttonAddTanker.TabIndex = 1; - buttonAddTanker.Text = "Добавление грузовика"; - buttonAddTanker.UseVisualStyleBackColor = true; - buttonAddTanker.Click += ButtonAddTanker_Click; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(6, 291); + comboBoxSelectorCompany.Location = new Point(6, 321); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(167, 23); + comboBoxSelectorCompany.Size = new Size(213, 23); comboBoxSelectorCompany.TabIndex = 0; comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(783, 616); + pictureBox.Size = new Size(861, 627); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // - // panelCompanyTools + // menuStrip // - panelCompanyTools.Controls.Add(buttonAddTanker); - panelCompanyTools.Controls.Add(maskedTextBoxPosition); - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(buttonRemoveTanker); - panelCompanyTools.Controls.Add(buttonGoToCheck); - panelCompanyTools.Dock = DockStyle.Bottom; - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 360); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(173, 253); - panelCompanyTools.TabIndex = 9; + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1086, 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"; // // FormTankerCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(962, 616); + AutoScroll = true; + ClientSize = new Size(1086, 651); Controls.Add(pictureBox); - Controls.Add(groupBoxTools); + Controls.Add(Инструменты); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormTankerCollection"; - Text = "Коллекция автомобилей"; - groupBoxTools.ResumeLayout(false); + Text = "Коллекция Грузовиков"; + Инструменты.ResumeLayout(false); + panelCompanyTools.ResumeLayout(false); + panelCompanyTools.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTools.ResumeLayout(false); - panelCompanyTools.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion - private GroupBox groupBoxTools; + private GroupBox Инструменты; private ComboBox comboBoxSelectorCompany; private Button buttonAddTanker; private Button buttonRemoveTanker; @@ -287,5 +338,11 @@ namespace ProjectGasolineTanker private Button buttonCollectionDel; private Button buttonCreateCompany; 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/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs index c12a09f..ea5f685 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs @@ -35,12 +35,7 @@ public partial class FormTankerCollection : Form /// private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) { - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new CarPark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); - break; - } + panelCompanyTools.Enabled = false; } /// @@ -134,10 +129,8 @@ public partial class FormTankerCollection : Form return; } - FormGasolineTanker form = new() - { - SetTanker = car - }; + FormGasolineTanker form = new FormGasolineTanker(); + form.SetTanker = car; form.ShowDialog(); } @@ -207,6 +200,7 @@ public partial class FormTankerCollection : Form RefreshListBoxItems(); } + private void ButtonCreateCompany_Click(object sender, EventArgs e) { if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) @@ -232,4 +226,46 @@ public partial class FormTankerCollection : Form panelCompanyTools.Enabled = true; RefreshListBoxItems(); } + /// + /// Обработка нажатия "Сохранение" + /// + /// + /// + 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)) + { + RefreshListBoxItems(); + MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Загрузка не выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx index 1af7de1..7dc5378 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx @@ -1,17 +1,17 @@  - @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 126, 17 + + + 255, 17 + \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.cs index 2776e7c..1b0edea 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerConfig.cs @@ -79,7 +79,7 @@ public partial class FormTankerConfig : Form break; case "labelModifiedObject": _tanker = new DrawningGasolineTanker((int)numericUpDownSpeed.Value, (double)numericUpDownWeight.Value, Color.White, - Color.Black, checkBoxTanker.Checked, checkBoxSignalbeacon.Checked); + Color.Black, checkBoxSignalbeacon.Checked, checkBoxTanker.Checked); break; } labelBodyColor.BackColor = Color.Empty;