лаб8 готовая
This commit is contained in:
parent
eb17902171
commit
514d9123a7
@ -49,7 +49,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningTrackedVehicle trackedVehicle)
|
||||
{
|
||||
return company._collection.Insert(trackedVehicle);
|
||||
return company._collection.Insert(trackedVehicle, new DrawningTrackedVehicleEqutables());
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
@ -101,4 +101,6 @@ public abstract class AbstractCompany
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
|
||||
public void Sort(IComparer<DrawningTrackedVehicle?> comparer) => _collection?.CollectionSort(comparer);
|
||||
}
|
||||
|
52
solution/lab1/CollectionGenericObjects/CollectionInfo.cs
Normal file
52
solution/lab1/CollectionGenericObjects/CollectionInfo.cs
Normal file
@ -0,0 +1,52 @@
|
||||
namespace lab1.CollectionGenericObjects;
|
||||
|
||||
public class CollectionInfo : IEquatable<CollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
|
||||
public CollectionType CollectionType { get; private set; }
|
||||
|
||||
public string Description { get; private set; }
|
||||
|
||||
private static readonly string _separator = "-";
|
||||
|
||||
public CollectionInfo(string name, CollectionType collectionType, string description)
|
||||
{
|
||||
Name = name;
|
||||
CollectionType = collectionType;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
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 override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using Microsoft.VisualBasic.Devices;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -17,20 +19,20 @@ public interface ICollectionGenericObjects<T>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int MaxCount { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавление объекта</param>
|
||||
/// <returns> true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, IEqualityComparer<T?>? comparer = null);
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавление объекта</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
@ -54,5 +56,5 @@ public interface ICollectionGenericObjects<T>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using lab1.Exceptions;
|
||||
using ProjectSeaplane.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -54,18 +55,33 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO вставка в конец набора
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
_collection.Add(obj);
|
||||
return Count;
|
||||
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (comparer != null)
|
||||
{
|
||||
if (_collection.Contains(obj, comparer))
|
||||
{
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
// TODO проверка, что не превышено максимальное количество элементов
|
||||
// TODO проверка позиции
|
||||
// TODO вставка по позиции
|
||||
@ -92,4 +108,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,6 @@
|
||||
using lab1.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using lab1.Drawnings;
|
||||
using ProjectSeaplane.Exceptions;
|
||||
|
||||
namespace lab1.CollectionGenericObjects;
|
||||
|
||||
@ -56,8 +53,16 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningTrackedVehicle>).Equals(obj as DrawningTrackedVehicle, item as DrawningTrackedVehicle))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
// TODO вставка в свободное место набора
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
@ -72,8 +77,16 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningTrackedVehicle>).Equals(obj as DrawningTrackedVehicle, item as DrawningTrackedVehicle))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
@ -126,4 +139,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
@ -17,17 +17,17 @@ public class StorageCollection<T>
|
||||
/// <summary>
|
||||
/// Словарь(хранилище) с коллекциями
|
||||
/// </summary>
|
||||
readonly Dictionary<string, ICollectionGenericObjects<T>> _storages;
|
||||
readonly Dictionary<CollectionInfo, ICollectionGenericObjects<T>> _storages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий коллекций
|
||||
/// </summary>
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<string, ICollectionGenericObjects<T>>();
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenericObjects<T>>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление коллекции в хранилище
|
||||
@ -38,17 +38,13 @@ public class StorageCollection<T>
|
||||
{
|
||||
// TODO проверка, что name не пустой и нет в словаре записи с таким ключом
|
||||
// TODO Прописать логику для добавления
|
||||
if (!(collectionType == CollectionType.None) && !_storages.ContainsKey(name))
|
||||
{
|
||||
if (collectionType == CollectionType.List)
|
||||
{
|
||||
_storages.Add(name, new ListGenericObjects<T>());
|
||||
}
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
{
|
||||
_storages.Add(name, new MassiveGenericObjects<T>());
|
||||
}
|
||||
}
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||
else if (collectionType == CollectionType.List)
|
||||
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление коллекции
|
||||
@ -57,10 +53,9 @@ public class StorageCollection<T>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления коллекции
|
||||
if (_storages.ContainsKey(name))
|
||||
{
|
||||
_storages.Remove(name);
|
||||
}
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
_storages.Remove(collectionInfo);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
@ -73,8 +68,9 @@ public class StorageCollection<T>
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения объекта
|
||||
if (_storages.ContainsKey(name))
|
||||
return _storages[name];
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
return _storages[collectionInfo];
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -96,12 +92,12 @@ public class StorageCollection<T>
|
||||
/// Сохранение информации по штурмовику в хранилище в файл
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
|
||||
public void SaveData(string filename)
|
||||
|
||||
public void SaveData(string filename)
|
||||
{
|
||||
if (_storages.Count == 0)
|
||||
{
|
||||
throw new Exception("В хранилище отсутствует коллекция для сохранения");
|
||||
throw new Exception("В хранилище отсутствуют коллекции для сохранения");
|
||||
}
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
@ -110,19 +106,19 @@ public class StorageCollection<T>
|
||||
using (StreamWriter writer = new StreamWriter(filename))
|
||||
{
|
||||
writer.Write(_collectionKey);
|
||||
foreach (KeyValuePair<string, ICollectionGenericObjects<T>> value in _storages)
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenericObjects<T>> value in _storages)
|
||||
{
|
||||
writer.Write(Environment.NewLine);
|
||||
StringBuilder sb = new();
|
||||
sb.Append(Environment.NewLine);
|
||||
// не сохраняем пустые коллекции
|
||||
if (value.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
writer.Write(value.Key);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.GetCollectionType);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.MaxCount);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
sb.Append(value.Key);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(value.Value.MaxCount);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
{
|
||||
string data = item?.GetDataForSave() ?? string.Empty;
|
||||
@ -130,18 +126,19 @@ public class StorageCollection<T>
|
||||
{
|
||||
continue;
|
||||
}
|
||||
writer.Write(data);
|
||||
writer.Write(_separatorItems);
|
||||
sb.Append(data);
|
||||
sb.Append(_separatorItems);
|
||||
}
|
||||
writer.Write(sb);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Загрузка информации по штурмовику в хранилище из файла
|
||||
/// </summary>
|
||||
/// <param name="filename">Путь и имя файла</param>
|
||||
|
||||
|
||||
public void LoadData(string filename)
|
||||
{
|
||||
if (!File.Exists(filename))
|
||||
@ -164,39 +161,38 @@ public class StorageCollection<T>
|
||||
while ((strs = fs.ReadLine()) != null)
|
||||
{
|
||||
string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 4)
|
||||
if (record.Length != 3)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||
throw new Exception("Не удалось создать коллекцию");
|
||||
if (collection == null)
|
||||
{
|
||||
throw new Exception("Не удалось создать коллекцию");
|
||||
throw new Exception("Не удалось определить тип коллекции:" + record[1]);
|
||||
}
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries);
|
||||
foreach (string elem in set)
|
||||
{
|
||||
if (elem?.CreateDrawningTrackedVehicle() is T fighter)
|
||||
if (elem?.CreateDrawningEntityFighter() is T airplan)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (collection.Insert(fighter) == -1)
|
||||
if (collection.Insert(airplan) == -1)
|
||||
{
|
||||
throw new Exception("Объект не удалось добавить в коллекцию" + record[3]);
|
||||
throw new Exception("Объект не удалось добавить в коллекцию: " + record[3]);
|
||||
}
|
||||
}
|
||||
catch (CollectionOverflowException ex)
|
||||
{
|
||||
throw new Exception("Коллекция переполнена", ex);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -13,6 +13,11 @@ public class TrackedVehicleSharingService : AbstractCompany
|
||||
{
|
||||
}
|
||||
|
||||
internal static int getAmountOfObjects()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
|
@ -1,5 +1,4 @@
|
||||
using lab1.Entities;
|
||||
|
||||
namespace lab1.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
@ -22,12 +21,6 @@ public class DrawningEntityFighter : DrawningTrackedVehicle
|
||||
|
||||
}
|
||||
|
||||
public DrawningEntityFighter(EntityFighter fighter) : base(91, 65)
|
||||
{
|
||||
EntityTrackedVehicle = new EntityFighter(fighter.Speed, fighter.Weight, fighter.BodyColor, fighter.AdditionalColor, fighter.Kovsh, fighter.Otval);
|
||||
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityTrackedVehicle == null || EntityTrackedVehicle is not EntityFighter fighter || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
|
@ -34,6 +34,7 @@ public class DrawningTrackedVehicle
|
||||
/// Верхняя координата прорисовки истребителя
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
private EntityTrackedVehicle fighter;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки истребителя
|
||||
@ -106,9 +107,9 @@ public class DrawningTrackedVehicle
|
||||
|
||||
}
|
||||
|
||||
public DrawningTrackedVehicle(EntityTrackedVehicle fighter): this()
|
||||
public DrawningTrackedVehicle(EntityTrackedVehicle fighter)
|
||||
{
|
||||
EntityTrackedVehicle = new EntityTrackedVehicle(fighter.Speed, fighter.Weight, fighter.BodyColor);
|
||||
this.fighter = fighter;
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,28 @@
|
||||
namespace lab1.Drawnings;
|
||||
|
||||
public class DrawningTrackedVehicleCompareByColor : IComparer<DrawningTrackedVehicle?>
|
||||
{
|
||||
public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
|
||||
{
|
||||
if (x == null || x.EntityTrackedVehicle == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityTrackedVehicle == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x.EntityTrackedVehicle.BodyColor.Name.CompareTo(y.EntityTrackedVehicle.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
namespace lab1.Drawnings;
|
||||
|
||||
public class DrawningTrackedVehicleCompareByType : IComparer<DrawningTrackedVehicle?>
|
||||
{
|
||||
public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
|
||||
{
|
||||
if (x == null || x.EntityTrackedVehicle == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityTrackedVehicle == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight);
|
||||
}
|
||||
}
|
58
solution/lab1/Drawnings/DrawningTrackedVehicleEqutables.cs
Normal file
58
solution/lab1/Drawnings/DrawningTrackedVehicleEqutables.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using lab1.Drawnings;
|
||||
using lab1.Entities;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace lab1;
|
||||
|
||||
public class DrawningTrackedVehicleEqutables : IEqualityComparer<DrawningTrackedVehicle?>
|
||||
{
|
||||
public bool Equals(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
|
||||
{
|
||||
if (x == null || x.EntityTrackedVehicle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityTrackedVehicle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTrackedVehicle.Speed != y.EntityTrackedVehicle.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTrackedVehicle.Weight != y.EntityTrackedVehicle.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityTrackedVehicle.BodyColor != y.EntityTrackedVehicle.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningEntityFighter && y is DrawningEntityFighter)
|
||||
{
|
||||
EntityFighter _x = (EntityFighter)x.EntityTrackedVehicle;
|
||||
EntityFighter _y = (EntityFighter)x.EntityTrackedVehicle;
|
||||
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.Kovsh != _y.Kovsh)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.Otval != _y.Otval)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningTrackedVehicle obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
@ -18,13 +18,13 @@ public static class ExtentionDrawningTrackedVehicle
|
||||
/// </summary>
|
||||
/// <param name="info">Строка с данными для создания объекта</param>
|
||||
/// <returns>Объект</returns>
|
||||
public static DrawningTrackedVehicle? CreateDrawningTrackedVehicle(this string info)
|
||||
public static DrawningTrackedVehicle? CreateDrawningEntityFighter(this string info)
|
||||
{
|
||||
string[] strs = info.Split(_separatorForObject);
|
||||
EntityTrackedVehicle? fighter = EntityFighter.CreateEntityStormtrooper(strs);
|
||||
EntityTrackedVehicle? fighter = EntityFighter.CreateEntityFighter(strs);
|
||||
if (fighter != null)
|
||||
{
|
||||
return new DrawningEntityFighter((EntityFighter)fighter);
|
||||
return new DrawingEntityFighter((EntityFighter)fighter);
|
||||
}
|
||||
|
||||
fighter = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs);
|
||||
@ -50,3 +50,10 @@ public static class ExtentionDrawningTrackedVehicle
|
||||
return string.Join(_separatorForObject, array);
|
||||
}
|
||||
}
|
||||
|
||||
internal class DrawingEntityFighter : DrawningTrackedVehicle
|
||||
{
|
||||
public DrawingEntityFighter(EntityTrackedVehicle fighter) : base(fighter)
|
||||
{
|
||||
}
|
||||
}
|
@ -68,6 +68,11 @@ public class EntityFighter : EntityTrackedVehicle
|
||||
}
|
||||
return new EntityFighter(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]), Color.FromName(strs[4]), Convert.ToBoolean(strs[5]), Convert.ToBoolean(strs[6]));
|
||||
}
|
||||
|
||||
internal static EntityTrackedVehicle? CreateEntityFighter(string[] strs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,6 +43,8 @@ public class EntityTrackedVehicle
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,7 +61,7 @@ public class EntityTrackedVehicle
|
||||
/// </summary>
|
||||
/// <param name="strs"></param>
|
||||
/// <returns></returns>
|
||||
internal static EntityTrackedVehicle? CreateEntityTrackedVehicle(string[] strs)
|
||||
public static EntityTrackedVehicle? CreateEntityBaseStormtrooper(string[] strs)
|
||||
{
|
||||
if (strs.Length != 4 || strs[0] != nameof(EntityTrackedVehicle))
|
||||
{
|
||||
@ -67,4 +69,9 @@ public class EntityTrackedVehicle
|
||||
}
|
||||
return new EntityTrackedVehicle(Convert.ToInt32(strs[1]), Convert.ToDouble(strs[2]), Color.FromName(strs[3]));
|
||||
}
|
||||
|
||||
internal static EntityTrackedVehicle? CreateEntityTrackedVehicle(string[] strs)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
13
solution/lab1/Exceptions/ObjectIsEqualException.cs
Normal file
13
solution/lab1/Exceptions/ObjectIsEqualException.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace ProjectSeaplane.Exceptions;
|
||||
|
||||
[Serializable]
|
||||
public class ObjectIsEqualException : ApplicationException
|
||||
{
|
||||
public ObjectIsEqualException(int count) : base("В коллекции содержится равный элемент: " + count) { }
|
||||
public ObjectIsEqualException() : base() { }
|
||||
public ObjectIsEqualException(string message) : base(message) { }
|
||||
public ObjectIsEqualException(string message, Exception exception) : base(message, exception) { }
|
||||
protected ObjectIsEqualException(SerializationInfo info, StreamingContext contex) : base(info, contex) { }
|
||||
}
|
135
solution/lab1/FormTrackedVehicleCollection.Designer.cs
generated
135
solution/lab1/FormTrackedVehicleCollection.Designer.cs
generated
@ -30,6 +30,8 @@
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonSortByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
buttonAddTrackedVehicle = new Button();
|
||||
buttonRefresh = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
@ -66,36 +68,56 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(652, 24);
|
||||
groupBoxTools.Margin = new Padding(2);
|
||||
groupBoxTools.Location = new Point(634, 33);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Padding = new Padding(2);
|
||||
groupBoxTools.Size = new Size(208, 490);
|
||||
groupBoxTools.Size = new Size(297, 724);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddTrackedVehicle);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveTrackedVehicle);
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(5, 302);
|
||||
panelCompanyTools.Margin = new Padding(2);
|
||||
panelCompanyTools.Location = new Point(3, 338);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(197, 184);
|
||||
panelCompanyTools.Size = new Size(281, 372);
|
||||
panelCompanyTools.TabIndex = 10;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByColor.Location = new Point(11, 322);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(267, 32);
|
||||
buttonSortByColor.TabIndex = 9;
|
||||
buttonSortByColor.Text = "Сортировать по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByType.Location = new Point(10, 282);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(268, 33);
|
||||
buttonSortByType.TabIndex = 8;
|
||||
buttonSortByType.Text = "Сортировать по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonAddTrackedVehicle
|
||||
//
|
||||
buttonAddTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddTrackedVehicle.Location = new Point(3, 2);
|
||||
buttonAddTrackedVehicle.Margin = new Padding(2);
|
||||
buttonAddTrackedVehicle.Location = new Point(6, 0);
|
||||
buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle";
|
||||
buttonAddTrackedVehicle.Size = new Size(191, 38);
|
||||
buttonAddTrackedVehicle.Size = new Size(273, 63);
|
||||
buttonAddTrackedVehicle.TabIndex = 3;
|
||||
buttonAddTrackedVehicle.Text = "Добавление гусеничной машины";
|
||||
buttonAddTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
@ -104,10 +126,9 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(3, 146);
|
||||
buttonRefresh.Margin = new Padding(2);
|
||||
buttonRefresh.Location = new Point(10, 243);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(190, 29);
|
||||
buttonRefresh.Size = new Size(271, 32);
|
||||
buttonRefresh.TabIndex = 7;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@ -115,11 +136,10 @@
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(4, 44);
|
||||
maskedTextBox.Margin = new Padding(2);
|
||||
maskedTextBox.Location = new Point(3, 123);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(191, 23);
|
||||
maskedTextBox.Size = new Size(284, 31);
|
||||
maskedTextBox.TabIndex = 4;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
maskedTextBox.MaskInputRejected += maskedTextBox1_MaskInputRejected;
|
||||
@ -127,10 +147,9 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(4, 104);
|
||||
buttonGoToCheck.Margin = new Padding(2);
|
||||
buttonGoToCheck.Location = new Point(7, 205);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(192, 38);
|
||||
buttonGoToCheck.Size = new Size(274, 33);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -139,10 +158,9 @@
|
||||
// buttonRemoveTrackedVehicle
|
||||
//
|
||||
buttonRemoveTrackedVehicle.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveTrackedVehicle.Location = new Point(1, 71);
|
||||
buttonRemoveTrackedVehicle.Margin = new Padding(2);
|
||||
buttonRemoveTrackedVehicle.Location = new Point(7, 162);
|
||||
buttonRemoveTrackedVehicle.Name = "buttonRemoveTrackedVehicle";
|
||||
buttonRemoveTrackedVehicle.Size = new Size(192, 29);
|
||||
buttonRemoveTrackedVehicle.Size = new Size(274, 38);
|
||||
buttonRemoveTrackedVehicle.TabIndex = 5;
|
||||
buttonRemoveTrackedVehicle.Text = "Удаление гусеничной машины";
|
||||
buttonRemoveTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
@ -150,10 +168,9 @@
|
||||
//
|
||||
// button1CreateCompany
|
||||
//
|
||||
button1CreateCompany.Location = new Point(7, 269);
|
||||
button1CreateCompany.Margin = new Padding(2);
|
||||
button1CreateCompany.Location = new Point(6, 298);
|
||||
button1CreateCompany.Name = "button1CreateCompany";
|
||||
button1CreateCompany.Size = new Size(193, 29);
|
||||
button1CreateCompany.Size = new Size(276, 33);
|
||||
button1CreateCompany.TabIndex = 9;
|
||||
button1CreateCompany.Text = "Создать компанию";
|
||||
button1CreateCompany.UseVisualStyleBackColor = true;
|
||||
@ -169,18 +186,16 @@
|
||||
panelStorage.Controls.Add(textBoxCollectionName);
|
||||
panelStorage.Controls.Add(labelCollectionName);
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(2, 18);
|
||||
panelStorage.Margin = new Padding(2);
|
||||
panelStorage.Location = new Point(3, 27);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(204, 220);
|
||||
panelStorage.Size = new Size(291, 227);
|
||||
panelStorage.TabIndex = 8;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(6, 183);
|
||||
buttonCollectionDel.Margin = new Padding(2);
|
||||
buttonCollectionDel.Location = new Point(3, 188);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(193, 35);
|
||||
buttonCollectionDel.Size = new Size(276, 33);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
@ -189,19 +204,17 @@
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(7, 130);
|
||||
listBoxCollection.Margin = new Padding(2);
|
||||
listBoxCollection.ItemHeight = 25;
|
||||
listBoxCollection.Location = new Point(6, 153);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(191, 49);
|
||||
listBoxCollection.Size = new Size(275, 29);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(7, 75);
|
||||
buttonCollectionAdd.Margin = new Padding(2);
|
||||
buttonCollectionAdd.Location = new Point(6, 113);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(193, 32);
|
||||
buttonCollectionAdd.Size = new Size(276, 33);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
@ -210,10 +223,9 @@
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(109, 52);
|
||||
radioButtonList.Margin = new Padding(2);
|
||||
radioButtonList.Location = new Point(153, 78);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(66, 19);
|
||||
radioButtonList.Size = new Size(96, 29);
|
||||
radioButtonList.TabIndex = 3;
|
||||
radioButtonList.TabStop = true;
|
||||
radioButtonList.Text = "Список";
|
||||
@ -222,10 +234,9 @@
|
||||
// radioButtonMassive
|
||||
//
|
||||
radioButtonMassive.AutoSize = true;
|
||||
radioButtonMassive.Location = new Point(29, 52);
|
||||
radioButtonMassive.Margin = new Padding(2);
|
||||
radioButtonMassive.Location = new Point(41, 78);
|
||||
radioButtonMassive.Name = "radioButtonMassive";
|
||||
radioButtonMassive.Size = new Size(67, 19);
|
||||
radioButtonMassive.Size = new Size(98, 29);
|
||||
radioButtonMassive.TabIndex = 2;
|
||||
radioButtonMassive.TabStop = true;
|
||||
radioButtonMassive.Text = "Массив";
|
||||
@ -234,19 +245,17 @@
|
||||
//
|
||||
// textBoxCollectionName
|
||||
//
|
||||
textBoxCollectionName.Location = new Point(3, 25);
|
||||
textBoxCollectionName.Margin = new Padding(2);
|
||||
textBoxCollectionName.Location = new Point(4, 42);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(196, 23);
|
||||
textBoxCollectionName.Size = new Size(278, 31);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(29, 8);
|
||||
labelCollectionName.Margin = new Padding(2, 0, 2, 0);
|
||||
labelCollectionName.Location = new Point(41, 13);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(125, 15);
|
||||
labelCollectionName.Size = new Size(186, 25);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Название коллекции:";
|
||||
//
|
||||
@ -256,20 +265,18 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(7, 242);
|
||||
comboBoxSelectorCompany.Margin = new Padding(2);
|
||||
comboBoxSelectorCompany.Location = new Point(3, 258);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(194, 23);
|
||||
comboBoxSelectorCompany.Size = new Size(284, 33);
|
||||
comboBoxSelectorCompany.TabIndex = 1;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Margin = new Padding(2);
|
||||
pictureBox.Location = new Point(0, 33);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(652, 490);
|
||||
pictureBox.Size = new Size(634, 724);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
pictureBox.Click += pictureBox1_Click;
|
||||
@ -280,8 +287,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Padding = new Padding(4, 1, 0, 1);
|
||||
menuStrip.Size = new Size(860, 24);
|
||||
menuStrip.Size = new Size(931, 33);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -289,14 +295,14 @@
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaveToolStripMenuItem, LoadToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(48, 22);
|
||||
файлToolStripMenuItem.Size = new Size(69, 29);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// SaveToolStripMenuItem
|
||||
//
|
||||
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
|
||||
SaveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||
SaveToolStripMenuItem.Size = new Size(181, 22);
|
||||
SaveToolStripMenuItem.Size = new Size(273, 34);
|
||||
SaveToolStripMenuItem.Text = "Сохранение";
|
||||
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
|
||||
//
|
||||
@ -304,7 +310,7 @@
|
||||
//
|
||||
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
|
||||
LoadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
|
||||
LoadToolStripMenuItem.Size = new Size(181, 22);
|
||||
LoadToolStripMenuItem.Size = new Size(273, 34);
|
||||
LoadToolStripMenuItem.Text = "Загрузка";
|
||||
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
|
||||
//
|
||||
@ -319,14 +325,13 @@
|
||||
//
|
||||
// FormTrackedVehicleCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(860, 514);
|
||||
ClientSize = new Size(931, 757);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Margin = new Padding(2);
|
||||
Name = "FormTrackedVehicleCollection";
|
||||
Text = "Коллекция гусеничных машин";
|
||||
Load += FormTrackedVehicleCollection_Load;
|
||||
@ -368,5 +373,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -103,6 +103,7 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
int tempSize = TrackedVehicleSharingService.getAmountOfObjects();
|
||||
try
|
||||
{
|
||||
if (_company - pos != null)
|
||||
@ -265,7 +266,7 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
listBoxCollection.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? colName = _storageCollection.Keys?[i];
|
||||
string? colName = _storageCollection.Keys?[i].Name;
|
||||
if (!string.IsNullOrEmpty(colName))
|
||||
{
|
||||
listBoxCollection.Items.Add(colName);
|
||||
@ -353,4 +354,24 @@ public partial class FormTrackedVehicleCollection : Form
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareTrackedVehicle(new DrawningTrackedVehicleCompareByType());
|
||||
}
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareTrackedVehicle(new DrawningTrackedVehicleCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareTrackedVehicle(IComparer<DrawningTrackedVehicle?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
||||
|
125
solution/lab1/FormTrackedVehicleConfig.Designer.cs
generated
125
solution/lab1/FormTrackedVehicleConfig.Designer.cs
generated
@ -73,10 +73,8 @@
|
||||
groupBoxConfig.Controls.Add(LabelSimpleObject);
|
||||
groupBoxConfig.Dock = DockStyle.Left;
|
||||
groupBoxConfig.Location = new Point(0, 0);
|
||||
groupBoxConfig.Margin = new Padding(2);
|
||||
groupBoxConfig.Name = "groupBoxConfig";
|
||||
groupBoxConfig.Padding = new Padding(2);
|
||||
groupBoxConfig.Size = new Size(444, 252);
|
||||
groupBoxConfig.Size = new Size(634, 420);
|
||||
groupBoxConfig.TabIndex = 0;
|
||||
groupBoxConfig.TabStop = false;
|
||||
groupBoxConfig.Text = "Параметры";
|
||||
@ -91,100 +89,89 @@
|
||||
groupBoxColors.Controls.Add(panelBlue);
|
||||
groupBoxColors.Controls.Add(panelGreen);
|
||||
groupBoxColors.Controls.Add(panelRed);
|
||||
groupBoxColors.Location = new Point(254, 13);
|
||||
groupBoxColors.Margin = new Padding(2);
|
||||
groupBoxColors.Location = new Point(363, 21);
|
||||
groupBoxColors.Name = "groupBoxColors";
|
||||
groupBoxColors.Padding = new Padding(2);
|
||||
groupBoxColors.Size = new Size(186, 83);
|
||||
groupBoxColors.Size = new Size(265, 120);
|
||||
groupBoxColors.TabIndex = 8;
|
||||
groupBoxColors.TabStop = false;
|
||||
//
|
||||
// panelPurple
|
||||
//
|
||||
panelPurple.BackColor = Color.Purple;
|
||||
panelPurple.Location = new Point(150, 46);
|
||||
panelPurple.Margin = new Padding(2);
|
||||
panelPurple.Location = new Point(214, 77);
|
||||
panelPurple.Name = "panelPurple";
|
||||
panelPurple.Size = new Size(24, 22);
|
||||
panelPurple.Size = new Size(34, 37);
|
||||
panelPurple.TabIndex = 5;
|
||||
panelPurple.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelBlack
|
||||
//
|
||||
panelBlack.BackColor = Color.Black;
|
||||
panelBlack.Location = new Point(108, 46);
|
||||
panelBlack.Margin = new Padding(2);
|
||||
panelBlack.Location = new Point(154, 77);
|
||||
panelBlack.Name = "panelBlack";
|
||||
panelBlack.Size = new Size(24, 22);
|
||||
panelBlack.Size = new Size(34, 37);
|
||||
panelBlack.TabIndex = 4;
|
||||
panelBlack.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelGray
|
||||
//
|
||||
panelGray.BackColor = Color.Gray;
|
||||
panelGray.Location = new Point(60, 46);
|
||||
panelGray.Margin = new Padding(2);
|
||||
panelGray.Location = new Point(85, 77);
|
||||
panelGray.Name = "panelGray";
|
||||
panelGray.Size = new Size(24, 22);
|
||||
panelGray.Size = new Size(34, 37);
|
||||
panelGray.TabIndex = 3;
|
||||
panelGray.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelWhite
|
||||
//
|
||||
panelWhite.BackColor = Color.White;
|
||||
panelWhite.Location = new Point(11, 46);
|
||||
panelWhite.Margin = new Padding(2);
|
||||
panelWhite.Location = new Point(16, 77);
|
||||
panelWhite.Name = "panelWhite";
|
||||
panelWhite.Size = new Size(24, 22);
|
||||
panelWhite.Size = new Size(34, 37);
|
||||
panelWhite.TabIndex = 2;
|
||||
panelWhite.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelYellow
|
||||
//
|
||||
panelYellow.BackColor = Color.Yellow;
|
||||
panelYellow.Location = new Point(150, 18);
|
||||
panelYellow.Margin = new Padding(2);
|
||||
panelYellow.Location = new Point(214, 30);
|
||||
panelYellow.Name = "panelYellow";
|
||||
panelYellow.Size = new Size(24, 22);
|
||||
panelYellow.Size = new Size(34, 37);
|
||||
panelYellow.TabIndex = 1;
|
||||
panelYellow.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelBlue
|
||||
//
|
||||
panelBlue.BackColor = Color.Blue;
|
||||
panelBlue.Location = new Point(108, 18);
|
||||
panelBlue.Margin = new Padding(2);
|
||||
panelBlue.Location = new Point(154, 30);
|
||||
panelBlue.Name = "panelBlue";
|
||||
panelBlue.Size = new Size(24, 22);
|
||||
panelBlue.Size = new Size(34, 37);
|
||||
panelBlue.TabIndex = 1;
|
||||
//
|
||||
// panelGreen
|
||||
//
|
||||
panelGreen.BackColor = Color.Green;
|
||||
panelGreen.Location = new Point(60, 18);
|
||||
panelGreen.Margin = new Padding(2);
|
||||
panelGreen.Location = new Point(85, 30);
|
||||
panelGreen.Name = "panelGreen";
|
||||
panelGreen.Size = new Size(24, 22);
|
||||
panelGreen.Size = new Size(34, 37);
|
||||
panelGreen.TabIndex = 1;
|
||||
panelGreen.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// panelRed
|
||||
//
|
||||
panelRed.BackColor = Color.Red;
|
||||
panelRed.Location = new Point(11, 18);
|
||||
panelRed.Margin = new Padding(2);
|
||||
panelRed.Location = new Point(16, 30);
|
||||
panelRed.Name = "panelRed";
|
||||
panelRed.Size = new Size(24, 22);
|
||||
panelRed.Size = new Size(34, 37);
|
||||
panelRed.TabIndex = 0;
|
||||
panelRed.MouseDown += Panel_MouseDown;
|
||||
//
|
||||
// checkBoxOtval
|
||||
//
|
||||
checkBoxOtval.AutoSize = true;
|
||||
checkBoxOtval.Location = new Point(8, 102);
|
||||
checkBoxOtval.Margin = new Padding(2);
|
||||
checkBoxOtval.Location = new Point(12, 147);
|
||||
checkBoxOtval.Name = "checkBoxOtval";
|
||||
checkBoxOtval.Size = new Size(234, 19);
|
||||
checkBoxOtval.Size = new Size(345, 29);
|
||||
checkBoxOtval.TabIndex = 7;
|
||||
checkBoxOtval.Text = "Признак наличия опор для фиксации";
|
||||
checkBoxOtval.UseVisualStyleBackColor = true;
|
||||
@ -192,63 +179,57 @@
|
||||
// checkBoxKovsh
|
||||
//
|
||||
checkBoxKovsh.AutoSize = true;
|
||||
checkBoxKovsh.Location = new Point(8, 79);
|
||||
checkBoxKovsh.Margin = new Padding(2);
|
||||
checkBoxKovsh.Location = new Point(12, 112);
|
||||
checkBoxKovsh.Name = "checkBoxKovsh";
|
||||
checkBoxKovsh.Size = new Size(162, 19);
|
||||
checkBoxKovsh.Size = new Size(238, 29);
|
||||
checkBoxKovsh.TabIndex = 6;
|
||||
checkBoxKovsh.Text = "Признак наличия ковша";
|
||||
checkBoxKovsh.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// numericUpDownWeight
|
||||
//
|
||||
numericUpDownWeight.Location = new Point(74, 45);
|
||||
numericUpDownWeight.Margin = new Padding(2);
|
||||
numericUpDownWeight.Location = new Point(105, 75);
|
||||
numericUpDownWeight.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownWeight.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownWeight.Name = "numericUpDownWeight";
|
||||
numericUpDownWeight.Size = new Size(176, 23);
|
||||
numericUpDownWeight.Size = new Size(252, 31);
|
||||
numericUpDownWeight.TabIndex = 5;
|
||||
numericUpDownWeight.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// labelWeight
|
||||
//
|
||||
labelWeight.AutoSize = true;
|
||||
labelWeight.Location = new Point(8, 45);
|
||||
labelWeight.Margin = new Padding(2, 0, 2, 0);
|
||||
labelWeight.Location = new Point(12, 75);
|
||||
labelWeight.Name = "labelWeight";
|
||||
labelWeight.Size = new Size(29, 15);
|
||||
labelWeight.Size = new Size(43, 25);
|
||||
labelWeight.TabIndex = 4;
|
||||
labelWeight.Text = "Вес:";
|
||||
//
|
||||
// numericUpDownSpeed
|
||||
//
|
||||
numericUpDownSpeed.Location = new Point(74, 22);
|
||||
numericUpDownSpeed.Margin = new Padding(2);
|
||||
numericUpDownSpeed.Location = new Point(105, 36);
|
||||
numericUpDownSpeed.Maximum = new decimal(new int[] { 1000, 0, 0, 0 });
|
||||
numericUpDownSpeed.Minimum = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
numericUpDownSpeed.Name = "numericUpDownSpeed";
|
||||
numericUpDownSpeed.Size = new Size(176, 23);
|
||||
numericUpDownSpeed.Size = new Size(252, 31);
|
||||
numericUpDownSpeed.TabIndex = 3;
|
||||
numericUpDownSpeed.Value = new decimal(new int[] { 100, 0, 0, 0 });
|
||||
//
|
||||
// labelSpeed
|
||||
//
|
||||
labelSpeed.AutoSize = true;
|
||||
labelSpeed.Location = new Point(4, 23);
|
||||
labelSpeed.Margin = new Padding(2, 0, 2, 0);
|
||||
labelSpeed.Location = new Point(6, 38);
|
||||
labelSpeed.Name = "labelSpeed";
|
||||
labelSpeed.Size = new Size(62, 15);
|
||||
labelSpeed.Size = new Size(93, 25);
|
||||
labelSpeed.TabIndex = 2;
|
||||
labelSpeed.Text = "Скорость:";
|
||||
//
|
||||
// LabelModifiedObject
|
||||
//
|
||||
LabelModifiedObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
LabelModifiedObject.Location = new Point(348, 102);
|
||||
LabelModifiedObject.Margin = new Padding(2, 0, 2, 0);
|
||||
LabelModifiedObject.Location = new Point(498, 147);
|
||||
LabelModifiedObject.Name = "LabelModifiedObject";
|
||||
LabelModifiedObject.Size = new Size(92, 24);
|
||||
LabelModifiedObject.Size = new Size(130, 38);
|
||||
LabelModifiedObject.TabIndex = 1;
|
||||
LabelModifiedObject.Text = "Продвинутый";
|
||||
LabelModifiedObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -257,10 +238,9 @@
|
||||
// LabelSimpleObject
|
||||
//
|
||||
LabelSimpleObject.BorderStyle = BorderStyle.FixedSingle;
|
||||
LabelSimpleObject.Location = new Point(254, 102);
|
||||
LabelSimpleObject.Margin = new Padding(2, 0, 2, 0);
|
||||
LabelSimpleObject.Location = new Point(360, 147);
|
||||
LabelSimpleObject.Name = "LabelSimpleObject";
|
||||
LabelSimpleObject.Size = new Size(86, 24);
|
||||
LabelSimpleObject.Size = new Size(122, 38);
|
||||
LabelSimpleObject.TabIndex = 0;
|
||||
LabelSimpleObject.Text = "Простой";
|
||||
LabelSimpleObject.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -268,19 +248,17 @@
|
||||
//
|
||||
// pictureBoxObject
|
||||
//
|
||||
pictureBoxObject.Location = new Point(461, 45);
|
||||
pictureBoxObject.Margin = new Padding(2);
|
||||
pictureBoxObject.Location = new Point(659, 75);
|
||||
pictureBoxObject.Name = "pictureBoxObject";
|
||||
pictureBoxObject.Size = new Size(203, 141);
|
||||
pictureBoxObject.Size = new Size(290, 227);
|
||||
pictureBoxObject.TabIndex = 1;
|
||||
pictureBoxObject.TabStop = false;
|
||||
//
|
||||
// buttonAdd
|
||||
//
|
||||
buttonAdd.Location = new Point(451, 205);
|
||||
buttonAdd.Margin = new Padding(2);
|
||||
buttonAdd.Location = new Point(640, 341);
|
||||
buttonAdd.Name = "buttonAdd";
|
||||
buttonAdd.Size = new Size(112, 36);
|
||||
buttonAdd.Size = new Size(106, 34);
|
||||
buttonAdd.TabIndex = 2;
|
||||
buttonAdd.Text = "Добавить";
|
||||
buttonAdd.UseVisualStyleBackColor = true;
|
||||
@ -288,10 +266,9 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(567, 205);
|
||||
buttonCancel.Margin = new Padding(2);
|
||||
buttonCancel.Location = new Point(752, 341);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(110, 36);
|
||||
buttonCancel.Size = new Size(103, 34);
|
||||
buttonCancel.TabIndex = 3;
|
||||
buttonCancel.Text = "Отмена";
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
@ -301,10 +278,9 @@
|
||||
panelObject1.AllowDrop = true;
|
||||
panelObject1.Controls.Add(labelAdditionalColor);
|
||||
panelObject1.Controls.Add(labelBodyColor);
|
||||
panelObject1.Location = new Point(451, 7);
|
||||
panelObject1.Margin = new Padding(2);
|
||||
panelObject1.Location = new Point(644, 12);
|
||||
panelObject1.Name = "panelObject1";
|
||||
panelObject1.Size = new Size(338, 194);
|
||||
panelObject1.Size = new Size(512, 323);
|
||||
panelObject1.TabIndex = 4;
|
||||
panelObject1.DragDrop += PanelObject1_DragDrop;
|
||||
panelObject1.DragEnter += PanelObject1_DragEnter;
|
||||
@ -313,10 +289,9 @@
|
||||
//
|
||||
labelAdditionalColor.AllowDrop = true;
|
||||
labelAdditionalColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelAdditionalColor.Location = new Point(116, 6);
|
||||
labelAdditionalColor.Margin = new Padding(2, 0, 2, 0);
|
||||
labelAdditionalColor.Location = new Point(102, 9);
|
||||
labelAdditionalColor.Name = "labelAdditionalColor";
|
||||
labelAdditionalColor.Size = new Size(97, 25);
|
||||
labelAdditionalColor.Size = new Size(103, 30);
|
||||
labelAdditionalColor.TabIndex = 2;
|
||||
labelAdditionalColor.Text = "Доп. Цвет";
|
||||
labelAdditionalColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -328,10 +303,9 @@
|
||||
//
|
||||
labelBodyColor.AllowDrop = true;
|
||||
labelBodyColor.BorderStyle = BorderStyle.FixedSingle;
|
||||
labelBodyColor.Location = new Point(10, 6);
|
||||
labelBodyColor.Margin = new Padding(2, 0, 2, 0);
|
||||
labelBodyColor.Location = new Point(3, 9);
|
||||
labelBodyColor.Name = "labelBodyColor";
|
||||
labelBodyColor.Size = new Size(102, 25);
|
||||
labelBodyColor.Size = new Size(93, 30);
|
||||
labelBodyColor.TabIndex = 1;
|
||||
labelBodyColor.Text = "Цвет";
|
||||
labelBodyColor.TextAlign = ContentAlignment.MiddleCenter;
|
||||
@ -340,15 +314,14 @@
|
||||
//
|
||||
// FormTrackedVehicleConfig
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(794, 252);
|
||||
ClientSize = new Size(1168, 420);
|
||||
Controls.Add(pictureBoxObject);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonAdd);
|
||||
Controls.Add(groupBoxConfig);
|
||||
Controls.Add(panelObject1);
|
||||
Margin = new Padding(2);
|
||||
Name = "FormTrackedVehicleConfig";
|
||||
Text = "Создание объекта";
|
||||
Load += FormTrackedVehicleConfig_Load;
|
||||
|
@ -24,7 +24,7 @@ public partial class FormTrackedVehicleConfig : Form
|
||||
/// <summary>
|
||||
/// Событие для предачи объекта
|
||||
/// </summary>
|
||||
private event Action<DrawningTrackedVehicle>? TrackedVehicleDelegate;
|
||||
private event TrackedVehicleDelegate? TrackedVehicleDelegate;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -47,17 +47,7 @@ public partial class FormTrackedVehicleConfig : Form
|
||||
/// </summary>
|
||||
/// <param name="trackedVehicleDelegate"></param>
|
||||
///
|
||||
public void AddEvent(Action<DrawningTrackedVehicle> trackedVehicleDelegate)
|
||||
{
|
||||
if (TrackedVehicleDelegate == null)
|
||||
{
|
||||
TrackedVehicleDelegate = trackedVehicleDelegate;
|
||||
}
|
||||
else
|
||||
{
|
||||
TrackedVehicleDelegate += trackedVehicleDelegate;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
@ -90,6 +80,7 @@ public partial class FormTrackedVehicleConfig : Form
|
||||
private void PanelObject1_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effect = e.Data?.GetDataPresent(DataFormats.Text) ?? false ? DragDropEffects.Copy : DragDropEffects.None;
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Действия при приёме перетаскиваемой информации
|
||||
@ -141,6 +132,10 @@ public partial class FormTrackedVehicleConfig : Form
|
||||
e.Effect = DragDropEffects.None;
|
||||
}
|
||||
}
|
||||
public void AddEvent(TrackedVehicleDelegate trainDelegate)
|
||||
{
|
||||
TrackedVehicleDelegate += trainDelegate;
|
||||
}
|
||||
|
||||
private void labelAdditionalColor_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user