diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs index 3f787d3..98a10dc 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs @@ -39,7 +39,7 @@ namespace HoistingCrane.CollectionGenericObjects pictureWidth = picWidth; pictureHeight = picHeight; arr = array; - arr.SetMaxCount = GetMaxCount; + arr.MaxCount = GetMaxCount; } public static int operator +(AbstractCompany company, DrawningTrackedVehicle car) diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs index adc295a..04b8de7 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -8,10 +8,10 @@ namespace HoistingCrane.CollectionGenericObjects /// Кол-во объектов в коллекции /// int Count { get; } - /// - /// Максимальное количество элементов + /// /// + /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление элемента в коллекцию /// @@ -37,5 +37,14 @@ namespace HoistingCrane.CollectionGenericObjects /// /// T? Get(int position); + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + /// + /// Получение объектов коллекции по одному + /// + /// + IEnumerable GetItems(); } } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs index 48bb52d..acb044f 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -25,8 +25,12 @@ namespace HoistingCrane.CollectionGenericObjects get { return list.Count; } } - public int SetMaxCount + public int MaxCount { + get + { + return list.Count; + } set { if (value > 0) @@ -36,6 +40,8 @@ namespace HoistingCrane.CollectionGenericObjects } } + public CollectionType GetCollectionType => CollectionType.List; + public T? Get(int position) { // TODO проверка позиции @@ -80,5 +86,13 @@ namespace HoistingCrane.CollectionGenericObjects } return null; } + + public IEnumerable GetItems() + { + for(int i = 0; i < list.Count; i++) + { + yield return list[i]; + } + } } } diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs index 39d6839..afe3a36 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/MassivGenericObjects.cs @@ -1,4 +1,5 @@ using System; + namespace HoistingCrane.CollectionGenericObjects { public class MassivGenericObjects : ICollectionGenericObjects where T : class @@ -12,8 +13,12 @@ namespace HoistingCrane.CollectionGenericObjects { get { return arr.Length; } } - public int SetMaxCount + public int MaxCount { + get + { + return arr.Length; + } set { if (value > 0) @@ -29,6 +34,9 @@ namespace HoistingCrane.CollectionGenericObjects } } } + + public CollectionType GetCollectionType => CollectionType.Massive; + public T? Get(int position) { if (position >= 0 && position < arr.Length) @@ -38,6 +46,14 @@ namespace HoistingCrane.CollectionGenericObjects return null; } + public IEnumerable GetItems() + { + for(int i = 0; i < arr.Length; i++) + { + yield return arr[i]; + } + } + public int Insert(T obj) { return Insert(obj, 0); diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs index d1e5183..d696adb 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs @@ -1,7 +1,10 @@ -using System; +using HoistingCrane.Drawning; +using System; +using System.Text; + namespace HoistingCrane.CollectionGenericObjects { - public class StorageCollection where T : class + public class StorageCollection where T : DrawningTrackedVehicle { /// /// Словарь (хранилище) с коллекциями @@ -12,6 +15,18 @@ namespace HoistingCrane.CollectionGenericObjects /// public List Keys => dict.Keys.ToList(); /// + /// Ключевое слово, с которого должен начинаться файл + /// + private readonly string _collectionKey = "CollectionsStorage"; + /// + /// Разделитель для записи ключа и значения элемента словаря + /// + private readonly string _separatorForKeyValue = "|"; + /// + /// Разделитель для записей коллекции данных в файл + /// + private readonly string _separatorItems = ";"; + /// /// Конструктор /// public StorageCollection() @@ -59,5 +74,128 @@ namespace HoistingCrane.CollectionGenericObjects return dict[name]; } } + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных + public bool SaveData(string filename) + { + if (dict.Count == 0) + { + return false; + } + + if (File.Exists(filename)) + { + File.Delete(filename); + } + + using (StreamWriter writer = new StreamWriter(filename)) + { + writer.Write(_collectionKey); + foreach (KeyValuePair> value in dict) + { + 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; + } + dict.Clear(); + string strs = ""; + while ((strs = fs.ReadLine()) != null) + { + 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?.CreateDrawningTrackedVehicle() is T truck) + { + if (collection.Insert(truck) == -1) + { + return false; + } + } + } + dict.Add(record[0], collection); + } + return true; + } + } + /// + /// Создание коллекции по типу + /// + /// + /// + private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) + { + return collectionType switch + { + CollectionType.Massive => new MassivGenericObjects(), + CollectionType.List => new ListGenericObjects(), + _ => null, + }; + } } } diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs index 2023b34..b52830c 100644 --- a/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs @@ -1,5 +1,6 @@ using HoistingCrane.Entities; using System.Configuration; +using System.Reflection.PortableExecutable; namespace HoistingCrane.Drawning; @@ -39,6 +40,15 @@ public class DrawningHoistingCrane : DrawningTrackedVehicle EntityTrackedVehicle = new EntityHoistingCrane(speed, weight, bodyColor, additionalColor, counterweight, platform); } + /// + /// Конструктор для Extention + /// + /// + public DrawningHoistingCrane(EntityHoistingCrane entityHoistingCrane) : base(115, 63) + { + EntityTrackedVehicle = new EntityHoistingCrane(entityHoistingCrane.Speed, entityHoistingCrane.Weight, entityHoistingCrane.BodyColor, entityHoistingCrane.AdditionalColor, entityHoistingCrane.Counterweight, entityHoistingCrane.Platform); + } + /// /// Метод отрисовки объекта /// @@ -49,7 +59,6 @@ public class DrawningHoistingCrane : DrawningTrackedVehicle { return; } - base.DrawTransport(gr); Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor); Pen pen = new Pen(EntityHoistingCrane.AdditionalColor); diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs index 29846b3..be19768 100644 --- a/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs +++ b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs @@ -1,4 +1,5 @@ using HoistingCrane.Entities; +using System.Reflection.PortableExecutable; namespace HoistingCrane.Drawning { @@ -80,6 +81,15 @@ namespace HoistingCrane.Drawning _startPosY = null; } + /// + /// Конструктор для Extention + /// + /// + public DrawningTrackedVehicle(EntityTrackedVehicle entityTrackedVehicle) : this() + { + EntityTrackedVehicle = new EntityTrackedVehicle(entityTrackedVehicle.Speed, entityTrackedVehicle.Weight, entityTrackedVehicle.BodyColor); + } + /// /// Метод отрисовки игрового поля diff --git a/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs new file mode 100644 index 0000000..ada1b71 --- /dev/null +++ b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs @@ -0,0 +1,55 @@ +using HoistingCrane.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HoistingCrane.Drawning +{ + public static class ExtentionDrawningCrane + { + /// + /// Разделитель для записи информации по объекту в файл + /// + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строки + /// + /// Строка с данными для создания объекта + /// Объект + public static DrawningTrackedVehicle? CreateDrawningTrackedVehicle(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityTrackedVehicle? trackedVehicle = EntityHoistingCrane.CreateEntityHoistingCrane(strs); + if (trackedVehicle != null) + { + return new DrawningHoistingCrane((EntityHoistingCrane)trackedVehicle); + } + trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs); + if (trackedVehicle != null) + { + return new DrawningTrackedVehicle(trackedVehicle); + } + return null; + } + + /// + /// Получение данных для сохранения в файл + /// + /// Сохраняемый объект + /// Строка с данными по объекту + public static string GetDataForSave(this DrawningTrackedVehicle drawningTrackedVehicle) + { + string[]? array = drawningTrackedVehicle?.EntityTrackedVehicle?.GetStringRepresentation(); + + if (array == null) + { + return string.Empty; + + } + return string.Join(_separatorForObject, array); + } + } +} diff --git a/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs index 3c6c8f9..ea0f5de 100644 --- a/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs +++ b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs @@ -30,7 +30,7 @@ public class EntityHoistingCrane : EntityTrackedVehicle // . - public EntityHoistingCrane(int Speed, int Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor) + public EntityHoistingCrane(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor) { this.AdditionalColor = AdditionalColor; this.Counterweight = Counterweight; @@ -42,4 +42,27 @@ public class EntityHoistingCrane : EntityTrackedVehicle { AdditionalColor = newColor; } + + /// + /// - + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityHoistingCrane), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Counterweight.ToString(), Platform.ToString()}; + } + + /// + /// + /// + /// + /// + public static EntityHoistingCrane? CreateEntityHoistingCrane(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityHoistingCrane)) + { + return null; + } + return new EntityHoistingCrane(Convert.ToInt32(strs[1]), Convert.ToInt32(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6])); + } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs index caef6bc..409e6e4 100644 --- a/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs +++ b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs @@ -43,11 +43,34 @@ this.Weight = Weight; this.BodyColor = BodyColor; } - + public void SetBodyColor(Color newBodyColor) { BodyColor = newBodyColor; } + /// + /// Получуеин строк со значениями свойств объекта класса-сущности + /// + /// + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityTrackedVehicle), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта из массива строк + /// + /// + /// + public static EntityTrackedVehicle? CreateEntityTrackedVehicle(string[] strs) + { + if(strs.Length != 4 || strs[0] != nameof(EntityTrackedVehicle)) + { + return null; + } + return new EntityTrackedVehicle(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } + } } diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs index 0977933..4991414 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelCompanyTool = new Panel(); + buttonCreateHoistingCrane = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonRefresh = new Button(); + buttonGoToChek = new Button(); + buttonDeleteCar = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonDeleteCollection = new Button(); @@ -38,18 +44,19 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonGoToChek = new Button(); - buttonRefresh = new Button(); - buttonDeleteCar = new Button(); - maskedTextBox = new MaskedTextBox(); comboBoxSelectorCompany = new ComboBox(); - buttonCreateHoistingCrane = new Button(); pictureBox = new PictureBox(); - panelCompanyTool = new Panel(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + saveFileDialog = new SaveFileDialog(); + openFileDialog = new OpenFileDialog(); groupBoxTools.SuspendLayout(); + panelCompanyTool.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTool.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -59,13 +66,79 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(763, 0); + groupBoxTools.Location = new Point(763, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(210, 509); + groupBoxTools.Size = new Size(210, 485); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // panelCompanyTool + // + panelCompanyTool.Anchor = AnchorStyles.None; + panelCompanyTool.Controls.Add(buttonCreateHoistingCrane); + panelCompanyTool.Controls.Add(maskedTextBox); + panelCompanyTool.Controls.Add(buttonRefresh); + panelCompanyTool.Controls.Add(buttonGoToChek); + panelCompanyTool.Controls.Add(buttonDeleteCar); + panelCompanyTool.Location = new Point(6, 312); + panelCompanyTool.Name = "panelCompanyTool"; + panelCompanyTool.Size = new Size(204, 185); + panelCompanyTool.TabIndex = 8; + // + // buttonCreateHoistingCrane + // + buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonCreateHoistingCrane.Location = new Point(9, 13); + buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; + buttonCreateHoistingCrane.Size = new Size(192, 22); + buttonCreateHoistingCrane.TabIndex = 0; + buttonCreateHoistingCrane.Text = "Добавить транспорт"; + buttonCreateHoistingCrane.UseVisualStyleBackColor = true; + buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click; + // + // maskedTextBox + // + maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + maskedTextBox.Location = new Point(9, 41); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(192, 23); + maskedTextBox.TabIndex = 3; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(9, 129); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(192, 27); + buttonRefresh.TabIndex = 5; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToChek + // + buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToChek.Location = new Point(9, 99); + buttonGoToChek.Name = "buttonGoToChek"; + buttonGoToChek.Size = new Size(192, 24); + buttonGoToChek.TabIndex = 6; + buttonGoToChek.Text = "Передать на тесты"; + buttonGoToChek.UseVisualStyleBackColor = true; + buttonGoToChek.Click += buttonGoToChek_Click; + // + // buttonDeleteCar + // + buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDeleteCar.Location = new Point(9, 70); + buttonDeleteCar.Name = "buttonDeleteCar"; + buttonDeleteCar.Size = new Size(192, 23); + buttonDeleteCar.TabIndex = 4; + buttonDeleteCar.Text = "Удалить автомобиль"; + buttonDeleteCar.UseVisualStyleBackColor = true; + buttonDeleteCar.Click += buttonDeleteCar_Click; + // // buttonCreateCompany // buttonCreateCompany.Location = new Point(12, 295); @@ -158,48 +231,6 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // - // buttonGoToChek - // - buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(9, 99); - buttonGoToChek.Name = "buttonGoToChek"; - buttonGoToChek.Size = new Size(192, 24); - buttonGoToChek.TabIndex = 6; - buttonGoToChek.Text = "Передать на тесты"; - buttonGoToChek.UseVisualStyleBackColor = true; - buttonGoToChek.Click += buttonGoToChek_Click; - // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(9, 129); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(192, 27); - buttonRefresh.TabIndex = 5; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += buttonRefresh_Click; - // - // buttonDeleteCar - // - buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDeleteCar.Location = new Point(9, 70); - buttonDeleteCar.Name = "buttonDeleteCar"; - buttonDeleteCar.Size = new Size(192, 23); - buttonDeleteCar.TabIndex = 4; - buttonDeleteCar.Text = "Удалить автомобиль"; - buttonDeleteCar.UseVisualStyleBackColor = true; - buttonDeleteCar.Click += buttonDeleteCar_Click; - // - // maskedTextBox - // - maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBox.Location = new Point(9, 41); - maskedTextBox.Mask = "00"; - maskedTextBox.Name = "maskedTextBox"; - maskedTextBox.Size = new Size(192, 23); - maskedTextBox.TabIndex = 3; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -212,38 +243,54 @@ comboBoxSelectorCompany.TabIndex = 2; comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; // - // buttonCreateHoistingCrane - // - buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonCreateHoistingCrane.Location = new Point(9, 13); - buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; - buttonCreateHoistingCrane.Size = new Size(192, 22); - buttonCreateHoistingCrane.TabIndex = 0; - buttonCreateHoistingCrane.Text = "Добавить транспорт"; - buttonCreateHoistingCrane.UseVisualStyleBackColor = true; - buttonCreateHoistingCrane.Click += buttonCreateHoistingCrane_Click; - // // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(763, 509); + pictureBox.Size = new Size(763, 485); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // - // panelCompanyTool + // menuStrip // - panelCompanyTool.Anchor = AnchorStyles.None; - panelCompanyTool.Controls.Add(buttonCreateHoistingCrane); - panelCompanyTool.Controls.Add(maskedTextBox); - panelCompanyTool.Controls.Add(buttonRefresh); - panelCompanyTool.Controls.Add(buttonGoToChek); - panelCompanyTool.Controls.Add(buttonDeleteCar); - panelCompanyTool.Location = new Point(6, 324); - panelCompanyTool.Name = "panelCompanyTool"; - panelCompanyTool.Size = new Size(204, 185); - panelCompanyTool.TabIndex = 8; + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(973, 24); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip1"; + // + // файлToolStripMenuItem + // + файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); + файлToolStripMenuItem.Name = "файлToolStripMenuItem"; + файлToolStripMenuItem.Size = new Size(50, 20); + файлToolStripMenuItem.Text = "Файл"; + // + // saveToolStripMenuItem + // + saveToolStripMenuItem.Name = "saveToolStripMenuItem"; + saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; + saveToolStripMenuItem.Size = new Size(186, 22); + saveToolStripMenuItem.Text = "Сохранение"; + saveToolStripMenuItem.Click += saveToolStripMenuItem_Click; + // + // loadToolStripMenuItem + // + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(186, 22); + loadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Click += loadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; // // FormCarCollection // @@ -252,15 +299,20 @@ ClientSize = new Size(973, 509); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormCarCollection"; Text = "FormCarCollections"; groupBoxTools.ResumeLayout(false); + panelCompanyTool.ResumeLayout(false); + panelCompanyTool.PerformLayout(); panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); - panelCompanyTool.ResumeLayout(false); - panelCompanyTool.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion @@ -283,5 +335,11 @@ private ListBox listBoxCollection; private Button buttonCollectionAdd; private Panel panelCompanyTool; + 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/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index bd42830..978fbe7 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -204,6 +204,47 @@ namespace HoistingCrane panelCompanyTool.Enabled = true; 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/HoistingCrane/HoistingCrane/FormCarCollection.resx b/HoistingCrane/HoistingCrane/FormCarCollection.resx index af32865..0430c52 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.resx +++ b/HoistingCrane/HoistingCrane/FormCarCollection.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 5 + + + 130, 5 + + + 270, 5 + + + 25 + \ No newline at end of file