diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs
index 0c756a0..1d4318f 100644
--- a/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/AbstractCompany.cs
@@ -2,9 +2,6 @@
namespace ProjectTank.CollectionGenericObjects;
-///
-/// Абстракция компании, хранящий коллекцию автомобилей
-///
public abstract class AbstractCompany
{
///
@@ -28,7 +25,7 @@ public abstract class AbstractCompany
protected readonly int _pictureHeight;
///
- /// Коллекция поездов
+ /// Коллекция машин
///
protected ICollectionGenericObjects? _collection = null;
@@ -42,24 +39,25 @@ public abstract class AbstractCompany
///
/// Ширина окна
/// Высота окна
- /// Коллекция поездов
- public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ /// Коллекция машин
+ public AbstractCompany(int picWidth, int picHeight,
+ ICollectionGenericObjects collection)
{
_pictureWidth = picWidth;
_pictureHeight = picHeight;
_collection = collection;
- _collection.SetMaxCount = GetMaxCount;
+ _collection.MaxCount = GetMaxCount;
}
///
/// Перегрузка оператора сложения для класса
///
/// Компания
- /// Добавляемый объект
+ /// Добавляемый объект
///
- public static int operator +(AbstractCompany company, DrawningTank2 tank)
+ public static int operator +(AbstractCompany company, DrawningTank2 tank2)
{
- return company._collection.Insert(tank);
+ return company._collection.Insert(tank2);
}
///
@@ -68,9 +66,9 @@ public abstract class AbstractCompany
/// Компания
/// Номер удаляемого объекта
///
- public static DrawningTank2? operator -(AbstractCompany company, int position)
+ public static DrawningTank2 operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position);
+ return company._collection.Remove(position);
}
///
@@ -92,14 +90,12 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics);
-
SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{
DrawningTank2? obj = _collection?.Get(i);
obj?.DrawTransport(graphics);
}
-
return bitmap;
}
@@ -108,9 +104,8 @@ public abstract class AbstractCompany
///
///
protected abstract void DrawBackgound(Graphics g);
-
///
/// Расстановка объектов
///
protected abstract void SetObjectsPosition();
-}
\ No newline at end of file
+}
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
index 89f081e..155effc 100644
--- a/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,9 +1,5 @@
namespace ProjectTank.CollectionGenericObjects;
-///
-/// Интерфейс описания действий для набора хранимых объектов
-///
-/// Параметр: ограничение - ссылочный тип
public interface ICollectionGenericObjects
where T : class
{
@@ -15,7 +11,7 @@ public interface ICollectionGenericObjects
///
/// Установка максимального количества элементов
///
- int SetMaxCount { set; }
+ int MaxCount { get; set; }
///
/// Добавление объекта в коллекцию
@@ -45,4 +41,15 @@ public interface ICollectionGenericObjects
/// Позиция
/// Объект
T? Get(int position);
-}
\ No newline at end of file
+
+ ///
+ /// Получение типа коллекции
+ ///
+ CollectionType GetCollectionType { get; }
+ ///
+ /// Получение объектов коллекции по одному
+ ///
+ /// Поэлементый вывод элементов коллекции
+ IEnumerable GetItems();
+}
+
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs
index efb07ca..5981b16 100644
--- a/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/ListGenericObjects.cs
@@ -7,12 +7,29 @@ public class ListGenericObjects : ICollectionGenericObjects
/// Список объектов, которые храним
///
private readonly List _collection;
+
///
/// Максимально допустимое число объектов в списке
///
private int _maxCount;
public int Count => _collection.Count;
- public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
+ public int MaxCount
+ {
+ get
+ {
+ return Count;
+ }
+ set
+ {
+ if (value > 0)
+ {
+ _maxCount = value;
+ }
+ }
+ }
+
+ public CollectionType GetCollectionType => CollectionType.List;
+
///
/// Конструктор
///
@@ -20,6 +37,7 @@ public class ListGenericObjects : ICollectionGenericObjects
{
_collection = new();
}
+
public T? Get(int position)
{
// TODO проверка позиции
@@ -55,4 +73,11 @@ public class ListGenericObjects : ICollectionGenericObjects
return temp;
}
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Count; ++i)
+ {
+ yield return _collection[i];
+ }
+ }
}
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
index 93a34cb..f0572fc 100644
--- a/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -1,7 +1,4 @@
-using System.Runtime.Remoting;
-using ProjectTank.Drawnings;
-
-namespace ProjectTank.CollectionGenericObjects;
+namespace ProjectTank.CollectionGenericObjects;
internal class MassiveGenericObjects : ICollectionGenericObjects
where T : class
@@ -13,8 +10,13 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
public int Count => _collection.Length;
- public int SetMaxCount
+ public int MaxCount
{
+ get
+ {
+ return _collection.Length;
+ }
+
set
{
if (value > 0)
@@ -29,7 +31,11 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
}
}
}
+
}
+
+ public CollectionType GetCollectionType => CollectionType.Massive;
+
///
/// Конструктор
///
@@ -40,17 +46,17 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- if (position >= 0 && position < Count)
+ // TODO проверка позиции
+ if (position <= Count)
{
return _collection[position];
}
-
- return null;
+ else
+ return null;
}
-
public int Insert(T obj)
{
- // вставка в свободное место набора
+ // TODO вставка в свободное место набора
for (int i = 0; i < Count; i++)
{
if (_collection[i] == null)
@@ -59,78 +65,60 @@ internal class MassiveGenericObjects : ICollectionGenericObjects
return i;
}
}
-
return -1;
}
public int Insert(T obj, int position)
{
- // проверка позиции
- if (position < 0 || position >= Count)
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет туда
+ // если нет после, ищем до
+ // TODO вставка
+ if (position < Count)
{
- return -1;
- }
-
- // проверка, что элемент массива по этой позиции пустой, если нет, то
- // ищется свободное место после этой позиции и идет вставка туда
- // если нет после, ищем до
- if (_collection[position] != null)
- {
- bool pushed = false;
- for (int index = position + 1; index < Count; index++)
+ if (position < 0 || position >= Count)
{
- if (_collection[index] == null)
- {
- position = index;
- pushed = true;
- break;
- }
+ return -1;
}
-
- if (!pushed)
+ if (_collection[position] == null)
{
- for (int index = position - 1; index >= 0; index--)
+ _collection[position] = obj;
+ return position;
+ }
+ else
+ {
+ for (int i = 0; i < Count; i++)
{
- if (_collection[index] == null)
+ if (_collection[i] == null)
{
- position = index;
- pushed = true;
- break;
+ _collection[i] = obj;
+ return i;
}
}
}
-
- if (!pushed)
- {
- return position;
- }
}
-
- // вставка
- _collection[position] = obj;
- return position;
+ return -1;
}
-
public T? Remove(int position)
{
- // проверка позиции
- if (position < 0 || position >= Count)
- {
- return null;
- }
-
- if (_collection[position] == null) return null;
-
- T? temp = _collection[position];
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ if (position >= Count || position < 0) return null;
+ T? myObject = _collection[position];
_collection[position] = null;
- return temp;
+ return myObject;
+ }
+
+ public IEnumerable GetItems()
+ {
+ for (int i = 0; i < _collection.Length; ++i)
+ {
+ yield return _collection[i];
+ }
}
}
-
-
-
-
diff --git a/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs b/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs
index c35f933..eff5415 100644
--- a/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs
+++ b/ProjectTank/ProjectTank/CollectionGenericObjects/StorageCollection.cs
@@ -1,11 +1,14 @@
-namespace ProjectTank.CollectionGenericObjects;
+using ProjectTank.Drawnings;
+using System.Text;
+
+namespace ProjectTank.CollectionGenericObjects;
///
/// Класс-хранилище коллекций
///
///
internal class StorageCollection
- where T : class
+ where T : DrawningTank2
{
///
/// Словарь (хранилище) с коллекциями
@@ -17,6 +20,20 @@ internal class StorageCollection
///
public List Keys => _storages.Keys.ToList();
+ ///
+ /// Ключевое слово, с которого должен начинаться файл
+ ///
+ private readonly string _collectionKey = "CollectionsStorage";
+ ///
+ /// Разделитель для записи ключа и значения элемента словаря
+ ///
+ private readonly string _separatorForKeyValue = "|";
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly string _separatorItems = ";";
+
+
///
/// Конструктор
///
@@ -34,19 +51,12 @@ internal class StorageCollection
{
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
// TODO Прописать логику для добавления
- if (name == null || _storages.ContainsKey(name))
- return;
- switch (collectionType)
- {
- case CollectionType.None:
- return;
- case CollectionType.Massive:
- _storages[name] = new MassiveGenericObjects();
- return;
- case CollectionType.List:
- _storages[name] = new ListGenericObjects();
- return;
- }
+ if (_storages.ContainsKey(name)) return;
+ if (collectionType == CollectionType.None) return;
+ else if (collectionType == CollectionType.Massive)
+ _storages[name] = new MassiveGenericObjects();
+ else if (collectionType == CollectionType.List)
+ _storages[name] = new ListGenericObjects();
}
@@ -71,10 +81,134 @@ internal class StorageCollection
get
{
// TODO Продумать логику получения объекта
- if (name == null || !_storages.ContainsKey(name))
- return null;
- return _storages[name];
+ if (_storages.ContainsKey(name))
+ return _storages[name];
+ return null;
}
}
+ ///
+ /// Сохранение информации по автомобилям в хранилище в файл
+ ///
+ /// Путь и имя файла
+ /// true - сохранение прошло успешно, false - ошибка при сохранении данных
+ public bool SaveData(string filename)
+ {
+ if (_storages.Count == 0)
+ {
+ return false;
+ }
+
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+
+ using (StreamWriter writer = new StreamWriter(filename))
+ {
+ writer.Write(_collectionKey);
+ foreach (KeyValuePair> value in _storages)
+ {
+ StringBuilder sb = new();
+ sb.Append(Environment.NewLine);
+
+ // не сохраняем пустые коллекции
+ if (value.Value.Count == 0)
+ {
+ continue;
+ }
+
+ sb.Append(value.Key);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(value.Value.GetCollectionType);
+ sb.Append(_separatorForKeyValue);
+ sb.Append(value.Value.MaxCount);
+ sb.Append(_separatorForKeyValue);
+ foreach (T? item in value.Value.GetItems())
+ {
+ string data = item?.GetDataForSave() ?? string.Empty;
+ if (string.IsNullOrEmpty(data))
+ {
+ continue;
+ }
+ sb.Append(data);
+ sb.Append(_separatorItems);
+ }
+ writer.Write(sb);
+ }
+
+ }
+ return true;
+
+ }
+
+ ///
+ /// Загрузка информации по автомобилям в хранилище из файла
+ ///
+ /// Путь и имя файла
+ /// true - загрузка прошла успешно, false - ошибка при загрузке данных
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+
+ using (StreamReader fs = File.OpenText(filename))
+ {
+ string str = fs.ReadLine();
+ if (str == null || str.Length == 0)
+ {
+ return false;
+ }
+ if (!str.StartsWith(_collectionKey))
+ {
+ return false;
+ }
+ _storages.Clear();
+ string strs = "";
+ while ((strs = fs.ReadLine()) != null)
+ {
+ 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?.CreateDrawningTank2() is T tank2)
+ {
+ if (collection.Insert(tank2) == -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/ProjectTank/ProjectTank/Drawnings/DrawningTank.cs b/ProjectTank/ProjectTank/Drawnings/DrawningTank.cs
index cc06063..4ca26a9 100644
--- a/ProjectTank/ProjectTank/Drawnings/DrawningTank.cs
+++ b/ProjectTank/ProjectTank/Drawnings/DrawningTank.cs
@@ -20,6 +20,16 @@ public class DrawningTank : DrawningTank2
EntityTank2 = new EntityTank(speed, weight, bodyColor, additionalColor, gunTurret, machineGun);
}
+ ///
+ /// Конструктор для Extention
+ ///
+ ///
+ public DrawningTank(EntityTank tank2) : base(200, 100)
+ {
+ EntityTank2 = new EntityTank(tank2.Speed, tank2.Weight, tank2.BodyColor, tank2.AdditionalColor, tank2.GunTurret, tank2.MachineGun);
+ }
+
+
public override void DrawTransport(Graphics g)
{
if (EntityTank2 == null || EntityTank2 is not EntityTank tank || !_startPosX.HasValue || !_startPosY.HasValue)
@@ -36,6 +46,7 @@ public class DrawningTank : DrawningTank2
base.DrawTransport(g);
_startPosX -= 37;
+
if (tank.GunTurret)
{
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 17, 85, 8);
diff --git a/ProjectTank/ProjectTank/Drawnings/DrawningTank2.cs b/ProjectTank/ProjectTank/Drawnings/DrawningTank2.cs
index a3c4fb1..d565b09 100644
--- a/ProjectTank/ProjectTank/Drawnings/DrawningTank2.cs
+++ b/ProjectTank/ProjectTank/Drawnings/DrawningTank2.cs
@@ -87,6 +87,15 @@ public class DrawningTank2
_drawningTankHeight = drawningTankHeight;
}
+ //
+ /// Конструктор для Extention
+ ///
+ ///
+ public DrawningTank2(EntityTank2 tank2) : this()
+ {
+ EntityTank2 = new EntityTank2(tank2.Speed, tank2.Weight, tank2.BodyColor);
+ }
+
///
/// Установка границ поля
///
diff --git a/ProjectTank/ProjectTank/Drawnings/ExtentionDrawningTank.cs b/ProjectTank/ProjectTank/Drawnings/ExtentionDrawningTank.cs
new file mode 100644
index 0000000..674110a
--- /dev/null
+++ b/ProjectTank/ProjectTank/Drawnings/ExtentionDrawningTank.cs
@@ -0,0 +1,58 @@
+using ProjectTank.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectTank.Drawnings;
+
+///
+/// Расширение для класса EntityCar
+///
+public static class ExtentionDrawningTank
+{
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly string _separatorForObject = ":";
+
+ ///
+ /// Создание объекта из строки
+ ///
+ /// Строка с данными для создания объекта
+ /// Объект
+ public static DrawningTank2? CreateDrawningTank2(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+ EntityTank2? tank2 = EntityTank.CreateEntityTank(strs);
+ if (tank2 != null)
+ {
+ return new DrawningTank((EntityTank)tank2);
+ }
+ tank2 = EntityTank2.CreateEntityTank2(strs);
+ if (tank2 != null)
+ {
+ return new DrawningTank2(tank2);
+ }
+ return null;
+ }
+
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ /// Сохраняемый объект
+ /// Строка с данными по объекту
+ public static string GetDataForSave(this DrawningTank2 drawningTank2)
+ {
+ string[]? array = drawningTank2?.EntityTank2?.GetStringRepresentation();
+
+ if (array == null)
+ {
+ return string.Empty;
+
+ }
+ return string.Join(_separatorForObject, array);
+ }
+
+}
diff --git a/ProjectTank/ProjectTank/Entities/EntityTank.cs b/ProjectTank/ProjectTank/Entities/EntityTank.cs
index 484b36a..6ed7009 100644
--- a/ProjectTank/ProjectTank/Entities/EntityTank.cs
+++ b/ProjectTank/ProjectTank/Entities/EntityTank.cs
@@ -44,4 +44,30 @@ public class EntityTank : EntityTank2
GunTurret = gunTurret;
MachineGun = machineGun;
}
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public override string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityTank), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name,
+ GunTurret.ToString(), MachineGun.ToString()};
+ }
+
+ ///
+ /// Создание продвинутого объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityTank? CreateEntityTank(string[] strs)
+ {
+ if (strs.Length != 7 || strs[0] != nameof(EntityTank))
+ {
+ return null;
+ }
+ return new EntityTank(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/ProjectTank/ProjectTank/Entities/EntityTank2.cs b/ProjectTank/ProjectTank/Entities/EntityTank2.cs
index 164645f..2bdab0c 100644
--- a/ProjectTank/ProjectTank/Entities/EntityTank2.cs
+++ b/ProjectTank/ProjectTank/Entities/EntityTank2.cs
@@ -42,4 +42,29 @@ public class EntityTank2
Weight = weight;
BodyColor = bodyColor;
}
-}
\ No newline at end of file
+
+ ///
+ /// Получение строк со значениями свойств объекта класса-сущности
+ ///
+ ///
+ public virtual string[] GetStringRepresentation()
+ {
+ return new[] { nameof(EntityTank2), Speed.ToString(), Weight.ToString(), BodyColor.Name };
+ }
+
+ ///
+ /// Создание объекта из массива строк
+ ///
+ ///
+ ///
+ public static EntityTank2? CreateEntityTank2(string[] strs)
+ {
+ if (strs.Length != 4 || strs[0] != nameof(EntityTank2))
+ {
+ return null;
+ }
+
+ return new EntityTank2(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
+ }
+
+}
diff --git a/ProjectTank/ProjectTank/FormTankCollection.Designer.cs b/ProjectTank/ProjectTank/FormTankCollection.Designer.cs
index 4a7a954..af37bbc 100644
--- a/ProjectTank/ProjectTank/FormTankCollection.Designer.cs
+++ b/ProjectTank/ProjectTank/FormTankCollection.Designer.cs
@@ -1,4 +1,6 @@
-namespace ProjectTank
+using System.Windows.Forms;
+
+namespace ProjectTank
{
partial class FormTankCollection
{
@@ -29,6 +31,12 @@
private void InitializeComponent()
{
groupBoxTools = new GroupBox();
+ panelCompanyTools = new Panel();
+ buttonDelTank = new Button();
+ buttonRefresh = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddTank = new Button();
+ buttonGoToCheck = new Button();
buttonCreateCompany = new Button();
panelStorage = new Panel();
buttonCollectinDel = new Button();
@@ -38,18 +46,19 @@
radioButtonMassive = new RadioButton();
textBoxCollectionName = new TextBox();
labelCollectionName = new Label();
- buttonRefresh = new Button();
- buttonGoToCheck = new Button();
- buttonDelTank = new Button();
- maskedTextBox = new MaskedTextBox();
- buttonAddTank = 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
@@ -59,13 +68,81 @@
groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right;
- groupBoxTools.Location = new Point(931, 0);
+ groupBoxTools.Location = new Point(931, 28);
groupBoxTools.Name = "groupBoxTools";
- groupBoxTools.Size = new Size(218, 687);
+ groupBoxTools.Size = new Size(218, 659);
groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
+ // panelCompanyTools
+ //
+ panelCompanyTools.Controls.Add(buttonDelTank);
+ panelCompanyTools.Controls.Add(buttonRefresh);
+ panelCompanyTools.Controls.Add(maskedTextBox);
+ panelCompanyTools.Controls.Add(buttonAddTank);
+ panelCompanyTools.Controls.Add(buttonGoToCheck);
+ panelCompanyTools.Dock = DockStyle.Bottom;
+ panelCompanyTools.Enabled = false;
+ panelCompanyTools.Location = new Point(3, 379);
+ panelCompanyTools.Name = "panelCompanyTools";
+ panelCompanyTools.Size = new Size(212, 277);
+ panelCompanyTools.TabIndex = 9;
+ //
+ // buttonDelTank
+ //
+ buttonDelTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonDelTank.Location = new Point(3, 120);
+ buttonDelTank.Name = "buttonDelTank";
+ buttonDelTank.Size = new Size(203, 49);
+ buttonDelTank.TabIndex = 4;
+ buttonDelTank.Text = "Удалить танка ";
+ buttonDelTank.UseVisualStyleBackColor = true;
+ buttonDelTank.Click += ButtonDelTank_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(4, 225);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(202, 49);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBox.Location = new Point(4, 87);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(202, 27);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddTank
+ //
+ buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddTank.Location = new Point(3, 3);
+ buttonAddTank.Name = "buttonAddTank";
+ buttonAddTank.Size = new Size(205, 49);
+ buttonAddTank.TabIndex = 1;
+ buttonAddTank.Text = "Добавление бронированной машины";
+ buttonAddTank.UseVisualStyleBackColor = true;
+ buttonAddTank.Click += ButtonAddTank_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(3, 173);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(203, 49);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
// buttonCreateCompany
//
buttonCreateCompany.Location = new Point(6, 339);
@@ -158,62 +235,6 @@
labelCollectionName.TabIndex = 0;
labelCollectionName.Text = "Название коллекции:";
//
- // buttonRefresh
- //
- buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonRefresh.Location = new Point(4, 253);
- buttonRefresh.Name = "buttonRefresh";
- buttonRefresh.Size = new Size(202, 49);
- buttonRefresh.TabIndex = 6;
- buttonRefresh.Text = "Обновить";
- buttonRefresh.UseVisualStyleBackColor = true;
- buttonRefresh.Click += ButtonRefresh_Click;
- //
- // buttonGoToCheck
- //
- buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonGoToCheck.Location = new Point(3, 198);
- buttonGoToCheck.Name = "buttonGoToCheck";
- buttonGoToCheck.Size = new Size(203, 49);
- buttonGoToCheck.TabIndex = 5;
- buttonGoToCheck.Text = "Передать на тесты";
- buttonGoToCheck.UseVisualStyleBackColor = true;
- buttonGoToCheck.Click += ButtonGoToCheck_Click;
- //
- // buttonDelTank
- //
- buttonDelTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonDelTank.Location = new Point(3, 143);
- buttonDelTank.Name = "buttonDelTank";
- buttonDelTank.Size = new Size(203, 49);
- buttonDelTank.TabIndex = 4;
- buttonDelTank.Text = "Удалить танка ";
- buttonDelTank.UseVisualStyleBackColor = true;
- buttonDelTank.Click += ButtonDelTank_Click;
- //
- // maskedTextBox
- //
- maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- maskedTextBox.Location = new Point(4, 110);
- maskedTextBox.Mask = "00";
- maskedTextBox.Name = "maskedTextBox";
- maskedTextBox.Size = new Size(202, 27);
- maskedTextBox.TabIndex = 3;
- maskedTextBox.ValidatingType = typeof(int);
- //
-
- //
- // buttonAddTank
- //
- buttonAddTank.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
- buttonAddTank.Location = new Point(4, 0);
- buttonAddTank.Name = "buttonAddTank";
- buttonAddTank.Size = new Size(202, 49);
- buttonAddTank.TabIndex = 1;
- buttonAddTank.Text = "Добавление бронированной машины";
- buttonAddTank.UseVisualStyleBackColor = true;
- buttonAddTank.Click += ButtonAddTank_Click;
- //
// comboBoxSelectorCompany
//
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
@@ -229,25 +250,52 @@
// pictureBox
//
pictureBox.Dock = DockStyle.Fill;
- pictureBox.Location = new Point(0, 0);
+ pictureBox.Location = new Point(0, 28);
pictureBox.Name = "pictureBox";
- pictureBox.Size = new Size(931, 687);
+ pictureBox.Size = new Size(931, 659);
pictureBox.TabIndex = 1;
pictureBox.TabStop = false;
//
- // panelCompanyTools
+ // menuStrip
//
- panelCompanyTools.Controls.Add(buttonDelTank);
- panelCompanyTools.Controls.Add(buttonRefresh);
- panelCompanyTools.Controls.Add(maskedTextBox);
- panelCompanyTools.Controls.Add(buttonAddTank);
- panelCompanyTools.Controls.Add(buttonGoToCheck);
- panelCompanyTools.Dock = DockStyle.Bottom;
- panelCompanyTools.Enabled = false;
- panelCompanyTools.Location = new Point(3, 382);
- panelCompanyTools.Name = "panelCompanyTools";
- panelCompanyTools.Size = new Size(212, 302);
- panelCompanyTools.TabIndex = 9;
+ 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(1149, 28);
+ menuStrip.TabIndex = 6;
+ 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(227, 26);
+ saveToolStripMenuItem.Text = "Сохранение";
+ saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
+ //
+ // loadToolStripMenuItem
+ //
+ loadToolStripMenuItem.Name = "loadToolStripMenuItem";
+ loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
+ loadToolStripMenuItem.Size = new Size(227, 26);
+ loadToolStripMenuItem.Text = "Загрузка";
+ loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
+ //
+ // saveFileDialog
+ //
+ saveFileDialog.Filter = "txt file | *.txt";
+ //
+ // openFileDialog
+ //
+ openFileDialog.Filter = "txt file | *.txt";
//
// FormTankCollection
//
@@ -256,17 +304,24 @@
ClientSize = new Size(1149, 687);
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
private GroupBox groupBoxTools;
@@ -287,5 +342,11 @@
private ListBox listBoxCollection;
private Button buttonCollectionAdd;
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/ProjectTank/ProjectTank/FormTankCollection.cs b/ProjectTank/ProjectTank/FormTankCollection.cs
index 01c59c6..229f4d5 100644
--- a/ProjectTank/ProjectTank/FormTankCollection.cs
+++ b/ProjectTank/ProjectTank/FormTankCollection.cs
@@ -1,6 +1,5 @@
using ProjectTank.CollectionGenericObjects;
using ProjectTank.Drawnings;
-using System.Windows.Forms;
namespace ProjectTank;
@@ -35,7 +34,7 @@ public partial class FormTankCollection : Form
///
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{
- panelCompanyTools.Enabled = false;
+ panelCompanyTools.Enabled = false;
}
///
@@ -245,7 +244,53 @@ public partial class FormTankCollection : Form
_company = new TankBase(pictureBox.Width, pictureBox.Height, collection);
break;
}
- panelCompanyTools.Enabled = true;
+ panelCompanyTools.Enabled = true;
RerfreshListBoxItems();
}
-}
\ No newline at end of file
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ ///
+
+ 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)
+ {
+ // TODO продумать логику
+ 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/ProjectTank/ProjectTank/FormTankCollection.resx b/ProjectTank/ProjectTank/FormTankCollection.resx
index af32865..7fd4394 100644
--- a/ProjectTank/ProjectTank/FormTankCollection.resx
+++ b/ProjectTank/ProjectTank/FormTankCollection.resx
@@ -117,4 +117,16 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 145, 17
+
+
+ 302, 17
+
+
+ 25
+
\ No newline at end of file