Compare commits
No commits in common. "7fc6a50c1b404b44a9988c256568a3e244e74d62" and "507118762322d6568cadd14529075ecac9de956e" have entirely different histories.
7fc6a50c1b
...
5071187623
@ -30,17 +30,13 @@ public abstract class AbstractCompany
|
||||
}
|
||||
|
||||
// Перегрузка оператора сложения для класса
|
||||
// [ ! ] insted of bool:
|
||||
public static int operator +(AbstractCompany company,
|
||||
DrawningBase transport) => company._collection.Insert(transport, new DrawiningShipEqutables());
|
||||
DrawningBase trasport) => company._collection.Insert(trasport);
|
||||
|
||||
// Перегрузка оператора удаления для класса
|
||||
public static DrawningBase operator -(AbstractCompany company,
|
||||
int pos) => company._collection?.Remove(pos);
|
||||
|
||||
// Сортировка ----------------------------------------------------------- [!]
|
||||
public void Sort(IComparer<DrawningBase?> comparer) =>
|
||||
_collection?.CollectionSort(comparer);
|
||||
|
||||
int pos) => company._collection.Remove(pos);
|
||||
|
||||
// Получение случайного объекта из коллекции
|
||||
public DrawningBase? GetRandomObject()
|
||||
|
@ -1,5 +1,4 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
using ProjectCruiser.Exceptions;
|
||||
using ProjectCruiser.Exceptions;
|
||||
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
@ -47,19 +46,16 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||
throw new ObjectNotFoundException(index);
|
||||
|
||||
return _collection[index];
|
||||
|
||||
// CollectionOverflowException
|
||||
// PositionOutOfCollectionException
|
||||
// ObjectNotFoundException
|
||||
}
|
||||
|
||||
public int Insert(T? item, IEqualityComparer<DrawningBase?>? cmpr = null)
|
||||
public int Insert(T? item)
|
||||
{
|
||||
if (item == null) throw
|
||||
new NullReferenceException("> Inserting item is null");
|
||||
else
|
||||
{
|
||||
if (cmpr != null && item == cmpr)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
// выход за границы, курируется CollectionOverflowException
|
||||
if (Count >= _maxCount) throw new CollectionOverflowException(Count);
|
||||
@ -74,23 +70,18 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||
}
|
||||
}
|
||||
return Count;
|
||||
|
||||
// NullReferenceException
|
||||
// CollectionOverflowException
|
||||
}
|
||||
|
||||
public int Insert(T? item, int index, IEqualityComparer<DrawningBase?>? cmpr = null)
|
||||
public int Insert(T? item, int index)
|
||||
{
|
||||
|
||||
if (index < 0 || index >= _maxCount) throw new PositionOutOfCollectionException(index);
|
||||
if (Count >= _maxCount) throw new CollectionOverflowException(Count);
|
||||
|
||||
if (item == null) throw
|
||||
new NullReferenceException("> Inserting item (at position) is null");
|
||||
else
|
||||
{
|
||||
if (cmpr != null && item == cmpr)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
@ -113,6 +104,10 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||
_collection[firstNullIndex] = item;
|
||||
return firstNullIndex;
|
||||
}
|
||||
|
||||
// PositionOutOfCollectionException
|
||||
// CollectionOverflowException
|
||||
// NullReferenceException
|
||||
}
|
||||
|
||||
public T? Remove(int index)
|
||||
@ -129,6 +124,9 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||
if (item == null) throw new ObjectNotFoundException(index);
|
||||
|
||||
return item;
|
||||
|
||||
// PositionOutOfCollectionException
|
||||
// ObjectNotFoundException
|
||||
}
|
||||
|
||||
public IEnumerable<T?> GetItems()
|
||||
@ -138,10 +136,5 @@ public class ArrayGenObj<T> : ICollectionGenObj<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenObj<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
Array.Sort(_collection, comparer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
// Класс, хранящиий информацию по коллекции
|
||||
/// </summary>
|
||||
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)
|
||||
{
|
||||
// if (Name != other.Name) return false; >>>
|
||||
// else if (CollectionType != other.CollectionType) return false;
|
||||
// else if (Description != other.Description) return false;
|
||||
|
||||
return Name == other?.Name;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return Equals(obj as CollectionInfo);
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public interface ICollectionGenObj<T> where T : class
|
||||
{
|
||||
@ -13,8 +11,8 @@ public interface ICollectionGenObj<T> where T : class
|
||||
/// Добавление объекта в коллекцию
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, IEqualityComparer<DrawningBase?>? cmpr = null);
|
||||
int Insert(T obj, int position, IEqualityComparer<DrawningBase?>? cmpr = null);
|
||||
int Insert(T obj);
|
||||
int Insert(T obj, int position);
|
||||
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// <param name="position">Позиция</param>
|
||||
@ -29,8 +27,4 @@ public interface ICollectionGenObj<T> where T : class
|
||||
|
||||
// Получение объектов коллекции по одному
|
||||
IEnumerable<T?> GetItems();
|
||||
|
||||
// Сортировка коллекции
|
||||
/// <param name="comparer">Сравнитель объектов</param>
|
||||
void CollectionSort(IComparer<T?> comparer);
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
using ProjectCruiser.Exceptions;
|
||||
using ProjectCruiser.Exceptions;
|
||||
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
@ -49,17 +48,10 @@ public class ListGenObj<T> : ICollectionGenObj<T>
|
||||
return _collection[position];
|
||||
}
|
||||
|
||||
public int Insert(T? obj, IEqualityComparer<DrawningBase?>? cmpr = null)
|
||||
public int Insert(T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new NullReferenceException("> Inserting object is null");
|
||||
else
|
||||
{
|
||||
if (cmpr != null && obj == cmpr)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
// выход за границы, курируется CollectionOverflowException
|
||||
if (Count >= _maxCount) throw new CollectionOverflowException(Count);
|
||||
@ -68,7 +60,7 @@ public class ListGenObj<T> : ICollectionGenObj<T>
|
||||
return Count;
|
||||
}
|
||||
|
||||
public int Insert(T? obj, int position, IEqualityComparer<DrawningBase?>? cmpr = null)
|
||||
public int Insert(T? obj, int position)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
throw new PositionOutOfCollectionException(position);
|
||||
@ -76,13 +68,6 @@ public class ListGenObj<T> : ICollectionGenObj<T>
|
||||
|
||||
if (obj == null)
|
||||
throw new NullReferenceException("> Inserting object (at position) is null");
|
||||
else
|
||||
{
|
||||
if (cmpr != null && obj == cmpr)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
_collection.Insert(position, obj);
|
||||
return position;
|
||||
@ -111,9 +96,4 @@ public class ListGenObj<T> : ICollectionGenObj<T>
|
||||
yield return _collection[i];
|
||||
}
|
||||
}
|
||||
|
||||
void ICollectionGenObj<T>.CollectionSort(IComparer<T?> comparer)
|
||||
{
|
||||
_collection.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +1,56 @@
|
||||
using System.CodeDom;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using ProjectCruiser.DrawningSamples;
|
||||
using ProjectCruiser.Exceptions;
|
||||
|
||||
namespace ProjectCruiser.CollectionGenericObj;
|
||||
|
||||
public class StorageCollection<T>
|
||||
where T : DrawningBase // class
|
||||
{
|
||||
// Разделитель для записи ключа и значения элемента словаря
|
||||
private readonly string _separatorForKeyValue = "|";
|
||||
// Разделитель для записей коллекции данных в файл
|
||||
private readonly string _separatorItems = ";";
|
||||
|
||||
// Ключевое слово, с которого должен начинаться файл
|
||||
private readonly string _collectionKey = "CollectionsStorage";
|
||||
|
||||
// Словарь (хранилище) с коллекциями < CollectionInfo, type (class) >
|
||||
readonly Dictionary<CollectionInfo, ICollectionGenObj<T>> _storages;
|
||||
// Словарь (хранилище) с коллекциями < name, type (class) >
|
||||
readonly Dictionary<string, ICollectionGenObj<T>> _storages;
|
||||
|
||||
// Возвращение списка коллекций
|
||||
public List<CollectionInfo> Keys => _storages.Keys.ToList();
|
||||
// Возвращение списка названий коллекций
|
||||
public List<string> Keys => _storages.Keys.ToList();
|
||||
|
||||
public StorageCollection()
|
||||
{
|
||||
_storages = new Dictionary<CollectionInfo, ICollectionGenObj<T>>();
|
||||
_storages = new Dictionary<string, ICollectionGenObj<T>>();
|
||||
}
|
||||
|
||||
// Добавление коллекции в хранилище
|
||||
public void AddCollection(string name, CollectionType collType)
|
||||
{
|
||||
// descroption [ ? ] >>>
|
||||
CollectionInfo coll = new CollectionInfo(name, collType, string.Empty);
|
||||
|
||||
if (name == null || _storages.ContainsKey(coll)
|
||||
if (name == null || _storages.ContainsKey(name)
|
||||
|| collType == CollectionType.None)
|
||||
{
|
||||
throw new NullReferenceException("> Not enough information to save");
|
||||
}
|
||||
|
||||
_storages.Add(coll, CreateCollection(collType));
|
||||
ICollectionGenObj<T> collection = CreateCollection(collType);
|
||||
_storages.Add(name, collection);
|
||||
}
|
||||
|
||||
// Удаление коллекции ( по ключу-строке - её имени )
|
||||
public void DelCollection(string name)
|
||||
{
|
||||
// descroption [ ? ] >>>
|
||||
CollectionInfo coll = new CollectionInfo(name,
|
||||
CollectionType.None, string.Empty);
|
||||
|
||||
if (_storages.ContainsKey(coll)) _storages.Remove(coll);
|
||||
if (_storages.ContainsKey(name)) _storages.Remove(name);
|
||||
else throw new NullReferenceException("> No such key in the list");
|
||||
}
|
||||
|
||||
// Доступ к коллекции , индексатор [!!!]
|
||||
// Доступ к коллекции ( по ключу-строке - её имени ) - индексатор [!!!]
|
||||
public ICollectionGenObj<T>? this[string name]
|
||||
{
|
||||
get => _storages.ContainsKey(new CollectionInfo(name, CollectionType.None, string.Empty))
|
||||
? _storages[new CollectionInfo(name, CollectionType.None, string.Empty)] : null;
|
||||
get => _storages.ContainsKey(name) ? _storages[name] : null;
|
||||
}
|
||||
|
||||
/// Сохранение информации по автомобилям в хранилище в файл
|
||||
@ -70,14 +68,15 @@ public class StorageCollection<T>
|
||||
|
||||
sb.Append(_collectionKey); // const
|
||||
|
||||
foreach (KeyValuePair<CollectionInfo, ICollectionGenObj<T>> pair in _storages)
|
||||
foreach (KeyValuePair<string, ICollectionGenObj<T>> pair in _storages)
|
||||
{
|
||||
sb.Append(Environment.NewLine); // не сохраняем пустые коллекции
|
||||
if (pair.Value.Count == 0) { continue; }
|
||||
|
||||
sb.Append(pair.Key);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
// <...>
|
||||
sb.Append(pair.Value.GetCollectionType);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
sb.Append(pair.Value.MaxCount);
|
||||
sb.Append(_separatorForKeyValue);
|
||||
|
||||
@ -145,19 +144,18 @@ public class StorageCollection<T>
|
||||
foreach (string data in companies)
|
||||
{
|
||||
string[] record = data.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (record.Length != 3) // >
|
||||
// [key + collType] | maxcount | all next inf > 4
|
||||
if (record.Length != 4) // >
|
||||
// key | collType | maxcount | all next inf > 4
|
||||
{ continue; }
|
||||
|
||||
CollectionInfo? collInfo = CollectionInfo.GetCollectionInfo(record[0]) ??
|
||||
throw new Exception("[!] Failed to decode information : " + record[0]);
|
||||
CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]);
|
||||
ICollectionGenObj<T>? collection = StorageCollection<T>.CreateCollection(collectionType);
|
||||
|
||||
ICollectionGenObj<T>? collection = StorageCollection<T>.CreateCollection(
|
||||
collInfo.CollectionType) ??
|
||||
throw new Exception("[!] Failed to create a collection");
|
||||
if (collection == null)
|
||||
throw new NullReferenceException("[!] Failed to create collection");
|
||||
|
||||
collection.MaxCount = Convert.ToInt32(record[1]);
|
||||
string[] set = record[2].Split(_separatorItems,
|
||||
collection.MaxCount = Convert.ToInt32(record[2]);
|
||||
string[] set = record[3].Split(_separatorItems,
|
||||
StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
foreach (string elem in set)
|
||||
@ -167,6 +165,10 @@ public class StorageCollection<T>
|
||||
try
|
||||
{
|
||||
collection.Insert(ship);
|
||||
|
||||
// throw new IndexOutOfRangeException IF IT WAS Insert(item, pos)
|
||||
// NullReferenceException >
|
||||
// CollectionOverflowException >
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -174,7 +176,7 @@ public class StorageCollection<T>
|
||||
}
|
||||
}
|
||||
}
|
||||
_storages.Add(collInfo, collection);
|
||||
_storages.Add(record[0], collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,31 +0,0 @@
|
||||
namespace ProjectCruiser.DrawningSamples;
|
||||
|
||||
// Сравнение по типу, скорости, весу
|
||||
public class DrawningShipCompare : IComparer<DrawningBase?>
|
||||
{
|
||||
public int Compare(DrawningBase? x, DrawningBase? y)
|
||||
{
|
||||
if (x == null || x.EntityTransport == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityTransport == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityTransport.Speed.CompareTo(y.EntityTransport.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityTransport.Weight.CompareTo(y.EntityTransport.Weight);
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
namespace ProjectCruiser.DrawningSamples;
|
||||
|
||||
public class DrawningShipCompareByColor : IComparer<DrawningBase?>
|
||||
{
|
||||
public int Compare(DrawningBase? x, DrawningBase? y)
|
||||
{
|
||||
if (x == null || x.EntityTransport == null)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (y == null || y.EntityTransport == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
var bodycolorCompare = x.EntityTransport.MainColor.Name.CompareTo(
|
||||
y.EntityTransport.MainColor.Name);
|
||||
|
||||
if (bodycolorCompare != 0)
|
||||
{
|
||||
return bodycolorCompare;
|
||||
}
|
||||
|
||||
var speedCompare = x.EntityTransport.Speed.CompareTo(y.EntityTransport.Speed);
|
||||
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
|
||||
return x.EntityTransport.Weight.CompareTo(y.EntityTransport.Weight);
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using ProjectCruiser.Entities;
|
||||
|
||||
namespace ProjectCruiser.DrawningSamples;
|
||||
|
||||
// Реализация сравнения двух объектов класса-прорисовки
|
||||
public class DrawiningShipEqutables : IEqualityComparer<DrawningBase?>
|
||||
{
|
||||
public bool Equals(DrawningBase? x, DrawningBase? y)
|
||||
{
|
||||
if (x == null || x.EntityTransport == null) return false;
|
||||
if (y == null || y.EntityTransport == null) return false;
|
||||
if (x.GetType().Name != y.GetType().Name) return false;
|
||||
|
||||
if (x.EntityTransport.Speed != y.EntityTransport.Speed) return false;
|
||||
if (x.EntityTransport.Weight != y.EntityTransport.Weight) return false;
|
||||
if (x.EntityTransport.MainColor != y.EntityTransport.MainColor) return false;
|
||||
|
||||
if (x is DrawningCruiser && y is DrawningCruiser)
|
||||
{
|
||||
/* public Color AdditionalColor { get; private set; } // доп. цвет
|
||||
// признаки (наличия)
|
||||
public bool HelicopterPads { get; private set; } // вертолетная площадка
|
||||
public bool Hangars { get; private set; } // ангар */
|
||||
|
||||
EntityCruiser EntityX = (EntityCruiser)x.EntityTransport;
|
||||
EntityCruiser EntityY = (EntityCruiser)y.EntityTransport;
|
||||
|
||||
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
|
||||
return false;
|
||||
|
||||
if (EntityX.Hangars != EntityY.Hangars)
|
||||
return false;
|
||||
|
||||
if (EntityX.HelicopterPads != EntityY.HelicopterPads)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public int GetHashCode([DisallowNull] DrawningBase obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
|
78
ProjectCruiser/ServiceForm2.Designer.cs
generated
78
ProjectCruiser/ServiceForm2.Designer.cs
generated
@ -52,8 +52,6 @@
|
||||
loadToolStripMenuItem = new ToolStripMenuItem();
|
||||
saveFileDialog = new SaveFileDialog();
|
||||
openFileDialog = new OpenFileDialog();
|
||||
btnSortType = new Button();
|
||||
btnSortColor = new Button();
|
||||
groupBox.SuspendLayout();
|
||||
companyPanel.SuspendLayout();
|
||||
toolPanel.SuspendLayout();
|
||||
@ -66,7 +64,7 @@
|
||||
comboBoxArrList.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxArrList.FormattingEnabled = true;
|
||||
comboBoxArrList.Items.AddRange(new object[] { "Storage" });
|
||||
comboBoxArrList.Location = new Point(17, 38);
|
||||
comboBoxArrList.Location = new Point(17, 51);
|
||||
comboBoxArrList.Name = "comboBoxArrList";
|
||||
comboBoxArrList.Size = new Size(241, 40);
|
||||
comboBoxArrList.TabIndex = 0;
|
||||
@ -79,9 +77,9 @@
|
||||
groupBox.Controls.Add(toolPanel);
|
||||
groupBox.Controls.Add(btnCreateCompany);
|
||||
groupBox.Controls.Add(comboBoxArrList);
|
||||
groupBox.Location = new Point(1421, 43);
|
||||
groupBox.Location = new Point(1421, 47);
|
||||
groupBox.Name = "groupBox";
|
||||
groupBox.Size = new Size(273, 964);
|
||||
groupBox.Size = new Size(273, 934);
|
||||
groupBox.TabIndex = 2;
|
||||
groupBox.TabStop = false;
|
||||
groupBox.Text = "Tool panel";
|
||||
@ -95,17 +93,17 @@
|
||||
companyPanel.Controls.Add(rBtnArray);
|
||||
companyPanel.Controls.Add(maskedTxtBoxCName);
|
||||
companyPanel.Controls.Add(label);
|
||||
companyPanel.Location = new Point(17, 83);
|
||||
companyPanel.Location = new Point(17, 98);
|
||||
companyPanel.Name = "companyPanel";
|
||||
companyPanel.Size = new Size(243, 359);
|
||||
companyPanel.Size = new Size(243, 391);
|
||||
companyPanel.TabIndex = 7;
|
||||
//
|
||||
// btnDeleteCollection
|
||||
//
|
||||
btnDeleteCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnDeleteCollection.Location = new Point(16, 276);
|
||||
btnDeleteCollection.Location = new Point(15, 312);
|
||||
btnDeleteCollection.Name = "btnDeleteCollection";
|
||||
btnDeleteCollection.Size = new Size(214, 76);
|
||||
btnDeleteCollection.Size = new Size(214, 73);
|
||||
btnDeleteCollection.TabIndex = 11;
|
||||
btnDeleteCollection.Text = "Remove Collection";
|
||||
btnDeleteCollection.UseVisualStyleBackColor = true;
|
||||
@ -114,17 +112,17 @@
|
||||
// listBox
|
||||
//
|
||||
listBox.FormattingEnabled = true;
|
||||
listBox.Location = new Point(16, 171);
|
||||
listBox.Location = new Point(16, 174);
|
||||
listBox.Name = "listBox";
|
||||
listBox.Size = new Size(214, 100);
|
||||
listBox.Size = new Size(214, 132);
|
||||
listBox.TabIndex = 10;
|
||||
//
|
||||
// btnAddCollection
|
||||
//
|
||||
btnAddCollection.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddCollection.Location = new Point(15, 118);
|
||||
btnAddCollection.Location = new Point(15, 119);
|
||||
btnAddCollection.Name = "btnAddCollection";
|
||||
btnAddCollection.Size = new Size(214, 49);
|
||||
btnAddCollection.Size = new Size(214, 50);
|
||||
btnAddCollection.TabIndex = 7;
|
||||
btnAddCollection.Text = "Add Collection";
|
||||
btnAddCollection.UseVisualStyleBackColor = true;
|
||||
@ -144,7 +142,7 @@
|
||||
// rBtnArray
|
||||
//
|
||||
rBtnArray.AutoSize = true;
|
||||
rBtnArray.Location = new Point(16, 79);
|
||||
rBtnArray.Location = new Point(16, 80);
|
||||
rBtnArray.Name = "rBtnArray";
|
||||
rBtnArray.Size = new Size(100, 36);
|
||||
rBtnArray.TabIndex = 8;
|
||||
@ -171,25 +169,23 @@
|
||||
//
|
||||
// toolPanel
|
||||
//
|
||||
toolPanel.Controls.Add(btnSortColor);
|
||||
toolPanel.Controls.Add(btnSortType);
|
||||
toolPanel.Controls.Add(btnUpdate);
|
||||
toolPanel.Controls.Add(btnTest);
|
||||
toolPanel.Controls.Add(maskedTextBoxPosition);
|
||||
toolPanel.Controls.Add(btnDelete);
|
||||
toolPanel.Controls.Add(btnAddCruiser);
|
||||
toolPanel.Enabled = false;
|
||||
toolPanel.Location = new Point(26, 537);
|
||||
toolPanel.Location = new Point(26, 608);
|
||||
toolPanel.Name = "toolPanel";
|
||||
toolPanel.Size = new Size(226, 415);
|
||||
toolPanel.Size = new Size(226, 317);
|
||||
toolPanel.TabIndex = 13;
|
||||
//
|
||||
// btnUpdate
|
||||
//
|
||||
btnUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnUpdate.Location = new Point(16, 350);
|
||||
btnUpdate.Location = new Point(16, 257);
|
||||
btnUpdate.Name = "btnUpdate";
|
||||
btnUpdate.Size = new Size(193, 57);
|
||||
btnUpdate.Size = new Size(192, 41);
|
||||
btnUpdate.TabIndex = 6;
|
||||
btnUpdate.Text = "Update";
|
||||
btnUpdate.UseVisualStyleBackColor = true;
|
||||
@ -198,9 +194,9 @@
|
||||
// btnTest
|
||||
//
|
||||
btnTest.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnTest.Location = new Point(17, 142);
|
||||
btnTest.Location = new Point(17, 162);
|
||||
btnTest.Name = "btnTest";
|
||||
btnTest.Size = new Size(192, 80);
|
||||
btnTest.Size = new Size(192, 89);
|
||||
btnTest.TabIndex = 5;
|
||||
btnTest.Text = "Choose\r\nfor testing";
|
||||
btnTest.UseVisualStyleBackColor = true;
|
||||
@ -209,7 +205,7 @@
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
maskedTextBoxPosition.Location = new Point(17, 55);
|
||||
maskedTextBoxPosition.Location = new Point(17, 68);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(192, 39);
|
||||
@ -219,9 +215,9 @@
|
||||
// btnDelete
|
||||
//
|
||||
btnDelete.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnDelete.Location = new Point(17, 99);
|
||||
btnDelete.Location = new Point(16, 113);
|
||||
btnDelete.Name = "btnDelete";
|
||||
btnDelete.Size = new Size(192, 41);
|
||||
btnDelete.Size = new Size(192, 43);
|
||||
btnDelete.TabIndex = 4;
|
||||
btnDelete.Text = "Delete";
|
||||
btnDelete.UseVisualStyleBackColor = true;
|
||||
@ -230,9 +226,9 @@
|
||||
// btnAddCruiser
|
||||
//
|
||||
btnAddCruiser.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnAddCruiser.Location = new Point(16, 4);
|
||||
btnAddCruiser.Location = new Point(17, 13);
|
||||
btnAddCruiser.Name = "btnAddCruiser";
|
||||
btnAddCruiser.Size = new Size(192, 48);
|
||||
btnAddCruiser.Size = new Size(192, 49);
|
||||
btnAddCruiser.TabIndex = 2;
|
||||
btnAddCruiser.Text = "Add cruiser";
|
||||
btnAddCruiser.UseVisualStyleBackColor = true;
|
||||
@ -241,9 +237,9 @@
|
||||
// btnCreateCompany
|
||||
//
|
||||
btnCreateCompany.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnCreateCompany.Location = new Point(17, 447);
|
||||
btnCreateCompany.Location = new Point(16, 510);
|
||||
btnCreateCompany.Name = "btnCreateCompany";
|
||||
btnCreateCompany.Size = new Size(245, 85);
|
||||
btnCreateCompany.Size = new Size(245, 79);
|
||||
btnCreateCompany.TabIndex = 12;
|
||||
btnCreateCompany.Text = "Create or switch to Company";
|
||||
btnCreateCompany.UseVisualStyleBackColor = true;
|
||||
@ -299,28 +295,6 @@
|
||||
//
|
||||
openFileDialog.Filter = "txt file|*.txt";
|
||||
//
|
||||
// btnSortType
|
||||
//
|
||||
btnSortType.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnSortType.Location = new Point(16, 232);
|
||||
btnSortType.Name = "btnSortType";
|
||||
btnSortType.Size = new Size(192, 52);
|
||||
btnSortType.TabIndex = 7;
|
||||
btnSortType.Text = "Sort by type";
|
||||
btnSortType.UseVisualStyleBackColor = true;
|
||||
btnSortType.Click += btnSortType_Click;
|
||||
//
|
||||
// btnSortColor
|
||||
//
|
||||
btnSortColor.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
|
||||
btnSortColor.Location = new Point(16, 285);
|
||||
btnSortColor.Name = "btnSortColor";
|
||||
btnSortColor.Size = new Size(192, 52);
|
||||
btnSortColor.TabIndex = 8;
|
||||
btnSortColor.Text = "Sort by color";
|
||||
btnSortColor.UseVisualStyleBackColor = true;
|
||||
btnSortColor.Click += btnSortColor_Click;
|
||||
//
|
||||
// ServiceForm2
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(13F, 32F);
|
||||
@ -370,7 +344,5 @@
|
||||
private ToolStripMenuItem loadToolStripMenuItem;
|
||||
private SaveFileDialog saveFileDialog;
|
||||
private OpenFileDialog openFileDialog;
|
||||
private Button btnSortColor;
|
||||
private Button btnSortType;
|
||||
}
|
||||
}
|
@ -177,8 +177,7 @@ public partial class ServiceForm2 : Form
|
||||
{
|
||||
MessageBox.Show("Collection was not choosed");
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Are you sure?", "Removing",
|
||||
} if (MessageBox.Show("Are you sure?", "Removing",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Question)
|
||||
!= DialogResult.OK) return;
|
||||
|
||||
@ -200,8 +199,7 @@ public partial class ServiceForm2 : Form
|
||||
listBox.Items.Clear();
|
||||
for (int i = 0; i < _storageCollection.Keys?.Count; ++i)
|
||||
{
|
||||
string? collName = _storageCollection.Keys?[i].Name;
|
||||
|
||||
string? collName = _storageCollection.Keys?[i];
|
||||
if (!string.IsNullOrEmpty(collName))
|
||||
{
|
||||
listBox.Items.Add(collName);
|
||||
@ -266,6 +264,12 @@ public partial class ServiceForm2 : Form
|
||||
try
|
||||
{
|
||||
_storageCollection.LoadData(openFileDialog.FileName);
|
||||
// LoadData() : Exceptions
|
||||
// FileNotFoundException
|
||||
// NullReferenceException
|
||||
// InvalidDataException
|
||||
// IndexOutOfRangeException
|
||||
// CollectionOverflowException
|
||||
|
||||
MessageBox.Show(" < Loaded succesfully >",
|
||||
"Result :", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
@ -281,25 +285,4 @@ public partial class ServiceForm2 : Form
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Сортировка по сравнителю
|
||||
private void CompareShips(IComparer<DrawningBase?> comparer)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_company.Sort(comparer);
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
private void btnSortType_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareShips(new DrawningShipCompare());
|
||||
}
|
||||
|
||||
private void btnSortColor_Click(object sender, EventArgs e)
|
||||
{
|
||||
CompareShips(new DrawningShipCompareByColor());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user