From 9deaccb1e1a5365630109a3b7badd58e2552cadd Mon Sep 17 00:00:00 2001 From: Victoria_Isaeva Date: Wed, 17 Apr 2024 12:19:09 +0400 Subject: [PATCH] 6 --- .../AbstractCompany.cs | 2 +- .../AerodromService.cs | 2 +- .../ICollectionGenericObjects.cs | 6 +- .../ListGenericObjects.cs | 11 + .../MassiveGenericObjects.cs | 21 +- .../StorageCollection.cs | 161 +++++- .../ProjectAirbus/Drawnings/DrawningAirbus.cs | 8 +- .../ProjectAirbus/Drawnings/DrawningBus.cs | 9 +- .../Drawnings/ExtentionDrawningBus.cs | 45 ++ .../ProjectAirbus/Entities/EntityAirbus.cs | 27 +- .../ProjectAirbus/Entities/EntityBus.cs | 17 +- .../FormBusCollection.Designer.cs | 153 ++++-- .../ProjectAirbus/FormBusCollection.cs | 477 ++++++++++-------- .../ProjectAirbus/FormBusCollection.resx | 12 + .../ProjectAirbus/FormBusConfig.Designer.cs | 1 + 15 files changed, 628 insertions(+), 324 deletions(-) create mode 100644 ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawningBus.cs diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs index 0c58f0a..390debd 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectAirbus/ProjectAirbus/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/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs index 4e8a603..6f6b55d 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs @@ -59,7 +59,7 @@ public class AerodromService : AbstractCompany if (_collection.Get(i) != null) { _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); - _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 15); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 35); } if (curWidth > 0) diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs index 4dffeec..9df6a33 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -11,10 +11,14 @@ public interface ICollectionGenericObjects where T : class { int Count { get; } - int SetMaxCount { set; } + int MaxCount{get;set;} int Insert(T obj); int Insert(T obj, int position); T Remove(int position); T? Get(int position); + + CollectionType GetCollectionType { get; } + + IEnumerable GetItems(); } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs index bae84d7..dbbb11b 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ListGenericObjects.cs @@ -22,6 +22,10 @@ public class ListGenericObjects : ICollectionGenericObjects public int Count => _collection.Count; public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + + public CollectionType GetCollectionType => CollectionType.List; + + public int MaxCount { get; set; } /// /// Конструктор @@ -67,4 +71,11 @@ public class ListGenericObjects : ICollectionGenericObjects _collection.RemoveAt(position); return pos; } + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; i++) + { + yield return _collection[i]; + } + } } diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs index 1e6503f..1826aaf 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace ProjectAirbus.CollectionGenericObjects; @@ -18,8 +14,12 @@ internal class MassiveGenericObjects : ICollectionGenericObjects public int Count => _collection.Length; - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } set { if (value > 0) @@ -34,8 +34,10 @@ internal class MassiveGenericObjects : ICollectionGenericObjects } } } + } + public CollectionType GetCollectionType => CollectionType.Massive; /// /// Конструктор /// @@ -118,6 +120,13 @@ internal 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/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs index 70f8695..9bed029 100644 --- a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/StorageCollection.cs @@ -1,40 +1,34 @@  using ProjectAirbus.CollectionGenericObjects; +using ProjectAirbus.Drawnings; +using System.Text; namespace ProjectAirBus.CollectionGenericObjects; -/// -/// Класс-хранилище коллекций -/// -/// + public class StorageCollection - where T : class + where T : DrawningBus { - /// - /// Словарь (хранилище) с коллекциями - /// + readonly Dictionary> _storages; - /// - /// Возвращение списка названий коллекций - /// + public List Keys => _storages.Keys.ToList(); - /// - /// Конструктор - /// + private readonly string _collectionKey = "CollectionStorage"; + + private readonly string _separatorForKeyValue = "|"; + + private readonly string _separatorItem = ";"; + public StorageCollection() { _storages = new Dictionary>(); } - /// - /// Добавление коллекции в хранилище - /// - /// Название коллекции - /// тип коллекции + public void AddCollection(string name, CollectionType collectionType) { // TODO проверка, что name не пустой и нет в словаре записи с таким ключом @@ -54,10 +48,7 @@ public class StorageCollection } } - /// - /// Удаление коллекции - /// - /// Название коллекции + public void DelCollection(string name) { // TODO Прописать логику для удаления коллекции @@ -65,11 +56,7 @@ public class StorageCollection _storages.Remove(name); } - /// - /// Доступ к коллекции - /// - /// Название коллекции - /// + public ICollectionGenericObjects? this[string name] { get @@ -79,4 +66,122 @@ public class StorageCollection return _storages[name]; } } + 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(_separatorItem); + } + } + + using FileStream fs = new(filename, FileMode.Create); + byte[] info = new UTF8Encoding().GetBytes(sb.ToString()); + fs.Write(info, 0, info.Length); + return true; + } + + 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 UTF8Encoding(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.Length == 0 || strs == null) + { + 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(_separatorItem, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawningBus() is T bus) + { + if (collection.Insert(bus) == -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/ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs index 57cf812..80e7910 100644 --- a/ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs +++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningAirbus.cs @@ -4,11 +4,17 @@ namespace ProjectAirbus.Drawnings; public class DrawningAirbus : DrawningBus { + private EntityAirbus bus; + + public DrawningAirbus(EntityBus bus) : base(bus) + { + } + public DrawningAirbus(int speed, double weight, Color bodyColor, Color additionalColor, bool compartment, bool engine) : base(140, 60) { EntityBus = new EntityAirbus(speed, weight, bodyColor, additionalColor, compartment, engine); - } + public override void DrawTransport(Graphics g) { if (EntityBus == null || EntityBus is not EntityAirbus airbus || !_startPosX.HasValue || !_startPosY.HasValue) diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBus.cs b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBus.cs index dd790db..16a936f 100644 --- a/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBus.cs +++ b/ProjectAirbus/ProjectAirbus/Drawnings/DrawningBus.cs @@ -39,12 +39,11 @@ public class DrawningBus _startPosY = null; } - public DrawningBus(int speed, double weight, Color bodyColor) : this() { EntityBus = new EntityBus(speed, weight, bodyColor); - } + //конструктор для наследников protected DrawningBus(int drawningBusWidth, int drawningBusHeigh) : this() { @@ -52,6 +51,12 @@ public class DrawningBus drawningBusHeigh = drawningBusHeigh; //высота } + + public DrawningBus(EntityBus bus) + { + EntityBus = bus; + } + public bool SetPictureSize(int width, int height) { if (_drawningBusWidth < width && _drawningBusHeight < height) diff --git a/ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawningBus.cs b/ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawningBus.cs new file mode 100644 index 0000000..229987e --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/Drawnings/ExtentionDrawningBus.cs @@ -0,0 +1,45 @@ +using ProjectAirbus.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAirbus.Drawnings; + +public static class ExtentionDrawningBus +{ + private static readonly string _separatorForObject = ":"; + + + public static DrawningBus? CreateDrawningBus(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityBus? bus = EntityAirbus.CreateEntityAirbus(strs); + if (bus != null) + { + return new DrawningAirbus(bus); + } + + bus = EntityBus.CreateEntityBus(strs); + if (bus != null) + { + return new DrawningBus(bus); + } + + return null; + } + + + public static string GetDataForSave(this DrawningBus drawningBus) + { + string[]? array = drawningBus?.EntityBus?.GetStringRepresentation(); + + if (array == null) + { + return string.Empty; + } + + return string.Join(_separatorForObject, array); + } +} diff --git a/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs index 5948644..d033370 100644 --- a/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs +++ b/ProjectAirbus/ProjectAirbus/Entities/EntityAirbus.cs @@ -1,16 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectAirbus.Entities; +namespace ProjectAirbus.Entities; public class EntityAirbus : EntityBus { public Color AdditionalColor { get; private set; } - public void SetAdditionalColor(Color color) { AdditionalColor = color; } + public void SetAdditionalColor(Color color) + { + AdditionalColor = color; + } public bool Compartment { get; private set; } @@ -23,5 +20,19 @@ public class EntityAirbus : EntityBus Engine = engine; } + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityAirbus), Speed.ToString(), Weight.ToString(), BodyColor.Name,AdditionalColor.Name, Compartment.ToString(), Engine.ToString() }; + } + public static EntityAirbus? CreateEntityAirbus(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityAirbus)) + { + return null; + } + + return new EntityAirbus(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/ProjectAirbus/ProjectAirbus/Entities/EntityBus.cs b/ProjectAirbus/ProjectAirbus/Entities/EntityBus.cs index 5e1a0d3..c2e4b64 100644 --- a/ProjectAirbus/ProjectAirbus/Entities/EntityBus.cs +++ b/ProjectAirbus/ProjectAirbus/Entities/EntityBus.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; namespace ProjectAirbus.Entities; + public class EntityBus { public int Speed { get; set; } @@ -15,11 +16,25 @@ public class EntityBus public void SetBodyColor(Color color) { BodyColor = color; } public double Step => Speed * 100 / Weight; + public EntityBus(int speed, double weight, Color bodyColor) { Speed = speed; Weight = weight; BodyColor = bodyColor; } -} + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityBus), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + public static EntityBus? CreateEntityBus(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityBus)) + return null; + + return new EntityBus(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } + +} \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs index 2741b1a..cd51ea8 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs @@ -29,16 +29,15 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); - buttonCreateCompany = new Button(); - comboBoxSelectorCompany = new ComboBox(); panelCompanyTools = new Panel(); buttonRefresh = new Button(); + comboBoxSelectorCompany = new ComboBox(); buttonGoToChek = new Button(); buttonAddBus = new Button(); buttonDelBus = new Button(); - buttonAddAirBus = new Button(); maskedTextBox = new MaskedTextBox(); panelStorage = new Panel(); + buttonCreateCompany = new Button(); buttonCollectionDel = new Button(); listBoxCollection = new ListBox(); buttonCollectionAdd = new Button(); @@ -47,67 +46,50 @@ textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); pictureBox1 = 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)pictureBox1).BeginInit(); + menuStrip.SuspendLayout(); SuspendLayout(); // // groupBoxTools // - groupBoxTools.Controls.Add(buttonCreateCompany); - groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(panelCompanyTools); groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(825, 0); + groupBoxTools.Location = new Point(825, 28); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(303, 644); + groupBoxTools.Size = new Size(303, 581); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // - // buttonCreateCompany - // - buttonCreateCompany.Location = new Point(15, 316); - buttonCreateCompany.Name = "buttonCreateCompany"; - buttonCreateCompany.Size = new Size(270, 29); - buttonCreateCompany.TabIndex = 7; - buttonCreateCompany.Text = "Создать компанию "; - buttonCreateCompany.UseVisualStyleBackColor = true; - buttonCreateCompany.Click += buttonCreateCompany_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(18, 350); - comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; - comboBoxSelectorCompany.Size = new Size(267, 28); - comboBoxSelectorCompany.TabIndex = 0; - comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; - // // panelCompanyTools // panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(comboBoxSelectorCompany); panelCompanyTools.Controls.Add(buttonGoToChek); panelCompanyTools.Controls.Add(buttonAddBus); panelCompanyTools.Controls.Add(buttonDelBus); - panelCompanyTools.Controls.Add(buttonAddAirBus); panelCompanyTools.Controls.Add(maskedTextBox); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 384); + panelCompanyTools.Location = new Point(3, 343); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(297, 257); + panelCompanyTools.Size = new Size(297, 235); panelCompanyTools.TabIndex = 2; // // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(12, 216); + buttonRefresh.Location = new Point(10, 191); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(275, 35); buttonRefresh.TabIndex = 6; @@ -115,10 +97,22 @@ buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.Click += buttonRefresh_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(11, 3); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(267, 28); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + // // buttonGoToChek // buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(14, 173); + buttonGoToChek.Location = new Point(12, 150); buttonGoToChek.Name = "buttonGoToChek"; buttonGoToChek.Size = new Size(273, 37); buttonGoToChek.TabIndex = 5; @@ -129,7 +123,7 @@ // buttonAddBus // buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddBus.Location = new Point(11, 17); + buttonAddBus.Location = new Point(11, 37); buttonAddBus.Name = "buttonAddBus"; buttonAddBus.Size = new Size(270, 33); buttonAddBus.TabIndex = 1; @@ -140,27 +134,16 @@ // buttonDelBus // buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelBus.Location = new Point(15, 132); + buttonDelBus.Location = new Point(11, 109); buttonDelBus.Name = "buttonDelBus"; buttonDelBus.Size = new Size(272, 35); buttonDelBus.TabIndex = 4; buttonDelBus.Text = "Удалить самолет"; buttonDelBus.UseVisualStyleBackColor = true; - // - // buttonAddAirBus - // - buttonAddAirBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddAirBus.Location = new Point(12, 56); - buttonAddAirBus.Name = "buttonAddAirBus"; - buttonAddAirBus.Size = new Size(270, 37); - buttonAddAirBus.TabIndex = 2; - buttonAddAirBus.Text = "Добавление аэробуса"; - buttonAddAirBus.UseVisualStyleBackColor = true; - // // maskedTextBox // - maskedTextBox.Location = new Point(11, 99); + maskedTextBox.Location = new Point(11, 76); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(276, 27); @@ -169,6 +152,7 @@ // // panelStorage // + panelStorage.Controls.Add(buttonCreateCompany); panelStorage.Controls.Add(buttonCollectionDel); panelStorage.Controls.Add(listBoxCollection); panelStorage.Controls.Add(buttonCollectionAdd); @@ -179,9 +163,19 @@ panelStorage.Dock = DockStyle.Top; panelStorage.Location = new Point(3, 23); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(297, 287); + panelStorage.Size = new Size(297, 317); panelStorage.TabIndex = 2; // + // buttonCreateCompany + // + buttonCreateCompany.Location = new Point(12, 288); + buttonCreateCompany.Name = "buttonCreateCompany"; + buttonCreateCompany.Size = new Size(270, 29); + buttonCreateCompany.TabIndex = 7; + buttonCreateCompany.Text = "Создать компанию "; + buttonCreateCompany.UseVisualStyleBackColor = true; + buttonCreateCompany.Click += buttonCreateCompany_Click; + // // buttonCollectionDel // buttonCollectionDel.Location = new Point(12, 251); @@ -251,19 +245,63 @@ // pictureBox1 // pictureBox1.Dock = DockStyle.Fill; - pictureBox1.Location = new Point(0, 0); + pictureBox1.Location = new Point(0, 28); pictureBox1.Name = "pictureBox1"; - pictureBox1.Size = new Size(825, 644); + pictureBox1.Size = new Size(825, 581); pictureBox1.TabIndex = 1; pictureBox1.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(1128, 28); + menuStrip.TabIndex = 2; + menuStrip.Text = "menuStrip1"; + // + // файл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(231, 26); + saveToolStripMenuItem.Text = "Сохранение "; + saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; + // + // loadToolStripMenuItem + // + loadToolStripMenuItem.Name = "loadToolStripMenuItem"; + loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; + loadToolStripMenuItem.Size = new Size(231, 26); + loadToolStripMenuItem.Text = "Загрузка"; + loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; + // + // saveFileDialog + // + saveFileDialog.Filter = "txt file | *.txt"; + // + // openFileDialog + // + openFileDialog.Filter = "txt file | *.txt"; + // // FormBusCollection // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1128, 644); + ClientSize = new Size(1128, 609); Controls.Add(pictureBox1); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + FormBorderStyle = FormBorderStyle.FixedSingle; + MainMenuStrip = menuStrip; Name = "FormBusCollection"; Text = "Коллекция самолетов "; groupBoxTools.ResumeLayout(false); @@ -272,14 +310,16 @@ panelStorage.ResumeLayout(false); panelStorage.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ResumeLayout(false); + PerformLayout(); } #endregion private GroupBox groupBoxTools; private ComboBox comboBoxSelectorCompany; - private Button buttonAddAirBus; private Button buttonAddBus; private PictureBox pictureBox1; private Button buttonDelBus; @@ -296,5 +336,12 @@ private Button buttonCreateCompany; private Button buttonCollectionDel; 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/ProjectAirbus/ProjectAirbus/FormBusCollection.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs index f1b30ed..43460b2 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs @@ -2,238 +2,271 @@ using ProjectAirbus.Drawnings; using ProjectAirBus.CollectionGenericObjects; -namespace ProjectAirbus +namespace ProjectAirbus; + +public partial class FormBusCollection : Form { - public partial class FormBusCollection : Form + private readonly StorageCollection _storageCollection; + + private AbstractCompany? _company; + public FormBusCollection() { - private readonly StorageCollection _storageCollection; + InitializeComponent(); + _storageCollection = new(); + } - private AbstractCompany? _company; - public FormBusCollection() + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + panelCompanyTools.Enabled = false; + } + + + + + + /// + /// добавить самолет + /// + /// + /// + private void ButtonAddBus_Click(object sender, EventArgs e) + { + FormBusConfig form = new(); + form.Show(); + form.AddEvent(SetBus); + + + } + + private void SetBus(DrawningBus? bus) + { + if (_company == null || bus == null) { - InitializeComponent(); - _storageCollection = new(); + return; } - private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + if (_company + bus != -1) { - panelCompanyTools.Enabled = false; - } - - - - - - /// - /// добавить самолет - /// - /// - /// - private void ButtonAddBus_Click(object sender, EventArgs e) - { - FormBusConfig form = new(); - form.Show(); - form.AddEvent(SetBus); - - - } - - private void SetBus(DrawningBus? bus) - { - if (_company == null || bus == null) - { - return; - } - - if (_company + bus != -1) - { - MessageBox.Show("Объект добавлен"); - pictureBox1.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось добавить объект"); - } - } - - - - /// - /// Удаление объекта - /// - /// - /// - private void buttonDelPlane_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) - { - return; - } - - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - - int pos = Convert.ToInt32(maskedTextBox.Text); - if (_company - pos != null) - { - MessageBox.Show("Объект удален"); - pictureBox1.Image = _company.Show(); - } - else - { - MessageBox.Show("Не удалось удалить объект"); - } - } - - /// - /// Передача объекта в другую форму - /// - /// - /// - private void buttonGoToCheck_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - - DrawningBus? bus = null; - int counter = 100; - while (bus == null) - { - bus = _company.GetRandomObject(); - counter--; - if (counter <= 0) - { - break; - } - } - - if (bus == null) - { - return; - } - - FormAirbus form = new(); - form.SetBus = bus; - form.ShowDialog(); - } - - /// - /// Перерисовка коллекции - /// - /// - /// - private void buttonRefresh_Click(object sender, EventArgs e) - { - if (_company == null) - { - return; - } - + MessageBox.Show("Объект добавлен"); pictureBox1.Image = _company.Show(); } - - /// - /// Добавление коллекции - /// - /// - /// - private void buttonCollectionAdd_Click(object sender, EventArgs e) + else { - if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) - { - MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - - CollectionType collectionType = CollectionType.None; - if (radioButtonMassive.Checked) - { - collectionType = CollectionType.Massive; - } - else if (radioButtonList.Checked) - { - collectionType = CollectionType.List; - } - - _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); - RerfreshListBoxItems(); - } - /// - /// Удаление коллекции - /// - /// - /// - private void buttonCollectionDel_Click(object sender, EventArgs e) - { - // TODO прописать логику удаления элемента из коллекции - // нужно убедиться, что есть выбранная коллекция - // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись - // удалить и обновить ListBox - - if (listBoxCollection.SelectedItem == null) - { - MessageBox.Show("Коллекция не выбрана"); - return; - } - if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) - { - return; - } - _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); - RerfreshListBoxItems(); - } - - /// - /// Обновление списка в listBoxCollection - /// - private void RerfreshListBoxItems() - { - listBoxCollection.Items.Clear(); - for (int i = 0; i < _storageCollection.Keys?.Count; ++i) - { - string? colName = _storageCollection.Keys?[i]; - if (!string.IsNullOrEmpty(colName)) - { - listBoxCollection.Items.Add(colName); - } - } - - } - - - /// - /// Создание компании - /// - /// - /// - private void buttonCreateCompany_Click(object sender, EventArgs e) - { - if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) - { - MessageBox.Show("Коллекция не выбрана"); - return; - } - - ICollectionGenericObjects? collection =_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; - if (collection == null) - { - MessageBox.Show("Коллекция не проинициализирована"); - return; - } - - switch (comboBoxSelectorCompany.Text) - { - case "Хранилище": - _company = new AerodromService(pictureBox1.Width, pictureBox1.Height,collection); - break; - } - - panelCompanyTools.Enabled = true; - RerfreshListBoxItems(); + MessageBox.Show("Не удалось добавить объект"); } } + + + + /// + /// Удаление объекта + /// + /// + /// + private void buttonDelPlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox1.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void buttonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningBus? bus = null; + int counter = 100; + while (bus == null) + { + bus = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (bus == null) + { + return; + } + + FormAirbus form = new(); + form.SetBus = bus; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox1.Image = _company.Show(); + } + + /// + /// Добавление коллекции + /// + /// + /// + private void buttonCollectionAdd_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCollectionName.Text) || (!radioButtonList.Checked && !radioButtonMassive.Checked)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + CollectionType collectionType = CollectionType.None; + if (radioButtonMassive.Checked) + { + collectionType = CollectionType.Massive; + } + else if (radioButtonList.Checked) + { + collectionType = CollectionType.List; + } + + _storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); + RerfreshListBoxItems(); + } + /// + /// Удаление коллекции + /// + /// + /// + private void buttonCollectionDel_Click(object sender, EventArgs e) + { + // TODO прописать логику удаления элемента из коллекции + // нужно убедиться, что есть выбранная коллекция + // спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись + // удалить и обновить ListBox + + if (listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + _storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); + RerfreshListBoxItems(); + } + + /// + /// Обновление списка в listBoxCollection + /// + private void RerfreshListBoxItems() + { + listBoxCollection.Items.Clear(); + for (int i = 0; i < _storageCollection.Keys?.Count; ++i) + { + string? colName = _storageCollection.Keys?[i]; + if (!string.IsNullOrEmpty(colName)) + { + listBoxCollection.Items.Add(colName); + } + } + + } + + + /// + /// Создание компании + /// + /// + /// + private void buttonCreateCompany_Click(object sender, EventArgs e) + { + if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null) + { + MessageBox.Show("Коллекция не выбрана"); + return; + } + + ICollectionGenericObjects? collection = _storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; + if (collection == null) + { + MessageBox.Show("Коллекция не проинициализирована"); + return; + } + + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new AerodromService(pictureBox1.Width, pictureBox1.Height, collection); + break; + } + + panelCompanyTools.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/ProjectAirbus/ProjectAirbus/FormBusCollection.resx b/ProjectAirbus/ProjectAirbus/FormBusCollection.resx index af32865..a4f11d6 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusCollection.resx +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.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 + + + 25 + \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormBusConfig.Designer.cs b/ProjectAirbus/ProjectAirbus/FormBusConfig.Designer.cs index df372cc..4d2b4be 100644 --- a/ProjectAirbus/ProjectAirbus/FormBusConfig.Designer.cs +++ b/ProjectAirbus/ProjectAirbus/FormBusConfig.Designer.cs @@ -256,6 +256,7 @@ buttonAdd.TabIndex = 2; buttonAdd.Text = "Добавить "; buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAddAirbus_Click; // // buttonCancel //