From 964f5593c3d5400d1a5eeab98927e5b2a920e093 Mon Sep 17 00:00:00 2001 From: ILYAkuznetsov73 <148066069+ILYAkuznetsov73@users.noreply.github.com> Date: Tue, 21 May 2024 20:44:31 +0400 Subject: [PATCH 1/3] =?UTF-8?q?8=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 10 +- .../CollectionInfo.cs | 76 +++++++++++ .../ICollectionGenericObjects.cs | 6 +- .../ListGenericObjects.cs | 93 +++++++------ .../MassiveGenericObjects.cs | 85 ++++++------ .../StorageCollection.cs | 127 ++++++++++-------- .../TankerCompareByColor.cs | 36 +++++ .../TankerCompareByType.cs | 39 ++++++ .../Drawings/DrawingTankerEqutables.cs | 68 ++++++++++ .../Exceptions/ObjectExistException.cs | 18 +++ .../FormTankerCollection.Designer.cs | 62 ++++++--- .../FormTankerCollection.cs | 31 ++++- .../FormTankerCollection.resx | 2 +- 13 files changed, 493 insertions(+), 160 deletions(-) create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs index dbb2052..8660dde 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs @@ -53,7 +53,7 @@ public abstract class AbstractCompany _collection = collection; _collection.MaxCount = GetMaxCount; } - + /// /// Перегрузка оператора сложения для класса /// @@ -62,7 +62,11 @@ public abstract class AbstractCompany /// public static int operator +(AbstractCompany company, DrawingTanker tanker) { - return company._collection.Insert(tanker); + if (company._collection.Insert(tanker, new DrawingTankerEqutables())) + { + return 1; + } + return 0; } /// @@ -106,6 +110,8 @@ public abstract class AbstractCompany return bitmap; } + public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer); + /// /// Вывод заднего фона /// diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs new file mode 100644 index 0000000..1dfb482 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs @@ -0,0 +1,76 @@ +using ProjectGasolineTanker.CollectionGenericObjects; + +/// +/// Класс, хранящиий информацию по коллекции +/// +public class CollectionInfo : IEquatable +{ + /// + /// Название + /// + 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; + } + + /// + /// Создание объекта из строки + /// + /// Строка + /// Объект или null + 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(); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs index 56dd8b0..a3aed4d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -28,7 +28,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj); + bool Insert(T obj, IEqualityComparer? comparer = null); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -36,7 +36,7 @@ public interface ICollectionGenericObjects /// Добавляемый объект /// Позиция /// 1 - вставка прошла удачно, -1 - вставка не удалась - int Insert(T obj, int position); + bool Insert(T obj, int position, IEqualityComparer? comparer = null); /// /// Удаление объекта из коллекции с конкретной позиции @@ -62,4 +62,6 @@ public interface ICollectionGenericObjects /// /// Поэлементый вывод элементов коллекции IEnumerable GetItems(); + + void CollectionSort(IComparer comparer); } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs index 8de8d91..e5df9d6 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs @@ -1,12 +1,11 @@ -using ProjectGasolineTanker.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectGasolineTanker.CollectionGenericObjects; +using NLog.LayoutRenderers; +using ProjectGasolineTanker.CollectionGenericObjects; +using ProjectGasolineTanker.Exceptions; +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип public class ListGenericObjects : ICollectionGenericObjects where T : class { @@ -20,15 +19,9 @@ public class ListGenericObjects : ICollectionGenericObjects /// private int _maxCount; - public int Count => _collection.Count; - public int MaxCount { - get - { - return _maxCount; - } - + get => _maxCount; set { if (value > 0) @@ -37,9 +30,10 @@ public class ListGenericObjects : ICollectionGenericObjects } } } - public CollectionType GetCollectionType => CollectionType.List; + public int Count => _collection.Count; + /// /// Конструктор /// @@ -50,39 +44,57 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position >= Count || position < 0) - throw new PositionOutOfCollectionException(position); - + if (position > _collection.Count || position < 0) + { + throw new PositionOutOfCollectionException(); + } + if (_collection[position] == null) + { + throw new ObjectNotFoundException(); + } return _collection[position]; } - public int Insert(T obj) + public bool Insert(T obj, IEqualityComparer? comparer = null) { - if (Count + 1 > _maxCount) - throw new CollectionOverflowException(Count); - + if (Count + 1 > MaxCount) + { + throw new CollectionOverflowException(); + } + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(); + } _collection.Add(obj); - return Count; + + return true; } - public int Insert(T obj, int position) + public bool Insert(T obj, int position, IEqualityComparer? comparer = null) { - if (Count + 1 > _maxCount) - throw new CollectionOverflowException(Count); - - if (position < 0 || position > Count) - throw new PositionOutOfCollectionException(position); - + if (_collection.Count + 1 < _maxCount) + { + throw new CollectionOverflowException(); + } + if (position > _collection.Count || position < 0) + { + throw new PositionOutOfCollectionException(); + } + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(position); + } _collection.Insert(position, obj); - return 1; + return true; } - public T? Remove(int position) + public T Remove(int position) { - if (position < 0 || position > Count) - throw new PositionOutOfCollectionException(position); - - T? temp = _collection[position]; + if (position > _collection.Count || position < 0) + { + throw new PositionOutOfCollectionException(); + } + T temp = _collection[position]; _collection.RemoveAt(position); return temp; } @@ -94,4 +106,9 @@ public class ListGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } -} + + public void CollectionSort(IComparer comparer) + { + _collection.Sort(comparer); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs index aebffc2..c79f469 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,9 +1,4 @@ using ProjectGasolineTanker.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ProjectGasolineTanker.CollectionGenericObjects; @@ -52,7 +47,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position < 0 || position >= Count) + if (position < 0 || position > _collection.Length - 1) throw new PositionOutOfCollectionException(position); if (position >= _collection.Length && _collection[position] == null) @@ -61,52 +56,48 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) - { - for (int i = 0; i < Count; i++) + public bool Insert(T obj, IEqualityComparer? comparer = null) + { + int index = Array.IndexOf(_collection, null); + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(index); + } + if (index >= 0) + { + _collection[index] = obj; + return true; + } + throw new CollectionOverflowException(); + } + + public bool Insert(T obj, int position, IEqualityComparer? comparer = null) + { + if (position < 0 || position > _collection.Length - 1) + { + throw new PositionOutOfCollectionException(); + } + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(position); + } + for (int i = position; i < _collection.Length; i++) { if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } - throw new CollectionOverflowException(Count); - } - - public int Insert(T obj, int position) - { - if (position < 0 || position >= Count) - throw new PositionOutOfCollectionException(position); - - if (_collection[position] == null) + for (int i = position; i >= 0; i--) { - _collection[position] = obj; - return position; - } - - int temp = position + 1; - while (temp < Count) - { - if (_collection[temp] == null) + if (_collection[i] == null) { - _collection[temp] = obj; - return temp; + _collection[i] = obj; + return true; } - temp++; } - - temp = position - 1; - while (temp > 0) - { - if (_collection[temp] == null) - { - _collection[temp] = obj; - return temp; - } - temp--; - } - throw new CollectionOverflowException(Count); + return false; } public T? Remove(int position) @@ -129,5 +120,15 @@ public class MassiveGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } + + public void CollectionSort(IComparer comparer) + { + if (_collection?.Length > 0) + { + Array.Sort(_collection, comparer); + Array.Reverse(_collection); + } + + } } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs index 1c90976..ae802ee 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ -using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.CollectionGenericObjects; +using ProjectGasolineTanker.Drawings; using ProjectGasolineTanker.Exceptions; using System; using System.Collections.Generic; @@ -14,13 +15,12 @@ public class StorageCollection /// /// Словарь (хранилище) с коллекциями /// - readonly Dictionary> _storages; + readonly Dictionary> _storages; /// /// Возвращение списка названий коллекций /// - public List Keys => _storages.Keys.ToList(); - + public List Keys => _storages.Keys.ToList(); /// /// Ключевое слово, с которого должен начинаться файл /// @@ -36,12 +36,13 @@ public class StorageCollection /// private readonly string _separatorItems = ";"; + /// /// Конструктор /// public StorageCollection() { - _storages = new Dictionary>(); + _storages = new Dictionary>(); } /// @@ -51,20 +52,21 @@ public class StorageCollection /// тип коллекции public void AddCollection(string name, CollectionType collectionType) { - if (name == null || _storages.ContainsKey(name)) - return; + CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty); + if (collectionInfo.Name == null || _storages.ContainsKey(collectionInfo)) { return; } + switch (collectionInfo.CollectionType) - switch (collectionType) { case CollectionType.None: return; case CollectionType.Massive: - _storages[name] = new MassiveGenericObjects(); + _storages.Add(collectionInfo, new MassiveGenericObjects { }); return; case CollectionType.List: - _storages[name] = new ListGenericObjects(); + _storages.Add(collectionInfo, new ListGenericObjects { }); return; } + } /// @@ -73,8 +75,9 @@ public class StorageCollection /// Название коллекции public void DelCollection(string name) { - if (_storages.ContainsKey(name)) - _storages.Remove(name); + CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty); + if (collectionInfo.Name == null || !_storages.ContainsKey(collectionInfo)) { return; } + _storages.Remove(collectionInfo); } /// @@ -82,42 +85,50 @@ public class StorageCollection /// /// Название коллекции /// - public ICollectionGenericObjects? this[string name] + public ICollectionGenericObjects? this[string collectionName] { get { - if (name == null || !_storages.ContainsKey(name)) - return null; - - return _storages[name]; + CollectionInfo collectionInfo = new CollectionInfo(collectionName, CollectionType.None, ""); + if (collectionInfo == null || !_storages.ContainsKey(collectionInfo)) { return null; } + return _storages[collectionInfo]; } } - + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных public void SaveData(string filename) { if (_storages.Count == 0) - throw new InvalidDataException("В хранилище отсутсвуют коллекции для сохранения"); + { + throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения"); + + } if (File.Exists(filename)) + { File.Delete(filename); + } + using FileStream fs = new(filename, FileMode.Create); - using StreamWriter sw = new StreamWriter(fs); - sw.Write(_collectionKey); - foreach (KeyValuePair> value in _storages) + using StreamWriter streamWriter = new StreamWriter(fs); + streamWriter.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) { - sw.Write(Environment.NewLine); + streamWriter.Write(Environment.NewLine); + // не сохраняем пустые коллекции if (value.Value.Count == 0) { continue; } - sw.Write(value.Key); - sw.Write(_separatorForKeyValue); - sw.Write(value.Value.GetCollectionType); - sw.Write(_separatorForKeyValue); - sw.Write(value.Value.MaxCount); - sw.Write(_separatorForKeyValue); + streamWriter.Write(value.Key); + streamWriter.Write(_separatorForKeyValue); + streamWriter.Write(value.Value.MaxCount); + streamWriter.Write(_separatorForKeyValue); foreach (T? item in value.Value.GetItems()) { @@ -127,8 +138,8 @@ public class StorageCollection continue; } - sw.Write(data); - sw.Write(_separatorItems); + streamWriter.Write(data); + streamWriter.Write(_separatorItems); } } } @@ -142,60 +153,62 @@ public class StorageCollection using (FileStream fs = new(filename, FileMode.Open)) { - using StreamReader sr = new StreamReader(fs); - - string str = sr.ReadLine(); - if (str == null || str.Length == 0) + using StreamReader streamReader = new StreamReader(fs); + string firstString = streamReader.ReadLine(); + if (firstString == null || firstString.Length == 0) { - throw new InvalidDataException("В файле нет данных"); + throw new ArgumentException("В файле нет данных"); + } + if (!firstString.Equals(_collectionKey)) + { + //если нет такой записи, то это не те данные + throw new InvalidDataException("В файле неверные данные"); } - if (!str.Equals(_collectionKey)) - { - throw new InvalidOperationException("В файле неверные данные"); - } _storages.Clear(); - - while (!sr.EndOfStream) + while (!streamReader.EndOfStream) { - string[] record = sr.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 4) + string[] record = streamReader.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 3) { continue; } + CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? + throw new Exception("Не удалось определить информацию коллекции:" + record[0]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ?? + throw new Exception("Не удалось определить тип коллекции:" + record[1]); + collection.MaxCount = Convert.ToInt32(record[1]); - CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); - ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); - if (collection == null) - { - throw new InvalidOperationException("Не удалось создать коллекцию"); - } - - collection.MaxCount = Convert.ToInt32(record[2]); - - string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); + string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { if (elem?.CreateDrawingTanker() is T tanker) { try { - if (collection.Insert(tanker) == -1) + if (!collection.Insert(tanker)) { throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]); } } catch (CollectionOverflowException ex) { - throw new ArgumentOutOfRangeException("Коллекция переполнена", ex); + throw new CollectionOverflowException("Коллекция переполнена", ex); } } } - _storages.Add(record[0], collection); + + _storages.Add(collectionInfo, collection); } } + } + /// + /// Создание коллекции по типу + /// + /// + /// private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) { return collectionType switch diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs new file mode 100644 index 0000000..08bffc0 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs @@ -0,0 +1,36 @@ +using ProjectGasolineTanker.Drawings; + +namespace ProjectGasolineTanker.Drawnings; + +/// +/// Сравнение по цвету, скорости, весу +/// +public class TankerCompareByColor : IComparer +{ + public int Compare(DrawingTanker? x, DrawingTanker? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null || x.EntityTanker == null) + { + return -1; + } + + if (y == null || y.EntityTanker == null) + { + return 1; + } + if (x.EntityTanker.BodyColor.Name != y.EntityTanker.BodyColor.Name) + { + return x.EntityTanker.BodyColor.Name.CompareTo(y.EntityTanker.BodyColor.Name); + } + var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs new file mode 100644 index 0000000..ec0909a --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs @@ -0,0 +1,39 @@ +using ProjectGasolineTanker.Drawings; + +namespace ProjectGasolineTanker.Drawnings; +/// +/// Сравнение по типу, скорости, весу +/// +public class TankerCompareByType : IComparer +{ + public int Compare(DrawingTanker? x, DrawingTanker? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null || x.EntityTanker == null) + { + return -1; + } + + if (y == null || y.EntityTanker == null) + { + return 1; + } + + if (!x.GetType().Name.Equals(y.GetType().Name)) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + + var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + + + return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs new file mode 100644 index 0000000..a212dad --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs @@ -0,0 +1,68 @@ +using ProjectGasolineTanker.Entities; +using System.Diagnostics.CodeAnalysis; + +namespace ProjectGasolineTanker.Drawings; + +public class DrawingTankerEqutables : IEqualityComparer +{ + public bool Equals(DrawingTanker? x, DrawingTanker? y) + { + if (x == null || x.EntityTanker == null) + { + return false; + } + + if (y == null || y.EntityTanker == null) + { + return false; + } + + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + + if (x.EntityTanker.Speed != y.EntityTanker.Speed) + { + return false; + } + + if (x.EntityTanker.Weight != y.EntityTanker.Weight) + { + return false; + } + + if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor) + { + return false; + } + if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor) + { + return false; + } + if (x is DrawingGasolineTanker && y is DrawingGasolineTanker) + { + EntityGasolineTanker entityX = (EntityGasolineTanker)x.EntityTanker; + EntityGasolineTanker entityY = (EntityGasolineTanker)y.EntityTanker; + if (entityX.OrnamentWheels != entityY.OrnamentWheels) + { + return false; + } + if (entityX.Tank != entityY.Tank) + { + return false; + } + if (entityX.AdditionalColor != entityY.AdditionalColor) + { + return false; + } + } + + return true; + } + + public int GetHashCode([DisallowNull] DrawingTanker obj) + { + return obj.GetHashCode(); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs new file mode 100644 index 0000000..508fbea --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs @@ -0,0 +1,18 @@ +using System.Runtime.Serialization; + +namespace ProjectGasolineTanker.Exceptions; + +[Serializable] +internal class ObjectExistException : ApplicationException +{ + public ObjectExistException(int count) : base("Вставка уже существующего объекта") { } + + public ObjectExistException() : base() { } + + public ObjectExistException(string message) : base(message) { } + + public ObjectExistException(string message, Exception exception) : base(message, exception) { } + + protected ObjectExistException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} + diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs index 8fc59f6..45e208d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs @@ -30,6 +30,8 @@ { groupBoxTools = new GroupBox(); panelCompanyTools = new Panel(); + buttonSortByColor = new Button(); + buttonSortByType = new Button(); buttonAddTanker = new Button(); buttonRefresh = new Button(); maskedTextBox1 = new MaskedTextBox(); @@ -66,15 +68,17 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(1222, 33); + groupBoxTools.Location = new Point(1063, 33); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(258, 784); + groupBoxTools.Size = new Size(258, 791); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // // panelCompanyTools // + panelCompanyTools.Controls.Add(buttonSortByColor); + panelCompanyTools.Controls.Add(buttonSortByType); panelCompanyTools.Controls.Add(buttonAddTanker); panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Controls.Add(maskedTextBox1); @@ -82,11 +86,33 @@ panelCompanyTools.Controls.Add(buttonDelTanker); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 463); + panelCompanyTools.Location = new Point(3, 438); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(252, 318); + panelCompanyTools.Size = new Size(252, 350); panelCompanyTools.TabIndex = 2; // + // buttonSortByColor + // + buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonSortByColor.Location = new Point(13, 294); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(230, 43); + 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(13, 245); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(230, 43); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // // buttonAddTanker // buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -101,9 +127,9 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(13, 237); + buttonRefresh.Location = new Point(13, 196); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(226, 55); + buttonRefresh.Size = new Size(230, 43); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -111,7 +137,7 @@ // // maskedTextBox1 // - maskedTextBox1.Location = new Point(13, 78); + maskedTextBox1.Location = new Point(13, 63); maskedTextBox1.Mask = "00"; maskedTextBox1.Name = "maskedTextBox1"; maskedTextBox1.Size = new Size(230, 31); @@ -121,9 +147,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(13, 176); + buttonGoToCheck.Location = new Point(13, 149); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(230, 55); + buttonGoToCheck.Size = new Size(230, 41); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -132,9 +158,9 @@ // buttonDelTanker // buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelTanker.Location = new Point(13, 115); + buttonDelTanker.Location = new Point(13, 100); buttonDelTanker.Name = "buttonDelTanker"; - buttonDelTanker.Size = new Size(230, 55); + buttonDelTanker.Size = new Size(230, 43); buttonDelTanker.TabIndex = 4; buttonDelTanker.Text = "Удаление грузовика"; buttonDelTanker.UseVisualStyleBackColor = true; @@ -142,7 +168,7 @@ // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(16, 374); + buttonCreateCompany.Location = new Point(16, 359); buttonCreateCompany.Name = "buttonCreateCompany"; buttonCreateCompany.Size = new Size(226, 34); buttonCreateCompany.TabIndex = 8; @@ -162,7 +188,7 @@ panelStorage.Dock = DockStyle.Top; panelStorage.Location = new Point(3, 27); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(252, 328); + panelStorage.Size = new Size(252, 326); panelStorage.TabIndex = 7; // // buttonCollectionDel @@ -238,7 +264,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(16, 417); + comboBoxSelectorCompany.Location = new Point(16, 399); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(230, 33); comboBoxSelectorCompany.TabIndex = 0; @@ -249,7 +275,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 33); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1222, 784); + pictureBox.Size = new Size(1063, 791); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -259,7 +285,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1480, 33); + menuStrip.Size = new Size(1321, 33); menuStrip.TabIndex = 2; menuStrip.Text = "menuStrip"; // @@ -298,7 +324,7 @@ // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1480, 817); + ClientSize = new Size(1321, 824); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); @@ -343,5 +369,7 @@ private ToolStripMenuItem loadToolStripMenuItem; private SaveFileDialog saveFileDialog; private OpenFileDialog openFileDialog; + private Button buttonSortByColor; + private Button buttonSortByType; } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs index 4652365..7be1c2d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using ProjectGasolineTanker.Drawings; using Microsoft.Extensions.Logging; using ProjectGasolineTanker.Exceptions; +using ProjectGasolineTanker.Drawnings; namespace ProjectGasolineTanker; @@ -76,6 +77,11 @@ public partial class FormTankerCollection : Form MessageBox.Show(ex.Message); _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (ObjectExistException ex) + { + MessageBox.Show("Такой объект есть в коллекции"); + _logger.LogWarning($"Добавление существующего объекта: {ex.Message}"); + } } /// @@ -223,9 +229,11 @@ public partial class FormTankerCollection : 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); + } } } @@ -307,4 +315,25 @@ public partial class FormTankerCollection : Form } } } + + private void buttonSortByType_Click(object sender, EventArgs e) + { + CompareTankers(new TankerCompareByType()); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) + { + CompareTankers(new TankerCompareByColor()); + } + + private void CompareTankers(IComparer comparer) + { + if (_company == null) + { + return; + } + + _company.Sort(comparer); + pictureBox.Image = _company.Show(); + } } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx index 37c7fa4..005058f 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx @@ -127,6 +127,6 @@ 355, 17 - 57 + 25 \ No newline at end of file -- 2.25.1 From 100266bb2620bc33ad0964003497a280cc020f20 Mon Sep 17 00:00:00 2001 From: ILYAkuznetsov73 <148066069+ILYAkuznetsov73@users.noreply.github.com> Date: Tue, 21 May 2024 20:44:31 +0400 Subject: [PATCH 2/3] =?UTF-8?q?8=20=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AbstractCompany.cs | 10 +- .../CollectionInfo.cs | 76 +++++++++++ .../ICollectionGenericObjects.cs | 6 +- .../ListGenericObjects.cs | 93 +++++++------ .../MassiveGenericObjects.cs | 85 ++++++------ .../StorageCollection.cs | 127 ++++++++++-------- .../TankerCompareByColor.cs | 36 +++++ .../TankerCompareByType.cs | 39 ++++++ .../Drawings/DrawingTankerEqutables.cs | 68 ++++++++++ .../Exceptions/ObjectExistException.cs | 18 +++ .../FormTankerCollection.Designer.cs | 62 ++++++--- .../FormTankerCollection.cs | 31 ++++- .../FormTankerCollection.resx | 2 +- 13 files changed, 493 insertions(+), 160 deletions(-) create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs create mode 100644 ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs index dbb2052..8660dde 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/AbstractCompany.cs @@ -53,7 +53,7 @@ public abstract class AbstractCompany _collection = collection; _collection.MaxCount = GetMaxCount; } - + /// /// Перегрузка оператора сложения для класса /// @@ -62,7 +62,11 @@ public abstract class AbstractCompany /// public static int operator +(AbstractCompany company, DrawingTanker tanker) { - return company._collection.Insert(tanker); + if (company._collection.Insert(tanker, new DrawingTankerEqutables())) + { + return 1; + } + return 0; } /// @@ -106,6 +110,8 @@ public abstract class AbstractCompany return bitmap; } + public void Sort(IComparer comparer) => _collection?.CollectionSort(comparer); + /// /// Вывод заднего фона /// diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs new file mode 100644 index 0000000..1dfb482 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/CollectionInfo.cs @@ -0,0 +1,76 @@ +using ProjectGasolineTanker.CollectionGenericObjects; + +/// +/// Класс, хранящиий информацию по коллекции +/// +public class CollectionInfo : IEquatable +{ + /// + /// Название + /// + 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; + } + + /// + /// Создание объекта из строки + /// + /// Строка + /// Объект или null + 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(); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs index 56dd8b0..a3aed4d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -28,7 +28,7 @@ public interface ICollectionGenericObjects /// /// Добавляемый объект /// true - вставка прошла удачно, false - вставка не удалась - int Insert(T obj); + bool Insert(T obj, IEqualityComparer? comparer = null); /// /// Добавление объекта в коллекцию на конкретную позицию @@ -36,7 +36,7 @@ public interface ICollectionGenericObjects /// Добавляемый объект /// Позиция /// 1 - вставка прошла удачно, -1 - вставка не удалась - int Insert(T obj, int position); + bool Insert(T obj, int position, IEqualityComparer? comparer = null); /// /// Удаление объекта из коллекции с конкретной позиции @@ -62,4 +62,6 @@ public interface ICollectionGenericObjects /// /// Поэлементый вывод элементов коллекции IEnumerable GetItems(); + + void CollectionSort(IComparer comparer); } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs index 8de8d91..e5df9d6 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/ListGenericObjects.cs @@ -1,12 +1,11 @@ -using ProjectGasolineTanker.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectGasolineTanker.CollectionGenericObjects; +using NLog.LayoutRenderers; +using ProjectGasolineTanker.CollectionGenericObjects; +using ProjectGasolineTanker.Exceptions; +/// +/// Параметризованный набор объектов +/// +/// Параметр: ограничение - ссылочный тип public class ListGenericObjects : ICollectionGenericObjects where T : class { @@ -20,15 +19,9 @@ public class ListGenericObjects : ICollectionGenericObjects /// private int _maxCount; - public int Count => _collection.Count; - public int MaxCount { - get - { - return _maxCount; - } - + get => _maxCount; set { if (value > 0) @@ -37,9 +30,10 @@ public class ListGenericObjects : ICollectionGenericObjects } } } - public CollectionType GetCollectionType => CollectionType.List; + public int Count => _collection.Count; + /// /// Конструктор /// @@ -50,39 +44,57 @@ public class ListGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position >= Count || position < 0) - throw new PositionOutOfCollectionException(position); - + if (position > _collection.Count || position < 0) + { + throw new PositionOutOfCollectionException(); + } + if (_collection[position] == null) + { + throw new ObjectNotFoundException(); + } return _collection[position]; } - public int Insert(T obj) + public bool Insert(T obj, IEqualityComparer? comparer = null) { - if (Count + 1 > _maxCount) - throw new CollectionOverflowException(Count); - + if (Count + 1 > MaxCount) + { + throw new CollectionOverflowException(); + } + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(); + } _collection.Add(obj); - return Count; + + return true; } - public int Insert(T obj, int position) + public bool Insert(T obj, int position, IEqualityComparer? comparer = null) { - if (Count + 1 > _maxCount) - throw new CollectionOverflowException(Count); - - if (position < 0 || position > Count) - throw new PositionOutOfCollectionException(position); - + if (_collection.Count + 1 < _maxCount) + { + throw new CollectionOverflowException(); + } + if (position > _collection.Count || position < 0) + { + throw new PositionOutOfCollectionException(); + } + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(position); + } _collection.Insert(position, obj); - return 1; + return true; } - public T? Remove(int position) + public T Remove(int position) { - if (position < 0 || position > Count) - throw new PositionOutOfCollectionException(position); - - T? temp = _collection[position]; + if (position > _collection.Count || position < 0) + { + throw new PositionOutOfCollectionException(); + } + T temp = _collection[position]; _collection.RemoveAt(position); return temp; } @@ -94,4 +106,9 @@ public class ListGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } -} + + public void CollectionSort(IComparer comparer) + { + _collection.Sort(comparer); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs index aebffc2..c79f469 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/MassiveGenericObjects.cs @@ -1,9 +1,4 @@ using ProjectGasolineTanker.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ProjectGasolineTanker.CollectionGenericObjects; @@ -52,7 +47,7 @@ public class MassiveGenericObjects : ICollectionGenericObjects public T? Get(int position) { - if (position < 0 || position >= Count) + if (position < 0 || position > _collection.Length - 1) throw new PositionOutOfCollectionException(position); if (position >= _collection.Length && _collection[position] == null) @@ -61,52 +56,48 @@ public class MassiveGenericObjects : ICollectionGenericObjects return _collection[position]; } - public int Insert(T obj) - { - for (int i = 0; i < Count; i++) + public bool Insert(T obj, IEqualityComparer? comparer = null) + { + int index = Array.IndexOf(_collection, null); + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(index); + } + if (index >= 0) + { + _collection[index] = obj; + return true; + } + throw new CollectionOverflowException(); + } + + public bool Insert(T obj, int position, IEqualityComparer? comparer = null) + { + if (position < 0 || position > _collection.Length - 1) + { + throw new PositionOutOfCollectionException(); + } + if (_collection.Contains(obj, comparer)) + { + throw new ObjectExistException(position); + } + for (int i = position; i < _collection.Length; i++) { if (_collection[i] == null) { _collection[i] = obj; - return i; + return true; } } - throw new CollectionOverflowException(Count); - } - - public int Insert(T obj, int position) - { - if (position < 0 || position >= Count) - throw new PositionOutOfCollectionException(position); - - if (_collection[position] == null) + for (int i = position; i >= 0; i--) { - _collection[position] = obj; - return position; - } - - int temp = position + 1; - while (temp < Count) - { - if (_collection[temp] == null) + if (_collection[i] == null) { - _collection[temp] = obj; - return temp; + _collection[i] = obj; + return true; } - temp++; } - - temp = position - 1; - while (temp > 0) - { - if (_collection[temp] == null) - { - _collection[temp] = obj; - return temp; - } - temp--; - } - throw new CollectionOverflowException(Count); + return false; } public T? Remove(int position) @@ -129,5 +120,15 @@ public class MassiveGenericObjects : ICollectionGenericObjects yield return _collection[i]; } } + + public void CollectionSort(IComparer comparer) + { + if (_collection?.Length > 0) + { + Array.Sort(_collection, comparer); + Array.Reverse(_collection); + } + + } } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs index 1c90976..ae802ee 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/StorageCollection.cs @@ -1,4 +1,5 @@ -using ProjectGasolineTanker.Drawings; +using ProjectGasolineTanker.CollectionGenericObjects; +using ProjectGasolineTanker.Drawings; using ProjectGasolineTanker.Exceptions; using System; using System.Collections.Generic; @@ -14,13 +15,12 @@ public class StorageCollection /// /// Словарь (хранилище) с коллекциями /// - readonly Dictionary> _storages; + readonly Dictionary> _storages; /// /// Возвращение списка названий коллекций /// - public List Keys => _storages.Keys.ToList(); - + public List Keys => _storages.Keys.ToList(); /// /// Ключевое слово, с которого должен начинаться файл /// @@ -36,12 +36,13 @@ public class StorageCollection /// private readonly string _separatorItems = ";"; + /// /// Конструктор /// public StorageCollection() { - _storages = new Dictionary>(); + _storages = new Dictionary>(); } /// @@ -51,20 +52,21 @@ public class StorageCollection /// тип коллекции public void AddCollection(string name, CollectionType collectionType) { - if (name == null || _storages.ContainsKey(name)) - return; + CollectionInfo collectionInfo = new CollectionInfo(name, collectionType, string.Empty); + if (collectionInfo.Name == null || _storages.ContainsKey(collectionInfo)) { return; } + switch (collectionInfo.CollectionType) - switch (collectionType) { case CollectionType.None: return; case CollectionType.Massive: - _storages[name] = new MassiveGenericObjects(); + _storages.Add(collectionInfo, new MassiveGenericObjects { }); return; case CollectionType.List: - _storages[name] = new ListGenericObjects(); + _storages.Add(collectionInfo, new ListGenericObjects { }); return; } + } /// @@ -73,8 +75,9 @@ public class StorageCollection /// Название коллекции public void DelCollection(string name) { - if (_storages.ContainsKey(name)) - _storages.Remove(name); + CollectionInfo collectionInfo = new CollectionInfo(name, CollectionType.None, string.Empty); + if (collectionInfo.Name == null || !_storages.ContainsKey(collectionInfo)) { return; } + _storages.Remove(collectionInfo); } /// @@ -82,42 +85,50 @@ public class StorageCollection /// /// Название коллекции /// - public ICollectionGenericObjects? this[string name] + public ICollectionGenericObjects? this[string collectionName] { get { - if (name == null || !_storages.ContainsKey(name)) - return null; - - return _storages[name]; + CollectionInfo collectionInfo = new CollectionInfo(collectionName, CollectionType.None, ""); + if (collectionInfo == null || !_storages.ContainsKey(collectionInfo)) { return null; } + return _storages[collectionInfo]; } } - + /// + /// Сохранение информации по автомобилям в хранилище в файл + /// + /// Путь и имя файла + /// true - сохранение прошло успешно, false - ошибка при сохранении данных public void SaveData(string filename) { if (_storages.Count == 0) - throw new InvalidDataException("В хранилище отсутсвуют коллекции для сохранения"); + { + throw new ArgumentException("В хранилище отсутствуют коллекции для сохранения"); + + } if (File.Exists(filename)) + { File.Delete(filename); + } + using FileStream fs = new(filename, FileMode.Create); - using StreamWriter sw = new StreamWriter(fs); - sw.Write(_collectionKey); - foreach (KeyValuePair> value in _storages) + using StreamWriter streamWriter = new StreamWriter(fs); + streamWriter.Write(_collectionKey); + foreach (KeyValuePair> value in _storages) { - sw.Write(Environment.NewLine); + streamWriter.Write(Environment.NewLine); + // не сохраняем пустые коллекции if (value.Value.Count == 0) { continue; } - sw.Write(value.Key); - sw.Write(_separatorForKeyValue); - sw.Write(value.Value.GetCollectionType); - sw.Write(_separatorForKeyValue); - sw.Write(value.Value.MaxCount); - sw.Write(_separatorForKeyValue); + streamWriter.Write(value.Key); + streamWriter.Write(_separatorForKeyValue); + streamWriter.Write(value.Value.MaxCount); + streamWriter.Write(_separatorForKeyValue); foreach (T? item in value.Value.GetItems()) { @@ -127,8 +138,8 @@ public class StorageCollection continue; } - sw.Write(data); - sw.Write(_separatorItems); + streamWriter.Write(data); + streamWriter.Write(_separatorItems); } } } @@ -142,60 +153,62 @@ public class StorageCollection using (FileStream fs = new(filename, FileMode.Open)) { - using StreamReader sr = new StreamReader(fs); - - string str = sr.ReadLine(); - if (str == null || str.Length == 0) + using StreamReader streamReader = new StreamReader(fs); + string firstString = streamReader.ReadLine(); + if (firstString == null || firstString.Length == 0) { - throw new InvalidDataException("В файле нет данных"); + throw new ArgumentException("В файле нет данных"); + } + if (!firstString.Equals(_collectionKey)) + { + //если нет такой записи, то это не те данные + throw new InvalidDataException("В файле неверные данные"); } - if (!str.Equals(_collectionKey)) - { - throw new InvalidOperationException("В файле неверные данные"); - } _storages.Clear(); - - while (!sr.EndOfStream) + while (!streamReader.EndOfStream) { - string[] record = sr.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 4) + string[] record = streamReader.ReadLine().Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 3) { continue; } + CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? + throw new Exception("Не удалось определить информацию коллекции:" + record[0]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.CollectionType) ?? + throw new Exception("Не удалось определить тип коллекции:" + record[1]); + collection.MaxCount = Convert.ToInt32(record[1]); - CollectionType collectionType = (CollectionType)Enum.Parse(typeof(CollectionType), record[1]); - ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionType); - if (collection == null) - { - throw new InvalidOperationException("Не удалось создать коллекцию"); - } - - collection.MaxCount = Convert.ToInt32(record[2]); - - string[] set = record[3].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); + string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); foreach (string elem in set) { if (elem?.CreateDrawingTanker() is T tanker) { try { - if (collection.Insert(tanker) == -1) + if (!collection.Insert(tanker)) { throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[3]); } } catch (CollectionOverflowException ex) { - throw new ArgumentOutOfRangeException("Коллекция переполнена", ex); + throw new CollectionOverflowException("Коллекция переполнена", ex); } } } - _storages.Add(record[0], collection); + + _storages.Add(collectionInfo, collection); } } + } + /// + /// Создание коллекции по типу + /// + /// + /// private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) { return collectionType switch diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs new file mode 100644 index 0000000..08bffc0 --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByColor.cs @@ -0,0 +1,36 @@ +using ProjectGasolineTanker.Drawings; + +namespace ProjectGasolineTanker.Drawnings; + +/// +/// Сравнение по цвету, скорости, весу +/// +public class TankerCompareByColor : IComparer +{ + public int Compare(DrawingTanker? x, DrawingTanker? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null || x.EntityTanker == null) + { + return -1; + } + + if (y == null || y.EntityTanker == null) + { + return 1; + } + if (x.EntityTanker.BodyColor.Name != y.EntityTanker.BodyColor.Name) + { + return x.EntityTanker.BodyColor.Name.CompareTo(y.EntityTanker.BodyColor.Name); + } + var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs new file mode 100644 index 0000000..ec0909a --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/CollectionGenericObjects/TankerCompareByType.cs @@ -0,0 +1,39 @@ +using ProjectGasolineTanker.Drawings; + +namespace ProjectGasolineTanker.Drawnings; +/// +/// Сравнение по типу, скорости, весу +/// +public class TankerCompareByType : IComparer +{ + public int Compare(DrawingTanker? x, DrawingTanker? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null || x.EntityTanker == null) + { + return -1; + } + + if (y == null || y.EntityTanker == null) + { + return 1; + } + + if (!x.GetType().Name.Equals(y.GetType().Name)) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + + var speedCompare = x.EntityTanker.Speed.CompareTo(y.EntityTanker.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + + + return x.EntityTanker.Weight.CompareTo(y.EntityTanker.Weight); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs new file mode 100644 index 0000000..a212dad --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Drawings/DrawingTankerEqutables.cs @@ -0,0 +1,68 @@ +using ProjectGasolineTanker.Entities; +using System.Diagnostics.CodeAnalysis; + +namespace ProjectGasolineTanker.Drawings; + +public class DrawingTankerEqutables : IEqualityComparer +{ + public bool Equals(DrawingTanker? x, DrawingTanker? y) + { + if (x == null || x.EntityTanker == null) + { + return false; + } + + if (y == null || y.EntityTanker == null) + { + return false; + } + + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + + if (x.EntityTanker.Speed != y.EntityTanker.Speed) + { + return false; + } + + if (x.EntityTanker.Weight != y.EntityTanker.Weight) + { + return false; + } + + if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor) + { + return false; + } + if (x.EntityTanker.BodyColor != y.EntityTanker.BodyColor) + { + return false; + } + if (x is DrawingGasolineTanker && y is DrawingGasolineTanker) + { + EntityGasolineTanker entityX = (EntityGasolineTanker)x.EntityTanker; + EntityGasolineTanker entityY = (EntityGasolineTanker)y.EntityTanker; + if (entityX.OrnamentWheels != entityY.OrnamentWheels) + { + return false; + } + if (entityX.Tank != entityY.Tank) + { + return false; + } + if (entityX.AdditionalColor != entityY.AdditionalColor) + { + return false; + } + } + + return true; + } + + public int GetHashCode([DisallowNull] DrawingTanker obj) + { + return obj.GetHashCode(); + } +} \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs b/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs new file mode 100644 index 0000000..508fbea --- /dev/null +++ b/ProjectGasolineTanker/ProjectGasolineTanker/Exceptions/ObjectExistException.cs @@ -0,0 +1,18 @@ +using System.Runtime.Serialization; + +namespace ProjectGasolineTanker.Exceptions; + +[Serializable] +internal class ObjectExistException : ApplicationException +{ + public ObjectExistException(int count) : base("Вставка уже существующего объекта") { } + + public ObjectExistException() : base() { } + + public ObjectExistException(string message) : base(message) { } + + public ObjectExistException(string message, Exception exception) : base(message, exception) { } + + protected ObjectExistException(SerializationInfo info, StreamingContext contex) : base(info, contex) { } +} + diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs index 8fc59f6..45e208d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.Designer.cs @@ -30,6 +30,8 @@ { groupBoxTools = new GroupBox(); panelCompanyTools = new Panel(); + buttonSortByColor = new Button(); + buttonSortByType = new Button(); buttonAddTanker = new Button(); buttonRefresh = new Button(); maskedTextBox1 = new MaskedTextBox(); @@ -66,15 +68,17 @@ groupBoxTools.Controls.Add(panelStorage); groupBoxTools.Controls.Add(comboBoxSelectorCompany); groupBoxTools.Dock = DockStyle.Right; - groupBoxTools.Location = new Point(1222, 33); + groupBoxTools.Location = new Point(1063, 33); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(258, 784); + groupBoxTools.Size = new Size(258, 791); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; // // panelCompanyTools // + panelCompanyTools.Controls.Add(buttonSortByColor); + panelCompanyTools.Controls.Add(buttonSortByType); panelCompanyTools.Controls.Add(buttonAddTanker); panelCompanyTools.Controls.Add(buttonRefresh); panelCompanyTools.Controls.Add(maskedTextBox1); @@ -82,11 +86,33 @@ panelCompanyTools.Controls.Add(buttonDelTanker); panelCompanyTools.Dock = DockStyle.Bottom; panelCompanyTools.Enabled = false; - panelCompanyTools.Location = new Point(3, 463); + panelCompanyTools.Location = new Point(3, 438); panelCompanyTools.Name = "panelCompanyTools"; - panelCompanyTools.Size = new Size(252, 318); + panelCompanyTools.Size = new Size(252, 350); panelCompanyTools.TabIndex = 2; // + // buttonSortByColor + // + buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonSortByColor.Location = new Point(13, 294); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(230, 43); + 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(13, 245); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(230, 43); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // // buttonAddTanker // buttonAddTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; @@ -101,9 +127,9 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(13, 237); + buttonRefresh.Location = new Point(13, 196); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(226, 55); + buttonRefresh.Size = new Size(230, 43); buttonRefresh.TabIndex = 6; buttonRefresh.Text = "Обновить"; buttonRefresh.UseVisualStyleBackColor = true; @@ -111,7 +137,7 @@ // // maskedTextBox1 // - maskedTextBox1.Location = new Point(13, 78); + maskedTextBox1.Location = new Point(13, 63); maskedTextBox1.Mask = "00"; maskedTextBox1.Name = "maskedTextBox1"; maskedTextBox1.Size = new Size(230, 31); @@ -121,9 +147,9 @@ // buttonGoToCheck // buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToCheck.Location = new Point(13, 176); + buttonGoToCheck.Location = new Point(13, 149); buttonGoToCheck.Name = "buttonGoToCheck"; - buttonGoToCheck.Size = new Size(230, 55); + buttonGoToCheck.Size = new Size(230, 41); buttonGoToCheck.TabIndex = 5; buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.UseVisualStyleBackColor = true; @@ -132,9 +158,9 @@ // buttonDelTanker // buttonDelTanker.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDelTanker.Location = new Point(13, 115); + buttonDelTanker.Location = new Point(13, 100); buttonDelTanker.Name = "buttonDelTanker"; - buttonDelTanker.Size = new Size(230, 55); + buttonDelTanker.Size = new Size(230, 43); buttonDelTanker.TabIndex = 4; buttonDelTanker.Text = "Удаление грузовика"; buttonDelTanker.UseVisualStyleBackColor = true; @@ -142,7 +168,7 @@ // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(16, 374); + buttonCreateCompany.Location = new Point(16, 359); buttonCreateCompany.Name = "buttonCreateCompany"; buttonCreateCompany.Size = new Size(226, 34); buttonCreateCompany.TabIndex = 8; @@ -162,7 +188,7 @@ panelStorage.Dock = DockStyle.Top; panelStorage.Location = new Point(3, 27); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(252, 328); + panelStorage.Size = new Size(252, 326); panelStorage.TabIndex = 7; // // buttonCollectionDel @@ -238,7 +264,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(16, 417); + comboBoxSelectorCompany.Location = new Point(16, 399); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(230, 33); comboBoxSelectorCompany.TabIndex = 0; @@ -249,7 +275,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 33); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(1222, 784); + pictureBox.Size = new Size(1063, 791); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -259,7 +285,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { файлToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1480, 33); + menuStrip.Size = new Size(1321, 33); menuStrip.TabIndex = 2; menuStrip.Text = "menuStrip"; // @@ -298,7 +324,7 @@ // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1480, 817); + ClientSize = new Size(1321, 824); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); @@ -343,5 +369,7 @@ private ToolStripMenuItem loadToolStripMenuItem; private SaveFileDialog saveFileDialog; private OpenFileDialog openFileDialog; + private Button buttonSortByColor; + private Button buttonSortByType; } } \ No newline at end of file diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs index 4652365..7be1c2d 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.cs @@ -11,6 +11,7 @@ using System.Windows.Forms; using ProjectGasolineTanker.Drawings; using Microsoft.Extensions.Logging; using ProjectGasolineTanker.Exceptions; +using ProjectGasolineTanker.Drawnings; namespace ProjectGasolineTanker; @@ -76,6 +77,11 @@ public partial class FormTankerCollection : Form MessageBox.Show(ex.Message); _logger.LogError("Ошибка: {Message}", ex.Message); } + catch (ObjectExistException ex) + { + MessageBox.Show("Такой объект есть в коллекции"); + _logger.LogWarning($"Добавление существующего объекта: {ex.Message}"); + } } /// @@ -223,9 +229,11 @@ public partial class FormTankerCollection : 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); + } } } @@ -307,4 +315,25 @@ public partial class FormTankerCollection : Form } } } + + private void buttonSortByType_Click(object sender, EventArgs e) + { + CompareTankers(new TankerCompareByType()); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) + { + CompareTankers(new TankerCompareByColor()); + } + + private void CompareTankers(IComparer comparer) + { + if (_company == null) + { + return; + } + + _company.Sort(comparer); + pictureBox.Image = _company.Show(); + } } diff --git a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx index 37c7fa4..005058f 100644 --- a/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx +++ b/ProjectGasolineTanker/ProjectGasolineTanker/FormTankerCollection.resx @@ -127,6 +127,6 @@ 355, 17 - 57 + 25 \ No newline at end of file -- 2.25.1 From 969b5c422b00c1ef53795de0440a93f5847602a9 Mon Sep 17 00:00:00 2001 From: ILYAkuznetsov73 <148066069+ILYAkuznetsov73@users.noreply.github.com> Date: Tue, 21 May 2024 21:13:12 +0400 Subject: [PATCH 3/3] =?UTF-8?q?8=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Aop4/Aop4.sln | 31 ---- Aop4/Aop4/Aop4.cpp | 128 --------------- Aop4/Aop4/Aop4.vcxproj | 136 ---------------- Aop4/Aop4/Aop4.vcxproj.filters | 22 --- Coursework/Coursework.sln | 25 --- Coursework/Coursework/Coursework.csproj | 11 -- Coursework/Coursework/Program.cs | 18 --- Coursework/Coursework/classes/Manager.cs | 46 ------ Coursework/Coursework/classes/Parameters.cs | 13 -- .../classes/SortedArrayOperation.cs | 39 ----- Coursework/Coursework/classes/State.cs | 17 -- Coursework/Coursework/classes/StateStorage.cs | 59 ------- Coursework/Coursework/classes/Visualizer.cs | 20 --- .../Coursework/forms/InputForm.Designer.cs | 39 ----- Coursework/Coursework/forms/InputForm.cs | 62 ------- Coursework/Coursework/forms/InputForm.resx | 120 -------------- .../Coursework/forms/MainForm.Designer.cs | 39 ----- Coursework/Coursework/forms/MainForm.cs | 56 ------- Coursework/Coursework/forms/MainForm.resx | 120 -------------- Coursework2/Coursework2.sln | 25 --- Coursework2/Coursework2/Coursework2.csproj | 11 -- Coursework2/Coursework2/Program.cs | 17 -- Lab1_OAP/Lab1_OAP.sln | 31 ---- Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp | 1 - Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj | 135 ---------------- Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters | 22 --- laboap1/laboap1.sln | 31 ---- laboap1/laboap1/laboap1.cpp | 151 ------------------ laboap1/laboap1/laboap1.vcxproj | 136 ---------------- laboap1/laboap1/laboap1.vcxproj.filters | 22 --- 30 files changed, 1583 deletions(-) delete mode 100644 Aop4/Aop4.sln delete mode 100644 Aop4/Aop4/Aop4.cpp delete mode 100644 Aop4/Aop4/Aop4.vcxproj delete mode 100644 Aop4/Aop4/Aop4.vcxproj.filters delete mode 100644 Coursework/Coursework.sln delete mode 100644 Coursework/Coursework/Coursework.csproj delete mode 100644 Coursework/Coursework/Program.cs delete mode 100644 Coursework/Coursework/classes/Manager.cs delete mode 100644 Coursework/Coursework/classes/Parameters.cs delete mode 100644 Coursework/Coursework/classes/SortedArrayOperation.cs delete mode 100644 Coursework/Coursework/classes/State.cs delete mode 100644 Coursework/Coursework/classes/StateStorage.cs delete mode 100644 Coursework/Coursework/classes/Visualizer.cs delete mode 100644 Coursework/Coursework/forms/InputForm.Designer.cs delete mode 100644 Coursework/Coursework/forms/InputForm.cs delete mode 100644 Coursework/Coursework/forms/InputForm.resx delete mode 100644 Coursework/Coursework/forms/MainForm.Designer.cs delete mode 100644 Coursework/Coursework/forms/MainForm.cs delete mode 100644 Coursework/Coursework/forms/MainForm.resx delete mode 100644 Coursework2/Coursework2.sln delete mode 100644 Coursework2/Coursework2/Coursework2.csproj delete mode 100644 Coursework2/Coursework2/Program.cs delete mode 100644 Lab1_OAP/Lab1_OAP.sln delete mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp delete mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj delete mode 100644 Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters delete mode 100644 laboap1/laboap1.sln delete mode 100644 laboap1/laboap1/laboap1.cpp delete mode 100644 laboap1/laboap1/laboap1.vcxproj delete mode 100644 laboap1/laboap1/laboap1.vcxproj.filters diff --git a/Aop4/Aop4.sln b/Aop4/Aop4.sln deleted file mode 100644 index 351e1a6..0000000 --- a/Aop4/Aop4.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Aop4", "Aop4\Aop4.vcxproj", "{325E9151-1DD3-46F9-92DF-38BF04D3741F}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Debug|x64.ActiveCfg = Debug|x64 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Debug|x64.Build.0 = Debug|x64 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Debug|x86.ActiveCfg = Debug|Win32 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Debug|x86.Build.0 = Debug|Win32 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Release|x64.ActiveCfg = Release|x64 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Release|x64.Build.0 = Release|x64 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Release|x86.ActiveCfg = Release|Win32 - {325E9151-1DD3-46F9-92DF-38BF04D3741F}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {11FE05AC-626B-4577-BD0E-7AA74D8175A2} - EndGlobalSection -EndGlobal diff --git a/Aop4/Aop4/Aop4.cpp b/Aop4/Aop4/Aop4.cpp deleted file mode 100644 index a13f1e6..0000000 --- a/Aop4/Aop4/Aop4.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#define _CRT_SECURE_NO_WARNINGS - -#include - -#include -#include -#include -#include - -#define SIZE 10 - -struct DataItem { - int key; - int data; -}; - -struct DataItem* hashArray[SIZE]; -struct DataItem* dummyItem; - -int hashCode1(int key) { - return key % SIZE; -} - -int hashCode2(int key) { - return 7 - (key % 7); // should be a prime number less than SIZE -} - -void insert(int key, int data) { - struct DataItem* item = (struct DataItem*)malloc(sizeof(struct DataItem)); - item->key = key; - item->data = data; - - int hashIndex = hashCode1(key); - int stepSize = hashCode2(key); - - while (hashArray[hashIndex] != NULL && hashArray[hashIndex]->key != -1) { - hashIndex += stepSize; - hashIndex %= SIZE; - } - - hashArray[hashIndex] = item; -} - -struct DataItem* search(int key) { - int hashIndex = hashCode1(key); - int stepSize = hashCode2(key); - - while (hashArray[hashIndex] != NULL) { - if (hashArray[hashIndex]->key == key) { - return hashArray[hashIndex]; - } - - hashIndex += stepSize; - hashIndex %= SIZE; - } - - return NULL; -} - -void display() { - int i; - for (i = 0; i < SIZE; i++) { - if (hashArray[i] != NULL) { - printf("(%d,%d) ", hashArray[i]->key, hashArray[i]->data); - } - else { - printf("~ "); - } - } - printf("\n"); -} - -int main() { - int choice, key, data; - dummyItem = (struct DataItem*)malloc(sizeof(struct DataItem)); - dummyItem->key = -1; - dummyItem->data = -1; - - // Fill the hash table with random values at the start - srand(time(NULL)); - for (int i = 0; i < SIZE; i++) { - int key = rand() % 100; // Generate a random key - int data = rand() % 1000; // Generate a random data - insert(key, data); - } - - while (1) { - printf("\n--- Menu ---\n"); - printf("1. Insert an element"); - printf("2. Search for an element"); - printf("3. Display the hash table"); - printf("4. Exit"); - printf("Choose an action: "); - scanf("%d", &choice); - - switch (choice) { - case 1: - printf("Enter key: "); - scanf("%d", &key); - printf("Enter data: "); - scanf("%d", &data); - insert(key, data); - break; - case 2: - printf("Enter key to search for: "); - scanf("%d", &key); - struct DataItem* item = search(key); - if (item != NULL) { - printf("Element found: (%d, %d)\n", item->key, item->data); - } - else { - printf("Element not found.\n"); - } - break; - case 3: - printf("Hash table: "); - display(); - break; - case 4: - printf("Program terminated.\n"); - exit(0); - default: - printf("Invalid choice. Please try again.\n"); - } - } - - return 0; -} \ No newline at end of file diff --git a/Aop4/Aop4/Aop4.vcxproj b/Aop4/Aop4/Aop4.vcxproj deleted file mode 100644 index b34cf0b..0000000 --- a/Aop4/Aop4/Aop4.vcxproj +++ /dev/null @@ -1,136 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {325e9151-1dd3-46f9-92df-38bf04d3741f} - Aop4 - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdc11 - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/Aop4/Aop4/Aop4.vcxproj.filters b/Aop4/Aop4/Aop4.vcxproj.filters deleted file mode 100644 index 656314d..0000000 --- a/Aop4/Aop4/Aop4.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file diff --git a/Coursework/Coursework.sln b/Coursework/Coursework.sln deleted file mode 100644 index 6b0f705..0000000 --- a/Coursework/Coursework.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Coursework", "Coursework\Coursework.csproj", "{937829AA-8125-47BC-9126-78E67D379D9D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {937829AA-8125-47BC-9126-78E67D379D9D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {937829AA-8125-47BC-9126-78E67D379D9D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {937829AA-8125-47BC-9126-78E67D379D9D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {937829AA-8125-47BC-9126-78E67D379D9D}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {DA38A496-655D-4DA5-B898-F9A1FB78DA07} - EndGlobalSection -EndGlobal diff --git a/Coursework/Coursework/Coursework.csproj b/Coursework/Coursework/Coursework.csproj deleted file mode 100644 index e1a0735..0000000 --- a/Coursework/Coursework/Coursework.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net7.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/Coursework/Coursework/Program.cs b/Coursework/Coursework/Program.cs deleted file mode 100644 index a99519e..0000000 --- a/Coursework/Coursework/Program.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Coursework.forms; - -namespace Coursework; - -public class Program -{ - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new MainForm()); - } -} \ No newline at end of file diff --git a/Coursework/Coursework/classes/Manager.cs b/Coursework/Coursework/classes/Manager.cs deleted file mode 100644 index 728c3d4..0000000 --- a/Coursework/Coursework/classes/Manager.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coursework.classes -{ - public class Manager - { - private SortedArrayOperation arrayOperation; - private StateStorage stateStorage; - - public Manager() - { - arrayOperation = new SortedArrayOperation(); - stateStorage = new StateStorage(); - } - - public void PerformOperation(int element, bool isAddOperation) - { - if (isAddOperation) - { - arrayOperation.AddElement(element); - } - else - { - arrayOperation.RemoveElement(element); - } - - State currentState = arrayOperation.GetState(); - stateStorage.AddState(currentState); - } - - public void SaveStates(string filePath) - { - stateStorage.SaveStatesToFile(filePath); - } - - public void LoadStates(string filePath) - { - stateStorage.LoadStatesFromFile(filePath); - } - } - -} diff --git a/Coursework/Coursework/classes/Parameters.cs b/Coursework/Coursework/classes/Parameters.cs deleted file mode 100644 index 90c64de..0000000 --- a/Coursework/Coursework/classes/Parameters.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coursework.classes; - -public class Parameters -{ - public int InitialSize { get; set; } - public int InitialMaxValue { get; set; } -} diff --git a/Coursework/Coursework/classes/SortedArrayOperation.cs b/Coursework/Coursework/classes/SortedArrayOperation.cs deleted file mode 100644 index 4661305..0000000 --- a/Coursework/Coursework/classes/SortedArrayOperation.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.IO; -using System.Windows.Forms; -using static System.Windows.Forms.AxHost; - -namespace Coursework.classes; - -public class SortedArrayOperation -{ - private List sortedArray; - - public SortedArrayOperation() - { - sortedArray = new List(); - } - - public void AddElement(int element) - { - int index = sortedArray.BinarySearch(element); - if (index < 0) - { - sortedArray.Insert(~index, element); - } - } - - public void RemoveElement(int element) - { - sortedArray.Remove(element); - } - - public State GetState() - { - return new State(sortedArray); - } -} diff --git a/Coursework/Coursework/classes/State.cs b/Coursework/Coursework/classes/State.cs deleted file mode 100644 index 883c8d0..0000000 --- a/Coursework/Coursework/classes/State.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coursework.classes; - -public class State -{ - public List ArrayState { get; } - - public State(List arrayState) - { - ArrayState = new List(arrayState); - } -} diff --git a/Coursework/Coursework/classes/StateStorage.cs b/Coursework/Coursework/classes/StateStorage.cs deleted file mode 100644 index d1564f3..0000000 --- a/Coursework/Coursework/classes/StateStorage.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coursework.classes; - -public class StateStorage -{ - private List states; - - public StateStorage() - { - states = new List(); - } - - public void AddState(State state) - { - states.Add(state); - } - - public void SaveStatesToFile(string filePath) - { - using (StreamWriter writer = new StreamWriter(filePath)) - { - foreach (State state in states) - { - foreach (int element in state.ArrayState) - { - writer.WriteLine(element); - } - writer.WriteLine(); - } - } - } - - public void LoadStatesFromFile(string filePath) - { - states.Clear(); - using (StreamReader reader = new StreamReader(filePath)) - { - List currentState = new List(); - string line; - while ((line = reader.ReadLine()) != null) - { - if (line == "") - { - states.Add(new State(currentState)); - currentState.Clear(); - } - else - { - currentState.Add(int.Parse(line)); - } - } - } - } -} diff --git a/Coursework/Coursework/classes/Visualizer.cs b/Coursework/Coursework/classes/Visualizer.cs deleted file mode 100644 index 52fd97a..0000000 --- a/Coursework/Coursework/classes/Visualizer.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coursework.classes; - -public class Visualizer -{ - public void Visualize(State state) - { - // Implement visualization of the array state - foreach (int element in state.ArrayState) - { - Console.Write(element + " "); - } - Console.WriteLine(); - } -} diff --git a/Coursework/Coursework/forms/InputForm.Designer.cs b/Coursework/Coursework/forms/InputForm.Designer.cs deleted file mode 100644 index e32b7a9..0000000 --- a/Coursework/Coursework/forms/InputForm.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Coursework.forms -{ - partial class InputForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "InputForm"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Coursework/Coursework/forms/InputForm.cs b/Coursework/Coursework/forms/InputForm.cs deleted file mode 100644 index ff607e4..0000000 --- a/Coursework/Coursework/forms/InputForm.cs +++ /dev/null @@ -1,62 +0,0 @@ -using Coursework.classes; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Coursework.forms -{ - public partial class InputForm : Form - { - private Manager manager; - - public InputForm(Manager manager) - { - this.manager = manager; - - Label label1 = new Label(); - label1.Text = "Initial Size:"; - TextBox sizeTextBox = new TextBox(); - - Label label2 = new Label(); - label2.Text = "Initial Max Value:"; - TextBox maxValueTextBox = new TextBox(); - - Button submitButton = new Button(); - submitButton.Text = "Submit"; - submitButton.Click += (sender, e) => - { - int size = int.Parse(sizeTextBox.Text); - int maxValue = int.Parse(maxValueTextBox.Text); - - // Set initial parameters - Parameters initialParameters = new Parameters - { - InitialSize = size, - InitialMaxValue = maxValue - }; - - // Initialize array with initial values - Random random = new Random(); - for (int i = 0; i < size; i++) - { - manager.PerformOperation(random.Next(maxValue), true); - } - - this.Close(); - }; - - Controls.Add(label1); - Controls.Add(sizeTextBox); - Controls.Add(label2); - Controls.Add(maxValueTextBox); - Controls.Add(submitButton); - } - } - -} diff --git a/Coursework/Coursework/forms/InputForm.resx b/Coursework/Coursework/forms/InputForm.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Coursework/Coursework/forms/InputForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Coursework/Coursework/forms/MainForm.Designer.cs b/Coursework/Coursework/forms/MainForm.Designer.cs deleted file mode 100644 index edd5ccd..0000000 --- a/Coursework/Coursework/forms/MainForm.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace Coursework.forms -{ - partial class MainForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "MainForm"; - } - - #endregion - } -} \ No newline at end of file diff --git a/Coursework/Coursework/forms/MainForm.cs b/Coursework/Coursework/forms/MainForm.cs deleted file mode 100644 index f8692ff..0000000 --- a/Coursework/Coursework/forms/MainForm.cs +++ /dev/null @@ -1,56 +0,0 @@ -using Coursework.classes; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Coursework.forms -{ - public partial class MainForm : Form - { - private Manager manager; - private TextBox elementTextBox; - - public MainForm() - { - InitializeComponent(); - manager = new Manager(); - - // Create TableLayoutPanel - var tableLayoutPanel = new TableLayoutPanel(); - tableLayoutPanel.Dock = DockStyle.Top; - tableLayoutPanel.RowCount = 1; - tableLayoutPanel.ColumnCount = 3; - - // Add controls to TableLayoutPanel - tableLayoutPanel.Controls.Add(new Label { Text = "Element:" }, 0, 0); - elementTextBox = new TextBox(); - tableLayoutPanel.Controls.Add(elementTextBox, 1, 0); - var addButton = new Button { Text = "Add Element" }; - addButton.Click += AddButtonClick; - tableLayoutPanel.Controls.Add(addButton, 2, 0); - var removeButton = new Button { Text = "Remove Element" }; - removeButton.Click += RemoveButtonClick; - tableLayoutPanel.Controls.Add(removeButton, 3, 0); - - Controls.Add(tableLayoutPanel); - } - - private void AddButtonClick(object sender, EventArgs e) - { - int element = int.Parse(elementTextBox.Text); - manager.PerformOperation(element, true); - } - - private void RemoveButtonClick(object sender, EventArgs e) - { - int element = int.Parse(elementTextBox.Text); - manager.PerformOperation(element, false); - } - } -} diff --git a/Coursework/Coursework/forms/MainForm.resx b/Coursework/Coursework/forms/MainForm.resx deleted file mode 100644 index 1af7de1..0000000 --- a/Coursework/Coursework/forms/MainForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/Coursework2/Coursework2.sln b/Coursework2/Coursework2.sln deleted file mode 100644 index 99b07de..0000000 --- a/Coursework2/Coursework2.sln +++ /dev/null @@ -1,25 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Coursework2", "Coursework2\Coursework2.csproj", "{CFEAC293-2FF8-4540-8CA3-4A4FBCFD8DAD}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {CFEAC293-2FF8-4540-8CA3-4A4FBCFD8DAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {CFEAC293-2FF8-4540-8CA3-4A4FBCFD8DAD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {CFEAC293-2FF8-4540-8CA3-4A4FBCFD8DAD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {CFEAC293-2FF8-4540-8CA3-4A4FBCFD8DAD}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {6AF063FA-1D75-4AAD-91B5-FCB220F89BAB} - EndGlobalSection -EndGlobal diff --git a/Coursework2/Coursework2/Coursework2.csproj b/Coursework2/Coursework2/Coursework2.csproj deleted file mode 100644 index e1a0735..0000000 --- a/Coursework2/Coursework2/Coursework2.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net7.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/Coursework2/Coursework2/Program.cs b/Coursework2/Coursework2/Program.cs deleted file mode 100644 index f794ce3..0000000 --- a/Coursework2/Coursework2/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Coursework2 -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP.sln b/Lab1_OAP/Lab1_OAP.sln deleted file mode 100644 index 92627e6..0000000 --- a/Lab1_OAP/Lab1_OAP.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lab1_OAP", "Lab1_OAP\Lab1_OAP.vcxproj", "{39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.ActiveCfg = Debug|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x64.Build.0 = Debug|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.ActiveCfg = Debug|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Debug|x86.Build.0 = Debug|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.ActiveCfg = Release|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x64.Build.0 = Release|x64 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.ActiveCfg = Release|Win32 - {39E703FF-4168-4ACA-84CA-CDD94BFE3FD3}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {AD8890FA-E7D7-4EB8-996C-597872ABE83B} - EndGlobalSection -EndGlobal diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp b/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp deleted file mode 100644 index 5f28270..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.cpp +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj deleted file mode 100644 index 7b4bd6f..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj +++ /dev/null @@ -1,135 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {39e703ff-4168-4aca-84ca-cdd94bfe3fd3} - Lab1OAP - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters b/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters deleted file mode 100644 index 0805cb7..0000000 --- a/Lab1_OAP/Lab1_OAP/Lab1_OAP.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file diff --git a/laboap1/laboap1.sln b/laboap1/laboap1.sln deleted file mode 100644 index 9f5ffa8..0000000 --- a/laboap1/laboap1.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34525.116 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "laboap1", "laboap1\laboap1.vcxproj", "{1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.ActiveCfg = Debug|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x64.Build.0 = Debug|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.ActiveCfg = Debug|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Debug|x86.Build.0 = Debug|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.ActiveCfg = Release|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x64.Build.0 = Release|x64 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.ActiveCfg = Release|Win32 - {1F4724C2-6BC1-42C2-ACC1-93AAA85BA624}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {898933DD-7FA8-4FA7-872F-63991ACB024A} - EndGlobalSection -EndGlobal diff --git a/laboap1/laboap1/laboap1.cpp b/laboap1/laboap1/laboap1.cpp deleted file mode 100644 index 0329b66..0000000 --- a/laboap1/laboap1/laboap1.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include -#include -#include - -void printArray(int arr[], int size) { - for (int i = 0; i < size; i++) { - printf("%d ", arr[i]); - } - printf("\n"); -} - -void insertionSort(int arr[], int size) { - int i, key, j; - for (i = 1; i < size; i++) { - key = arr[i]; - j = i - 1; - - while (j >= 0 && arr[j] > key) { - arr[j + 1] = arr[j]; - j = j - 1; - } - arr[j + 1] = key; - } -} - -void merge(int arr[], int left, int mid, int right) { - int i, j, k; - int n1 = mid - left + 1; - int n2 = right - mid; - - int L[n1], R[n2]; - - for (i = 0; i < n1; i++) - L[i] = arr[left + i]; - for (j = 0; j < n2; j++) - R[j] = arr[mid + 1 + j]; - - i = 0; - j = 0; - k = left; - while (i < n1 && j < n2) { - if (L[i] <= R[j]) { - arr[k] = L[i]; - i++; - } - else { - arr[k] = R[j]; - j++; - } - k++; - } - - while (i < n1) { - arr[k] = L[i]; - i++; - k++; - } - - while (j < n2) { - arr[k] = R[j]; - j++; - k++; - } -} - -void mergeSort(int arr[], int left, int right) { - if (left < right) { - int mid = left + (right - left) / 2; - - mergeSort(arr, left, mid); - mergeSort(arr, mid + 1, right); - - merge(arr, left, mid, right); - } -} - -int main() { - srand(time(0)); - - int size; - printf("Enter the size of the array: "); - scanf("%d", &size); - - int arr[size]; - for (int i = 0; i < size; i++) { - arr[i] = rand() % 100; - } - - printf("Randomly generated array: "); - printArray(arr, size); - - int choice; - printf("Enter 1 to delete an element, 2 to insert a new element: "); - scanf("%d", &choice); - - if (choice == 1) { - int index; - printf("Enter the index of the element you want to delete: "); - scanf("%d", &index); - - for (int i = index; i < size - 1; i++) { - arr[i] = arr[i + 1]; - } - size--; - } - else if (choice == 2) { - int index, element; - printf("Enter the index at which you want to insert the new element: "); - scanf("%d", &index); - printf("Enter the new element: "); - scanf("%d", &element); - - for (int i = size; i > index; i--) { - arr[i] = arr[i - 1]; - } - arr[index] = element; - size++; - } - else { - printf("Invalid choice"); - return 0; - } - - printf("Modified array: "); - printArray(arr, size); - - int arr_copy[size]; - for (int i = 0; i < size; i++) { - arr_copy[i] = arr[i]; - } - - clock_t start_time = clock(); - insertionSort(arr, size); - clock_t end_time = clock(); - double insertion_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; - - printf("Array sorted using Insertion Sort: "); - printArray(arr, size); - printf("Time taken by Insertion Sort: %f seconds\n", insertion_time); - - start_time = clock(); - mergeSort(arr_copy, 0, size - 1); - end_time = clock(); - double merge_time = ((double)(end_time - start_time)) / CLOCKS_PER_SEC; - - printf("Array sorted using Merge Sort: "); - printArray(arr_copy, size); - printf("Time taken by Merge Sort: %f seconds\n", merge_time); - - return 0; -} \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj b/laboap1/laboap1/laboap1.vcxproj deleted file mode 100644 index 085cb5f..0000000 --- a/laboap1/laboap1/laboap1.vcxproj +++ /dev/null @@ -1,136 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {1f4724c2-6bc1-42c2-acc1-93aaa85ba624} - laboap1 - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level3 - true - _DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - Default - - - Console - true - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - \ No newline at end of file diff --git a/laboap1/laboap1/laboap1.vcxproj.filters b/laboap1/laboap1/laboap1.vcxproj.filters deleted file mode 100644 index 2bff827..0000000 --- a/laboap1/laboap1/laboap1.vcxproj.filters +++ /dev/null @@ -1,22 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Исходные файлы - - - \ No newline at end of file -- 2.25.1