PIBD-14 Boyko_M.S, LabWork08 Simple #10

Closed
LivelyPuer wants to merge 1 commits from lab8-develop into lab7-develop
15 changed files with 716 additions and 404 deletions

View File

@ -61,7 +61,8 @@ public abstract class AbstractCompany
/// <returns></returns> /// <returns></returns>
public static int operator +(AbstractCompany company, DrawingTrans trans) public static int operator +(AbstractCompany company, DrawingTrans trans)
{ {
return company._collection.Insert(trans); return company._collection?.Insert(trans, new DrawingTransEquitables()) ??
throw new DrawingEquitablesException();
} }
/// <summary> /// <summary>
@ -75,6 +76,13 @@ public abstract class AbstractCompany
return company._collection?.Remove(position); return company._collection?.Remove(position);
} }
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer">Сравнитель объектов</param>
public void Sort(IComparer<DrawingTrans?> comparer) =>
_collection?.CollectionSort(comparer);
/// <summary> /// <summary>
/// Получение случайного объекта из коллекции /// Получение случайного объекта из коллекции
/// </summary> /// </summary>

View File

@ -0,0 +1,82 @@
namespace ProjectElectroTrans.CollectionGenericObjects;
public class CollectionInfo : IEquatable<CollectionInfo>
{
/// <summary>
/// Название
/// </summary>
public string Name { get; private set; }
/// <summary>
/// Тип
/// </summary>
public CollectionType CollectionType { get; private set; }
/// <summary>
/// Описание
/// </summary>
public string Description { get; private set; }
/// <summary>
/// Разделитель для записи информации по объекту в файл
/// </summary>
private static readonly string _separator = "-";
/// <summary>
/// Конструктор
/// </summary>
/// <param name="name">Название</param>
/// <param name="collectionType">Тип</param>
/// <param name="description">Описание</param>
public CollectionInfo(string name, CollectionType collectionType, string
description)
{
Name = name;
CollectionType = collectionType;
Description = description;
}
/// <summary>
/// Создание объекта из строки
/// </summary>
/// <param name="data">Строка</param>
/// <returns>Объект или null</returns>
public static CollectionInfo? GetCollectionInfo(string data)
{
string[] strs = data.Split(_separator,
StringSplitOptions.RemoveEmptyEntries);
if (strs.Length < 1 || strs.Length > 3)
{
return null;
}
return new CollectionInfo(strs[0],
(CollectionType)Enum.Parse(typeof(CollectionType), strs[1]), strs.Length > 2 ? strs[2] : string.Empty);
}
public override string ToString()
{
return Name + _separator + CollectionType + _separator + Description;
}
public bool Equals(CollectionInfo? other)
{
return Name == other?.Name;
}
public override bool Equals(object? obj)
{
return Equals(obj as CollectionInfo);
}
public bool IsEmpty()
{
if (string.IsNullOrEmpty(Name) && CollectionType != CollectionType.None) return true;
return false;
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
}

View File

@ -22,7 +22,7 @@ public interface ICollectionGenericObjects<T>
/// </summary> /// </summary>
/// <param name="obj">Добавляемый объект</param> /// <param name="obj">Добавляемый объект</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns> /// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj); int Insert(T obj, IEqualityComparer<T?>? comparer = null);
/// <summary> /// <summary>
/// Добавление объекта в коллекцию на конкретную позицию /// Добавление объекта в коллекцию на конкретную позицию
@ -30,7 +30,7 @@ public interface ICollectionGenericObjects<T>
/// <param name="obj">Добавляемый объект</param> /// <param name="obj">Добавляемый объект</param>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns> /// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
int Insert(T obj, int position); int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
/// <summary> /// <summary>
/// Удаление объекта из коллекции с конкретной позиции /// Удаление объекта из коллекции с конкретной позиции
@ -56,4 +56,11 @@ public interface ICollectionGenericObjects<T>
/// </summary> /// </summary>
/// <returns>Поэлементый вывод элементов коллекции</returns> /// <returns>Поэлементый вывод элементов коллекции</returns>
IEnumerable<T?> GetItems(); IEnumerable<T?> GetItems();
/// <summary>
/// Сортировка коллекции
/// </summary>
/// <param name="comparer">Сравнитель объектов</param>
void CollectionSort(IComparer<T?> comparer);
} }

View File

@ -49,17 +49,40 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
{ {
if (Count == _maxCount) throw new CollectionOverflowException(Count); if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (comparer != null)
{
for (int i = 0; i < Count; i++)
Review

У списка есть метод Contains для проверки

У списка есть метод Contains для проверки
{
if (comparer.Equals(_collection[i], obj))
{
throw new CollectionInsertException(obj);
}
}
}
_collection.Add(obj); _collection.Add(obj);
return Count; return Count;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
{ {
if (Count == _maxCount) throw new CollectionOverflowException(Count); if (Count == _maxCount) throw new CollectionOverflowException(Count);
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
if (comparer != null)
{
for (int i = 0; i < Count; i++)
{
if (comparer.Equals(_collection[i], obj))
{
throw new CollectionInsertException(obj);
}
}
}
_collection.Insert(position, obj); _collection.Insert(position, obj);
return position; return position;
} }
@ -79,4 +102,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
yield return _collection[i]; yield return _collection[i];
} }
} }
public void CollectionSort(IComparer<T?> comparer)
{
_collection.Sort(comparer);
}
} }

View File

@ -1,4 +1,5 @@
using ProjectElectroTrans.Exceptions; using ProjectElectroTrans.Exceptions;
using System.Collections.Generic;
namespace ProjectElectroTrans.CollectionGenericObjects; namespace ProjectElectroTrans.CollectionGenericObjects;
@ -52,8 +53,20 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
{ {
if (comparer != null)
{
for (int i = 0; i < Count; i++)
{
if (comparer.Equals(_collection[i], obj))
{
throw new CollectionInsertException(obj);
}
}
}
// вставка в свободное место набора // вставка в свободное место набора
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
@ -67,14 +80,22 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
throw new CollectionOverflowException(Count); throw new CollectionOverflowException(Count);
} }
public int Insert(T obj, int position) public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
{ {
// проверка позиции // проверка позиции
if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position); if (position < 0 || position >= Count) throw new PositionOutOfCollectionException(position);
// проверка, что элемент массива по этой позиции пустой, если нет, то if (comparer != null)
// ищется свободное место после этой позиции и идет вставка туда {
// если нет после, ищем до for (int i = 0; i < Count; i++)
{
if (comparer.Equals(_collection[i], obj))
{
throw new CollectionInsertException(obj);
}
}
}
if (_collection[position] != null) if (_collection[position] != null)
{ {
bool pushed = false; bool pushed = false;
@ -107,7 +128,6 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
} }
// вставка
_collection[position] = obj; _collection[position] = obj;
return position; return position;
} }
@ -131,4 +151,14 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
yield return _collection[i]; yield return _collection[i];
} }
} }
public void CollectionSort(IComparer<T?> comparer)
{
List<T?> lst = [.._collection];
lst.Sort(comparer.Compare);
for (int i = 0; i < _collection.Length; ++i)
{
_collection[i] = lst[i];
}
}
} }

View File

@ -17,12 +17,12 @@ public class StorageCollection<T>
/// <summary> /// <summary>
/// Словарь (хранилище) с коллекциями /// Словарь (хранилище) с коллекциями
/// </summary> /// </summary>
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages; readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
/// <summary> /// <summary>
/// Возвращение списка названий коллекций /// Возвращение списка названий коллекций
/// </summary> /// </summary>
public List<string> Keys => _storages.Keys.ToList(); public List<CollectionInfo> Keys => _storages.Keys.ToList();
/// <summary> /// <summary>
/// Ключевое слово, с которого должен начинаться файл /// Ключевое слово, с которого должен начинаться файл
@ -44,33 +44,32 @@ public class StorageCollection<T>
/// </summary> /// </summary>
public StorageCollection() public StorageCollection()
{ {
_storages = new Dictionary<string, ICollectionGenericObjects<T>>(); _storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
} }
/// <summary> /// <summary>
/// Добавление коллекции в хранилище /// Добавление коллекции в хранилище
/// </summary> /// </summary>
/// <param name="name">Название коллекции</param> /// <param name="collectionInfo">тип коллекции</param>
/// <param name="collectionType">тип коллекции</param> public void AddCollection(CollectionInfo collectionInfo)
public void AddCollection(string name, CollectionType collectionType)
{ {
if (_storages.ContainsKey(name)) throw new CollectionAlreadyExistsException(name); if (_storages.ContainsKey(collectionInfo)) throw new CollectionAlreadyExistsException(collectionInfo);
if (collectionType == CollectionType.None) throw new CollectionTypeException("Пустой тип коллекции"); if (collectionInfo.CollectionType == CollectionType.None)
if (collectionType == CollectionType.Massive) throw new CollectionTypeException("Пустой тип коллекции");
_storages[name] = new MassiveGenericObjects<T>(); if (collectionInfo.CollectionType == CollectionType.Massive)
else if (collectionType == CollectionType.List) _storages[collectionInfo] = new MassiveGenericObjects<T>();
_storages[name] = new ListGenericObjects<T>(); else if (collectionInfo.CollectionType == CollectionType.List)
_storages[collectionInfo] = new ListGenericObjects<T>();
} }
/// <summary> /// <summary>
/// Удаление коллекции /// Удаление коллекции
/// </summary> /// </summary>
/// <param name="name">Название коллекции</param> /// <param name="collectionInfo">тип коллекции</param>
public void DelCollection(string name) public void DelCollection(CollectionInfo collectionInfo)
{ {
if (_storages.ContainsKey(name)) if (_storages.ContainsKey(collectionInfo))
_storages.Remove(name); _storages.Remove(collectionInfo);
} }
/// <summary> /// <summary>
@ -78,12 +77,12 @@ public class StorageCollection<T>
/// </summary> /// </summary>
/// <param name="name">Название коллекции</param> /// <param name="name">Название коллекции</param>
/// <returns></returns> /// <returns></returns>
public ICollectionGenericObjects<T>? this[string name] public ICollectionGenericObjects<T>? this[CollectionInfo collectionInfo]
{ {
get get
{ {
if (_storages.ContainsKey(name)) if (_storages.ContainsKey(collectionInfo))
return _storages[name]; return _storages[collectionInfo];
return null; return null;
} }
} }
@ -93,7 +92,7 @@ public class StorageCollection<T>
/// </summary> /// </summary>
/// <param name="filename">Путь и имя файла</param> /// <param name="filename">Путь и имя файла</param>
/// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns> /// <returns>true - сохранение прошло успешно, false - ошибка при сохранении данных</returns>
public bool SaveData(string filename) public void SaveData(string filename)
{ {
if (_storages.Count == 0) if (_storages.Count == 0)
{ {
@ -108,7 +107,7 @@ public class StorageCollection<T>
using (StreamWriter writer = new StreamWriter(filename)) using (StreamWriter writer = new StreamWriter(filename))
{ {
writer.Write(_collectionKey); writer.Write(_collectionKey);
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages) foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
{ {
StringBuilder sb = new(); StringBuilder sb = new();
sb.Append(Environment.NewLine); sb.Append(Environment.NewLine);
@ -120,8 +119,6 @@ public class StorageCollection<T>
sb.Append(value.Key); sb.Append(value.Key);
sb.Append(_separatorForKeyValue); sb.Append(_separatorForKeyValue);
sb.Append(value.Value.GetCollectionType);
sb.Append(_separatorForKeyValue);
sb.Append(value.Value.MaxCount); sb.Append(value.Value.MaxCount);
sb.Append(_separatorForKeyValue); sb.Append(_separatorForKeyValue);
foreach (T? item in value.Value.GetItems()) foreach (T? item in value.Value.GetItems())
@ -139,8 +136,6 @@ public class StorageCollection<T>
writer.Write(sb); writer.Write(sb);
} }
} }
return true;
} }
/// <summary> /// <summary>
@ -148,11 +143,11 @@ public class StorageCollection<T>
/// </summary> /// </summary>
/// <param name="filename">Путь и имя файла</param> /// <param name="filename">Путь и имя файла</param>
/// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns> /// <returns>true - загрузка прошла успешно, false - ошибка при загрузке данных</returns>
public bool LoadData(string filename) public void LoadData(string filename)
{ {
if (!File.Exists(filename)) if (!File.Exists(filename))
{ {
return false; throw new FileNotFoundException(filename);
} }
using (StreamReader fs = File.OpenText(filename)) using (StreamReader fs = File.OpenText(filename))
@ -160,8 +155,7 @@ public class StorageCollection<T>
string str = fs.ReadLine(); string str = fs.ReadLine();
if (string.IsNullOrEmpty(str)) if (string.IsNullOrEmpty(str))
{ {
throw new FileNotFoundException(filename); throw new EmptyFileExeption(filename);
} }
if (!str.StartsWith(_collectionKey)) if (!str.StartsWith(_collectionKey))
@ -174,20 +168,21 @@ public class StorageCollection<T>
while ((strs = fs.ReadLine()) != null) while ((strs = fs.ReadLine()) != null)
{ {
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
if (record.Length != 4) if (record.Length != 3)
{ {
continue; continue;
} }
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); CollectionInfo? collectionInfo =
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType); CollectionInfo.GetCollectionInfo(record[0]) ??
if (collection == null) throw new CollectionInfoException("Не удалось определить информацию коллекции:" + record[0]);
{
throw new CollectionTypeException("Не удалось определить тип коллекции:" + record[1]);
}
collection.MaxCount = Convert.ToInt32(record[2]); ICollectionGenericObjects<T>? collection =
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
throw new CollectionTypeException("Не удалось определить тип коллекции:" + record[1]);
collection.MaxCount = Convert.ToInt32(record[1]);
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
foreach (string elem in set) foreach (string elem in set)
{ {
if (elem?.CreateDrawningTrans() is T ship) if (elem?.CreateDrawningTrans() is T ship)
@ -203,67 +198,8 @@ public class StorageCollection<T>
} }
} }
_storages.Add(record[0], collection); _storages.Add(collectionInfo, collection);
} }
return true;
}
if (!File.Exists(filename))
{
}
using (StreamReader fs = File.OpenText(filename))
{
string str = fs.ReadLine();
if (string.IsNullOrEmpty(str))
{
throw new EmptyFileExeption(filename);
}
if (!str.StartsWith(_collectionKey))
{
}
_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)
{
}
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)
{
try
{
if (collection.Insert(ship) == -1)
{
throw new CollectionTypeException("Объект не удалось добавить в коллекцию: " + record[3]);
}
}
catch (CollectionOverflowException ex)
{
throw ex.InnerException!;
}
}
}
_storages.Add(record[0], collection);
}
return true;
} }
} }
@ -272,7 +208,8 @@ public class StorageCollection<T>
/// </summary> /// </summary>
/// <param name="collectionType"></param> /// <param name="collectionType"></param>
/// <returns></returns> /// <returns></returns>
private static ICollectionGenericObjects<T>? CreateCollection(CollectionType collectionType) private static ICollectionGenericObjects<T>?
CreateCollection(CollectionType collectionType)
{ {
return collectionType switch return collectionType switch
{ {

View File

@ -0,0 +1,35 @@
namespace ProjectElectroTrans.Drawnings;
public class DrawingTransCompareByColor : IComparer<DrawingTrans?>
{
public int Compare(DrawingTrans? x, DrawingTrans? y)
{
if (x == null && y == null) return 0;
if (x == null || x.EntityTrans == null)
{
return 1;
}
if (y == null || y.EntityTrans == null)
{
return -1;
}
if (ToHex(x.EntityTrans.BodyColor) != ToHex(y.EntityTrans.BodyColor))
{
return String.Compare(ToHex(x.EntityTrans.BodyColor), ToHex(y.EntityTrans.BodyColor),
StringComparison.Ordinal);
}
var speedCompare = x.EntityTrans.Speed.CompareTo(y.EntityTrans.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityTrans.Weight.CompareTo(y.EntityTrans.Weight);
}
private static String ToHex(Color c)
=> $"#{c.R:X2}{c.G:X2}{c.B:X2}";
}

View File

@ -0,0 +1,31 @@
namespace ProjectElectroTrans.Drawnings;
public class DrawingTransCompareByType : IComparer<DrawingTrans?>
{
public int Compare(DrawingTrans? x, DrawingTrans? y)
{
if (x == null && y == null) return 0;
if (x == null || x.EntityTrans == null)
{
return 1;
}
if (y == null || y.EntityTrans == null)
{
return -1;
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityTrans.Speed.CompareTo(y.EntityTrans.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityTrans.Weight.CompareTo(y.EntityTrans.Weight);
}
}

View File

@ -0,0 +1,59 @@
using System.Diagnostics.CodeAnalysis;
using ProjectElectroTrans.Entities;
namespace ProjectElectroTrans.Drawnings;
public class DrawingTransEquitables : IEqualityComparer<DrawingTrans?>
{
public bool Equals(DrawingTrans? x, DrawingTrans? y)
{
if (ReferenceEquals(x, null)) return false;
if (ReferenceEquals(y, null)) return false;
if (x.GetType() != y.GetType()) return false;
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityTrans != null && y.EntityTrans != null && x.EntityTrans.Speed != y.EntityTrans.Speed)
{
return false;
}
if (x.EntityTrans.Weight != y.EntityTrans.Weight)
{
return false;
}
if (x.EntityTrans.BodyColor != y.EntityTrans.BodyColor)
{
return false;
}
if (x is DrawingElectroTrans && y is DrawingElectroTrans)
{
if (((EntityElectroTrans)x.EntityTrans).AdditionalColor !=
Review

Зачем неоднократные преобразования, что мешает сделать это один раз?

Зачем неоднократные преобразования, что мешает сделать это один раз?
((EntityElectroTrans)y.EntityTrans).AdditionalColor)
{
return false;
}
if (((EntityElectroTrans)x.EntityTrans).Battery!=
((EntityElectroTrans)y.EntityTrans).Battery)
{
return false;
}
if (((EntityElectroTrans)x.EntityTrans).Horns!=
((EntityElectroTrans)y.EntityTrans).Horns)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawingTrans obj)
{
return obj.GetHashCode();
}
}

View File

@ -1,11 +1,12 @@
using System.Runtime.Serialization; using System.Runtime.Serialization;
using ProjectElectroTrans.CollectionGenericObjects;
namespace ProjectElectroTrans.Exceptions; namespace ProjectElectroTrans.Exceptions;
public class CollectionAlreadyExistsException : Exception public class CollectionAlreadyExistsException : Exception
{ {
public CollectionAlreadyExistsException() : base() { } public CollectionAlreadyExistsException() : base() { }
public CollectionAlreadyExistsException(string name) : base($"Коллекция {name} уже существует!") { } public CollectionAlreadyExistsException(CollectionInfo collectionInfo) : base($"Коллекция {collectionInfo} уже существует!") { }
public CollectionAlreadyExistsException(string name, Exception exception) : public CollectionAlreadyExistsException(string name, Exception exception) :
base($"Коллекция {name} уже существует!", exception) { } base($"Коллекция {name} уже существует!", exception) { }
protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext protected CollectionAlreadyExistsException(SerializationInfo info, StreamingContext

View File

@ -0,0 +1,13 @@
using System.Runtime.Serialization;
namespace ProjectElectroTrans.Exceptions;
public class CollectionInfoException : Exception
{
public CollectionInfoException() : base() { }
public CollectionInfoException(string message) : base(message) { }
public CollectionInfoException(string message, Exception exception) :
base(message, exception) { }
protected CollectionInfoException(SerializationInfo info, StreamingContext
contex) : base(info, contex) { }
}

View File

@ -1,9 +1,11 @@
using System.Runtime.Serialization; using System.Runtime.Serialization;
using ProjectElectroTrans.Drawnings;
namespace ProjectElectroTrans.Exceptions; namespace ProjectElectroTrans.Exceptions;
public class CollectionInsertException : Exception public class CollectionInsertException : Exception
{ {
public CollectionInsertException(object obj) : base($"Объект {obj} не удволетворяет уникальности") { }
public CollectionInsertException() : base() { } public CollectionInsertException() : base() { }
public CollectionInsertException(string message) : base(message) { } public CollectionInsertException(string message) : base(message) { }
public CollectionInsertException(string message, Exception exception) : public CollectionInsertException(string message, Exception exception) :

View File

@ -0,0 +1,13 @@
using System.Runtime.Serialization;
namespace ProjectElectroTrans.Exceptions;
public class DrawingEquitablesException : Exception
{
public DrawingEquitablesException() : base("Объекты прорисовки одинаковые") { }
public DrawingEquitablesException(string message) : base(message) { }
public DrawingEquitablesException(string message, Exception exception) :
base(message, exception) { }
protected DrawingEquitablesException(SerializationInfo info, StreamingContext
contex) : base(info, contex) { }
}

View File

@ -33,291 +33,317 @@ namespace ProjectElectroTrans
private void InitializeComponent() private void InitializeComponent()
{ {
groupBoxTools = new GroupBox(); groupBoxTools = new GroupBox();
panelCompanyTools = new Panel(); panelCompanyTools = new Panel();
buttonAddCar = new Button(); buttonSortByColor = new Button();
maskedTextBoxPosition = new MaskedTextBox(); buttonSortByType = new Button();
buttonRefresh = new Button(); buttonAddCar = new Button();
buttonRemoveCar = new Button(); maskedTextBoxPosition = new MaskedTextBox();
buttonGoToCheck = new Button(); buttonRefresh = new Button();
buttonCreateCompany = new Button(); buttonRemoveCar = new Button();
panelStorage = new Panel(); buttonGoToCheck = new Button();
buttonCollectionDel = new Button(); buttonCreateCompany = new Button();
listBoxCollection = new ListBox(); panelStorage = new Panel();
buttonCollectionAdd = new Button(); buttonCollectionDel = new Button();
radioButtonList = new RadioButton(); listBoxCollection = new ListBox();
radioButtonMassive = new RadioButton(); buttonCollectionAdd = new Button();
textBoxCollectionName = new TextBox(); radioButtonList = new RadioButton();
labelCollectionName = new Label(); radioButtonMassive = new RadioButton();
comboBoxSelectorCompany = new ComboBox(); textBoxCollectionName = new TextBox();
pictureBox = new PictureBox(); labelCollectionName = new Label();
menuStrip = new MenuStrip(); comboBoxSelectorCompany = new ComboBox();
файлToolStripMenuItem = new ToolStripMenuItem(); pictureBox = new PictureBox();
saveToolStripMenuItem = new ToolStripMenuItem(); menuStrip = new MenuStrip();
loadToolStripMenuItem = new ToolStripMenuItem(); файлToolStripMenuItem = new ToolStripMenuItem();
saveFileDialog = new SaveFileDialog(); saveToolStripMenuItem = new ToolStripMenuItem();
openFileDialog = new OpenFileDialog(); loadToolStripMenuItem = new ToolStripMenuItem();
groupBoxTools.SuspendLayout(); saveFileDialog = new SaveFileDialog();
panelCompanyTools.SuspendLayout(); openFileDialog = new OpenFileDialog();
panelStorage.SuspendLayout(); groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); panelCompanyTools.SuspendLayout();
menuStrip.SuspendLayout(); panelStorage.SuspendLayout();
SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
// menuStrip.SuspendLayout();
// groupBoxTools SuspendLayout();
// //
groupBoxTools.Controls.Add(panelCompanyTools); // groupBoxTools
groupBoxTools.Controls.Add(buttonCreateCompany); //
groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(panelCompanyTools);
groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Controls.Add(buttonCreateCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Controls.Add(panelStorage);
groupBoxTools.Location = new Point(783, 24); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Size = new Size(179, 608); groupBoxTools.Location = new Point(783, 24);
groupBoxTools.TabIndex = 0; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.TabStop = false; groupBoxTools.Size = new Size(179, 657);
groupBoxTools.Text = "Инструменты"; groupBoxTools.TabIndex = 0;
// groupBoxTools.TabStop = false;
// panelCompanyTools groupBoxTools.Text = "Инструменты";
// //
panelCompanyTools.Controls.Add(buttonAddCar); // panelCompanyTools
panelCompanyTools.Controls.Add(maskedTextBoxPosition); //
panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Controls.Add(buttonSortByColor);
panelCompanyTools.Controls.Add(buttonRemoveCar); panelCompanyTools.Controls.Add(buttonSortByType);
panelCompanyTools.Controls.Add(buttonGoToCheck); panelCompanyTools.Controls.Add(buttonAddCar);
panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Controls.Add(maskedTextBoxPosition);
panelCompanyTools.Enabled = false; panelCompanyTools.Controls.Add(buttonRefresh);
panelCompanyTools.Location = new Point(3, 352); panelCompanyTools.Controls.Add(buttonRemoveCar);
panelCompanyTools.Name = "panelCompanyTools"; panelCompanyTools.Controls.Add(buttonGoToCheck);
panelCompanyTools.Size = new Size(173, 253); panelCompanyTools.Dock = DockStyle.Bottom;
panelCompanyTools.TabIndex = 9; panelCompanyTools.Enabled = false;
// panelCompanyTools.Location = new Point(3, 355);
// buttonAddCar panelCompanyTools.Name = "panelCompanyTools";
// panelCompanyTools.Size = new Size(173, 299);
buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; panelCompanyTools.TabIndex = 9;
buttonAddCar.Location = new Point(3, 3); //
buttonAddCar.Name = "buttonAddCar"; // buttonSortByColor
buttonAddCar.Size = new Size(167, 40); //
buttonAddCar.TabIndex = 1; buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddCar.Text = "Добавление автомобиля"; buttonSortByColor.Location = new Point(3, 250);
buttonAddCar.UseVisualStyleBackColor = true; buttonSortByColor.Name = "buttonSortByColor";
buttonAddCar.Click += ButtonAddTrans_Click; buttonSortByColor.Size = new Size(167, 40);
// buttonSortByColor.TabIndex = 8;
// maskedTextBoxPosition buttonSortByColor.Text = "Сортировка по цвету";
// buttonSortByColor.UseVisualStyleBackColor = true;
maskedTextBoxPosition.Location = new Point(3, 95); buttonSortByColor.Click += ButtonSortByColor_Click;
maskedTextBoxPosition.Mask = "00"; //
maskedTextBoxPosition.Name = "maskedTextBoxPosition"; // buttonSortByType
maskedTextBoxPosition.Size = new Size(167, 23); //
maskedTextBoxPosition.TabIndex = 3; buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
maskedTextBoxPosition.ValidatingType = typeof(int); buttonSortByType.Location = new Point(3, 210);
// buttonSortByType.Name = "buttonSortByType";
// buttonRefresh buttonSortByType.Size = new Size(167, 40);
// buttonSortByType.TabIndex = 7;
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonSortByType.Text = "Сортировка по типу";
buttonRefresh.Location = new Point(3, 210); buttonSortByType.UseVisualStyleBackColor = true;
buttonRefresh.Name = "buttonRefresh"; buttonSortByType.Click += ButtonSortByType_Click;
buttonRefresh.Size = new Size(167, 40); //
buttonRefresh.TabIndex = 6; // buttonAddCar
buttonRefresh.Text = "Обновить"; //
buttonRefresh.UseVisualStyleBackColor = true; buttonAddCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Click += ButtonRefresh_Click; buttonAddCar.Location = new Point(3, 3);
// buttonAddCar.Name = "buttonAddCar";
// buttonRemoveCar buttonAddCar.Size = new Size(167, 40);
// buttonAddCar.TabIndex = 1;
buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddCar.Text = "Добавление поезда";
buttonRemoveCar.Location = new Point(3, 124); buttonAddCar.UseVisualStyleBackColor = true;
buttonRemoveCar.Name = "buttonRemoveCar"; buttonAddCar.Click += ButtonAddTrans_Click;
buttonRemoveCar.Size = new Size(167, 40); //
buttonRemoveCar.TabIndex = 4; // maskedTextBoxPosition
buttonRemoveCar.Text = "Удалить автомобиль"; //
buttonRemoveCar.UseVisualStyleBackColor = true; maskedTextBoxPosition.Location = new Point(3, 49);
buttonRemoveCar.Click += ButtonRemoveTrans_Click; maskedTextBoxPosition.Mask = "00";
// maskedTextBoxPosition.Name = "maskedTextBoxPosition";
// buttonGoToCheck maskedTextBoxPosition.Size = new Size(167, 23);
// maskedTextBoxPosition.TabIndex = 3;
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; maskedTextBoxPosition.ValidatingType = typeof(int);
buttonGoToCheck.Location = new Point(3, 170); //
buttonGoToCheck.Name = "buttonGoToCheck"; // buttonRefresh
buttonGoToCheck.Size = new Size(167, 40); //
buttonGoToCheck.TabIndex = 5; buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Text = "Передать на тесты"; buttonRefresh.Location = new Point(3, 164);
buttonGoToCheck.UseVisualStyleBackColor = true; buttonRefresh.Name = "buttonRefresh";
buttonGoToCheck.Click += ButtonGoToCheck_Click; buttonRefresh.Size = new Size(167, 40);
// buttonRefresh.TabIndex = 6;
// buttonCreateCompany buttonRefresh.Text = "Обновить";
// buttonRefresh.UseVisualStyleBackColor = true;
buttonCreateCompany.Location = new Point(6, 320); buttonRefresh.Click += ButtonRefresh_Click;
buttonCreateCompany.Name = "buttonCreateCompany"; //
buttonCreateCompany.Size = new Size(167, 23); // buttonRemoveCar
buttonCreateCompany.TabIndex = 8; //
buttonCreateCompany.Text = "Создать компанию"; buttonRemoveCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonCreateCompany.UseVisualStyleBackColor = true; buttonRemoveCar.Location = new Point(3, 78);
buttonCreateCompany.Click += ButtonCreateCompany_Click; buttonRemoveCar.Name = "buttonRemoveCar";
// buttonRemoveCar.Size = new Size(167, 40);
// panelStorage buttonRemoveCar.TabIndex = 4;
// buttonRemoveCar.Text = "Удалить поезд";
panelStorage.Controls.Add(buttonCollectionDel); buttonRemoveCar.UseVisualStyleBackColor = true;
panelStorage.Controls.Add(listBoxCollection); buttonRemoveCar.Click += ButtonRemoveTrans_Click;
panelStorage.Controls.Add(buttonCollectionAdd); //
panelStorage.Controls.Add(radioButtonList); // buttonGoToCheck
panelStorage.Controls.Add(radioButtonMassive); //
panelStorage.Controls.Add(textBoxCollectionName); buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
panelStorage.Controls.Add(labelCollectionName); buttonGoToCheck.Location = new Point(3, 124);
panelStorage.Dock = DockStyle.Top; buttonGoToCheck.Name = "buttonGoToCheck";
panelStorage.Location = new Point(3, 19); buttonGoToCheck.Size = new Size(167, 40);
panelStorage.Name = "panelStorage"; buttonGoToCheck.TabIndex = 5;
panelStorage.Size = new Size(173, 266); buttonGoToCheck.Text = "Передать на тесты";
panelStorage.TabIndex = 7; buttonGoToCheck.UseVisualStyleBackColor = true;
// buttonGoToCheck.Click += ButtonGoToCheck_Click;
// buttonCollectionDel //
// // buttonCreateCompany
buttonCollectionDel.Location = new Point(3, 227); //
buttonCollectionDel.Name = "buttonCollectionDel"; buttonCreateCompany.Location = new Point(6, 320);
buttonCollectionDel.Size = new Size(167, 23); buttonCreateCompany.Name = "buttonCreateCompany";
buttonCollectionDel.TabIndex = 6; buttonCreateCompany.Size = new Size(167, 23);
buttonCollectionDel.Text = "Удалить коллекцию"; buttonCreateCompany.TabIndex = 8;
buttonCollectionDel.UseVisualStyleBackColor = true; buttonCreateCompany.Text = "Создать компанию";
buttonCollectionDel.Click += ButtonCollectionDel_Click; buttonCreateCompany.UseVisualStyleBackColor = true;
// buttonCreateCompany.Click += ButtonCreateCompany_Click;
// listBoxCollection //
// // panelStorage
listBoxCollection.FormattingEnabled = true; //
listBoxCollection.ItemHeight = 15; panelStorage.Controls.Add(buttonCollectionDel);
listBoxCollection.Location = new Point(3, 112); panelStorage.Controls.Add(listBoxCollection);
listBoxCollection.Name = "listBoxCollection"; panelStorage.Controls.Add(buttonCollectionAdd);
listBoxCollection.Size = new Size(167, 109); panelStorage.Controls.Add(radioButtonList);
listBoxCollection.TabIndex = 5; panelStorage.Controls.Add(radioButtonMassive);
// panelStorage.Controls.Add(textBoxCollectionName);
// buttonCollectionAdd panelStorage.Controls.Add(labelCollectionName);
// panelStorage.Dock = DockStyle.Top;
buttonCollectionAdd.Location = new Point(3, 83); panelStorage.Location = new Point(3, 19);
buttonCollectionAdd.Name = "buttonCollectionAdd"; panelStorage.Name = "panelStorage";
buttonCollectionAdd.Size = new Size(167, 23); panelStorage.Size = new Size(173, 266);
buttonCollectionAdd.TabIndex = 4; panelStorage.TabIndex = 7;
buttonCollectionAdd.Text = "Добавить коллекцию"; //
buttonCollectionAdd.UseVisualStyleBackColor = true; // buttonCollectionDel
buttonCollectionAdd.Click += ButtonCollectionAdd_Click; //
// buttonCollectionDel.Location = new Point(3, 227);
// radioButtonList buttonCollectionDel.Name = "buttonCollectionDel";
// buttonCollectionDel.Size = new Size(167, 23);
radioButtonList.AutoSize = true; buttonCollectionDel.TabIndex = 6;
radioButtonList.Location = new Point(98, 58); buttonCollectionDel.Text = "Удалить коллекцию";
radioButtonList.Name = "radioButtonList"; buttonCollectionDel.UseVisualStyleBackColor = true;
radioButtonList.Size = new Size(66, 19); buttonCollectionDel.Click += ButtonCollectionDel_Click;
radioButtonList.TabIndex = 3; //
radioButtonList.TabStop = true; // listBoxCollection
radioButtonList.Text = "Список"; //
radioButtonList.UseVisualStyleBackColor = true; listBoxCollection.FormattingEnabled = true;
// listBoxCollection.ItemHeight = 15;
// radioButtonMassive listBoxCollection.Location = new Point(3, 112);
// listBoxCollection.Name = "listBoxCollection";
radioButtonMassive.AutoSize = true; listBoxCollection.Size = new Size(167, 109);
radioButtonMassive.Location = new Point(16, 58); listBoxCollection.TabIndex = 5;
radioButtonMassive.Name = "radioButtonMassive"; //
radioButtonMassive.Size = new Size(67, 19); // buttonCollectionAdd
radioButtonMassive.TabIndex = 2; //
radioButtonMassive.TabStop = true; buttonCollectionAdd.Location = new Point(3, 83);
radioButtonMassive.Text = "Массив"; buttonCollectionAdd.Name = "buttonCollectionAdd";
radioButtonMassive.UseVisualStyleBackColor = true; buttonCollectionAdd.Size = new Size(167, 23);
// buttonCollectionAdd.TabIndex = 4;
// textBoxCollectionName buttonCollectionAdd.Text = "Добавить коллекцию";
// buttonCollectionAdd.UseVisualStyleBackColor = true;
textBoxCollectionName.Location = new Point(3, 29); buttonCollectionAdd.Click += ButtonCollectionAdd_Click;
textBoxCollectionName.Name = "textBoxCollectionName"; //
textBoxCollectionName.Size = new Size(167, 23); // radioButtonList
textBoxCollectionName.TabIndex = 1; //
// radioButtonList.AutoSize = true;
// labelCollectionName radioButtonList.Location = new Point(98, 58);
// radioButtonList.Name = "radioButtonList";
labelCollectionName.AutoSize = true; radioButtonList.Size = new Size(66, 19);
labelCollectionName.Location = new Point(26, 11); radioButtonList.TabIndex = 3;
labelCollectionName.Name = "labelCollectionName"; radioButtonList.TabStop = true;
labelCollectionName.Size = new Size(125, 15); radioButtonList.Text = "Список";
labelCollectionName.TabIndex = 0; radioButtonList.UseVisualStyleBackColor = true;
labelCollectionName.Text = "Название коллекции:"; //
// // radioButtonMassive
// comboBoxSelectorCompany //
// radioButtonMassive.AutoSize = true;
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; radioButtonMassive.Location = new Point(16, 58);
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; radioButtonMassive.Name = "radioButtonMassive";
comboBoxSelectorCompany.FormattingEnabled = true; radioButtonMassive.Size = new Size(67, 19);
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); radioButtonMassive.TabIndex = 2;
comboBoxSelectorCompany.Location = new Point(6, 291); radioButtonMassive.TabStop = true;
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; radioButtonMassive.Text = "Массив";
comboBoxSelectorCompany.Size = new Size(167, 23); radioButtonMassive.UseVisualStyleBackColor = true;
comboBoxSelectorCompany.TabIndex = 0; //
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; // textBoxCollectionName
// //
// pictureBox textBoxCollectionName.Location = new Point(3, 29);
// textBoxCollectionName.Name = "textBoxCollectionName";
pictureBox.Dock = DockStyle.Fill; textBoxCollectionName.Size = new Size(167, 23);
pictureBox.Location = new Point(0, 24); textBoxCollectionName.TabIndex = 1;
pictureBox.Name = "pictureBox"; //
pictureBox.Size = new Size(783, 608); // labelCollectionName
pictureBox.TabIndex = 1; //
pictureBox.TabStop = false; labelCollectionName.AutoSize = true;
// labelCollectionName.Location = new Point(26, 11);
// menuStrip labelCollectionName.Name = "labelCollectionName";
// labelCollectionName.Size = new Size(125, 15);
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); labelCollectionName.TabIndex = 0;
menuStrip.Location = new Point(0, 0); labelCollectionName.Text = "Название коллекции:";
menuStrip.Name = "menuStrip"; //
menuStrip.Size = new Size(962, 24); // comboBoxSelectorCompany
menuStrip.TabIndex = 2; //
menuStrip.Text = "menuStrip"; comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
// comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
// файлToolStripMenuItem comboBoxSelectorCompany.FormattingEnabled = true;
// comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem }); comboBoxSelectorCompany.Location = new Point(6, 291);
файлToolStripMenuItem.Name = айлToolStripMenuItem"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
файлToolStripMenuItem.Size = new Size(48, 20); comboBoxSelectorCompany.Size = new Size(167, 23);
файлToolStripMenuItem.Text = "Файл"; comboBoxSelectorCompany.TabIndex = 0;
// comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// saveToolStripMenuItem //
// // pictureBox
saveToolStripMenuItem.Name = "saveToolStripMenuItem"; //
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S; pictureBox.Dock = DockStyle.Fill;
saveToolStripMenuItem.Size = new Size(181, 22); pictureBox.Location = new Point(0, 24);
saveToolStripMenuItem.Text = "Сохранение"; pictureBox.Name = "pictureBox";
saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click; pictureBox.Size = new Size(783, 657);
// pictureBox.TabIndex = 1;
// loadToolStripMenuItem pictureBox.TabStop = false;
// //
loadToolStripMenuItem.Name = "loadToolStripMenuItem"; // menuStrip
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L; //
loadToolStripMenuItem.Size = new Size(181, 22); menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
loadToolStripMenuItem.Text = "Загрузка"; menuStrip.Location = new Point(0, 0);
loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click; menuStrip.Name = "menuStrip";
// menuStrip.Size = new Size(962, 24);
// saveFileDialog menuStrip.TabIndex = 2;
// menuStrip.Text = "menuStrip";
saveFileDialog.Filter = "txt file | *.txt"; //
// // файлToolStripMenuItem
// openFileDialog //
// файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
openFileDialog.Filter = "txt file | *.txt"; файлToolStripMenuItem.Name = айлToolStripMenuItem";
// файлToolStripMenuItem.Size = new Size(48, 20);
// FormCarCollection файлToolStripMenuItem.Text = "Файл";
// //
AutoScaleDimensions = new SizeF(7F, 15F); // saveToolStripMenuItem
AutoScaleMode = AutoScaleMode.Font; //
ClientSize = new Size(962, 632); saveToolStripMenuItem.Name = "saveToolStripMenuItem";
Controls.Add(pictureBox); saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
Controls.Add(groupBoxTools); saveToolStripMenuItem.Size = new Size(181, 22);
Controls.Add(menuStrip); saveToolStripMenuItem.Text = "Сохранение";
MainMenuStrip = menuStrip; saveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
Name = "FormCarCollection"; //
Text = "Коллекция автомобилей"; // loadToolStripMenuItem
groupBoxTools.ResumeLayout(false); //
panelCompanyTools.ResumeLayout(false); loadToolStripMenuItem.Name = "loadToolStripMenuItem";
panelCompanyTools.PerformLayout(); loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
panelStorage.ResumeLayout(false); loadToolStripMenuItem.Size = new Size(181, 22);
panelStorage.PerformLayout(); loadToolStripMenuItem.Text = "Загрузка";
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); loadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
menuStrip.ResumeLayout(false); //
menuStrip.PerformLayout(); // saveFileDialog
ResumeLayout(false); //
PerformLayout(); saveFileDialog.Filter = "txt file | *.txt";
//
// openFileDialog
//
openFileDialog.Filter = "txt file | *.txt";
//
// FormCarCollection
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(962, 681);
Controls.Add(pictureBox);
Controls.Add(groupBoxTools);
Controls.Add(menuStrip);
MainMenuStrip = menuStrip;
Name = "FormTransCollection";
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
@ -346,5 +372,7 @@ namespace ProjectElectroTrans
private ToolStripMenuItem loadToolStripMenuItem; private ToolStripMenuItem loadToolStripMenuItem;
private SaveFileDialog saveFileDialog; private SaveFileDialog saveFileDialog;
private OpenFileDialog openFileDialog; private OpenFileDialog openFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
} }
} }

View File

@ -69,6 +69,7 @@ public partial class FormTransCollection : Form
{ {
return; return;
} }
try try
{ {
var res = _company + drawingTrans; var res = _company + drawingTrans;
@ -195,7 +196,7 @@ public partial class FormTransCollection : Form
try try
{ {
_storageCollection.AddCollection(textBoxCollectionName.Text, collectionType); _storageCollection.AddCollection(new CollectionInfo(textBoxCollectionName.Text, collectionType, "ХЗ"));
_logger.LogInformation("Добавление коллекции"); _logger.LogInformation("Добавление коллекции");
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
@ -204,7 +205,6 @@ public partial class FormTransCollection : Form
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogError($"Ошибка: {ex.Message}", ex.Message); _logger.LogError($"Ошибка: {ex.Message}", ex.Message);
} }
} }
/// <summary> /// <summary>
@ -226,7 +226,8 @@ public partial class FormTransCollection : Form
return; return;
} }
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString()); CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(listBoxCollection.SelectedItem.ToString()!);
_storageCollection.DelCollection(collectionInfo!);
_logger.LogInformation("Коллекция удалена"); _logger.LogInformation("Коллекция удалена");
RerfreshListBoxItems(); RerfreshListBoxItems();
} }
@ -239,10 +240,10 @@ public partial class FormTransCollection : Form
listBoxCollection.Items.Clear(); listBoxCollection.Items.Clear();
for (int i = 0; i < _storageCollection.Keys?.Count; ++i) for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
{ {
string? colName = _storageCollection.Keys?[i]; CollectionInfo? col = _storageCollection.Keys?[i];
if (!string.IsNullOrEmpty(colName)) if (!col!.IsEmpty())
{ {
listBoxCollection.Items.Add(colName); listBoxCollection.Items.Add(col);
} }
} }
} }
@ -261,7 +262,9 @@ public partial class FormTransCollection : Form
} }
ICollectionGenericObjects<DrawingTrans>? collection = ICollectionGenericObjects<DrawingTrans>? collection =
_storageCollection[listBoxCollection.SelectedItem.ToString() ?? string.Empty]; _storageCollection[
CollectionInfo.GetCollectionInfo(listBoxCollection.SelectedItem.ToString()!) ??
new CollectionInfo("", CollectionType.None, "")];
if (collection == null) if (collection == null)
{ {
MessageBox.Show("Коллекция не проинициализирована"); MessageBox.Show("Коллекция не проинициализирована");
@ -332,4 +335,39 @@ public partial class FormTransCollection : Form
} }
} }
} }
/// <summary>
/// Сортировка по типу
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSortByType_Click(object sender, EventArgs e)
{
CompareCars(new DrawingTransCompareByType());
}
/// <summary>
/// Сортировка по цвету
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonSortByColor_Click(object sender, EventArgs e)
{
CompareCars(new DrawingTransCompareByColor());
}
/// <summary>
/// Сортировка по сравнителю
/// </summary>
/// <param name="comparer">Сравнитель объектов</param>
private void CompareCars(IComparer<DrawingTrans?> comparer)
{
if (_company == null)
{
return;
}
_company.Sort(comparer);
pictureBox.Image = _company.Show();
}
} }