Лабораторная работа №6
This commit is contained in:
parent
74a2fe9de4
commit
85bb53b062
@ -48,7 +48,7 @@ public abstract class AbstractCompany
|
|||||||
_pictureWidth = picWidth;
|
_pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeight;
|
_pictureHeight = picHeight;
|
||||||
_collection = collection;
|
_collection = collection;
|
||||||
_collection.SetMaxCount = GetMaxCount;
|
_collection.MaxCount = GetMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -15,7 +15,7 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка максимального количества элементов
|
/// Установка максимального количества элементов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int SetMaxCount { set; }
|
int MaxCount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию
|
/// Добавление объекта в коллекцию
|
||||||
@ -45,4 +45,15 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns>Объект</returns>
|
/// <returns>Объект</returns>
|
||||||
T? Get(int position);
|
T? Get(int position);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение типа коллекции
|
||||||
|
/// </summary>
|
||||||
|
CollectionType GetCollectionType { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение объектов коллекции по одному
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||||
|
IEnumerable<T?> GetItems();
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
namespace ProjectLiner.CollectionGenericObjects;
|
|
||||||
|
namespace ProjectLiner.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Параметризованный набор объектов
|
/// Параметризованный набор объектов
|
||||||
@ -19,7 +20,19 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public int Count => _collection.Count;
|
public int Count => _collection.Count;
|
||||||
|
|
||||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
public int MaxCount {
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _maxCount;
|
||||||
|
}
|
||||||
|
set {
|
||||||
|
if (value > 0) {
|
||||||
|
_maxCount = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.List;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -63,4 +76,12 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
_collection.RemoveAt(position);
|
_collection.RemoveAt(position);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _collection[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace ProjectLiner.CollectionGenericObjects;
|
namespace ProjectLiner.CollectionGenericObjects;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -15,8 +16,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
|
|
||||||
public int Count => _collection.Length;
|
public int Count => _collection.Length;
|
||||||
|
|
||||||
public int SetMaxCount
|
public int MaxCount
|
||||||
{
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _collection.Length;
|
||||||
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value > 0)
|
if (value > 0)
|
||||||
@ -33,6 +38,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -98,4 +105,12 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Length; ++i)
|
||||||
|
{
|
||||||
|
yield return _collection[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,4 +1,7 @@
|
|||||||
namespace ProjectLiner.CollectionGenericObjects;
|
using ProjectLiner.Drawnings;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace ProjectLiner.CollectionGenericObjects;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -6,24 +9,39 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class StorageCollection<T>
|
public class StorageCollection<T>
|
||||||
where T : class
|
where T : DrawningShip
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ключевое слово, с которого должен начинаться файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _collectionKey = "CollectionsStorage";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _separatorForKeyValue = "|";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _separatorItems = ";";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище) с коллекциями
|
/// Словарь (хранилище) с коллекциями
|
||||||
/// </summary>
|
/// </summary>
|
||||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storage;
|
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Возвращение списка названий коллекций
|
/// Возвращение списка названий коллекций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Keys => _storage.Keys.ToList();
|
public List<string> Keys => _storages.Keys.ToList();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public StorageCollection()
|
public StorageCollection()
|
||||||
{
|
{
|
||||||
_storage = new Dictionary<string, ICollectionGenericObjects<T>>();
|
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -33,7 +51,7 @@ public class StorageCollection<T>
|
|||||||
/// <param name="collectionType">тип коллекции</param>
|
/// <param name="collectionType">тип коллекции</param>
|
||||||
public void AddCollection(string name, CollectionType collectionType)
|
public void AddCollection(string name, CollectionType collectionType)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(name) || _storage.ContainsKey(name))
|
if (string.IsNullOrEmpty(name) || _storages.ContainsKey(name))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -43,11 +61,11 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
if (collectionType == CollectionType.Massive)
|
if (collectionType == CollectionType.Massive)
|
||||||
{
|
{
|
||||||
_storage[name] = new MassiveGenericObjects<T>();
|
_storages[name] = new MassiveGenericObjects<T>();
|
||||||
}
|
}
|
||||||
else if (collectionType == CollectionType.List)
|
else if (collectionType == CollectionType.List)
|
||||||
{
|
{
|
||||||
_storage[name] = new ListGenericObjects<T>();
|
_storages[name] = new ListGenericObjects<T>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,11 +75,11 @@ public class StorageCollection<T>
|
|||||||
/// <param name="name">Название коллекции</param>
|
/// <param name="name">Название коллекции</param>
|
||||||
public void DelCollection(string name)
|
public void DelCollection(string name)
|
||||||
{
|
{
|
||||||
if (name == null || !_storage.ContainsKey(name))
|
if (name == null || !_storages.ContainsKey(name))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_storage.Remove(name);
|
_storages.Remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -73,9 +91,9 @@ public class StorageCollection<T>
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_storage.ContainsKey(name))
|
if (_storages.ContainsKey(name))
|
||||||
{
|
{
|
||||||
return _storage[name];
|
return _storages[name];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -83,4 +101,153 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранение информации по кораблям в хранилище в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
|
||||||
|
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<string, ICollectionGenericObjects<T>> 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(_separatorItems);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
using FileStream fs = new(filename, FileMode.Create);
|
||||||
|
byte[] info = new UTF8Encoding(true).GetBytes(sb.ToString());
|
||||||
|
fs.Write(info, 0, info.Length);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Загрузка информации по кораблям в хранилище из файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="filename">Путь и имя файла</param>
|
||||||
|
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
|
||||||
|
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(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 == null || strs.Length == 0)
|
||||||
|
{
|
||||||
|
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<T>? collection = StorageCollection<T>.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?.CreateDrawningShip() is T ship)
|
||||||
|
{
|
||||||
|
if (collection.Insert(ship) == -1)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_storages.Add(record[0], collection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание коллекции по типу
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="collectionType"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType)
|
||||||
|
{
|
||||||
|
return collectionType switch
|
||||||
|
{
|
||||||
|
CollectionType.Massive => new MassiveGenericObjects<T>(),
|
||||||
|
CollectionType.List => new ListGenericObjects<T>(),
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,16 @@ public class DrawningLiner : DrawningShip
|
|||||||
EntityShip = new EntityLiner(speed, weight, bodyColor, additionalColor, secondDeck, pool);
|
EntityShip = new EntityLiner(speed, weight, bodyColor, additionalColor, secondDeck, pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор принимающий сущность
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ship">Объект класса-сущность</param>
|
||||||
|
public DrawningLiner(EntityShip entityShip) : base()
|
||||||
|
{
|
||||||
|
EntityShip = entityShip;
|
||||||
|
}
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityShip == null || EntityShip is not EntityLiner Liner || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityShip == null || EntityShip is not EntityLiner Liner || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
@ -29,7 +39,6 @@ public class DrawningLiner : DrawningShip
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pen pen = new(Color.Black, 2);
|
Pen pen = new(Color.Black, 2);
|
||||||
Brush br = new SolidBrush(Liner.BodyColor);
|
|
||||||
Brush additionalBrush = new SolidBrush(Liner.AdditionalColor);
|
Brush additionalBrush = new SolidBrush(Liner.AdditionalColor);
|
||||||
|
|
||||||
// Вторая палуба
|
// Вторая палуба
|
||||||
|
@ -65,7 +65,7 @@ public class DrawningShip
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Пустой конструктор
|
/// Пустой конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private DrawningShip()
|
protected DrawningShip()
|
||||||
{
|
{
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
@ -84,6 +84,15 @@ public class DrawningShip
|
|||||||
EntityShip = new EntityShip(speed, weight, bodyColor);
|
EntityShip = new EntityShip(speed, weight, bodyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор принимающий сущность
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ship">Объект класса-сущность</param>
|
||||||
|
public DrawningShip(EntityShip entityShip) : base()
|
||||||
|
{
|
||||||
|
EntityShip = entityShip;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор для наследников
|
/// Конструктор для наследников
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
50
ProjectLiner/ProjectLiner/Drawnings/ExtentionDrawningShip.cs
Normal file
50
ProjectLiner/ProjectLiner/Drawnings/ExtentionDrawningShip.cs
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
using ProjectLiner.Entities;
|
||||||
|
|
||||||
|
namespace ProjectLiner.Drawnings;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Расширение для класса EntityShip
|
||||||
|
/// </summary>
|
||||||
|
public static class ExtentionDrawningShip
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи информации по объекту в файл
|
||||||
|
/// </summary>
|
||||||
|
private static readonly string _separatorForObject = ":";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawningShip? CreateDrawningShip(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
EntityShip? ship = EntityLiner.CreateEntityLiner(strs);
|
||||||
|
if (ship != null)
|
||||||
|
{
|
||||||
|
return new DrawningLiner(ship);
|
||||||
|
}
|
||||||
|
ship = EntityShip.CreateEntityShip(strs);
|
||||||
|
if (ship != null)
|
||||||
|
{
|
||||||
|
return new DrawningShip(ship);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningShip">Сохраняемый объект</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawningShip drawningShip)
|
||||||
|
{
|
||||||
|
string[]? array = drawningShip?.EntityShip?.GetStringRepresentation();
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
return string.Join(_separatorForObject, array);
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,6 @@
|
|||||||
namespace ProjectLiner.Entities;
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace ProjectLiner.Entities;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Класс-сущность "Лайнер"
|
/// Класс-сущность "Лайнер"
|
||||||
@ -39,4 +41,28 @@ public class EntityLiner : EntityShip
|
|||||||
{
|
{
|
||||||
AdditionalColor = color;
|
AdditionalColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение строк со значениями свойств объекта класса-сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public override string[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new[] { nameof(EntityLiner), Speed.ToString(), Weight.ToString(), BodyColor.Name, AdditionalColor.Name, SecondDeck.ToString(), Pool.ToString() };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из массива строк
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strs"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static EntityLiner? CreateEntityLiner(string[] strs)
|
||||||
|
{
|
||||||
|
if (strs.Length != 7 || strs[0] != nameof(EntityLiner))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new EntityLiner(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]),
|
||||||
|
Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||||
|
}
|
||||||
}
|
}
|
@ -42,4 +42,28 @@ public class EntityShip
|
|||||||
{
|
{
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение строк со значениями свойств объекта класса-сущности
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public virtual string[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new[] { nameof(EntityShip), Speed.ToString(), Weight.ToString(), BodyColor.Name };
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из массива строк
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strs"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static EntityShip? CreateEntityShip(string[] strs)
|
||||||
|
{
|
||||||
|
if (strs.Length != 4 || strs[0] != nameof(EntityShip))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new EntityShip(Convert.ToInt32(strs[1]),
|
||||||
|
Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||||||
|
}
|
||||||
}
|
}
|
@ -50,10 +50,17 @@ namespace ProjectLiner
|
|||||||
labelCollectionName = new Label();
|
labelCollectionName = new Label();
|
||||||
comboBoxSelectorCompany = new ComboBox();
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
pictureBox = new PictureBox();
|
pictureBox = new PictureBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
FileToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
saveToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||||
|
saveFileDialog = new SaveFileDialog();
|
||||||
|
openFileDialog = new OpenFileDialog();
|
||||||
groupBoxTools.SuspendLayout();
|
groupBoxTools.SuspendLayout();
|
||||||
panelCompanyTools.SuspendLayout();
|
panelCompanyTools.SuspendLayout();
|
||||||
panelStorage.SuspendLayout();
|
panelStorage.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||||
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// groupBoxTools
|
// groupBoxTools
|
||||||
@ -63,9 +70,9 @@ namespace ProjectLiner
|
|||||||
groupBoxTools.Controls.Add(panelStorage);
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(793, 0);
|
groupBoxTools.Location = new Point(793, 24);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(144, 571);
|
groupBoxTools.Size = new Size(144, 547);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
@ -81,7 +88,7 @@ namespace ProjectLiner
|
|||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(3, 321);
|
panelCompanyTools.Location = new Point(3, 321);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(138, 247);
|
panelCompanyTools.Size = new Size(138, 223);
|
||||||
panelCompanyTools.TabIndex = 10;
|
panelCompanyTools.TabIndex = 10;
|
||||||
//
|
//
|
||||||
// buttonAddShip
|
// buttonAddShip
|
||||||
@ -96,7 +103,7 @@ namespace ProjectLiner
|
|||||||
//
|
//
|
||||||
// buttonRefresh
|
// buttonRefresh
|
||||||
//
|
//
|
||||||
buttonRefresh.Location = new Point(3, 202);
|
buttonRefresh.Location = new Point(4, 172);
|
||||||
buttonRefresh.Name = "buttonRefresh";
|
buttonRefresh.Name = "buttonRefresh";
|
||||||
buttonRefresh.Size = new Size(126, 42);
|
buttonRefresh.Size = new Size(126, 42);
|
||||||
buttonRefresh.TabIndex = 6;
|
buttonRefresh.TabIndex = 6;
|
||||||
@ -106,7 +113,7 @@ namespace ProjectLiner
|
|||||||
//
|
//
|
||||||
// maskedTextBoxPosition
|
// maskedTextBoxPosition
|
||||||
//
|
//
|
||||||
maskedTextBoxPosition.Location = new Point(4, 101);
|
maskedTextBoxPosition.Location = new Point(4, 71);
|
||||||
maskedTextBoxPosition.Mask = "00";
|
maskedTextBoxPosition.Mask = "00";
|
||||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||||
maskedTextBoxPosition.Size = new Size(126, 23);
|
maskedTextBoxPosition.Size = new Size(126, 23);
|
||||||
@ -115,7 +122,7 @@ namespace ProjectLiner
|
|||||||
//
|
//
|
||||||
// buttonGoToCheck
|
// buttonGoToCheck
|
||||||
//
|
//
|
||||||
buttonGoToCheck.Location = new Point(4, 166);
|
buttonGoToCheck.Location = new Point(4, 136);
|
||||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||||
buttonGoToCheck.Size = new Size(126, 30);
|
buttonGoToCheck.Size = new Size(126, 30);
|
||||||
buttonGoToCheck.TabIndex = 5;
|
buttonGoToCheck.TabIndex = 5;
|
||||||
@ -125,7 +132,7 @@ namespace ProjectLiner
|
|||||||
//
|
//
|
||||||
// buttonRemoveShip
|
// buttonRemoveShip
|
||||||
//
|
//
|
||||||
buttonRemoveShip.Location = new Point(4, 130);
|
buttonRemoveShip.Location = new Point(4, 100);
|
||||||
buttonRemoveShip.Name = "buttonRemoveShip";
|
buttonRemoveShip.Name = "buttonRemoveShip";
|
||||||
buttonRemoveShip.Size = new Size(126, 30);
|
buttonRemoveShip.Size = new Size(126, 30);
|
||||||
buttonRemoveShip.TabIndex = 4;
|
buttonRemoveShip.TabIndex = 4;
|
||||||
@ -242,12 +249,52 @@ namespace ProjectLiner
|
|||||||
// pictureBox
|
// pictureBox
|
||||||
//
|
//
|
||||||
pictureBox.Dock = DockStyle.Fill;
|
pictureBox.Dock = DockStyle.Fill;
|
||||||
pictureBox.Location = new Point(0, 0);
|
pictureBox.Location = new Point(0, 24);
|
||||||
pictureBox.Name = "pictureBox";
|
pictureBox.Name = "pictureBox";
|
||||||
pictureBox.Size = new Size(793, 571);
|
pictureBox.Size = new Size(793, 547);
|
||||||
pictureBox.TabIndex = 1;
|
pictureBox.TabIndex = 1;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { FileToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(937, 24);
|
||||||
|
menuStrip.TabIndex = 0;
|
||||||
|
menuStrip.Text = "menuStrip";
|
||||||
|
//
|
||||||
|
// FileToolStripMenuItem
|
||||||
|
//
|
||||||
|
FileToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||||
|
FileToolStripMenuItem.Name = "FileToolStripMenuItem";
|
||||||
|
FileToolStripMenuItem.Size = new Size(48, 20);
|
||||||
|
FileToolStripMenuItem.Text = "Файл";
|
||||||
|
//
|
||||||
|
// saveToolStripMenuItem
|
||||||
|
//
|
||||||
|
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||||
|
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||||
|
saveToolStripMenuItem.Size = new Size(181, 22);
|
||||||
|
saveToolStripMenuItem.Text = "Сохранение";
|
||||||
|
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// loadToolStripMenuItem
|
||||||
|
//
|
||||||
|
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||||
|
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
|
||||||
|
loadToolStripMenuItem.Size = new Size(181, 22);
|
||||||
|
loadToolStripMenuItem.Text = "Загрузка";
|
||||||
|
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
|
||||||
|
//
|
||||||
|
// saveFileDialog
|
||||||
|
//
|
||||||
|
saveFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
|
// openFileDialog
|
||||||
|
//
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
// FormShipCollection
|
// FormShipCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
@ -255,6 +302,8 @@ namespace ProjectLiner
|
|||||||
ClientSize = new Size(937, 571);
|
ClientSize = new Size(937, 571);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
Name = "FormShipCollection";
|
Name = "FormShipCollection";
|
||||||
Text = "Коллекция кораблей";
|
Text = "Коллекция кораблей";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
@ -263,7 +312,10 @@ namespace ProjectLiner
|
|||||||
panelStorage.ResumeLayout(false);
|
panelStorage.ResumeLayout(false);
|
||||||
panelStorage.PerformLayout();
|
panelStorage.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||||
|
menuStrip.ResumeLayout(false);
|
||||||
|
menuStrip.PerformLayout();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -286,5 +338,11 @@ namespace ProjectLiner
|
|||||||
private Button buttonCollectionDel;
|
private Button buttonCollectionDel;
|
||||||
private Button buttonCreateCompany;
|
private Button buttonCreateCompany;
|
||||||
private Panel panelCompanyTools;
|
private Panel panelCompanyTools;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem FileToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem saveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,6 @@
|
|||||||
using ProjectLiner.CollectionGenericObjects;
|
using ProjectLiner.CollectionGenericObjects;
|
||||||
using ProjectLiner.Drawnings;
|
using ProjectLiner.Drawnings;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace ProjectLiner;
|
namespace ProjectLiner;
|
||||||
|
|
||||||
@ -77,7 +78,7 @@ public partial class FormShipCollection : Form
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
private void ButtonRemoveShip_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -235,4 +236,45 @@ public partial class FormShipCollection : Form
|
|||||||
panelCompanyTools.Enabled = true;
|
panelCompanyTools.Enabled = true;
|
||||||
RefreshListBoxItems();
|
RefreshListBoxItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка нажатия "Сохранение"
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Обработка кнопки загрузки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
if (_storageCollection.LoadData(openFileDialog.FileName))
|
||||||
|
{
|
||||||
|
RefreshListBoxItems();
|
||||||
|
MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show("Загрузка не выполнена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -117,4 +117,13 @@
|
|||||||
<resheader name="writer">
|
<resheader name="writer">
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
</resheader>
|
</resheader>
|
||||||
|
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>17, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="saveFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>126, 17</value>
|
||||||
|
</metadata>
|
||||||
|
<metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||||
|
<value>261, 17</value>
|
||||||
|
</metadata>
|
||||||
</root>
|
</root>
|
Loading…
x
Reference in New Issue
Block a user