PIbd-11 ShtyrkinE.D. LabWork08 Simple #8
@ -64,7 +64,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningWarship warship)
|
||||
{
|
||||
return company._collection.Insert(warship);
|
||||
return company._collection.Insert(warship, new DrawningWarshipEqutables());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -122,4 +122,10 @@ public abstract class AbstractCompany
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectPosition();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningWarship?> comparer) => _collection?.CollectionSort(comparer);
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAircraftCarrier.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();
|
||||
}
|
||||
}
|
@ -27,16 +27,18 @@ public interface ICollectionGenericObjects<T>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="comparer">Сравнение двух объектов</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>
|
||||
/// <param name="comparer">Сравнение двух объектов</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@ -62,4 +64,10 @@ public interface ICollectionGenericObjects<T>
|
||||
/// </summary>
|
||||
/// <returns>Поэлементный вывод элементов коллекции</returns>
|
||||
IEnumerable<T> GetItems();
|
||||
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
@ -48,15 +48,29 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
if (Count == _maxCount) throw new CollectionOverflowException(Count);
|
||||
if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
_collection.Insert(position, obj);
|
||||
@ -77,4 +91,9 @@ public class ListGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
using ProjectAircraftCarrier.Exceptions;
|
||||
using ProjectAircraftCarrier.Drawnings;
|
||||
using ProjectAircraftCarrier.Exceptions;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -60,8 +62,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<DrawningWarship>).Equals(obj as DrawningWarship, item as DrawningWarship))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
@ -75,8 +85,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<DrawningWarship>).Equals(obj as DrawningWarship, item as DrawningWarship))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
@ -122,4 +140,9 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
@ -10,19 +10,19 @@ 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>
|
||||
@ -32,12 +32,13 @@ public class StorageCollection<T>
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
if (_storages.ContainsKey(name)) return;
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo)) return;
|
||||
if (collectionType == CollectionType.None) return;
|
||||
else if (collectionType == CollectionType.Massive)
|
||||
_storages[name] = new MassiveGenericObjects<T>();
|
||||
_storages[collectionInfo] = new MassiveGenericObjects<T>();
|
||||
else if (collectionType == CollectionType.List)
|
||||
_storages[name] = new ListGenericObjects<T>();
|
||||
_storages[collectionInfo] = new ListGenericObjects<T>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -46,8 +47,9 @@ public class StorageCollection<T>
|
||||
/// <param name="name">Название коллекции</param>
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
if (_storages.ContainsKey(name))
|
||||
_storages.Remove(name);
|
||||
CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty);
|
||||
if (_storages.ContainsKey(collectionInfo))
|
||||
_storages.Remove(collectionInfo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -59,8 +61,9 @@ public class StorageCollection<T>
|
||||
{
|
||||
get
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -100,7 +103,7 @@ 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);
|
||||
if (value.Value.Count == 0)
|
||||
@ -110,8 +113,6 @@ public class StorageCollection<T>
|
||||
|
||||
writer.Write(value.Key);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.GetCollectionType);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.MaxCount);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
|
||||
@ -160,20 +161,22 @@ 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("Не удалось создать коллекцию");
|
||||
}
|
||||
|
||||
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?.CreateDrawningWarship() is T warship)
|
||||
@ -191,7 +194,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAircraftCarrier.Drawnings;
|
||||
|
||||
public class DrawningWarshipCompareByColor : IComparer<DrawningWarship?>
|
||||
{
|
||||
public int Compare(DrawningWarship? x, DrawningWarship? y)
|
||||
{
|
||||
if (x == null || x.EntityWarship == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityWarship == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x.EntityWarship.BodyColor.Name.CompareTo(y.EntityWarship.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x.EntityWarship.Speed.CompareTo(y.EntityWarship.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityWarship.Weight.CompareTo(y.EntityWarship.Weight);
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAircraftCarrier.Drawnings;
|
||||
|
||||
public class DrawningWarshipCompareByType : IComparer<DrawningWarship?>
|
||||
{
|
||||
public int Compare(DrawningWarship? x, DrawningWarship? y)
|
||||
{
|
||||
if (x == null || x.EntityWarship == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityWarship == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityWarship.Speed.CompareTo(y.EntityWarship.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityWarship.Weight.CompareTo(y.EntityWarship.Weight);
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ProjectAircraftCarrier.Entities;
|
||||
|
||||
namespace ProjectAircraftCarrier.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация сравнения двух объектов класса-прорисовки
|
||||
/// </summary>
|
||||
public class DrawningWarshipEqutables : IEqualityComparer<DrawningWarship?>
|
||||
{
|
||||
public bool Equals(DrawningWarship? x, DrawningWarship? y)
|
||||
{
|
||||
if (x == null || x.EntityWarship == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityWarship == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityWarship.Speed != y.EntityWarship.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityWarship.Weight != y.EntityWarship.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityWarship.BodyColor != y.EntityWarship.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningAircraftCarrier && y is DrawningAircraftCarrier)
|
||||
{
|
||||
EntityAircraftCarrier _x = (EntityAircraftCarrier)x.EntityWarship;
|
||||
EntityAircraftCarrier _y = (EntityAircraftCarrier)x.EntityWarship;
|
||||
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.AircraftDeck != _y.AircraftDeck)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.ControlRoom != _y.ControlRoom)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningWarship obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectAircraftCarrier.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, описывающий ошибку переполнения коллекции
|
||||
/// </summary>
|
||||
[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) { }
|
||||
}
|
@ -52,6 +52,8 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
buttonSortByColor = new Button();
|
||||
buttonSortByType = new Button();
|
||||
groupBoxTools.SuspendLayout();
|
||||
panelCompanyTools.SuspendLayout();
|
||||
panelStorage.SuspendLayout();
|
||||
@ -66,15 +68,19 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(916, 28);
|
||||
groupBoxTools.Location = new Point(802, 24);
|
||||
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(205, 731);
|
||||
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxTools.Size = new Size(179, 640);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonAddWarship);
|
||||
panelCompanyTools.Controls.Add(maskedTextBox);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
@ -82,17 +88,19 @@
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Dock = DockStyle.Bottom;
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(3, 400);
|
||||
panelCompanyTools.Location = new Point(3, 345);
|
||||
panelCompanyTools.Margin = new Padding(3, 2, 3, 2);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(199, 328);
|
||||
panelCompanyTools.Size = new Size(173, 293);
|
||||
panelCompanyTools.TabIndex = 9;
|
||||
//
|
||||
// buttonAddWarship
|
||||
//
|
||||
buttonAddWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddWarship.Location = new Point(3, 21);
|
||||
buttonAddWarship.Location = new Point(3, 2);
|
||||
buttonAddWarship.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAddWarship.Name = "buttonAddWarship";
|
||||
buttonAddWarship.Size = new Size(193, 52);
|
||||
buttonAddWarship.Size = new Size(168, 39);
|
||||
buttonAddWarship.TabIndex = 1;
|
||||
buttonAddWarship.Text = "Добавление\r\nвоенного корабля";
|
||||
buttonAddWarship.UseVisualStyleBackColor = true;
|
||||
@ -100,19 +108,21 @@
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(3, 119);
|
||||
maskedTextBox.Location = new Point(3, 44);
|
||||
maskedTextBox.Margin = new Padding(3, 2, 3, 2);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(193, 27);
|
||||
maskedTextBox.Size = new Size(169, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(3, 268);
|
||||
buttonRefresh.Location = new Point(3, 158);
|
||||
buttonRefresh.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(193, 52);
|
||||
buttonRefresh.Size = new Size(168, 39);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
@ -121,9 +131,10 @@
|
||||
// buttonRemoveWarship
|
||||
//
|
||||
buttonRemoveWarship.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveWarship.Location = new Point(3, 152);
|
||||
buttonRemoveWarship.Location = new Point(3, 71);
|
||||
buttonRemoveWarship.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRemoveWarship.Name = "buttonRemoveWarship";
|
||||
buttonRemoveWarship.Size = new Size(193, 52);
|
||||
buttonRemoveWarship.Size = new Size(168, 39);
|
||||
buttonRemoveWarship.TabIndex = 4;
|
||||
buttonRemoveWarship.Text = "Удалить \r\nвоенный корабль";
|
||||
buttonRemoveWarship.UseVisualStyleBackColor = true;
|
||||
@ -132,9 +143,10 @@
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(3, 210);
|
||||
buttonGoToCheck.Location = new Point(3, 115);
|
||||
buttonGoToCheck.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(193, 52);
|
||||
buttonGoToCheck.Size = new Size(168, 39);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
@ -142,9 +154,10 @@
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(6, 369);
|
||||
buttonCreateCompany.Location = new Point(5, 277);
|
||||
buttonCreateCompany.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(193, 29);
|
||||
buttonCreateCompany.Size = new Size(169, 22);
|
||||
buttonCreateCompany.TabIndex = 8;
|
||||
buttonCreateCompany.Text = "Создать компанию";
|
||||
buttonCreateCompany.UseVisualStyleBackColor = true;
|
||||
@ -160,16 +173,18 @@
|
||||
panelStorage.Controls.Add(textBoxCollectionName);
|
||||
panelStorage.Controls.Add(labelCollectionName);
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 23);
|
||||
panelStorage.Location = new Point(3, 18);
|
||||
panelStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(199, 290);
|
||||
panelStorage.Size = new Size(173, 218);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(3, 241);
|
||||
buttonCollectionDel.Location = new Point(3, 181);
|
||||
buttonCollectionDel.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(193, 29);
|
||||
buttonCollectionDel.Size = new Size(169, 22);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
buttonCollectionDel.Text = "Удалить коллекцию";
|
||||
buttonCollectionDel.UseVisualStyleBackColor = true;
|
||||
@ -178,17 +193,19 @@
|
||||
// listBoxCollection
|
||||
//
|
||||
listBoxCollection.FormattingEnabled = true;
|
||||
listBoxCollection.ItemHeight = 20;
|
||||
listBoxCollection.Location = new Point(6, 131);
|
||||
listBoxCollection.ItemHeight = 15;
|
||||
listBoxCollection.Location = new Point(5, 98);
|
||||
listBoxCollection.Margin = new Padding(3, 2, 3, 2);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(193, 104);
|
||||
listBoxCollection.Size = new Size(169, 79);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
//
|
||||
buttonCollectionAdd.Location = new Point(3, 96);
|
||||
buttonCollectionAdd.Location = new Point(3, 72);
|
||||
buttonCollectionAdd.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonCollectionAdd.Name = "buttonCollectionAdd";
|
||||
buttonCollectionAdd.Size = new Size(193, 29);
|
||||
buttonCollectionAdd.Size = new Size(169, 22);
|
||||
buttonCollectionAdd.TabIndex = 4;
|
||||
buttonCollectionAdd.Text = "Добавить коллекцию";
|
||||
buttonCollectionAdd.UseVisualStyleBackColor = true;
|
||||
@ -197,9 +214,10 @@
|
||||
// radioButtonList
|
||||
//
|
||||
radioButtonList.AutoSize = true;
|
||||
radioButtonList.Location = new Point(101, 66);
|
||||
radioButtonList.Location = new Point(88, 50);
|
||||
radioButtonList.Margin = new Padding(3, 2, 3, 2);
|
||||
radioButtonList.Name = "radioButtonList";
|
||||
radioButtonList.Size = new Size(80, 24);
|
||||
radioButtonList.Size = new Size(66, 19);
|
||||
radioButtonList.TabIndex = 3;
|
||||
radioButtonList.TabStop = true;
|
||||
radioButtonList.Text = "Список";
|
||||
@ -208,9 +226,10 @@
|
||||
// radioButtonMassive
|
||||
//
|
||||
radioButtonMassive.AutoSize = true;
|
||||
radioButtonMassive.Location = new Point(13, 66);
|
||||
radioButtonMassive.Location = new Point(11, 50);
|
||||
radioButtonMassive.Margin = new Padding(3, 2, 3, 2);
|
||||
radioButtonMassive.Name = "radioButtonMassive";
|
||||
radioButtonMassive.Size = new Size(82, 24);
|
||||
radioButtonMassive.Size = new Size(67, 19);
|
||||
radioButtonMassive.TabIndex = 2;
|
||||
radioButtonMassive.TabStop = true;
|
||||
radioButtonMassive.Text = "Массив";
|
||||
@ -218,17 +237,18 @@
|
||||
//
|
||||
// textBoxCollectionName
|
||||
//
|
||||
textBoxCollectionName.Location = new Point(3, 33);
|
||||
textBoxCollectionName.Location = new Point(3, 25);
|
||||
textBoxCollectionName.Margin = new Padding(3, 2, 3, 2);
|
||||
textBoxCollectionName.Name = "textBoxCollectionName";
|
||||
textBoxCollectionName.Size = new Size(193, 27);
|
||||
textBoxCollectionName.Size = new Size(169, 23);
|
||||
textBoxCollectionName.TabIndex = 1;
|
||||
//
|
||||
// labelCollectionName
|
||||
//
|
||||
labelCollectionName.AutoSize = true;
|
||||
labelCollectionName.Location = new Point(20, 10);
|
||||
labelCollectionName.Location = new Point(18, 8);
|
||||
labelCollectionName.Name = "labelCollectionName";
|
||||
labelCollectionName.Size = new Size(158, 20);
|
||||
labelCollectionName.Size = new Size(125, 15);
|
||||
labelCollectionName.TabIndex = 0;
|
||||
labelCollectionName.Text = "Название коллекции:";
|
||||
//
|
||||
@ -238,18 +258,20 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 335);
|
||||
comboBoxSelectorCompany.Location = new Point(5, 251);
|
||||
comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(193, 28);
|
||||
comboBoxSelectorCompany.Size = new Size(169, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 28);
|
||||
pictureBox.Location = new Point(0, 24);
|
||||
pictureBox.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(916, 731);
|
||||
pictureBox.Size = new Size(802, 640);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -259,7 +281,8 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1121, 28);
|
||||
menuStrip.Padding = new Padding(5, 2, 0, 2);
|
||||
menuStrip.Size = new Size(981, 24);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip";
|
||||
//
|
||||
@ -267,14 +290,14 @@
|
||||
//
|
||||
файлToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { saveToolStripMenuItem, loadToolStripMenuItem });
|
||||
файлToolStripMenuItem.Name = "файлToolStripMenuItem";
|
||||
файлToolStripMenuItem.Size = new Size(59, 24);
|
||||
файлToolStripMenuItem.Size = new Size(48, 20);
|
||||
файлToolStripMenuItem.Text = "Файл";
|
||||
//
|
||||
// saveToolStripMenuItem
|
||||
//
|
||||
saveToolStripMenuItem.Name = "saveToolStripMenuItem";
|
||||
saveToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.S;
|
||||
saveToolStripMenuItem.Size = new Size(227, 26);
|
||||
saveToolStripMenuItem.Size = new Size(181, 22);
|
||||
saveToolStripMenuItem.Text = "Сохранение";
|
||||
saveToolStripMenuItem.Click += saveToolStripMenuItem_Click;
|
||||
//
|
||||
@ -282,7 +305,7 @@
|
||||
//
|
||||
loadToolStripMenuItem.Name = "loadToolStripMenuItem";
|
||||
loadToolStripMenuItem.ShortcutKeys = Keys.Control | Keys.L;
|
||||
loadToolStripMenuItem.Size = new Size(227, 26);
|
||||
loadToolStripMenuItem.Size = new Size(181, 22);
|
||||
loadToolStripMenuItem.Text = "Загрузка";
|
||||
loadToolStripMenuItem.Click += loadToolStripMenuItem_Click;
|
||||
//
|
||||
@ -294,15 +317,40 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file | *.txt";
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByColor.Location = new Point(2, 244);
|
||||
buttonSortByColor.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(168, 39);
|
||||
buttonSortByColor.TabIndex = 8;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByType.Location = new Point(2, 201);
|
||||
buttonSortByType.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(168, 39);
|
||||
buttonSortByType.TabIndex = 7;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// FormWarshipCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1121, 759);
|
||||
ClientSize = new Size(981, 664);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
MainMenuStrip = menuStrip;
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormWarshipCollection";
|
||||
Text = "Коллекция военных кораблей";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
@ -343,5 +391,7 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByColor;
|
||||
private Button buttonSortByType;
|
||||
}
|
||||
}
|
@ -78,6 +78,11 @@ public partial class FormWarshipCollection : Form
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
catch (ObjectIsEqualException ex)
|
||||
{
|
||||
MessageBox.Show("Такой объект уже есть в коллекции");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRemoveWarship_Click(object sender, EventArgs e)
|
||||
@ -153,7 +158,7 @@ public partial class FormWarshipCollection : 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);
|
||||
@ -273,4 +278,24 @@ public partial class FormWarshipCollection : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareWarship(new DrawningWarshipCompareByType());
|
||||
}
|
||||
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareWarship(new DrawningWarshipCompareByColor());
|
||||
}
|
||||
|
||||
private void CompareWarship(IComparer<DrawningWarship?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user