diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs index dd825a6..3b5d2f6 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/AbstractCompany.cs @@ -45,7 +45,7 @@ public abstract class AbstractCompany _pictureWidth = picWidth; _pictureHeight = picHeight; _collection = collection; - _collection.SetMaxCount = GetMaxCount; + _collection.MaxCount = GetMaxCount; } /// @@ -54,7 +54,7 @@ public abstract class AbstractCompany /// Компания /// Добавляемый объект /// - public static int operator +(AbstractCompany company, DrawningTank tank) + public static bool operator +(AbstractCompany company, DrawningTank tank) { return company._collection.Insert(tank); } @@ -65,11 +65,10 @@ public abstract class AbstractCompany /// Компания /// Номер удаляемого объекта /// - public static DrawningTank? operator -(AbstractCompany company, int position) + public static bool operator -(AbstractCompany company, int position) { - return company._collection?.Remove(position); + return company._collection.Remove(position); } - /// /// Получение случайного объекта из коллекции /// diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs index 07bd474..e25cacb 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -21,29 +21,28 @@ public interface ICollectionGenericObjects /// /// Установка максимального количества элементов /// - int SetMaxCount { set; } + int MaxCount { get; set; } /// /// Добавление объекта в коллекцию /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj); - + bool Insert(T obj); /// - /// Добавление объекта в коллекцию на конкретную позицию + /// вставить по позиции /// - /// Добавляемый объект - /// Позиция - /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj, int position); + /// добавляемый объект + /// индекс + /// + bool Insert(T obj, int position); /// /// Удаление объекта из коллекции с конкретной позиции /// /// Позиция /// true - удаление прошло удачно, false - удаление не удалось - T? Remove(int position); + bool Remove(int position); /// /// Получение объекта по позиции @@ -51,4 +50,15 @@ public interface ICollectionGenericObjects /// Позиция /// Объект T? Get(int position); + + /// + /// Получение типа коллекции + /// + CollectionType GetCollectionType { get; } + + /// + /// Получение объектов коллекции по одному + /// + /// + IEnumerable GetItems(); } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs index ed341fd..dab3305 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/ListGenericObjects.cs @@ -19,10 +19,24 @@ public class ListGenericObjects : ICollectionGenericObjects /// private int _maxCount; - public int Count => _collection.Count; + public int Count { get { return _collection.Count; } } public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } } + public CollectionType GetCollectionType => CollectionType.List; + + public int MaxCount + { + get + { + return _maxCount; + } + set + { + if (value > 0) _maxCount = value; + } + } + /// /// Конструктор /// @@ -33,30 +47,41 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position < 0 || position >= Count) return null; + if (position < 0 || position >= _collection.Count || _collection == null || _collection.Count == 0) return null; + return _collection[position]; } - public int Insert(T? obj) + public bool Insert(T obj) { - if (Count == _maxCount) return -1; + if (_collection == null || _collection.Count == _maxCount) return false; + _collection.Add(obj); - return Count - 1; + return true; } - public int Insert(T? obj, int position) + public bool Insert(T obj, int position) { - if (Count == _maxCount) return -1; - if (position < 0 || position >= Count) return -1; + if (_collection == null || position < 0 || position > _maxCount) return false; + _collection.Insert(position, obj); - return position; + return true; } - public T? Remove(int position) + public bool Remove(int position) { - if (position < 0 || position >= Count) return null; + if (_collection == null || position < 0 || position >= _collection.Count) return false; + T? obj = _collection[position]; - _collection.RemoveAt(position); - return obj; + _collection[position] = null; + return true; } -} \ No newline at end of file + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Count; i++) + { + yield return _collection[i]; + } + } +} diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs index b4e61f9..0de4dcf 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/MassiveGenericObjects.cs @@ -14,26 +14,28 @@ public class MassiveGenericObjects : ICollectionGenericObjects /// private T?[] _collection; - public int Count => _collection.Length; + public int Count { get { return _collection.Length; } } - public int SetMaxCount + public int MaxCount { + get + { + return _collection.Length; + } + set { - if (value > 0) + if (value > 0 && _collection.Length == 0) { - if (_collection.Length > 0) - { - Array.Resize(ref _collection, value); - } - else - { - _collection = new T?[value]; - } + _collection = new T?[value]; } } } + public CollectionType GetCollectionType => CollectionType.Massive; + + public int SetMaxCount { set => throw new NotImplementedException(); } + /// /// Конструктор /// @@ -49,27 +51,27 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) + public bool Insert(T obj) { for (int i = 0; i < _collection.Length; i++) { if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } - return -1; + return false; } - public int Insert(T obj, int position) + public bool Insert(T obj, int position) { - if (position < 0 || position >= _collection.Length) { return position; } + if (position < 0 || position >= _collection.Length) { return false; } if (_collection[position] == null) { _collection[position] = obj; - return position; + return true; } else { @@ -78,7 +80,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } @@ -87,21 +89,29 @@ public class MassiveGenericObjects : ICollectionGenericObjects if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } } - - return -1; + return false; } - public T? Remove(int position) + public bool Remove(int position) { - if (position < 0 || position >= _collection.Length || _collection[position] == null) - return null; - T? temp = _collection[position]; - _collection[position] = null; + if (position < 0 || position >= _collection.Length) { return false; } - return temp; + T? obj = _collection[position]; + _collection[position] = null; + return true; } + + public IEnumerable GetItems() + { + for (int i = 0; i < _collection.Length; i++) + { + yield return _collection[i]; + } + } + + } diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs index 033b7d2..7cd1557 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ -using System; +using SelfPropelledArtilleryUnit.Drawnings; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -7,7 +8,7 @@ using System.Threading.Tasks; namespace SelfPropelledArtilleryUnit.CollectionGenericObjects; public class StorageCollection - where T : class + where T : DrawningTank { /// /// Словарь (хранилище) с коллекциями @@ -19,6 +20,11 @@ public class StorageCollection /// public List Keys => _storages.Keys.ToList(); + private readonly string _collectionKey = "CollectionStorage"; + + private readonly string _separatorForKeyValue = "|"; + + private readonly string _separatorItem = ";"; /// /// Конструктор /// @@ -75,4 +81,106 @@ public class StorageCollection return null; } } + public bool SaveData(string filename) + { + if (_storages.Count == 0) + { + return false; + } + if (File.Exists(filename)) + { + File.Delete(filename); + } + using (StreamWriter writer = new StreamWriter(filename)) + { + writer.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) + { + StringBuilder sb = new(); + sb.Append(Environment.NewLine); + // не сохраняем пустые коллекции + if (value.Value.Count == 0) + { + continue; + } + sb.Append(value.Key); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.GetCollectionType); + sb.Append(_separatorForKeyValue); + sb.Append(value.Value.MaxCount); + sb.Append(_separatorForKeyValue); + foreach (T? item in value.Value.GetItems()) + { + string data = item?.GetDataForSave() ?? string.Empty; + if (string.IsNullOrEmpty(data)) + { + continue; + } + sb.Append(data); + sb.Append(_separatorItem); + } + writer.Write(sb); + } + return true; + } + } + + public bool LoadData(string filename) + { + if (!File.Exists(filename)) + { + return false; + } + using (StreamReader reader = File.OpenText(filename)) + { + string str = reader.ReadLine(); + if (str == null || str.Length == 0) + { + return false; + } + if (!str.StartsWith(_collectionKey)) + { + return false; + } + _storages.Clear(); + string strs = ""; + while ((strs = reader.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(_separatorItem, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawningTank() is T tank) + { + if (!collection.Insert(tank)) + { + 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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningArtillery.cs index be34f15..cb69bd8 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningArtillery.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningArtillery.cs @@ -20,7 +20,10 @@ public class DrawningArtillery : DrawningTank { EntityTank = new EntityArtillery(speed, weight, bodyColor, additionalColor, cannon, rocket); } - + public DrawningArtillery(EntityArtillery tank) : base(130, 20) + { + EntityTank = tank; + } public override void DrawTransport(Graphics g) { diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningTank.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningTank.cs index f063da9..db5728a 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningTank.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningTank.cs @@ -76,6 +76,10 @@ public class DrawningTank _drawningTankWidth = drawningTankWidth; _pictureHeight = drawningTankHeight; } + public DrawningTank(EntityTank tank) + { + EntityTank = tank; + } /// /// Установка границ поля /// diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/ExtentionDrawningTank.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/ExtentionDrawningTank.cs new file mode 100644 index 0000000..a0aa98b --- /dev/null +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/ExtentionDrawningTank.cs @@ -0,0 +1,51 @@ +using SelfPropelledArtilleryUnit.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SelfPropelledArtilleryUnit.Drawnings; + +public static class ExtentionDrawningTank +{ + private static readonly string _separatorForObject = ":"; + + /// + /// Создание объекта из строк характеристик + /// + /// + /// + public static DrawningTank? CreateDrawningTank(this string info) + { + string[] strs = info.Split(_separatorForObject); + EntityTank? tank = EntityArtillery.CreateEntityArtillery(strs); + if (tank != null && tank is EntityArtillery tankA) + { + return new DrawningArtillery(tankA); + } + + tank = EntityTank.CreateEntityTank(strs); + if (tank != null) + { + return new DrawningTank(tank); + } + + return null; + } + + /// + /// Подготовка данных для сохранения в файл + /// + /// + /// + public static string GetDataForSave(this DrawningTank drawningTank) + { + string[]? array = drawningTank?.EntityTank?.GetStringRepresentation(); + + if (array == null) { return string.Empty; } + + return string.Join(_separatorForObject, array); + } +} + diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityArtillery.cs index c2ace0b..ec215fa 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityArtillery.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityArtillery.cs @@ -38,6 +38,28 @@ public class EntityArtillery : EntityTank Cannon = cannon; Rocket = rocket; } + /// + /// Получение строк характеристик + /// + /// + public override string[] GetStringRepresentation() + { + return new[] { nameof(EntityArtillery), Speed.ToString(), Weight.ToString(), BodyColor.Name, + AdditionalColor.Name, Cannon.ToString(), Rocket.ToString() }; + } + /// + /// Создание объекта по строкам характеристик + /// + /// + /// + public static EntityArtillery? CreateEntityArtillery(string[] strs) + { + if (strs.Length != 7 || strs[0] != nameof(EntityArtillery)) { return null; } + + return new EntityArtillery(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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityTank.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityTank.cs index 5419804..769e6a5 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityTank.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityTank.cs @@ -35,5 +35,22 @@ public class EntityTank BodyColor = bodyColor; } + public virtual string[] GetStringRepresentation() + { + return new[] { nameof(EntityTank), Speed.ToString(), Weight.ToString(), BodyColor.Name }; + } + + /// + /// Создание объекта по строкам характеристик + /// + /// + /// + public static EntityTank? CreateEntityTank(string[] strs) + { + if (strs.Length != 4 || strs[0] != nameof(EntityTank)) { return null; } + + return new EntityTank(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3])); + } +} + -} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs index 3f48002..79d1c49 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.Designer.cs @@ -29,6 +29,13 @@ private void InitializeComponent() { groupBoxTools = new GroupBox(); + panelCompanyTools = new Panel(); + buttonAddTank = new Button(); + buttonAddArtillery = new Button(); + buttonRefresh = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonGoToCheak = new Button(); + buttonRemoveTank = new Button(); buttonCreateCompany = new Button(); panelStorage = new Panel(); buttonCollectionDel = new Button(); @@ -38,19 +45,19 @@ radioButtonMassive = new RadioButton(); textBoxCollectionName = new TextBox(); labelCollectionName = new Label(); - buttonRefresh = new Button(); - buttonGoToCheak = new Button(); - buttonRemoveTank = new Button(); - maskedTextBoxPosition = new MaskedTextBox(); - buttonAddTank = new Button(); - buttonAddArtillery = new Button(); comboBoxSelectorCompany = new ComboBox(); pictureBox = new PictureBox(); - panelCompanyTools = new Panel(); + menuStrip = new MenuStrip(); + файлToolStripMenuItem = new ToolStripMenuItem(); + saveToolStripMenuItem = new ToolStripMenuItem(); + loadToolStripMenuItem = new ToolStripMenuItem(); + saveFileDialog = new SaveFileDialog(); + openFileDialog = new OpenFileDialog(); groupBoxTools.SuspendLayout(); + panelCompanyTools.SuspendLayout(); panelStorage.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); - panelCompanyTools.SuspendLayout(); + menuStrip.SuspendLayout(); SuspendLayout(); // // groupBoxTools @@ -60,13 +67,91 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(715, 0); + groupBoxTools.Location = new Point(715, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(200, 508); + groupBoxTools.Size = new Size(200, 484); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // + // panelCompanyTools + // + panelCompanyTools.Controls.Add(buttonAddTank); + panelCompanyTools.Controls.Add(buttonAddArtillery); + panelCompanyTools.Controls.Add(buttonRefresh); + panelCompanyTools.Controls.Add(maskedTextBoxPosition); + panelCompanyTools.Controls.Add(buttonGoToCheak); + panelCompanyTools.Controls.Add(buttonRemoveTank); + panelCompanyTools.Dock = DockStyle.Bottom; + panelCompanyTools.Enabled = false; + panelCompanyTools.Location = new Point(3, 276); + panelCompanyTools.Name = "panelCompanyTools"; + panelCompanyTools.Size = new Size(194, 205); + panelCompanyTools.TabIndex = 9; + // + // buttonAddTank + // + buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddTank.Location = new Point(12, 9); + buttonAddTank.Name = "buttonAddTank"; + buttonAddTank.Size = new Size(170, 30); + buttonAddTank.TabIndex = 2; + buttonAddTank.Text = "Добавление танка"; + buttonAddTank.UseVisualStyleBackColor = true; + buttonAddTank.Click += ButtonAddTank_Click; + // + // buttonAddArtillery + // + buttonAddArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddArtillery.Location = new Point(12, 45); + buttonAddArtillery.Name = "buttonAddArtillery"; + buttonAddArtillery.Size = new Size(170, 31); + buttonAddArtillery.TabIndex = 1; + buttonAddArtillery.Text = "Добавление сау"; + buttonAddArtillery.UseVisualStyleBackColor = true; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(12, 174); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(170, 23); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(12, 82); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(176, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonGoToCheak + // + buttonGoToCheak.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheak.Location = new Point(12, 143); + buttonGoToCheak.Name = "buttonGoToCheak"; + buttonGoToCheak.Size = new Size(170, 25); + buttonGoToCheak.TabIndex = 5; + buttonGoToCheak.Text = "Передать на тесты"; + buttonGoToCheak.UseVisualStyleBackColor = true; + buttonGoToCheak.Click += ButtonGoToCheak_Click; + // + // buttonRemoveTank + // + buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveTank.Location = new Point(12, 110); + buttonRemoveTank.Name = "buttonRemoveTank"; + buttonRemoveTank.Size = new Size(170, 27); + buttonRemoveTank.TabIndex = 4; + buttonRemoveTank.Text = "Удалить танк"; + buttonRemoveTank.UseVisualStyleBackColor = true; + buttonRemoveTank.Click += ButtonRemoveTank_Click; + // // buttonCreateCompany // buttonCreateCompany.Location = new Point(5, 267); @@ -159,69 +244,6 @@ labelCollectionName.TabIndex = 0; labelCollectionName.Text = "Название коллекции:"; // - // buttonRefresh - // - buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(12, 174); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(170, 23); - buttonRefresh.TabIndex = 6; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += ButtonRefresh_Click; - // - // buttonGoToCheak - // - buttonGoToCheak.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheak.Location = new Point(12, 143); - buttonGoToCheak.Name = "buttonGoToCheak"; - buttonGoToCheak.Size = new Size(170, 25); - buttonGoToCheak.TabIndex = 5; - buttonGoToCheak.Text = "Передать на тесты"; - buttonGoToCheak.UseVisualStyleBackColor = true; - buttonGoToCheak.Click += ButtonGoToCheak_Click; - // - // buttonRemoveTank - // - buttonRemoveTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRemoveTank.Location = new Point(12, 110); - buttonRemoveTank.Name = "buttonRemoveTank"; - buttonRemoveTank.Size = new Size(170, 27); - buttonRemoveTank.TabIndex = 4; - buttonRemoveTank.Text = "Удалить танк"; - buttonRemoveTank.UseVisualStyleBackColor = true; - buttonRemoveTank.Click += ButtonRemoveTank_Click; - // - // maskedTextBoxPosition - // - maskedTextBoxPosition.Location = new Point(12, 82); - maskedTextBoxPosition.Mask = "00"; - maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - maskedTextBoxPosition.Size = new Size(176, 23); - maskedTextBoxPosition.TabIndex = 3; - maskedTextBoxPosition.ValidatingType = typeof(int); - // - // buttonAddTank - // - buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddTank.Location = new Point(12, 9); - buttonAddTank.Name = "buttonAddTank"; - buttonAddTank.Size = new Size(170, 30); - buttonAddTank.TabIndex = 2; - buttonAddTank.Text = "Добавление танка"; - buttonAddTank.UseVisualStyleBackColor = true; - buttonAddTank.Click += ButtonAddTank_Click; - // - // buttonAddArtillery - // - buttonAddArtillery.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonAddArtillery.Location = new Point(12, 45); - buttonAddArtillery.Name = "buttonAddArtillery"; - buttonAddArtillery.Size = new Size(170, 31); - buttonAddArtillery.TabIndex = 1; - buttonAddArtillery.Text = "Добавление сау"; - buttonAddArtillery.UseVisualStyleBackColor = true; - // // comboBoxSelectorCompany // comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -237,26 +259,53 @@ // pictureBox // pictureBox.Dock = DockStyle.Fill; - pictureBox.Location = new Point(0, 0); + pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(715, 508); + pictureBox.Size = new Size(715, 484); pictureBox.TabIndex = 1; pictureBox.TabStop = false; + pictureBox.Click += pictureBox_Click; // - // panelCompanyTools + // menuStrip // - panelCompanyTools.Controls.Add(buttonAddTank); - panelCompanyTools.Controls.Add(buttonAddArtillery); - panelCompanyTools.Controls.Add(buttonRefresh); - panelCompanyTools.Controls.Add(maskedTextBoxPosition); - panelCompanyTools.Controls.Add(buttonGoToCheak); - panelCompanyTools.Controls.Add(buttonRemoveTank); - panelCompanyTools.Dock = DockStyle.Bottom; - panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 300); - panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(194, 205); - panelCompanyTools.TabIndex = 9; + menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(915, 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.FileName = "openFileDialog1"; + openFileDialog.Filter = "txt file | *.txt"; // // FormTankCollection // @@ -265,15 +314,20 @@ ClientSize = new Size(915, 508); Controls.Add(pictureBox); Controls.Add(groupBoxTools); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; Name = "FormTankCollection"; Text = "Коллекция сау"; groupBoxTools.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 @@ -297,5 +351,11 @@ 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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs index 18fa67d..b5473bb 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.cs @@ -51,7 +51,7 @@ public partial class FormTankCollection : Form return; } - if (_company + tank != -1) + if (_company + tank) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _company.Show(); @@ -208,5 +208,57 @@ public partial class FormTankCollection : Form panelCompanyTools.Enabled = true; RerfreshListBoxItems(); } + + private void pictureBox_Click(object sender, EventArgs e) + { + + } + private void RefreshListBoxItems() + { + 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 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); + RefreshListBoxItems(); + } + else + { + MessageBox.Show("Не загрузилось", "Результат", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } } + diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.resx b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.resx index af32865..8b1dfa1 100644 --- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.resx +++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormTankCollection.resx @@ -117,4 +117,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + + + 126, 17 + + + 261, 17 + \ No newline at end of file