diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs index ba4efdf..5c8a67f 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/AbstractCompany.cs @@ -1,72 +1,53 @@ using HoistingCrane.Drawning; -namespace HoistingCrane.CollectionGenericObjects; -public abstract class AbstractCompany +namespace HoistingCrane.CollectionGenericObjects { - /// - /// Размер места (ширина) - /// - protected readonly int _placeSizeWidth = 180; - - /// - /// Размер места (высота) - /// - protected readonly int _placeSizeHeight = 100; - - /// - /// Ширина окна - /// - protected readonly int _pictureWidth; - - /// - /// Высота окна - /// - protected readonly int _pictureHeight; - - /// - /// Коллекция военных кораблей - /// - protected ICollectionGenericObjects? _collection = null; - - /// - /// Вычисление максимального количества элементов, которые можно разместить в окне - /// - private int GetMaxCount => (_pictureWidth / _placeSizeWidth) * (_pictureHeight / _placeSizeHeight); - - /// - /// Конструктор - /// - /// Ширина окна - /// Высота окна - /// Коллекция военных кораблей - public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection) + public abstract class AbstractCompany { - _pictureWidth = picWidth; - _pictureHeight = picHeight; - _collection = collection; - _collection.MaxCount = GetMaxCount; - } - - /// - /// Перегрузка оператора сложения для класса - /// - /// Компания - /// Добавляемый объект - /// - public static int operator +(AbstractCompany company, DrawningTrackedVehicle warship) - { - return company._collection.Insert(warship); - } - - /// - /// Перегрузка оператора удаления для класса - /// - /// Компания - /// Номер удаляемого объекта - /// - public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) - { - return company._collection.Remove(position); - } + /// + /// Ширина ячейки гаража + /// + protected readonly int _placeSizeWidth = 150; + /// + /// Высота ячейки гаража + /// + protected readonly int _placeSizeHeight = 90; + /// + /// Ширина окна + /// + protected readonly int pictureWidth; + /// + /// Высота окна + /// + protected readonly int pictureHeight; + /// + /// Коллекция автомобилей + /// + protected ICollectionGenericObjects? arr = null; + /// + /// Максимальное количество гаражей + /// + private int GetMaxCount + { + get + { + return (pictureWidth / _placeSizeWidth) * (pictureHeight * _placeSizeHeight); + } + } + public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects array) + { + pictureWidth = picWidth; + pictureHeight = picHeight; + arr = array; + arr.MaxCount = GetMaxCount; + } + public static int operator +(AbstractCompany company, DrawningTrackedVehicle car) + { + return company.arr.Insert(car, new DrawningCraneEqutables()); + } + public static DrawningTrackedVehicle operator -(AbstractCompany company, int position) + { + return company.arr?.Remove(position); + } /// /// Получение случайного объекта из коллекции @@ -106,9 +87,14 @@ public abstract class AbstractCompany /// protected abstract void DrawBackgound(Graphics g); - /// - /// Расстановка объектов - /// - protected abstract void SetObjectsPosition(); + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); + /// + /// Сортировка + /// + /// + public void Sort(IComparer comparer) => arr?.CollectionSort(comparer); + } } - diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs index fbc1fc7..c442077 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/CollectionInfo.cs @@ -11,7 +11,7 @@ namespace HoistingCrane.CollectionGenericObjects /// /// Тип /// - public CollectionType collectionType { get; private set; } + public CollectionType collectionType { get; private set; } /// /// Описание /// @@ -63,4 +63,4 @@ namespace HoistingCrane.CollectionGenericObjects return name.GetHashCode(); } } -} \ No newline at end of file +} diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs index b37f51c..6313a84 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/ListGenericObjects.cs @@ -41,48 +41,48 @@ public class ListGenericObjects : ICollectionGenericObjects where T : clas public CollectionType GetCollectionType => CollectionType.List; - public T? Get(int position) - { - if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); - return list[position]; - } - public int Insert(T obj, IEqualityComparer? comparer = null) - { - try + public T? Get(int position) { - if (list.Contains(obj, comparer)) throw new ObjectIsPresentInTheCollectionException(Count); - if (Count == _maxCount) throw new CollectionOverflowException(Count); - list.Add(obj); - return Count - 1; - } - catch (ObjectIsPresentInTheCollectionException ex) - { - MessageBox.Show(ex.Message); - return -1; - } - } - public int Insert(T obj, int position, IEqualityComparer? comparer = null) - { - try - { - if (comparer != null && list.Contains(obj, comparer)) - { - throw new ObjectIsPresentInTheCollectionException(Count); - } - - if (Count == _maxCount) throw new CollectionOverflowException(Count); - if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); - - list.Insert(position, obj); - return position; + return list[position]; } - catch (ObjectIsPresentInTheCollectionException ex) + public int Insert(T obj, IEqualityComparer? comparer = null) { - Console.WriteLine(ex.Message); - return -1; + try + { + if (list.Contains(obj, comparer)) throw new ObjectIsPresentInTheCollectionException(Count); + if (Count == _maxCount) throw new CollectionOverflowException(Count); + list.Add(obj); + return Count - 1; + } + catch (ObjectIsPresentInTheCollectionException ex) + { + MessageBox.Show(ex.Message); + return -1; + } + } + public int Insert(T obj, int position, IEqualityComparer? comparer = null) + { + try + { + if (comparer != null && list.Contains(obj, comparer)) + { + throw new ObjectIsPresentInTheCollectionException(Count); + } + + if (Count == _maxCount) throw new CollectionOverflowException(Count); + + if (position >= Count || position < 0) throw new PositionOutOfCollectionException(position); + + list.Insert(position, obj); + return position; + } + catch (ObjectIsPresentInTheCollectionException ex) + { + Console.WriteLine(ex.Message); + return -1; + } } - } public T? Remove(int position) { @@ -92,16 +92,17 @@ public class ListGenericObjects : ICollectionGenericObjects where T : clas return temp; } - public IEnumerable GetItems() - { - for (int i = 0; i < list.Count; i++) + public IEnumerable GetItems() { - yield return list[i]; + for(int i = 0; i < list.Count; i++) + { + yield return list[i]; + } + } + + public void CollectionSort(IComparer comparer) + { + list.Sort(comparer); } } - - public void CollectionSort(IComparer comparer) - { - list.Sort(comparer); - } } \ No newline at end of file diff --git a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs index 4d7f6c8..a2626d0 100644 --- a/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs +++ b/HoistingCrane/HoistingCrane/CollectionGenericObjects/StorageCollection.cs @@ -126,74 +126,75 @@ public class StorageCollection where T : DrawningTrackedVehicle } } - /// - /// Загрузка информации по грузовикам в хранилище из файла - /// - /// - /// - public void LoadData(string filename) - { - if (!File.Exists(filename)) + /// + /// Загрузка информации по грузовикам в хранилище из файла + /// + /// + /// + public void LoadData(string filename) { - throw new FileNotFoundException("Файл не существует"); - } - using (StreamReader fs = File.OpenText(filename)) - { - string str = fs.ReadLine(); - if (str == null || str.Length == 0) + if (!File.Exists(filename)) { - throw new InvalidOperationException("В файле не присутствуют данные"); + throw new FileNotFoundException("Файл не существует"); } - if (!str.StartsWith(_collectionKey)) + using (StreamReader fs = File.OpenText(filename)) { - throw new FormatException("В файле неверные данные"); - } - dict.Clear(); - string strs = ""; - while ((strs = fs.ReadLine()) != null) - { - string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); - if (record.Length != 3) + string str = fs.ReadLine(); + if (str == null || str.Length == 0) { - continue; + throw new InvalidOperationException("В файле не присутствуют данные"); } - CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? throw new InvalidOperationException("Не удалось определить информацию о коллекции: " + record[0]); - ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.collectionType) ?? throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]); - collection.MaxCount = Convert.ToInt32(record[1]); - string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + if (!str.StartsWith(_collectionKey)) { - if (elem?.CreateDrawningTrackedVehicle() is T crane) + throw new FormatException("В файле неверные данные"); + } + dict.Clear(); + string strs = ""; + while ((strs = fs.ReadLine()) != null) + { + string[] record = strs.Split(_separatorForKeyValue, StringSplitOptions.RemoveEmptyEntries); + if (record.Length != 3) { - try + continue; + } + CollectionInfo? collectionInfo = CollectionInfo.GetCollectionInfo(record[0]) ?? throw new InvalidOperationException("Не удалось определить информацию о коллекции: " + record[0]); + ICollectionGenericObjects? collection = StorageCollection.CreateCollection(collectionInfo.collectionType) ?? throw new InvalidOperationException("Не удалось определить тип коллекции:" + record[1]); + collection.MaxCount = Convert.ToInt32(record[1]); + string[] set = record[2].Split(_separatorItems, StringSplitOptions.RemoveEmptyEntries); + foreach (string elem in set) + { + if (elem?.CreateDrawningTrackedVehicle() is T crane) { - if (collection.Insert(crane) == -1) + try { - throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[2]); + if (collection.Insert(crane) == -1) + { + throw new InvalidOperationException("Объект не удалось добавить в коллекцию: " + record[2]); + } + } + catch(CollectionOverflowException ex) + { + throw new CollectionOverflowException("Коллекция переполнена", ex); } } - catch (CollectionOverflowException ex) - { - throw new CollectionOverflowException("Коллекция переполнена"); - } } + dict.Add(collectionInfo, collection); } - dict.Add(collectionInfo, collection); } } - } - /// - /// Создание коллекции по типу - /// - /// - /// - private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) - { - return collectionType switch + /// + /// Создание коллекции по типу + /// + /// + /// + private static ICollectionGenericObjects? CreateCollection(CollectionType collectionType) { - CollectionType.Massive => new MassivGenericObjects(), - CollectionType.List => new ListGenericObjects(), - _ => null, - }; + return collectionType switch + { + CollectionType.Massive => new MassivGenericObjects(), + CollectionType.List => new ListGenericObjects(), + _ => null, + }; + } } -} \ No newline at end of file +} diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs new file mode 100644 index 0000000..9902054 --- /dev/null +++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByColor.cs @@ -0,0 +1,18 @@ +namespace HoistingCrane.Drawning +{ + public class DrawningCraneCompareByColor : IComparer + { + public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y) + { + if (x == null || x.EntityTrackedVehicle == null) return -1; + if (y == null || y.EntityTrackedVehicle == null) return 1; + if (x.EntityTrackedVehicle.BodyColor.Name != y.EntityTrackedVehicle.BodyColor.Name) + return x.EntityTrackedVehicle.BodyColor.Name.CompareTo(y.EntityTrackedVehicle.BodyColor.Name); + var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed); + if (speedCompare != 0) return speedCompare; + return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight); + } + } +} + + diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs new file mode 100644 index 0000000..b2e59ef --- /dev/null +++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneCompareByType.cs @@ -0,0 +1,21 @@ +namespace HoistingCrane.Drawning +{ + public class DrawningCraneCompareByType : IComparer + { + /// + /// Сравнение по типу, скорости и весу + /// + /// + /// + /// + public int Compare(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y) + { + if (x == null || x.EntityTrackedVehicle == null) return -1; + if (y == null || y.EntityTrackedVehicle == null) return 1; + if (x.GetType().Name != y.GetType().Name) return x.GetType().Name.CompareTo(y.GetType().Name); + var speedCompare = x.EntityTrackedVehicle.Speed.CompareTo(y.EntityTrackedVehicle.Speed); + if(speedCompare != 0) return speedCompare; + return x.EntityTrackedVehicle.Weight.CompareTo(y.EntityTrackedVehicle.Weight); + } + } +} diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs new file mode 100644 index 0000000..432dd15 --- /dev/null +++ b/HoistingCrane/HoistingCrane/Drawning/DrawningCraneEqutables.cs @@ -0,0 +1,32 @@ +using HoistingCrane.Entities; +using System.Diagnostics.CodeAnalysis; + +namespace HoistingCrane.Drawning +{ + public class DrawningCraneEqutables : IEqualityComparer + { + public bool Equals(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y) + { + if (x == null || x.EntityTrackedVehicle == null) return false; + if (y == null || y.EntityTrackedVehicle == null) return false; + if (x.GetType().Name != y.GetType().Name) return false; + if (x.EntityTrackedVehicle.Speed != y.EntityTrackedVehicle.Speed) return false; + if (x.EntityTrackedVehicle.Weight != y.EntityTrackedVehicle.Weight) return false; + if (x.EntityTrackedVehicle.BodyColor != y.EntityTrackedVehicle.BodyColor) return false; + if ((x.EntityTrackedVehicle as EntityHoistingCrane)!= null && (y.EntityTrackedVehicle as EntityHoistingCrane)!=null) + { + var newX = x.EntityTrackedVehicle as EntityHoistingCrane; + var newY = y.EntityTrackedVehicle as EntityHoistingCrane; + if (newX?.AdditionalColor != newY?.AdditionalColor) return false; + if (newX?.Platform != newY?.Platform) return false; + if (newX?.Counterweight != newY?.Counterweight) return false; + } + return true; + } + + public int GetHashCode([DisallowNull] DrawningTrackedVehicle obj) + { + return obj.GetHashCode(); + } + } +} diff --git a/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs index ada1b71..2b9a11e 100644 --- a/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs +++ b/HoistingCrane/HoistingCrane/Drawning/ExtentionDrawningCrane.cs @@ -26,7 +26,7 @@ namespace HoistingCrane.Drawning if (trackedVehicle != null) { return new DrawningHoistingCrane((EntityHoistingCrane)trackedVehicle); - } + } trackedVehicle = EntityTrackedVehicle.CreateEntityTrackedVehicle(strs); if (trackedVehicle != null) { diff --git a/HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs b/HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs new file mode 100644 index 0000000..c4788f2 --- /dev/null +++ b/HoistingCrane/HoistingCrane/Drawning/StorageEqutables.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HoistingCrane.Drawning +{ + internal class StorageEqutables + { + } +} diff --git a/HoistingCrane/HoistingCrane/Exception/ObjectIsPresentInTheCollectionException.cs b/HoistingCrane/HoistingCrane/Exception/ObjectIsPresentInTheCollectionException.cs index 074762a..1175102 100644 --- a/HoistingCrane/HoistingCrane/Exception/ObjectIsPresentInTheCollectionException.cs +++ b/HoistingCrane/HoistingCrane/Exception/ObjectIsPresentInTheCollectionException.cs @@ -6,6 +6,7 @@ namespace HoistingCrane.Exceptions { public ObjectIsPresentInTheCollectionException(int objName) : base("В коллекции уже присустствует объект " + objName) { } public ObjectIsPresentInTheCollectionException() : base() { } + public ObjectIsPresentInTheCollectionException(string message, Exception exception) : base(message, exception) { } protected ObjectIsPresentInTheCollectionException(SerializationInfo info, StreamingContext context) : base(info, context) { } } -} \ No newline at end of file +} diff --git a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs index 47d3972..23ce26e 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.Designer.cs @@ -52,6 +52,8 @@ loadToolStripMenuItem = new ToolStripMenuItem(); saveFileDialog = new SaveFileDialog(); openFileDialog = new OpenFileDialog(); + buttonSortByType = new Button(); + buttonSortByColor = new Button(); groupBoxTools.SuspendLayout(); panelCompanyTool.SuspendLayout(); panelStorage.SuspendLayout(); @@ -68,7 +70,7 @@ groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Location = new Point(763, 24); groupBoxTools.Name = "groupBoxTools"; - groupBoxTools.Size = new Size(210, 499); + groupBoxTools.Size = new Size(210, 524); groupBoxTools.TabIndex = 0; groupBoxTools.TabStop = false; groupBoxTools.Text = "Инструменты"; @@ -76,20 +78,22 @@ // panelCompanyTool // panelCompanyTool.Anchor = AnchorStyles.None; + panelCompanyTool.Controls.Add(buttonSortByColor); + panelCompanyTool.Controls.Add(buttonSortByType); panelCompanyTool.Controls.Add(buttonCreateHoistingCrane); panelCompanyTool.Controls.Add(maskedTextBox); panelCompanyTool.Controls.Add(buttonRefresh); panelCompanyTool.Controls.Add(buttonGoToChek); panelCompanyTool.Controls.Add(buttonDeleteCar); - panelCompanyTool.Location = new Point(6, 319); + panelCompanyTool.Location = new Point(6, 296); panelCompanyTool.Name = "panelCompanyTool"; - panelCompanyTool.Size = new Size(204, 185); + panelCompanyTool.Size = new Size(204, 221); panelCompanyTool.TabIndex = 8; // // buttonCreateHoistingCrane // buttonCreateHoistingCrane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonCreateHoistingCrane.Location = new Point(9, 13); + buttonCreateHoistingCrane.Location = new Point(6, 3); buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane"; buttonCreateHoistingCrane.Size = new Size(192, 22); buttonCreateHoistingCrane.TabIndex = 0; @@ -100,7 +104,7 @@ // maskedTextBox // maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBox.Location = new Point(9, 41); + maskedTextBox.Location = new Point(6, 31); maskedTextBox.Mask = "00"; maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Size = new Size(192, 23); @@ -109,7 +113,7 @@ // buttonRefresh // buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonRefresh.Location = new Point(9, 129); + buttonRefresh.Location = new Point(6, 119); buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Size = new Size(192, 27); buttonRefresh.TabIndex = 5; @@ -120,7 +124,7 @@ // buttonGoToChek // buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonGoToChek.Location = new Point(9, 99); + buttonGoToChek.Location = new Point(6, 89); buttonGoToChek.Name = "buttonGoToChek"; buttonGoToChek.Size = new Size(192, 24); buttonGoToChek.TabIndex = 6; @@ -131,7 +135,7 @@ // buttonDeleteCar // buttonDeleteCar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - buttonDeleteCar.Location = new Point(9, 70); + buttonDeleteCar.Location = new Point(6, 60); buttonDeleteCar.Name = "buttonDeleteCar"; buttonDeleteCar.Size = new Size(192, 23); buttonDeleteCar.TabIndex = 4; @@ -141,7 +145,7 @@ // // buttonCreateCompany // - buttonCreateCompany.Location = new Point(12, 295); + buttonCreateCompany.Location = new Point(12, 267); buttonCreateCompany.Name = "buttonCreateCompany"; buttonCreateCompany.Size = new Size(192, 23); buttonCreateCompany.TabIndex = 7; @@ -161,12 +165,12 @@ panelStorage.Dock = DockStyle.Top; panelStorage.Location = new Point(3, 19); panelStorage.Name = "panelStorage"; - panelStorage.Size = new Size(204, 229); + panelStorage.Size = new Size(204, 216); panelStorage.TabIndex = 7; // // buttonDeleteCollection // - buttonDeleteCollection.Location = new Point(9, 199); + buttonDeleteCollection.Location = new Point(9, 186); buttonDeleteCollection.Name = "buttonDeleteCollection"; buttonDeleteCollection.Size = new Size(192, 27); buttonDeleteCollection.TabIndex = 6; @@ -178,14 +182,14 @@ // listBoxCollection.FormattingEnabled = true; listBoxCollection.ItemHeight = 15; - listBoxCollection.Location = new Point(9, 118); + listBoxCollection.Location = new Point(9, 101); listBoxCollection.Name = "listBoxCollection"; listBoxCollection.Size = new Size(192, 79); listBoxCollection.TabIndex = 5; // // buttonCollectionAdd // - buttonCollectionAdd.Location = new Point(9, 81); + buttonCollectionAdd.Location = new Point(9, 72); buttonCollectionAdd.Name = "buttonCollectionAdd"; buttonCollectionAdd.Size = new Size(192, 23); buttonCollectionAdd.TabIndex = 4; @@ -196,7 +200,7 @@ // radioButtonList // radioButtonList.AutoSize = true; - radioButtonList.Location = new Point(128, 56); + radioButtonList.Location = new Point(128, 47); radioButtonList.Name = "radioButtonList"; radioButtonList.Size = new Size(66, 19); radioButtonList.TabIndex = 3; @@ -207,7 +211,7 @@ // radioButtonMassive // radioButtonMassive.AutoSize = true; - radioButtonMassive.Location = new Point(18, 56); + radioButtonMassive.Location = new Point(12, 47); radioButtonMassive.Name = "radioButtonMassive"; radioButtonMassive.Size = new Size(67, 19); radioButtonMassive.TabIndex = 2; @@ -237,7 +241,7 @@ comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.FormattingEnabled = true; comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); - comboBoxSelectorCompany.Location = new Point(12, 266); + comboBoxSelectorCompany.Location = new Point(12, 238); comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; comboBoxSelectorCompany.Size = new Size(192, 23); comboBoxSelectorCompany.TabIndex = 2; @@ -248,7 +252,7 @@ pictureBox.Dock = DockStyle.Fill; pictureBox.Location = new Point(0, 24); pictureBox.Name = "pictureBox"; - pictureBox.Size = new Size(763, 499); + pictureBox.Size = new Size(763, 524); pictureBox.TabIndex = 1; pictureBox.TabStop = false; // @@ -292,11 +296,33 @@ // openFileDialog.Filter = "txt file | *.txt"; // + // buttonSortByType + // + buttonSortByType.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonSortByType.Location = new Point(6, 152); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(192, 27); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировка по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // + // buttonSortByColor + // + buttonSortByColor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonSortByColor.Location = new Point(6, 185); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(192, 27); + buttonSortByColor.TabIndex = 8; + buttonSortByColor.Text = "Сортировка по цвету"; + buttonSortByColor.UseVisualStyleBackColor = true; + buttonSortByColor.Click += buttonSortByColor_Click; + // // FormCarCollection // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(973, 523); + ClientSize = new Size(973, 548); Controls.Add(pictureBox); Controls.Add(groupBoxTools); Controls.Add(menuStrip); @@ -341,5 +367,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/HoistingCrane/HoistingCrane/FormCarCollection.cs b/HoistingCrane/HoistingCrane/FormCarCollection.cs index 9f06102..0d9e4f7 100644 --- a/HoistingCrane/HoistingCrane/FormCarCollection.cs +++ b/HoistingCrane/HoistingCrane/FormCarCollection.cs @@ -216,28 +216,46 @@ public partial class FormCarCollection : Form } } - /// - /// Обработка нажатия "Загразка" - /// - /// - /// - private void loadToolStripMenuItem_Click(object sender, EventArgs e) - { - if (openFileDialog.ShowDialog() == DialogResult.OK) + /// + /// Обработка нажатия "Загразка" + /// + /// + /// + private void loadToolStripMenuItem_Click(object sender, EventArgs e) { - try + if (openFileDialog.ShowDialog() == DialogResult.OK) { - _storageCollection.LoadData(openFileDialog.FileName); - RerfreshListBoxItems(); - MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); - logger.LogInformation("Загрузка из файла: {filename}", saveFileDialog.FileName.ToString()); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); - logger.LogError("Ошибка: {Message}", ex.Message); + try + { + _storageCollection.LoadData(openFileDialog.FileName); + RerfreshListBoxItems(); + MessageBox.Show("Загрузка прошла успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + logger.LogInformation("Загрузка в файл: {filename}", saveFileDialog.FileName); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + logger.LogError("Ошибка: {Message}", ex.Message); + } } } + + private void buttonSortByType_Click(object sender, EventArgs e) + { + compareCars(new DrawningCraneCompareByType()); + } + + private void buttonSortByColor_Click(object sender, EventArgs e) + { + compareCars(new DrawningCraneCompareByColor()); + } + + private void compareCars(IComparer comparer) + { + if (_company == null) return; + _company.Sort(comparer); + pictureBox.Image = _company.Show(); + } } } diff --git a/HoistingCrane/HoistingCrane/Program.cs b/HoistingCrane/HoistingCrane/Program.cs index 41f37ff..b2baa34 100644 --- a/HoistingCrane/HoistingCrane/Program.cs +++ b/HoistingCrane/HoistingCrane/Program.cs @@ -2,39 +2,40 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Serilog; -namespace HoistingCrane; - -internal static class Program +namespace HoistingCrane { - [STAThread] - static void Main() + internal static class Program { - ApplicationConfiguration.Initialize(); - ServiceCollection services = new(); - ConfigureServices(services); - using ServiceProvider serviceProvider = services.BuildServiceProvider(); - Application.Run(serviceProvider.GetRequiredService()); - } - private static void ConfigureServices(ServiceCollection services) - { - - string[] path = Directory.GetCurrentDirectory().Split('\\'); - string pathNeed = ""; - for (int i = 0; i < path.Length - 3; i++) + [STAThread] + static void Main() { - pathNeed += path[i] + "\\"; + ApplicationConfiguration.Initialize(); + ServiceCollection services = new(); + ConfigureServices(services); + using ServiceProvider serviceProvider = services.BuildServiceProvider(); + Application.Run(serviceProvider.GetRequiredService()); } - - - services.AddSingleton() - .AddLogging(option => + private static void ConfigureServices(ServiceCollection services) { - option.SetMinimumLevel(LogLevel.Information); - option.AddSerilog(new LoggerConfiguration() - .ReadFrom.Configuration(new ConfigurationBuilder() - .AddJsonFile($"{pathNeed}serilog.json") - .Build()) - .CreateLogger()); - }); + + string[] path = Directory.GetCurrentDirectory().Split('\\'); + string pathNeed = ""; + for (int i = 0; i < path.Length - 3; i++) + { + pathNeed += path[i] + "\\"; + } + + + services.AddSingleton() + .AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddSerilog(new LoggerConfiguration() + .ReadFrom.Configuration(new ConfigurationBuilder() + .AddJsonFile($"{pathNeed}serilog.json") + .Build()) + .CreateLogger()); + }); + } } } \ No newline at end of file