PIBD-14 Boyko_M.S, LabWork06 Simple #7

Closed
LivelyPuer wants to merge 2 commits from lab6-develop into lab5-develop
12 changed files with 753 additions and 343 deletions

View File

@ -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>

View File

@ -1,6 +1,4 @@
using ProjectElectroTrans.Drawnings; namespace ProjectElectroTrans.CollectionGenericObjects;
namespace ProjectElectroTrans.CollectionGenericObjects;
/// <summary> /// <summary>
/// Интерфейс описания действий для набора хранимых объектов /// Интерфейс описания действий для набора хранимых объектов
@ -17,7 +15,7 @@ public interface ICollectionGenericObjects<T>
/// <summary> /// <summary>
/// Установка максимального количества элементов /// Установка максимального количества элементов
/// </summary> /// </summary>
int SetMaxCount { set; } int MaxCount { get; set; }
/// <summary> /// <summary>
/// Добавление объекта в коллекцию /// Добавление объекта в коллекцию
@ -39,7 +37,7 @@ public interface ICollectionGenericObjects<T>
/// </summary> /// </summary>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns> /// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
T? Remove(int position); T Remove(int position);
/// <summary> /// <summary>
/// Получение объекта по позиции /// Получение объекта по позиции
@ -47,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();
} }

View File

@ -11,13 +11,27 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
/// Список объектов, которые храним /// Список объектов, которые храним
/// </summary> /// </summary>
private readonly List<T?> _collection; private readonly List<T?> _collection;
/// <summary> /// <summary>
/// Максимально допустимое число объектов в списке /// Максимально допустимое число объектов в списке
/// </summary> /// </summary>
private int _maxCount; private int _maxCount;
public int Count => _collection.Count; 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;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
@ -27,43 +41,40 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
_collection = new(); _collection = new();
} }
public T? Get(int position) public T Get(int position)
{ {
if (position >= Count || position < 0) return null;
if (position < 0 || position > _collection.Count - 1)
{
return null;
}
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
if (_collection.Count + 1 > _maxCount) { return 0; } if (Count == _maxCount) return -1;
_collection.Add(obj); _collection.Add(obj);
return Count;
return 1;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
if (_collection.Count + 1 < _maxCount) { return 0; } if (Count == _maxCount) return -1;
if (position > _collection.Count || position < 0) if (position >= Count || position < 0) return -1;
{
return 0;
}
_collection.Insert(position, obj); _collection.Insert(position, obj);
return 1; return position;
} }
public T Remove(int position) public T Remove(int position)
{ {
if (position > _collection.Count || position < 0) if (position >= _collection.Count || position < 0) return null;
{ T obj = _collection[position];
return null;
}
T temp = _collection[position];
_collection.RemoveAt(position); _collection.RemoveAt(position);
return temp; return obj;
}
public IEnumerable<T?> GetItems()
{
for (int i = 0; i < Count; ++i)
{
yield return _collection[i];
}
} }
} }

View File

@ -1,6 +1,4 @@
using System.Runtime.Remoting; 
using ProjectElectroTrans.Drawnings;
namespace ProjectElectroTrans.CollectionGenericObjects; namespace ProjectElectroTrans.CollectionGenericObjects;
/// <summary> /// <summary>
@ -8,42 +6,48 @@ namespace ProjectElectroTrans.CollectionGenericObjects;
/// </summary> /// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam> /// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
{ {
/// <summary> /// <summary>
/// Массив объектов, которые храним /// Массив объектов, которые храним
/// </summary> /// </summary>
private T?[] _collection; private T?[] _collection;
public int Count => _collection.Length; public int Count => _collection.Length;
public int SetMaxCount public int MaxCount
{ {
set get
{ {
if (value > 0) return _collection.Length;
{ }
if (_collection.Length > 0) set
{ {
Array.Resize(ref _collection, value); if (value > 0)
} {
else if (_collection.Length > 0)
{ {
_collection = new T?[value]; Array.Resize(ref _collection, value);
} }
} else
} {
} _collection = new T?[value];
}
}
}
}
/// <summary> public CollectionType GetCollectionType => CollectionType.Massive;
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position) /// <summary>
/// Конструктор
/// </summary>
public MassiveGenericObjects()
{
_collection = Array.Empty<T?>();
}
public T? Get(int position)
{ {
if (position >= 0 && position < Count) if (position >= 0 && position < Count)
{ {
@ -130,4 +134,12 @@ 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];
}
}
} }

View File

@ -1,11 +1,15 @@
namespace ProjectElectroTrans.CollectionGenericObjects; using ProjectElectroTrans.Drawnings;
using System.Text;
using ProjectElectroTrans.CollectionGenericObjects;
namespace ProjectElectroTrans.CollectionGenericObjects;
/// <summary> /// <summary>
/// Класс-хранилище коллекций /// Класс-хранилище коллекций
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
public class StorageCollection<T> public class StorageCollection<T>
where T : class where T : DrawingTrans
{ {
/// <summary> /// <summary>
/// Словарь (хранилище) с коллекциями /// Словарь (хранилище) с коллекциями
@ -17,6 +21,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>
@ -32,20 +51,12 @@ 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 (name == null || _storages.ContainsKey(name)) { return; } if (_storages.ContainsKey(name)) return;
switch (collectionType) if (collectionType == CollectionType.None) return;
else if (collectionType == CollectionType.Massive)
{ _storages[name] = new MassiveGenericObjects<T>();
case CollectionType.None: else if (collectionType == CollectionType.List)
return; _storages[name] = new ListGenericObjects<T>();
case CollectionType.Massive:
_storages.Add(name, new MassiveGenericObjects<T> { });
return;
case CollectionType.List:
_storages.Add(name, new ListGenericObjects<T> { });
return;
}
} }
/// <summary> /// <summary>
@ -54,8 +65,8 @@ 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 || !_storages.ContainsKey(name)) { return; } if (_storages.ContainsKey(name))
_storages.Remove(name); _storages.Remove(name);
} }
/// <summary> /// <summary>
@ -67,8 +78,141 @@ public class StorageCollection<T>
{ {
get get
{ {
if (name == null || !_storages.ContainsKey(name)) { return null; } if (_storages.ContainsKey(name))
return _storages[name]; return _storages[name];
return null;
} }
} }
/// <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);
}
using (StreamWriter writer = new StreamWriter(filename))
{
writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
{
StringBuilder sb = new();
sb.Append(Environment.NewLine);
Review

Записывать в файл можно сразу, без использования StringBuilder

Записывать в файл можно сразу, без использования StringBuilder
// не сохраняем пустые коллекции
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;
}
/// <summary>
/// Загрузка информации по автомобилям в хранилище из файла
/// </summary>
/// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
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<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?.CreateDrawningTrans() 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,
};
}
} }

View File

@ -22,6 +22,15 @@ public class DrawingElectroTrans : DrawingTrans
{ {
EntityTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, horns, battery); EntityTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, horns, battery);
} }
public DrawingElectroTrans(EntityTrans trans) : base(110, 60)
{
if (trans != null && trans is EntityElectroTrans electroTrans)
{
EntityTrans = new EntityElectroTrans(electroTrans.Speed, electroTrans.Weight, electroTrans.BodyColor, electroTrans.AdditionalColor, electroTrans.Horns, electroTrans.Battery);
}
}
public override void DrawTransport(Graphics g) public override void DrawTransport(Graphics g)
{ {
if (EntityTrans == null || EntityTrans is not EntityElectroTrans electroTrans || if (EntityTrans == null || EntityTrans is not EntityElectroTrans electroTrans ||

View File

@ -76,6 +76,19 @@ public class DrawingTrans
{ {
EntityTrans = new EntityTrans(speed, weight, bodyColor); EntityTrans = new EntityTrans(speed, weight, bodyColor);
} }
/// <summary>
/// Конструктор
/// </summary>
/// <param name="car">Класс-сущность</param>
public DrawingTrans(EntityTrans trans) : this()
{
if (trans != null)
{
EntityTrans = new EntityTrans(trans.Speed, trans.Weight, trans.BodyColor);
}
}
/// <summary> /// <summary>
/// Конструктор для наследников /// Конструктор для наследников
/// </summary> /// </summary>

View File

@ -0,0 +1,53 @@
using ProjectElectroTrans.Drawnings;
using ProjectElectroTrans.Entities;
namespace ProjectElectroTrans;
public static class ExtentionDrawningTrans
{
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separatorForObject = ":";
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="info">Строка с данными для создания объекта</param>
/// <returns>Объект</returns>
public static DrawingTrans? CreateDrawningTrans(this string info)
{
string[] strs = info.Split(_separatorForObject);
EntityTrans? airplan = EntityElectroTrans.CreateEntityElectroTrans(strs);
if (airplan != null)
{
return new DrawingElectroTrans((EntityElectroTrans)airplan);
}
airplan = EntityTrans.CreateEntityTrans(strs);
if (airplan != null)
{
return new DrawingTrans(airplan);
}
return null;
}
/// <summary>
/// Получение данных для сохранения в файл
/// </summary>
/// <param name="DrawingTrans">Сохраняемый объект</param>
/// <returns>Строка с данными по объекту</returns>
public static string GetDataForSave(this DrawingTrans DrawingTrans)
{
string[]? array = DrawingTrans?.EntityTrans?.GetStringRepresentation();
if (array == null)
{
return string.Empty;
}
return string.Join(_separatorForObject, array);
}
}

View File

@ -48,4 +48,34 @@ internal class EntityElectroTrans : EntityTrans
Horns = horns; Horns = horns;
Battery = battery; Battery = battery;
} }
/// <summary>
/// Получение строк со значениями свойств объекта класса-сущности
/// </summary>
/// <returns></returns>
public override string[] GetStringRepresentation()
{
return new[]
{
nameof(EntityElectroTrans), Speed.ToString(),
Weight.ToString(), BodyColor.Name, AdditionalColor.Name, Horns.ToString(), Battery.ToString()
};
}
/// <summary>
/// Создание объекта из массива строк
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityTrans? CreateEntityElectroTrans(string[] strs)
{
if (strs.Length != 7 || strs[0] != nameof(EntityElectroTrans))
{
return null;
}
return new EntityElectroTrans(Convert.ToInt32(strs[1]),
Convert.ToDouble(strs[2]), Color.FromName(strs[3]),
Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[5]));
}
} }

View File

@ -44,4 +44,29 @@ public class EntityTrans
BodyColor = bodyColor; BodyColor = bodyColor;
} }
/// <summary>
/// Получение строк со значениями свойств объекта класса-сущности
/// </summary>
/// <returns></returns>
public virtual string[] GetStringRepresentation()
{
return new[] { nameof(EntityTrans), Speed.ToString(),
Weight.ToString(), BodyColor.Name };
}
/// <summary>
/// Создание объекта из массива строк
/// </summary>
/// <param name="strs"></param>
/// <returns></returns>
public static EntityTrans? CreateEntityTrans(string[] strs)
{
if (strs.Length != 4 || strs[0] != nameof(EntityTrans))
{
return null;
}
return new EntityTrans(Convert.ToInt32(strs[1]),
Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
}
} }

View File

@ -24,268 +24,327 @@ namespace ProjectElectroTrans
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
buttonCreateCompany = new Button(); panelCompanyTools = new Panel();
panelStorage = new Panel(); buttonAddCar = new Button();
buttonCollectionDel = new Button(); maskedTextBoxPosition = new MaskedTextBox();
listBoxCollection = new ListBox(); buttonRefresh = new Button();
buttonCollectionAdd = new Button(); buttonRemoveCar = new Button();
radioButtonList = new RadioButton(); buttonGoToCheck = new Button();
radioButtonMassive = new RadioButton(); buttonCreateCompany = new Button();
textBoxCollectionName = new TextBox(); panelStorage = new Panel();
labelCollectionName = new Label(); buttonCollectionDel = new Button();
buttonRefresh = new Button(); listBoxCollection = new ListBox();
buttonGoToCheck = new Button(); buttonCollectionAdd = new Button();
buttonRemoveTrans = new Button(); radioButtonList = new RadioButton();
maskedTextBoxPosition = new MaskedTextBox(); radioButtonMassive = new RadioButton();
buttonAddTrans = new Button(); textBoxCollectionName = new TextBox();
comboBoxSelectorCompany = new ComboBox(); labelCollectionName = new Label();
pictureBox = new PictureBox(); comboBoxSelectorCompany = new ComboBox();
panelCompanyTools = new Panel(); pictureBox = new PictureBox();
groupBoxTools.SuspendLayout(); menuStrip = new MenuStrip();
panelStorage.SuspendLayout(); файлToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); saveToolStripMenuItem = new ToolStripMenuItem();
panelCompanyTools.SuspendLayout(); loadToolStripMenuItem = new ToolStripMenuItem();
SuspendLayout(); saveFileDialog = new SaveFileDialog();
// openFileDialog = new OpenFileDialog();
// groupBoxTools groupBoxTools.SuspendLayout();
// panelCompanyTools.SuspendLayout();
groupBoxTools.Controls.Add(panelCompanyTools); panelStorage.SuspendLayout();
groupBoxTools.Controls.Add(buttonCreateCompany); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
groupBoxTools.Controls.Add(panelStorage); menuStrip.SuspendLayout();
groupBoxTools.Controls.Add(comboBoxSelectorCompany); SuspendLayout();
groupBoxTools.Dock = DockStyle.Right; //
groupBoxTools.Location = new Point(783, 0); // groupBoxTools
groupBoxTools.Name = "groupBoxTools"; //
groupBoxTools.Size = new Size(179, 616); groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.TabIndex = 0; groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.TabStop = false; groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Text = "Инструменты"; groupBoxTools.Controls.Add(comboBoxSelectorCompany);
// groupBoxTools.Dock = DockStyle.Right;
// buttonCreateCompany groupBoxTools.Location = new Point(783, 24);
// groupBoxTools.Name = "groupBoxTools";
buttonCreateCompany.Location = new Point(6, 320); groupBoxTools.Size = new Size(179, 608);
buttonCreateCompany.Name = "buttonCreateCompany"; groupBoxTools.TabIndex = 0;
buttonCreateCompany.Size = new Size(167, 23); groupBoxTools.TabStop = false;
buttonCreateCompany.TabIndex = 8; groupBoxTools.Text = "Инструменты";
buttonCreateCompany.Text = "Создать компанию"; //
buttonCreateCompany.UseVisualStyleBackColor = true; // panelCompanyTools
buttonCreateCompany.Click += ButtonCreateCompany_Click; //
// panelCompanyTools.Controls.Add(buttonAddCar);
// panelStorage panelCompanyTools.Controls.Add(maskedTextBoxPosition);
// panelCompanyTools.Controls.Add(buttonRefresh);
panelStorage.Controls.Add(buttonCollectionDel); panelCompanyTools.Controls.Add(buttonRemoveCar);
panelStorage.Controls.Add(listBoxCollection); panelCompanyTools.Controls.Add(buttonGoToCheck);
panelStorage.Controls.Add(buttonCollectionAdd); panelCompanyTools.Dock = DockStyle.Bottom;
panelStorage.Controls.Add(radioButtonList); panelCompanyTools.Enabled = false;
panelStorage.Controls.Add(radioButtonMassive); panelCompanyTools.Location = new Point(3, 352);
panelStorage.Controls.Add(textBoxCollectionName); panelCompanyTools.Name = "panelCompanyTools";
panelStorage.Controls.Add(labelCollectionName); panelCompanyTools.Size = new Size(173, 253);
panelStorage.Dock = DockStyle.Top; panelCompanyTools.TabIndex = 9;
panelStorage.Location = new Point(3, 19); //
panelStorage.Name = "panelStorage"; // buttonAddCar
panelStorage.Size = new Size(173, 266); //
panelStorage.TabIndex = 7; buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
// buttonAddCar.Location = new Point(3, 3);
// buttonCollectionDel buttonAddCar.Name = "buttonAddCar";
// buttonAddCar.Size = new Size(167, 40);
buttonCollectionDel.Location = new Point(3, 227); buttonAddCar.TabIndex = 1;
buttonCollectionDel.Name = "buttonCollectionDel"; buttonAddCar.Text = "Добавление автомобиля";
buttonCollectionDel.Size = new Size(167, 23); buttonAddCar.UseVisualStyleBackColor = true;
buttonCollectionDel.TabIndex = 6; buttonAddCar.Click += ButtonAddTrans_Click;
buttonCollectionDel.Text = "Удалить коллекцию"; //
buttonCollectionDel.UseVisualStyleBackColor = true; // maskedTextBoxPosition
buttonCollectionDel.Click += ButtonCollectionDel_Click; //
// maskedTextBoxPosition.Location = new Point(3, 95);
// listBoxCollection maskedTextBoxPosition.Mask = "00";
// maskedTextBoxPosition.Name = "maskedTextBoxPosition";
listBoxCollection.FormattingEnabled = true; maskedTextBoxPosition.Size = new Size(167, 23);
listBoxCollection.ItemHeight = 15; maskedTextBoxPosition.TabIndex = 3;
listBoxCollection.Location = new Point(3, 112); maskedTextBoxPosition.ValidatingType = typeof(int);
listBoxCollection.Name = "listBoxCollection"; //
listBoxCollection.Size = new Size(167, 109); // buttonRefresh
listBoxCollection.TabIndex = 5; //
// buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
// buttonCollectionAdd buttonRefresh.Location = new Point(3, 210);
// buttonRefresh.Name = "buttonRefresh";
buttonCollectionAdd.Location = new Point(3, 83); buttonRefresh.Size = new Size(167, 40);
buttonCollectionAdd.Name = "buttonCollectionAdd"; buttonRefresh.TabIndex = 6;
buttonCollectionAdd.Size = new Size(167, 23); buttonRefresh.Text = "Обновить";
buttonCollectionAdd.TabIndex = 4; buttonRefresh.UseVisualStyleBackColor = true;
buttonCollectionAdd.Text = "Добавить коллекцию"; buttonRefresh.Click += ButtonRefresh_Click;
buttonCollectionAdd.UseVisualStyleBackColor = true; //
buttonCollectionAdd.Click += ButtonCollectionAdd_Click; // buttonRemoveCar
// //
// radioButtonList buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
// buttonRemoveCar.Location = new Point(3, 124);
radioButtonList.AutoSize = true; buttonRemoveCar.Name = "buttonRemoveCar";
radioButtonList.Location = new Point(98, 58); buttonRemoveCar.Size = new Size(167, 40);
radioButtonList.Name = "radioButtonList"; buttonRemoveCar.TabIndex = 4;
radioButtonList.Size = new Size(66, 19); buttonRemoveCar.Text = "Удалить автомобиль";
radioButtonList.TabIndex = 3; buttonRemoveCar.UseVisualStyleBackColor = true;
radioButtonList.TabStop = true; buttonRemoveCar.Click += ButtonRemoveTrans_Click;
radioButtonList.Text = "Список"; //
radioButtonList.UseVisualStyleBackColor = true; // buttonGoToCheck
// //
// radioButtonMassive buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
// buttonGoToCheck.Location = new Point(3, 170);
radioButtonMassive.AutoSize = true; buttonGoToCheck.Name = "buttonGoToCheck";
radioButtonMassive.Location = new Point(16, 58); buttonGoToCheck.Size = new Size(167, 40);
radioButtonMassive.Name = "radioButtonMassive"; buttonGoToCheck.TabIndex = 5;
radioButtonMassive.Size = new Size(67, 19); buttonGoToCheck.Text = "Передать на тесты";
radioButtonMassive.TabIndex = 2; buttonGoToCheck.UseVisualStyleBackColor = true;
radioButtonMassive.TabStop = true; buttonGoToCheck.Click += ButtonGoToCheck_Click;
radioButtonMassive.Text = "Массив"; //
radioButtonMassive.UseVisualStyleBackColor = true; // buttonCreateCompany
// //
// textBoxCollectionName buttonCreateCompany.Location = new Point(6, 320);
// buttonCreateCompany.Name = "buttonCreateCompany";
textBoxCollectionName.Location = new Point(3, 29); buttonCreateCompany.Size = new Size(167, 23);
textBoxCollectionName.Name = "textBoxCollectionName"; buttonCreateCompany.TabIndex = 8;
textBoxCollectionName.Size = new Size(167, 23); buttonCreateCompany.Text = "Создать компанию";
textBoxCollectionName.TabIndex = 1; buttonCreateCompany.UseVisualStyleBackColor = true;
// buttonCreateCompany.Click += ButtonCreateCompany_Click;
// labelCollectionName //
// // panelStorage
labelCollectionName.AutoSize = true; //
labelCollectionName.Location = new Point(26, 11); panelStorage.Controls.Add(buttonCollectionDel);
labelCollectionName.Name = "labelCollectionName"; panelStorage.Controls.Add(listBoxCollection);
labelCollectionName.Size = new Size(125, 15); panelStorage.Controls.Add(buttonCollectionAdd);
labelCollectionName.TabIndex = 0; panelStorage.Controls.Add(radioButtonList);
labelCollectionName.Text = "Название коллекции:"; panelStorage.Controls.Add(radioButtonMassive);
// panelStorage.Controls.Add(textBoxCollectionName);
// buttonRefresh panelStorage.Controls.Add(labelCollectionName);
// panelStorage.Dock = DockStyle.Top;
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelStorage.Location = new Point(3, 19);
buttonRefresh.Location = new Point(3, 210); panelStorage.Name = "panelStorage";
buttonRefresh.Name = "buttonRefresh"; panelStorage.Size = new Size(173, 266);
buttonRefresh.Size = new Size(167, 40); panelStorage.TabIndex = 7;
buttonRefresh.TabIndex = 6; //
buttonRefresh.Text = "Обновить"; // buttonCollectionDel
buttonRefresh.UseVisualStyleBackColor = true; //
buttonRefresh.Click += ButtonRefresh_Click; buttonCollectionDel.Location = new Point(3, 227);
// buttonCollectionDel.Name = "buttonCollectionDel";
// buttonGoToCheck buttonCollectionDel.Size = new Size(167, 23);
// buttonCollectionDel.TabIndex = 6;
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonCollectionDel.Text = "Удалить коллекцию";
buttonGoToCheck.Location = new Point(3, 170); buttonCollectionDel.UseVisualStyleBackColor = true;
buttonGoToCheck.Name = "buttonGoToCheck"; buttonCollectionDel.Click += ButtonCollectionDel_Click;
buttonGoToCheck.Size = new Size(167, 40); //
buttonGoToCheck.TabIndex = 5; // listBoxCollection
buttonGoToCheck.Text = "Передать на тесты"; //
buttonGoToCheck.UseVisualStyleBackColor = true; listBoxCollection.FormattingEnabled = true;
buttonGoToCheck.Click += ButtonGoToCheck_Click; listBoxCollection.ItemHeight = 15;
// listBoxCollection.Location = new Point(3, 112);
// buttonRemoveTrans listBoxCollection.Name = "listBoxCollection";
// listBoxCollection.Size = new Size(167, 109);
buttonRemoveTrans.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; listBoxCollection.TabIndex = 5;
buttonRemoveTrans.Location = new Point(3, 124); //
buttonRemoveTrans.Name = "buttonRemoveTrans"; // buttonCollectionAdd
buttonRemoveTrans.Size = new Size(167, 40); //
buttonRemoveTrans.TabIndex = 4; buttonCollectionAdd.Location = new Point(3, 83);
buttonRemoveTrans.Text = "Удалить поезд"; buttonCollectionAdd.Name = "buttonCollectionAdd";
buttonRemoveTrans.UseVisualStyleBackColor = true; buttonCollectionAdd.Size = new Size(167, 23);
buttonRemoveTrans.Click += ButtonRemoveTrans_Click; buttonCollectionAdd.TabIndex = 4;
// buttonCollectionAdd.Text = "Добавить коллекцию";
// maskedTextBoxPosition buttonCollectionAdd.UseVisualStyleBackColor = true;
// buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
maskedTextBoxPosition.Location = new Point(3, 95); //
maskedTextBoxPosition.Mask = "00"; // radioButtonList
maskedTextBoxPosition.Name = "maskedTextBoxPosition"; //
maskedTextBoxPosition.Size = new Size(167, 23); radioButtonList.AutoSize = true;
maskedTextBoxPosition.TabIndex = 3; radioButtonList.Location = new Point(98, 58);
maskedTextBoxPosition.ValidatingType = typeof(int); radioButtonList.Name = "radioButtonList";
// buttonAddTrans radioButtonList.Size = new Size(66, 19);
// radioButtonList.TabIndex = 3;
buttonAddTrans.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; radioButtonList.TabStop = true;
buttonAddTrans.Location = new Point(3, 3); radioButtonList.Text = "Список";
buttonAddTrans.Name = "buttonAddTrans"; radioButtonList.UseVisualStyleBackColor = true;
buttonAddTrans.Size = new Size(167, 40); //
buttonAddTrans.TabIndex = 1; // radioButtonMassive
buttonAddTrans.Text = "Добавление поезд"; //
buttonAddTrans.UseVisualStyleBackColor = true; radioButtonMassive.AutoSize = true;
buttonAddTrans.Click += ButtonAddTrans_Click; radioButtonMassive.Location = new Point(16, 58);
// radioButtonMassive.Name = "radioButtonMassive";
// comboBoxSelectorCompany radioButtonMassive.Size = new Size(67, 19);
// radioButtonMassive.TabIndex = 2;
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; radioButtonMassive.TabStop = true;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; radioButtonMassive.Text = "Массив";
comboBoxSelectorCompany.FormattingEnabled = true; radioButtonMassive.UseVisualStyleBackColor = true;
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); //
comboBoxSelectorCompany.Location = new Point(6, 291); // textBoxCollectionName
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; //
comboBoxSelectorCompany.Size = new Size(167, 23); textBoxCollectionName.Location = new Point(3, 29);
comboBoxSelectorCompany.TabIndex = 0; textBoxCollectionName.Name = "textBoxCollectionName";
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; textBoxCollectionName.Size = new Size(167, 23);
// textBoxCollectionName.TabIndex = 1;
// pictureBox //
// // labelCollectionName
pictureBox.Dock = DockStyle.Fill; //
pictureBox.Location = new Point(0, 0); labelCollectionName.AutoSize = true;
pictureBox.Name = "pictureBox"; labelCollectionName.Location = new Point(26, 11);
pictureBox.Size = new Size(783, 616); labelCollectionName.Name = "labelCollectionName";
pictureBox.TabIndex = 1; labelCollectionName.Size = new Size(125, 15);
pictureBox.TabStop = false; labelCollectionName.TabIndex = 0;
// labelCollectionName.Text = "Название коллекции:";
// panelCompanyTools //
// // comboBoxSelectorCompany
panelCompanyTools.Controls.Add(buttonAddTrans); //
panelCompanyTools.Controls.Add(maskedTextBoxPosition); comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
panelCompanyTools.Controls.Add(buttonRefresh); comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
panelCompanyTools.Controls.Add(buttonRemoveTrans); comboBoxSelectorCompany.FormattingEnabled = true;
panelCompanyTools.Controls.Add(buttonGoToCheck); comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
panelCompanyTools.Dock = DockStyle.Bottom; comboBoxSelectorCompany.Location = new Point(6, 291);
panelCompanyTools.Enabled = false; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
panelCompanyTools.Location = new Point(3, 360); comboBoxSelectorCompany.Size = new Size(167, 23);
panelCompanyTools.Name = "panelCompanyTools"; comboBoxSelectorCompany.TabIndex = 0;
panelCompanyTools.Size = new Size(173, 253); comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
panelCompanyTools.TabIndex = 9; //
// // pictureBox
// FormTransCollection //
// pictureBox.Dock = DockStyle.Fill;
AutoScaleDimensions = new SizeF(7F, 15F); pictureBox.Location = new Point(0, 24);
AutoScaleMode = AutoScaleMode.Font; pictureBox.Name = "pictureBox";
ClientSize = new Size(962, 616); pictureBox.Size = new Size(783, 608);
Controls.Add(pictureBox); pictureBox.TabIndex = 1;
Controls.Add(groupBoxTools); pictureBox.TabStop = false;
Name = "FormTransCollection"; //
Text = "Коллекция поездов"; // menuStrip
groupBoxTools.ResumeLayout(false); //
panelStorage.ResumeLayout(false); menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
panelStorage.PerformLayout(); menuStrip.Location = new Point(0, 0);
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); menuStrip.Name = "menuStrip";
panelCompanyTools.ResumeLayout(false); menuStrip.Size = new Size(962, 24);
panelCompanyTools.PerformLayout(); menuStrip.TabIndex = 2;
ResumeLayout(false); 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.Filter = "txt file | *.txt";
//
// FormCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(962, 632);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormCarCollection";
Text = "Коллекция автомобилей";
groupBoxTools.ResumeLayout(false);
panelCompanyTools.ResumeLayout(false);
panelCompanyTools.PerformLayout();
panelStorage.ResumeLayout(false);
panelStorage.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
menuStrip.ResumeLayout(false);
menuStrip.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
private ComboBox comboBoxSelectorCompany; private ComboBox comboBoxSelectorCompany;
private Button buttonAddTrans; private Button buttonAddCar;
private Button buttonRemoveTrans; private Button buttonRemoveCar;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private PictureBox pictureBox; private PictureBox pictureBox;
private Button buttonGoToCheck; private Button buttonGoToCheck;
private Button buttonRefresh; private Button buttonRefresh;
private Panel panelStorage; private Panel panelStorage;
private Label labelCollectionName; private Label labelCollectionName;
private TextBox textBoxCollectionName; private TextBox textBoxCollectionName;
private RadioButton radioButtonList; private RadioButton radioButtonList;
private RadioButton radioButtonMassive; private RadioButton radioButtonMassive;
private Button buttonCollectionAdd; private Button buttonCollectionAdd;
private ListBox listBoxCollection; private ListBox listBoxCollection;
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;
} }
} }

View File

@ -253,4 +253,49 @@ public partial class FormTransCollection : Form
panelCompanyTools.Enabled = true; panelCompanyTools.Enabled = true;
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
/// <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))
{
MessageBox.Show("Загрузка прошла успешно",
"Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
RerfreshListBoxItems();
}
else
{
MessageBox.Show("Не загружено", "Результат",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
} }