Laba8 BlokhinDA PIbd-21 Airbus #8
31
RPP/RPP/AirbusCollectionInfo.cs
Normal file
31
RPP/RPP/AirbusCollectionInfo.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP.DrawningObjects;
|
||||
using RPP.Generics;
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
internal class AirbusCollectionInfo : IEquatable<AirbusCollectionInfo>
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
public AirbusCollectionInfo(string name, string description)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
public bool Equals(AirbusCollectionInfo? other)
|
||||
{
|
||||
if (other == null || Name == null || other.Name == null) return false;
|
||||
if (Name == other.Name) return true;
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Name?.GetHashCode() ?? 0;
|
||||
}
|
||||
}
|
||||
}
|
39
RPP/RPP/AirbusCompareByColor.cs
Normal file
39
RPP/RPP/AirbusCompareByColor.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using RPP.DrawningObjects;
|
||||
using RPP.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
internal class AirbusCompareByColor : IComparer<DrawningAirbus?>
|
||||
{
|
||||
public int Compare(DrawningAirbus? x, DrawningAirbus? y)
|
||||
{
|
||||
if (x == null || x._EntityAirbus == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y._EntityAirbus == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x._EntityAirbus.BodyColor != y._EntityAirbus.BodyColor)
|
||||
{
|
||||
return x._EntityAirbus.BodyColor.Name.CompareTo(y._EntityAirbus.BodyColor.Name);
|
||||
}
|
||||
if (x.GetType() == y.GetType() && x is DrawningFlyAirbus)
|
||||
{
|
||||
return (x._EntityAirbus as EntityFlyAirbus).AdditionalColor.Name.CompareTo((y._EntityAirbus as EntityFlyAirbus).AdditionalColor.Name);
|
||||
}
|
||||
var speedCompare = x._EntityAirbus.Speed.CompareTo(y._EntityAirbus.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x._EntityAirbus.Weight.CompareTo(y._EntityAirbus.Weight);
|
||||
}
|
||||
}
|
||||
}
|
34
RPP/RPP/AirbusCompareByType.cs
Normal file
34
RPP/RPP/AirbusCompareByType.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using RPP.DrawningObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
internal class AirbusCompareByType : IComparer<DrawningAirbus?>
|
||||
{
|
||||
public int Compare(DrawningAirbus? x, DrawningAirbus? y)
|
||||
{
|
||||
if (x == null || x._EntityAirbus == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y._EntityAirbus == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType().Name != y.GetType().Name)
|
||||
{
|
||||
return x.GetType().Name.CompareTo(y.GetType().Name);
|
||||
}
|
||||
var speedCompare = x._EntityAirbus.Speed.CompareTo(y._EntityAirbus.Speed);
|
||||
if (speedCompare != 0)
|
||||
{
|
||||
return speedCompare;
|
||||
}
|
||||
return x._EntityAirbus.Weight.CompareTo(y._EntityAirbus.Weight);
|
||||
}
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ namespace RPP.Generics
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (bool)collect?._collection.Insert(obj);
|
||||
return (bool)collect?._collection.Insert(obj, new DrawiningAirbusEqutables());
|
||||
}
|
||||
|
||||
public static T? operator -(AirbusGenericCollection<T, U> collect, int
|
||||
@ -47,7 +47,7 @@ namespace RPP.Generics
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
public void Sort(IComparer<T> comparer) => _collection.SortSet(comparer);
|
||||
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
|
@ -5,15 +5,16 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP.MovementStrategy;
|
||||
using RPP.DrawningObjects;
|
||||
using System.Xml.Linq;
|
||||
|
||||
|
||||
namespace RPP.Generics
|
||||
{
|
||||
internal class AirbusGenericStorage
|
||||
{
|
||||
readonly Dictionary<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> _airbusStorages;
|
||||
readonly Dictionary<AirbusCollectionInfo, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> _airbusStorages;
|
||||
|
||||
public List<string> Keys => _airbusStorages.Keys.ToList();
|
||||
public List<AirbusCollectionInfo> Keys => _airbusStorages.Keys.ToList();
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
|
||||
@ -21,23 +22,25 @@ namespace RPP.Generics
|
||||
|
||||
public AirbusGenericStorage(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_airbusStorages = new Dictionary<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
|
||||
_airbusStorages = new Dictionary<AirbusCollectionInfo, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
|
||||
public void AddSet(string name)
|
||||
{
|
||||
if (_airbusStorages.ContainsKey(name))
|
||||
AirbusCollectionInfo Info = new AirbusCollectionInfo(name, string.Empty);
|
||||
if (_airbusStorages.ContainsKey(Info))
|
||||
return;
|
||||
_airbusStorages[name] = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight);
|
||||
_airbusStorages[Info] = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
|
||||
public void DelSet(string name)
|
||||
{
|
||||
if (!_airbusStorages.ContainsKey(name))
|
||||
AirbusCollectionInfo Info = new AirbusCollectionInfo(name, string.Empty);
|
||||
if (!_airbusStorages.ContainsKey(Info))
|
||||
return;
|
||||
_airbusStorages.Remove(name);
|
||||
_airbusStorages.Remove(Info);
|
||||
}
|
||||
|
||||
public AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>
|
||||
@ -45,8 +48,8 @@ namespace RPP.Generics
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_airbusStorages.ContainsKey(ind))
|
||||
return _airbusStorages[ind];
|
||||
AirbusCollectionInfo Info = new AirbusCollectionInfo(ind, string.Empty);
|
||||
if (_airbusStorages.ContainsKey(Info)) return _airbusStorages[Info];
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -62,14 +65,14 @@ namespace RPP.Generics
|
||||
File.Delete(filename);
|
||||
}
|
||||
StringBuilder data = new();
|
||||
foreach (KeyValuePair<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> record in _airbusStorages)
|
||||
foreach (KeyValuePair<AirbusCollectionInfo, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> record in _airbusStorages)
|
||||
{
|
||||
StringBuilder records = new();
|
||||
foreach (DrawningAirbus? elem in record.Value.GetAirbus)
|
||||
{
|
||||
records.Append($"{elem?.GetDataForSave(_separatorForObject)}{_separatorRecords}");
|
||||
}
|
||||
data.AppendLine($"{record.Key}{_separatorForKeyValue}{records}");
|
||||
data.AppendLine($"{record.Key.Name}{_separatorForKeyValue}{records}");
|
||||
|
||||
}
|
||||
if (data.Length == 0)
|
||||
@ -125,7 +128,7 @@ namespace RPP.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
_airbusStorages.Add(name, collection);
|
||||
_airbusStorages.Add(new AirbusCollectionInfo(name, string.Empty), collection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
63
RPP/RPP/DrawiningAirbusEqutables .cs
Normal file
63
RPP/RPP/DrawiningAirbusEqutables .cs
Normal file
@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RPP.Entities;
|
||||
using RPP.DrawningObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
internal class DrawiningAirbusEqutables : IEqualityComparer<DrawningAirbus?>
|
||||
{
|
||||
public bool Equals(DrawningAirbus? x, DrawningAirbus? y)
|
||||
{
|
||||
if (x == null || x._EntityAirbus == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(x));
|
||||
}
|
||||
if (y == null || y._EntityAirbus == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(y));
|
||||
}
|
||||
if (x.GetType() != y.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._EntityAirbus.Speed != y._EntityAirbus.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._EntityAirbus.Weight != y._EntityAirbus.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x._EntityAirbus.BodyColor != y._EntityAirbus.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (x is DrawningFlyAirbus && y is DrawningFlyAirbus)
|
||||
{
|
||||
if ((x._EntityAirbus as EntityFlyAirbus).AdditionalColor != (y._EntityAirbus as EntityFlyAirbus).AdditionalColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x._EntityAirbus as EntityFlyAirbus).Compartment != (y._EntityAirbus as EntityFlyAirbus).Compartment)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ((x._EntityAirbus as EntityFlyAirbus).Engine != (y._EntityAirbus as EntityFlyAirbus).Engine)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public int GetHashCode([DisallowNull] DrawningAirbus obj)
|
||||
{
|
||||
return obj.GetHashCode();
|
||||
}
|
||||
}
|
||||
}
|
40
RPP/RPP/FormAirbusCollection.Designer.cs
generated
40
RPP/RPP/FormAirbusCollection.Designer.cs
generated
@ -29,6 +29,8 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
panel1 = new Panel();
|
||||
ButtonSortByColor = new Button();
|
||||
ButtonSortByType = new Button();
|
||||
panel2 = new Panel();
|
||||
buttonDelObject = new Button();
|
||||
listBoxStorages = new ListBox();
|
||||
@ -55,6 +57,8 @@
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
panel1.Controls.Add(ButtonSortByColor);
|
||||
panel1.Controls.Add(ButtonSortByType);
|
||||
panel1.Controls.Add(panel2);
|
||||
panel1.Controls.Add(ButtonRefreshCollection);
|
||||
panel1.Controls.Add(ButtonRemoveAirbus);
|
||||
@ -64,9 +68,29 @@
|
||||
panel1.Dock = DockStyle.Right;
|
||||
panel1.Location = new Point(597, 0);
|
||||
panel1.Name = "panel1";
|
||||
panel1.Size = new Size(203, 450);
|
||||
panel1.Size = new Size(203, 556);
|
||||
panel1.TabIndex = 0;
|
||||
//
|
||||
// ButtonSortByColor
|
||||
//
|
||||
ButtonSortByColor.Location = new Point(16, 307);
|
||||
ButtonSortByColor.Name = "ButtonSortByColor";
|
||||
ButtonSortByColor.Size = new Size(172, 29);
|
||||
ButtonSortByColor.TabIndex = 8;
|
||||
ButtonSortByColor.Text = "Соритровка по цвету";
|
||||
ButtonSortByColor.UseVisualStyleBackColor = true;
|
||||
ButtonSortByColor.Click += ButtonSortByColor_Click;
|
||||
//
|
||||
// ButtonSortByType
|
||||
//
|
||||
ButtonSortByType.Location = new Point(16, 262);
|
||||
ButtonSortByType.Name = "ButtonSortByType";
|
||||
ButtonSortByType.Size = new Size(172, 29);
|
||||
ButtonSortByType.TabIndex = 7;
|
||||
ButtonSortByType.Text = "Сортировка по типу";
|
||||
ButtonSortByType.UseVisualStyleBackColor = true;
|
||||
ButtonSortByType.Click += ButtonSortByType_Click;
|
||||
//
|
||||
// panel2
|
||||
//
|
||||
panel2.Controls.Add(buttonDelObject);
|
||||
@ -136,7 +160,7 @@
|
||||
//
|
||||
// ButtonRefreshCollection
|
||||
//
|
||||
ButtonRefreshCollection.Location = new Point(7, 398);
|
||||
ButtonRefreshCollection.Location = new Point(6, 504);
|
||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||
ButtonRefreshCollection.Size = new Size(190, 40);
|
||||
ButtonRefreshCollection.TabIndex = 4;
|
||||
@ -146,7 +170,7 @@
|
||||
//
|
||||
// ButtonRemoveAirbus
|
||||
//
|
||||
ButtonRemoveAirbus.Location = new Point(5, 327);
|
||||
ButtonRemoveAirbus.Location = new Point(5, 424);
|
||||
ButtonRemoveAirbus.Name = "ButtonRemoveAirbus";
|
||||
ButtonRemoveAirbus.Size = new Size(190, 40);
|
||||
ButtonRemoveAirbus.TabIndex = 3;
|
||||
@ -156,14 +180,14 @@
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Location = new Point(40, 298);
|
||||
maskedTextBoxNumber.Location = new Point(55, 395);
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(98, 23);
|
||||
maskedTextBoxNumber.TabIndex = 2;
|
||||
//
|
||||
// AddAirbusButton
|
||||
//
|
||||
AddAirbusButton.Location = new Point(5, 252);
|
||||
AddAirbusButton.Location = new Point(6, 349);
|
||||
AddAirbusButton.Name = "AddAirbusButton";
|
||||
AddAirbusButton.Size = new Size(190, 40);
|
||||
AddAirbusButton.TabIndex = 1;
|
||||
@ -207,7 +231,7 @@
|
||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(597, 450);
|
||||
pictureBoxCollection.Size = new Size(597, 556);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
@ -223,7 +247,7 @@
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(800, 556);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Controls.Add(panel1);
|
||||
MainMenuStrip = menuStrip;
|
||||
@ -261,5 +285,7 @@
|
||||
private ToolStripMenuItem menuToolStripMenuItem;
|
||||
private ToolStripMenuItem SaveToolStripMenuItem;
|
||||
private ToolStripMenuItem LoadToolStripMenuItem;
|
||||
private Button ButtonSortByColor;
|
||||
private Button ButtonSortByType;
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using RPP.DrawningObjects;
|
||||
using RPP.Generics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Drawing.Text;
|
||||
|
||||
namespace RPP
|
||||
{
|
||||
@ -38,6 +39,11 @@ namespace RPP
|
||||
pictureBoxCollection.Image = obj.ShowCars();
|
||||
_logger.LogInformation($"Добавлен объект в набор {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (ArgumentException ex)
|
||||
{
|
||||
MessageBox.Show("Такой объект уже существует");
|
||||
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Не удалось добавить объект");
|
||||
@ -66,7 +72,7 @@ namespace RPP
|
||||
listBoxStorages.Items.Clear();
|
||||
foreach (var key in _storage.Keys)
|
||||
{
|
||||
listBoxStorages.Items.Add(key);
|
||||
listBoxStorages.Items.Add(key.Name);
|
||||
}
|
||||
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||
>= listBoxStorages.Items.Count))
|
||||
@ -201,5 +207,17 @@ namespace RPP
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ButtonSortByType_Click(object sender, EventArgs e) => CompareAirbus(new AirbusCompareByType());
|
||||
private void ButtonSortByColor_Click(object sender, EventArgs e) => CompareAirbus(new AirbusCompareByColor());
|
||||
private void CompareAirbus(IComparer<DrawningAirbus?> comparer)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
return;
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
return;
|
||||
obj.Sort(comparer);
|
||||
pictureBoxCollection.Image = obj.ShowCars();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ namespace RPP.Generics
|
||||
_places = new List<T?>(_maxCount);
|
||||
}
|
||||
|
||||
public bool Insert(T airbus)
|
||||
public bool Insert(T airbus, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
return Insert(airbus, 0);
|
||||
return Insert(airbus, 0, equal);
|
||||
}
|
||||
|
||||
public bool Insert(T airbus, int position)
|
||||
public bool Insert(T airbus, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
|
||||
if (position < 0 || position >= _maxCount)
|
||||
@ -35,7 +35,14 @@ namespace RPP.Generics
|
||||
{
|
||||
throw new StorageOverflowException(position);
|
||||
}
|
||||
|
||||
if (equal != null)
|
||||
{
|
||||
foreach (var i in _places)
|
||||
{
|
||||
if (equal.Equals(i, airbus))
|
||||
throw new ArgumentException($"Объект {airbus} уже существует");
|
||||
}
|
||||
}
|
||||
_places.Insert(0, airbus);
|
||||
return true;
|
||||
}
|
||||
@ -79,6 +86,7 @@ namespace RPP.Generics
|
||||
}
|
||||
}
|
||||
}
|
||||
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user