Лабораторная работа №6
This commit is contained in:
parent
874486dd20
commit
21741e196c
@ -3,6 +3,7 @@ using ProjectAccordionBus.MovementStrategy;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -27,12 +28,16 @@ public abstract class AbstractCompany
|
|||||||
_pictureWidth = picWidth;
|
_pictureWidth = picWidth;
|
||||||
_pictureHeight = picHeigth;
|
_pictureHeight = picHeigth;
|
||||||
_collection = collection;
|
_collection = collection;
|
||||||
_collection.SetMaxCount = GetMaxCount;
|
_collection.MaxCount = GetMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int operator +(AbstractCompany company, DrawningBus bus)
|
public static int operator +(AbstractCompany company, DrawningBus bus)
|
||||||
{
|
{
|
||||||
return company._collection.Insert(bus);
|
if (company._collection.Insert(bus))
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DrawningBus operator -(AbstractCompany company, int position)
|
public static DrawningBus operator -(AbstractCompany company, int position)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using System;
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -21,21 +22,21 @@ public interface ICollectionGenericObjects<T>
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Установка максимального кол-ва объектов
|
/// Установка максимального кол-ва объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
int SetMaxCount { set; }
|
int MaxCount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллецию
|
/// Добавление объекта в коллецию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
int Insert(T obj);
|
bool Insert(T obj);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Добавление объекта в коллекцию
|
/// Добавление объекта в коллекцию
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj">Добавляемый объект</param>
|
/// <param name="obj">Добавляемый объект</param>
|
||||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||||
int Insert(T obj, int position);
|
bool Insert(T obj, int position);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Удаление объекта из коллекции с конкретной позиции
|
/// Удаление объекта из коллекции с конкретной позиции
|
||||||
@ -50,5 +51,16 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,11 +12,21 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
private readonly List<T> _collection;
|
private readonly List<T> _collection;
|
||||||
|
|
||||||
private int _maxCount;
|
private int _maxCount;
|
||||||
public int MaxCount => _maxCount;
|
public int MaxCount {
|
||||||
|
get => _maxCount;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value > 0)
|
||||||
|
{
|
||||||
|
_maxCount = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int Count => _collection.Count;
|
public int Count => _collection.Count;
|
||||||
|
|
||||||
public int SetMaxCount { set { if (value > 0) { _maxCount = value; } } }
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.List;
|
||||||
|
|
||||||
public ListGenericObjects()
|
public ListGenericObjects()
|
||||||
{
|
{
|
||||||
@ -30,26 +40,26 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public bool Insert(T obj)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount)
|
if (Count == _maxCount)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_collection.Add(obj);
|
_collection.Add(obj);
|
||||||
return _collection.Count;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public bool Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
if (Count == _maxCount || position < 0 || position > Count)
|
if (Count == _maxCount || position < 0 || position > Count)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_collection.Insert(position, obj);
|
_collection.Insert(position, obj);
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
@ -61,5 +71,11 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _collection[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,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)
|
||||||
@ -38,6 +42,8 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CollectionType GetCollectionType => CollectionType.Massive;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -56,7 +62,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
return _collection[position];
|
return _collection[position];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj)
|
public bool Insert(T obj)
|
||||||
{
|
{
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while (index < _collection.Length)
|
while (index < _collection.Length)
|
||||||
@ -64,18 +70,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
if (_collection[index] == null)
|
if (_collection[index] == null)
|
||||||
{
|
{
|
||||||
_collection[index] = obj;
|
_collection[index] = obj;
|
||||||
return index;
|
return true;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T obj, int position)
|
public bool Insert(T obj, int position)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (position >= _collection.Length || position < 0)
|
if (position >= _collection.Length || position < 0)
|
||||||
return -1;
|
return false;
|
||||||
|
|
||||||
|
|
||||||
if (_collection[position] != null)
|
if (_collection[position] != null)
|
||||||
@ -93,7 +99,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
// Если пустого элемента нет, то выходим
|
// Если пустого элемента нет, то выходим
|
||||||
if (nullIndex < 0)
|
if (nullIndex < 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
// сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
|
||||||
int j = nullIndex - 1;
|
int j = nullIndex - 1;
|
||||||
@ -104,7 +110,7 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_collection[position] = obj;
|
_collection[position] = obj;
|
||||||
return position;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Remove(int position)
|
public T? Remove(int position)
|
||||||
@ -117,5 +123,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
|||||||
_collection[position] = null;
|
_collection[position] = null;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<T?> GetItems()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _collection.Length; ++i)
|
||||||
|
{
|
||||||
|
yield return _collection[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using ProjectAccordionBus.Drawnings;
|
||||||
|
using ProjectAccordionBus.CollectionGenericObjects;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -7,7 +9,7 @@ using System.Threading.Tasks;
|
|||||||
namespace ProjectAccordionBus.CollectionGenericObjects;
|
namespace ProjectAccordionBus.CollectionGenericObjects;
|
||||||
|
|
||||||
public class StorageCollection<T>
|
public class StorageCollection<T>
|
||||||
where T : class
|
where T : DrawningBus
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Словарь (хранилище) с коллекциями
|
/// Словарь (хранилище) с коллекциями
|
||||||
@ -18,7 +20,21 @@ public class StorageCollection<T>
|
|||||||
/// Возвращение списка названий коллекций
|
/// Возвращение списка названий коллекций
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public List<string> Keys => _storages.Keys.ToList();
|
public List<string> Keys => _storages.Keys.ToList();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ключевое слово, с которого должен начинаться файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _collectionKey = "CollectionsStorage";
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записи ключа и значения элемента словаря
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _separatorForKeyValue = "|";
|
||||||
|
/// <summary>
|
||||||
|
/// Разделитель для записей коллекции данных в файл
|
||||||
|
/// </summary>
|
||||||
|
private readonly string _separatorItems = ";";
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -75,4 +91,122 @@ public class StorageCollection<T>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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?.CreateDrawningBus() is T bus)
|
||||||
|
{
|
||||||
|
if (!collection.Insert(bus))
|
||||||
|
{
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,14 @@ public class DrawningAccordionBus : DrawningBus
|
|||||||
EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor, compartment, entrance, windows);
|
EntityBus = new EntityAccordionBus(speed, weight, bodyColor, additionalColor, compartment, entrance, windows);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawningAccordionBus(EntityBus? entityBus)
|
||||||
|
{
|
||||||
|
if (entityBus != null)
|
||||||
|
{
|
||||||
|
EntityBus = entityBus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public override void DrawTransport(Graphics g)
|
public override void DrawTransport(Graphics g)
|
||||||
{
|
{
|
||||||
if (EntityBus == null || EntityBus is not EntityAccordionBus accordionBus || !_startPosX.HasValue || !_startPosY.HasValue)
|
if (EntityBus == null || EntityBus is not EntityAccordionBus accordionBus || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||||
|
@ -64,7 +64,7 @@ public class DrawningBus
|
|||||||
public int GetHight => _drawningBusHeight;
|
public int GetHight => _drawningBusHeight;
|
||||||
|
|
||||||
// Пустой конструктор
|
// Пустой конструктор
|
||||||
private DrawningBus()
|
public DrawningBus()
|
||||||
{
|
{
|
||||||
_pictureWidth = null;
|
_pictureWidth = null;
|
||||||
_pictureHeight = null;
|
_pictureHeight = null;
|
||||||
@ -85,6 +85,14 @@ public class DrawningBus
|
|||||||
_drawningBusHeight = drawningBusHeight;
|
_drawningBusHeight = drawningBusHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DrawningBus(EntityBus? entityBus)
|
||||||
|
{
|
||||||
|
if (entityBus != null)
|
||||||
|
{
|
||||||
|
EntityBus = entityBus;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool SetPictureSize(int width, int height)
|
public bool SetPictureSize(int width, int height)
|
||||||
{
|
{
|
||||||
if (_drawningBusWidth <= width && _drawningBusHeight <= height)
|
if (_drawningBusWidth <= width && _drawningBusHeight <= height)
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using ProjectAccordionBus.Entities;
|
||||||
|
|
||||||
|
namespace ProjectAccordionBus.Drawnings;
|
||||||
|
|
||||||
|
public static class ExtentionDrawningBus
|
||||||
|
{
|
||||||
|
private static readonly string _separatorForObject = ":";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из строки
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="info">Строка с данными для создания объекта</param>
|
||||||
|
/// <returns>Объект</returns>
|
||||||
|
public static DrawningBus? CreateDrawningBus(this string info)
|
||||||
|
{
|
||||||
|
string[] strs = info.Split(_separatorForObject);
|
||||||
|
EntityBus? bus = EntityAccordionBus.CreateEntityAccordionBus(strs);
|
||||||
|
if (bus != null)
|
||||||
|
{
|
||||||
|
return new DrawningAccordionBus(bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
bus = EntityBus.CreateEntityBus(strs);
|
||||||
|
if (bus != null)
|
||||||
|
{
|
||||||
|
return new DrawningBus(bus);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получение данных для сохранения в файл
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="drawningBus">Сохраняемый объект</param>
|
||||||
|
/// <returns>Строка с данными по объекту</returns>
|
||||||
|
public static string GetDataForSave(this DrawningBus drawningBus)
|
||||||
|
{
|
||||||
|
string[]? array = drawningBus?.EntityBus?.GetStringRepresentation();
|
||||||
|
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Join(_separatorForObject, array);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using static System.Reflection.Metadata.BlobBuilder;
|
||||||
|
|
||||||
namespace ProjectAccordionBus.Entities;
|
namespace ProjectAccordionBus.Entities;
|
||||||
|
|
||||||
@ -34,4 +36,20 @@ public class EntityAccordionBus : EntityBus
|
|||||||
Windows = windows;
|
Windows = windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new[] { nameof(EntityAccordionBus), Speed.ToString(), Weight.ToString(), BodyColor.Name,
|
||||||
|
AdditionalColor.Name, Compartment.ToString(), Entrance.ToString(), Windows.ToString() };
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EntityAccordionBus? CreateEntityAccordionBus(string[] strs)
|
||||||
|
{
|
||||||
|
if (strs.Length != 8 || strs[0] != nameof(EntityAccordionBus))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EntityAccordionBus(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]),
|
||||||
|
Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]), Convert.ToBoolean(strs[7]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,4 +31,25 @@ public class EntityBus
|
|||||||
Weight = weight;
|
Weight = weight;
|
||||||
BodyColor = bodyColor;
|
BodyColor = bodyColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual string[] GetStringRepresentation()
|
||||||
|
{
|
||||||
|
return new[] { nameof(EntityBus), Speed.ToString(), Weight.ToString(), BodyColor.Name};
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Создание объекта из массива строк
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="strs"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static EntityBus? CreateEntityBus(string[] strs)
|
||||||
|
{
|
||||||
|
if (strs.Length != 4 || strs[0] != nameof(EntityBus))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new EntityBus(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,17 @@
|
|||||||
comboBoxSelectorCompany = new ComboBox();
|
comboBoxSelectorCompany = new ComboBox();
|
||||||
labelCollectionName = new Label();
|
labelCollectionName = new Label();
|
||||||
pictureBox = new PictureBox();
|
pictureBox = new PictureBox();
|
||||||
|
menuStrip = new MenuStrip();
|
||||||
|
файлToolStripMenuItem = 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
|
||||||
@ -57,9 +64,9 @@
|
|||||||
groupBoxTools.Controls.Add(panelCompanyTools);
|
groupBoxTools.Controls.Add(panelCompanyTools);
|
||||||
groupBoxTools.Controls.Add(panelStorage);
|
groupBoxTools.Controls.Add(panelStorage);
|
||||||
groupBoxTools.Dock = DockStyle.Right;
|
groupBoxTools.Dock = DockStyle.Right;
|
||||||
groupBoxTools.Location = new Point(625, 0);
|
groupBoxTools.Location = new Point(625, 24);
|
||||||
groupBoxTools.Name = "groupBoxTools";
|
groupBoxTools.Name = "groupBoxTools";
|
||||||
groupBoxTools.Size = new Size(175, 510);
|
groupBoxTools.Size = new Size(175, 511);
|
||||||
groupBoxTools.TabIndex = 0;
|
groupBoxTools.TabIndex = 0;
|
||||||
groupBoxTools.TabStop = false;
|
groupBoxTools.TabStop = false;
|
||||||
groupBoxTools.Text = "Инструменты";
|
groupBoxTools.Text = "Инструменты";
|
||||||
@ -73,7 +80,7 @@
|
|||||||
panelCompanyTools.Controls.Add(buttonAddBus);
|
panelCompanyTools.Controls.Add(buttonAddBus);
|
||||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||||
panelCompanyTools.Enabled = false;
|
panelCompanyTools.Enabled = false;
|
||||||
panelCompanyTools.Location = new Point(3, 316);
|
panelCompanyTools.Location = new Point(3, 317);
|
||||||
panelCompanyTools.Name = "panelCompanyTools";
|
panelCompanyTools.Name = "panelCompanyTools";
|
||||||
panelCompanyTools.Size = new Size(169, 191);
|
panelCompanyTools.Size = new Size(169, 191);
|
||||||
panelCompanyTools.TabIndex = 10;
|
panelCompanyTools.TabIndex = 10;
|
||||||
@ -244,19 +251,62 @@
|
|||||||
// 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(625, 510);
|
pictureBox.Size = new Size(625, 511);
|
||||||
pictureBox.TabIndex = 4;
|
pictureBox.TabIndex = 4;
|
||||||
pictureBox.TabStop = false;
|
pictureBox.TabStop = false;
|
||||||
//
|
//
|
||||||
|
// menuStrip
|
||||||
|
//
|
||||||
|
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||||
|
menuStrip.Location = new Point(0, 0);
|
||||||
|
menuStrip.Name = "menuStrip";
|
||||||
|
menuStrip.Size = new Size(800, 24);
|
||||||
|
menuStrip.TabIndex = 5;
|
||||||
|
menuStrip.Text = "menuStrip";
|
||||||
|
//
|
||||||
|
// файл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 = "openFileDialog";
|
||||||
|
openFileDialog.Filter = "txt file | *.txt";
|
||||||
|
//
|
||||||
// FormBusCollection
|
// FormBusCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 510);
|
ClientSize = new Size(800, 535);
|
||||||
Controls.Add(pictureBox);
|
Controls.Add(pictureBox);
|
||||||
Controls.Add(groupBoxTools);
|
Controls.Add(groupBoxTools);
|
||||||
|
Controls.Add(menuStrip);
|
||||||
|
MainMenuStrip = menuStrip;
|
||||||
Name = "FormBusCollection";
|
Name = "FormBusCollection";
|
||||||
Text = "Коллекция автобусов";
|
Text = "Коллекция автобусов";
|
||||||
groupBoxTools.ResumeLayout(false);
|
groupBoxTools.ResumeLayout(false);
|
||||||
@ -265,7 +315,10 @@
|
|||||||
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
|
||||||
@ -288,5 +341,11 @@
|
|||||||
private Button buttonCollectionDel;
|
private Button buttonCollectionDel;
|
||||||
private Button buttonCreateCompany;
|
private Button buttonCreateCompany;
|
||||||
private Panel panelCompanyTools;
|
private Panel panelCompanyTools;
|
||||||
|
private MenuStrip menuStrip;
|
||||||
|
private ToolStripMenuItem файлToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem saveToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem loadToolStripMenuItem;
|
||||||
|
private SaveFileDialog saveFileDialog;
|
||||||
|
private OpenFileDialog openFileDialog;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -269,4 +269,35 @@ public partial class FormBusCollection : Form
|
|||||||
panelCompanyTools.Enabled = true;
|
panelCompanyTools.Enabled = true;
|
||||||
RefreshListBoxItems();
|
RefreshListBoxItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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…
Reference in New Issue
Block a user