PIbd-11 AbakarovA.A LabWork08 Simple #8
BIN
CourseWork.zip
Normal file
BIN
CourseWork.zip
Normal file
Binary file not shown.
@ -60,7 +60,7 @@ public abstract class AbstractCompany
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningJet jet)
|
||||
{
|
||||
return company._collection.Insert(jet);
|
||||
return company._collection.Insert(jet, new DrawiningJetEqutables());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -112,4 +112,9 @@ public abstract class AbstractCompany
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
/// <summary>
|
||||
/// Сортировка
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
public void Sort(IComparer<DrawningJet?> comparer) => _collection?.CollectionSort(comparer);
|
||||
}
|
||||
|
49
ProjectFighterJet/CollectionGenericObjects/CollectionInfo.cs
Normal file
49
ProjectFighterJet/CollectionGenericObjects/CollectionInfo.cs
Normal file
@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFighterJet.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,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFighterJet.CollectionGenericObjects;
|
||||
namespace ProjectFighterJet.CollectionGenericObjects;
|
||||
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
@ -23,16 +17,18 @@ where T : class
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="comparer">Cравнение двух объектов</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">Cравнение двух объектов</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null);
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
@ -56,4 +52,9 @@ where T : class
|
||||
/// </summary>
|
||||
/// <returns>Поэлементый вывод элементов коллекции</returns>
|
||||
IEnumerable<T?> GetItems();
|
||||
/// <summary>
|
||||
/// Сортировка коллекции
|
||||
/// </summary>
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
@ -56,17 +56,30 @@ where T : class
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// 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)
|
||||
{
|
||||
// TODO выброс ошибки если переполнение
|
||||
// TODO выброс ошибки если за границу
|
||||
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);
|
||||
@ -87,4 +100,8 @@ where T : class
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -53,9 +53,17 @@ where T : class
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
public int Insert(T obj, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningJet>).Equals(obj as DrawningJet, item as DrawningJet))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
@ -69,10 +77,17 @@ where T : class
|
||||
throw new CollectionOverflowException(Count);
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO выброс ошибки если переполнение
|
||||
// TODO выброс ошибки если выход за границу
|
||||
public int Insert(T obj, int position, IEqualityComparer<T?>? comparer = null)
|
||||
{
|
||||
if (comparer != null)
|
||||
{
|
||||
foreach (T? item in _collection)
|
||||
{
|
||||
if ((comparer as IEqualityComparer<DrawningJet>).Equals(obj as DrawningJet, item as DrawningJet))
|
||||
throw new ObjectIsEqualException();
|
||||
}
|
||||
}
|
||||
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
@ -104,8 +119,6 @@ where T : class
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// TODO выброс ошибки если выход за границу
|
||||
// TODO выброс ошибки если объект пустой
|
||||
if (position >= _collection.Length || position < 0) throw new PositionOutOfCollectionException(position);
|
||||
if (_collection[position] == null) throw new ObjectNotFoundException(position);
|
||||
T obj = _collection[position];
|
||||
@ -120,4 +133,8 @@ where T : class
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
void ICollectionGenericObjects<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
@ -20,17 +20,17 @@ where T : DrawningJet
|
||||
/// <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>
|
||||
/// Добавление коллекции в хранилище
|
||||
@ -39,17 +39,13 @@ where T : DrawningJet
|
||||
/// <param name="collectionType">тип коллекции</param>
|
||||
public void AddCollection(string name, CollectionType collectionType)
|
||||
{
|
||||
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,7 +53,9 @@ where T : DrawningJet
|
||||
/// <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>
|
||||
/// Доступ к коллекции
|
||||
@ -68,10 +66,9 @@ where T : DrawningJet
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -105,7 +102,7 @@ where T : DrawningJet
|
||||
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);
|
||||
// не сохраняем пустые коллекции
|
||||
@ -115,8 +112,6 @@ where T : DrawningJet
|
||||
}
|
||||
writer.Write(value.Key);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.GetCollectionType);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
writer.Write(value.Value.MaxCount);
|
||||
writer.Write(_separatorForKeyValue);
|
||||
foreach (T? item in value.Value.GetItems())
|
||||
@ -161,18 +156,16 @@ where T : DrawningJet
|
||||
{
|
||||
|
||||
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);
|
||||
if (collection == null)
|
||||
{
|
||||
CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("Не удалось определить информацию коллекции: " + record[0]);
|
||||
ICollectionGenericObjects<T>? collection = StorageCollection<T>.CreateCollection(collectionInfo.CollectionType) ??
|
||||
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?.CreateDrawningJet() is T jet)
|
||||
@ -190,7 +183,7 @@ where T : DrawningJet
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(record[0], collection);
|
||||
_storages.Add(collectionInfo, collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
66
ProjectFighterJet/Drawnings/DrawiningJetEqutables.cs
Normal file
66
ProjectFighterJet/Drawnings/DrawiningJetEqutables.cs
Normal file
@ -0,0 +1,66 @@
|
||||
using ProjectFighterJet.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFighterJet.Drawnings;
|
||||
|
||||
public class DrawiningJetEqutables : IEqualityComparer<DrawningJet?>
|
||||
{
|
||||
public bool Equals(DrawningJet? x, DrawningJet? y)
|
||||
{
|
||||
if (x == null || x.EntityJet == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (y == null || y.EntityJet == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityJet.Speed != y.EntityJet.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityJet.Weight != y.EntityJet.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x.EntityJet.BodyColor != y.EntityJet.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningFighterJet && y is DrawningFighterJet)
|
||||
{
|
||||
EntityFighterJet _x = (EntityFighterJet)x.EntityJet;
|
||||
EntityFighterJet _y = (EntityFighterJet)x.EntityJet;
|
||||
if (_x.AdditionalColor != _y.AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.Engines != _y.Engines)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.Fuel != _y.Fuel)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (_x.Rockets != _y.Rockets)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningJet obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
34
ProjectFighterJet/Drawnings/DrawningJetCompareByColor.cs
Normal file
34
ProjectFighterJet/Drawnings/DrawningJetCompareByColor.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFighterJet.Drawnings;
|
||||
|
||||
internal class DrawningJetCompareByColor : IComparer<DrawningJet?>
|
||||
{
|
||||
public int Compare(DrawningJet? x, DrawningJet? y)
|
||||
{
|
||||
if (x == null || x.EntityJet == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityJet == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
var bodycolorCompare = x.EntityJet.BodyColor.Name.CompareTo(y.EntityJet.BodyColor.Name);
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
var speedCompare = x.EntityJet.Speed.CompareTo(y.EntityJet.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityJet.Weight.CompareTo(y.EntityJet.Weight);
|
||||
}
|
||||
}
|
35
ProjectFighterJet/Drawnings/DrawningJetCompareByType.cs
Normal file
35
ProjectFighterJet/Drawnings/DrawningJetCompareByType.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectFighterJet.Drawnings;
|
||||
|
||||
internal class DrawningJetCompareByType : IComparer<DrawningJet?>
|
||||
{
|
||||
public int Compare(DrawningJet? x, DrawningJet? y)
|
||||
{
|
||||
if (x == null || x.EntityJet == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityJet == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityJet.Speed.CompareTo(y.EntityJet.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x.EntityJet.Weight.CompareTo(y.EntityJet.Weight);
|
||||
}
|
||||
}
|
21
ProjectFighterJet/Exceptions/ObjectIsEqualException.cs
Normal file
21
ProjectFighterJet/Exceptions/ObjectIsEqualException.cs
Normal file
@ -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 ProjectFighterJet.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) { }
|
||||
}
|
62
ProjectFighterJet/FormJetCollection.Designer.cs
generated
62
ProjectFighterJet/FormJetCollection.Designer.cs
generated
@ -30,6 +30,8 @@
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
panelCompanyTools = new Panel();
|
||||
buttonSortByType = new Button();
|
||||
buttonSortByColor = new Button();
|
||||
buttonAddJet = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonGoToCheck = new Button();
|
||||
@ -66,7 +68,7 @@
|
||||
groupBoxTools.Controls.Add(panelStorage);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(911, 28);
|
||||
groupBoxTools.Location = new Point(881, 28);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(208, 637);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
@ -75,23 +77,47 @@
|
||||
//
|
||||
// panelCompanyTools
|
||||
//
|
||||
panelCompanyTools.Controls.Add(buttonSortByType);
|
||||
panelCompanyTools.Controls.Add(buttonSortByColor);
|
||||
panelCompanyTools.Controls.Add(buttonAddJet);
|
||||
panelCompanyTools.Controls.Add(maskedTextBoxPosition);
|
||||
panelCompanyTools.Controls.Add(buttonGoToCheck);
|
||||
panelCompanyTools.Controls.Add(buttonRemoveJet);
|
||||
panelCompanyTools.Controls.Add(buttonRefresh);
|
||||
panelCompanyTools.Enabled = false;
|
||||
panelCompanyTools.Location = new Point(9, 378);
|
||||
panelCompanyTools.Location = new Point(9, 360);
|
||||
panelCompanyTools.Name = "panelCompanyTools";
|
||||
panelCompanyTools.Size = new Size(199, 287);
|
||||
panelCompanyTools.Size = new Size(199, 305);
|
||||
panelCompanyTools.TabIndex = 8;
|
||||
//
|
||||
// buttonSortByType
|
||||
//
|
||||
buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByType.Location = new Point(3, 193);
|
||||
buttonSortByType.Name = "buttonSortByType";
|
||||
buttonSortByType.Size = new Size(190, 33);
|
||||
buttonSortByType.TabIndex = 8;
|
||||
buttonSortByType.Text = "Сортировка по типу";
|
||||
buttonSortByType.UseVisualStyleBackColor = true;
|
||||
buttonSortByType.Click += buttonSortByType_Click;
|
||||
//
|
||||
// buttonSortByColor
|
||||
//
|
||||
buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonSortByColor.Location = new Point(3, 232);
|
||||
buttonSortByColor.Name = "buttonSortByColor";
|
||||
buttonSortByColor.Size = new Size(190, 33);
|
||||
buttonSortByColor.TabIndex = 7;
|
||||
buttonSortByColor.Text = "Сортировка по цвету";
|
||||
buttonSortByColor.UseVisualStyleBackColor = true;
|
||||
buttonSortByColor.Click += buttonSortByColor_Click;
|
||||
//
|
||||
// buttonAddJet
|
||||
//
|
||||
buttonAddJet.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddJet.Location = new Point(3, 3);
|
||||
buttonAddJet.Name = "buttonAddJet";
|
||||
buttonAddJet.Size = new Size(190, 48);
|
||||
buttonAddJet.Size = new Size(190, 35);
|
||||
buttonAddJet.TabIndex = 1;
|
||||
buttonAddJet.Text = "Добавление самолёта";
|
||||
buttonAddJet.UseVisualStyleBackColor = true;
|
||||
@ -99,17 +125,17 @@
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(3, 111);
|
||||
maskedTextBoxPosition.Location = new Point(3, 44);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(202, 27);
|
||||
maskedTextBoxPosition.Size = new Size(190, 27);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.Location = new Point(3, 182);
|
||||
buttonGoToCheck.Location = new Point(3, 115);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(190, 33);
|
||||
buttonGoToCheck.TabIndex = 6;
|
||||
@ -120,7 +146,7 @@
|
||||
// buttonRemoveJet
|
||||
//
|
||||
buttonRemoveJet.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRemoveJet.Location = new Point(3, 144);
|
||||
buttonRemoveJet.Location = new Point(3, 77);
|
||||
buttonRemoveJet.Name = "buttonRemoveJet";
|
||||
buttonRemoveJet.Size = new Size(190, 32);
|
||||
buttonRemoveJet.TabIndex = 4;
|
||||
@ -131,7 +157,7 @@
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(3, 221);
|
||||
buttonRefresh.Location = new Point(3, 154);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(190, 33);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
@ -141,7 +167,7 @@
|
||||
//
|
||||
// buttonCreateCompany
|
||||
//
|
||||
buttonCreateCompany.Location = new Point(6, 343);
|
||||
buttonCreateCompany.Location = new Point(6, 325);
|
||||
buttonCreateCompany.Name = "buttonCreateCompany";
|
||||
buttonCreateCompany.Size = new Size(196, 29);
|
||||
buttonCreateCompany.TabIndex = 7;
|
||||
@ -162,12 +188,12 @@
|
||||
panelStorage.Dock = DockStyle.Top;
|
||||
panelStorage.Location = new Point(3, 23);
|
||||
panelStorage.Name = "panelStorage";
|
||||
panelStorage.Size = new Size(202, 280);
|
||||
panelStorage.Size = new Size(202, 262);
|
||||
panelStorage.TabIndex = 7;
|
||||
//
|
||||
// buttonCollectionDel
|
||||
//
|
||||
buttonCollectionDel.Location = new Point(3, 248);
|
||||
buttonCollectionDel.Location = new Point(0, 228);
|
||||
buttonCollectionDel.Name = "buttonCollectionDel";
|
||||
buttonCollectionDel.Size = new Size(196, 29);
|
||||
buttonCollectionDel.TabIndex = 6;
|
||||
@ -181,7 +207,7 @@
|
||||
listBoxCollection.ItemHeight = 20;
|
||||
listBoxCollection.Location = new Point(3, 138);
|
||||
listBoxCollection.Name = "listBoxCollection";
|
||||
listBoxCollection.Size = new Size(196, 104);
|
||||
listBoxCollection.Size = new Size(196, 84);
|
||||
listBoxCollection.TabIndex = 5;
|
||||
//
|
||||
// buttonCollectionAdd
|
||||
@ -239,7 +265,7 @@
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(6, 309);
|
||||
comboBoxSelectorCompany.Location = new Point(6, 291);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(196, 28);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
@ -250,7 +276,7 @@
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 28);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(911, 637);
|
||||
pictureBox.Size = new Size(881, 637);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
@ -260,7 +286,7 @@
|
||||
menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem });
|
||||
menuStrip.Location = new Point(0, 0);
|
||||
menuStrip.Name = "menuStrip";
|
||||
menuStrip.Size = new Size(1119, 28);
|
||||
menuStrip.Size = new Size(1089, 28);
|
||||
menuStrip.TabIndex = 2;
|
||||
menuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@ -299,7 +325,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1119, 665);
|
||||
ClientSize = new Size(1089, 665);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Controls.Add(menuStrip);
|
||||
@ -344,5 +370,7 @@
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button buttonSortByType;
|
||||
private Button buttonSortByColor;
|
||||
}
|
||||
}
|
@ -74,6 +74,11 @@ public partial class FormJetCollection : Form
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
catch (ObjectIsEqualException ex)
|
||||
{
|
||||
MessageBox.Show("Такой объект уже присутствует в коллекции");
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
@ -212,27 +217,33 @@ public partial class FormJetCollection : Form
|
||||
|
||||
private void buttonCollectionDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
// нужно убедиться, что есть выбранная коллекция
|
||||
// спросить у пользователя через MessageBox, что он подтверждает, что хочет удалить запись
|
||||
// удалить и обновить ListBox
|
||||
|
||||
if (listBoxCollection.SelectedIndex < 0 || listBoxCollection.SelectedItem == null)
|
||||
{
|
||||
MessageBox.Show("Коллекция не выбрана");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
try
|
||||
{
|
||||
return;
|
||||
if (MessageBox.Show("Удалить коллекцию?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
_logger.LogInformation("Коллекция: " + listBoxCollection.SelectedItem.ToString() + " удалена");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError("Ошибка: {Message}", ex.Message);
|
||||
}
|
||||
_storageCollection.DelCollection(listBoxCollection.SelectedItem.ToString());
|
||||
RerfreshListBoxItems();
|
||||
}
|
||||
private void RerfreshListBoxItems()
|
||||
{
|
||||
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);
|
||||
@ -293,7 +304,7 @@ public partial class FormJetCollection : Form
|
||||
|
||||
private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
try
|
||||
@ -310,4 +321,24 @@ public partial class FormJetCollection : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSortByType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareJet(new DrawningJetCompareByType());
|
||||
}
|
||||
|
||||
private void buttonSortByColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareJet(new DrawningJetCompareByColor());
|
||||
}
|
||||
private void CompareJet(IComparer<DrawningJet?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user