Compare commits

...

2 Commits

Author SHA1 Message Date
783ff07009 Lab8 сдана 2023-12-27 21:40:45 +04:00
e7f367dc4d фиксы с директивами 2023-12-25 19:03:46 +04:00
13 changed files with 159 additions and 49 deletions

View File

@ -5,9 +5,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber;
using AirBomber.Entities;
namespace AirBomber.DrawningObjects
namespace AirBomber
{
public class DrawningAirBomber : DrawningAirPlane
{

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.Entities;
using AirBomber;
namespace AirBomber.DrawningObjects
namespace AirBomber
{
public class DrawningAirPlane
{

View File

@ -4,8 +4,7 @@ using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.DrawningObjects;
using AirBomber.Entities;
using AirBomber;
namespace AirBomber
{

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using AirBomber;
namespace AirBomber.Entities
namespace AirBomber
{
public class EntityAirBomber : EntityAirPlane
{

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using AirBomber;
namespace AirBomber.Entities
namespace AirBomber
{
public class EntityAirPlane
{

View File

@ -34,6 +34,8 @@
buttonRefreshCollection = new Button();
maskedTextBoxNumber = new MaskedTextBox();
groupBoxTools = new GroupBox();
buttonSortByColor = new Button();
buttonSortByType = new Button();
groupBoxStorages = new GroupBox();
textBoxStorageName = new TextBox();
buttonDelObject = new Button();
@ -63,9 +65,9 @@
//
// buttonAddPlane
//
buttonAddPlane.Location = new Point(76, 417);
buttonAddPlane.Location = new Point(49, 525);
buttonAddPlane.Name = "buttonAddPlane";
buttonAddPlane.Size = new Size(160, 64);
buttonAddPlane.Size = new Size(209, 44);
buttonAddPlane.TabIndex = 0;
buttonAddPlane.Text = "Добавить самолет";
buttonAddPlane.UseVisualStyleBackColor = true;
@ -73,7 +75,7 @@
//
// buttonRemovePlane
//
buttonRemovePlane.Location = new Point(76, 549);
buttonRemovePlane.Location = new Point(76, 612);
buttonRemovePlane.Name = "buttonRemovePlane";
buttonRemovePlane.Size = new Size(160, 60);
buttonRemovePlane.TabIndex = 1;
@ -83,9 +85,9 @@
//
// buttonRefreshCollection
//
buttonRefreshCollection.Location = new Point(76, 648);
buttonRefreshCollection.Location = new Point(49, 678);
buttonRefreshCollection.Name = "buttonRefreshCollection";
buttonRefreshCollection.Size = new Size(160, 86);
buttonRefreshCollection.Size = new Size(209, 56);
buttonRefreshCollection.TabIndex = 2;
buttonRefreshCollection.Text = "Обновить коллекцию";
buttonRefreshCollection.UseVisualStyleBackColor = true;
@ -93,7 +95,7 @@
//
// maskedTextBoxNumber
//
maskedTextBoxNumber.Location = new Point(76, 501);
maskedTextBoxNumber.Location = new Point(76, 575);
maskedTextBoxNumber.Mask = "00";
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(160, 31);
@ -102,6 +104,8 @@
//
// groupBoxTools
//
groupBoxTools.Controls.Add(buttonSortByColor);
groupBoxTools.Controls.Add(buttonSortByType);
groupBoxTools.Controls.Add(groupBoxStorages);
groupBoxTools.Controls.Add(buttonAddPlane);
groupBoxTools.Controls.Add(buttonRefreshCollection);
@ -114,6 +118,26 @@
groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты";
//
// buttonSortByColor
//
buttonSortByColor.Location = new Point(49, 469);
buttonSortByColor.Name = "buttonSortByColor";
buttonSortByColor.Size = new Size(209, 48);
buttonSortByColor.TabIndex = 6;
buttonSortByColor.Text = "Сортировка по цвету";
buttonSortByColor.UseVisualStyleBackColor = true;
buttonSortByColor.Click += buttonSortByColor_Click;
//
// buttonSortByType
//
buttonSortByType.Location = new Point(49, 415);
buttonSortByType.Name = "buttonSortByType";
buttonSortByType.Size = new Size(209, 48);
buttonSortByType.TabIndex = 5;
buttonSortByType.Text = "Сортировка по типу";
buttonSortByType.UseVisualStyleBackColor = true;
buttonSortByType.Click += buttonSortByType_Click;
//
// groupBoxStorages
//
groupBoxStorages.Controls.Add(textBoxStorageName);
@ -184,14 +208,14 @@
// SaveToolStripMenuItem
//
SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
SaveToolStripMenuItem.Size = new Size(270, 34);
SaveToolStripMenuItem.Size = new Size(212, 34);
SaveToolStripMenuItem.Text = "Сохранение";
SaveToolStripMenuItem.Click += SaveToolStripMenuItem_Click;
//
// LoadToolStripMenuItem
//
LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
LoadToolStripMenuItem.Size = new Size(270, 34);
LoadToolStripMenuItem.Size = new Size(212, 34);
LoadToolStripMenuItem.Text = "Загрузка";
LoadToolStripMenuItem.Click += LoadToolStripMenuItem_Click;
//
@ -245,5 +269,7 @@
private ToolStripMenuItem LoadToolStripMenuItem;
private OpenFileDialog openFileDialog;
private SaveFileDialog saveFileDialog;
private Button buttonSortByColor;
private Button buttonSortByType;
}
}

View File

@ -94,6 +94,7 @@ namespace AirBomber
MessageBox.Show(ex.Message);
_logger.LogWarning($"Объект не добавлен в набор {listBoxStorages.SelectedItem.ToString()}");
}
}
/// <summary>
/// Удаление объекта из набора
@ -134,7 +135,7 @@ namespace AirBomber
{
MessageBox.Show(ex.Message);
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show("Неверный ввод");
_logger.LogWarning("Неверный ввод");
@ -228,12 +229,42 @@ namespace AirBomber
_logger.LogInformation("Загрузка прошла успешно");
ReloadObjects();
}
catch(Exception ex)
catch (Exception ex)
{
MessageBox.Show("Не загрузилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error);
_logger.LogWarning($"Не загрузилось: {ex.Message}");
}
}
}
/// <summary>
/// Сортировка по типу
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByType_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByType());
/// <summary>
/// Сортировка по цвету
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void buttonSortByColor_Click(object sender, EventArgs e) => ComparePlanes(new PlaneCompareByColor());
/// <summary>
/// Сортировка по сравнителю
/// </summary>
/// <param name="comparer"></param>
private void ComparePlanes(IComparer<DrawningAirPlane?> comparer)
{
if (listBoxStorages.SelectedIndex == -1)
{
return;
}
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
obj.Sort(comparer);
pictureBoxCollection.Image = obj.ShowPlanes();
}
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AirBomber
{
internal class PlaneCollectionInfo: IEquatable<PlaneCollectionInfo>
{
public string Name { get; private set; }
public string Description { get; private set; }
public PlaneCollectionInfo(string name, string description)
{
Name = name;
Description = description;
}
public bool Equals(PlaneCollectionInfo other)
{
if (Name != other?.Name)
return false;
return true;
}
public override int GetHashCode()
{
return Name.GetHashCode();
}
public override string ToString()
{
return Name;
}
}
}

View File

@ -3,8 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.DrawningObjects;
using AirBomber.Entities;
using AirBomber;
namespace AirBomber
{

View File

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber.DrawningObjects;
using AirBomber;
namespace AirBomber.Generics
namespace AirBomber
{
internal class PlaneCompareByType: IComparer<DrawningAirPlane?>
{

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AirBomber;
namespace AirBomber
{
@ -31,6 +32,11 @@ namespace AirBomber
/// </summary>
private readonly SetGeneric<T> _collection;
/// <summary>
/// Сортировка
/// </summary>
/// <param name="comparer"></param>
public void Sort(IComparer<T?> comparer) => _collection.SortSet(comparer);
/// <summary>
/// Конструктор
/// </summary>
/// <param name="picWidth"></param>
@ -49,13 +55,13 @@ namespace AirBomber
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static bool operator +(PlanesGenericCollection<T, U> collect, T obj)
public static int operator +(PlanesGenericCollection<T, U> collect, T obj)
{
if (obj == null)
{
return false;
return -1;
}
return collect._collection.Insert(obj);
return collect._collection.Insert(obj, new DrawningPlanesEquatables());
}
/// <summary>
/// Перегрузка оператора вычитания

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace AirBomber
{
@ -12,11 +13,11 @@ namespace AirBomber
/// <summary>
/// Словарь (хранилище)
/// </summary>
readonly Dictionary<string, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>> _planeStorages;
readonly Dictionary<PlaneCollectionInfo, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>> _planeStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<string> Keys => _planeStorages.Keys.ToList();
public List<PlaneCollectionInfo> Keys => _planeStorages.Keys.ToList();
/// <summary>
/// Ширина окна отрисовки
/// </summary>
@ -44,7 +45,7 @@ namespace AirBomber
/// <param name="pictureHeight"></param>
public PlanesGenericStorage(int pictureWidth, int pictureHeight)
{
_planeStorages = new Dictionary<string, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>();
_planeStorages = new Dictionary<PlaneCollectionInfo, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@ -55,9 +56,10 @@ namespace AirBomber
public void AddSet(string name)
{
// TODO Прописать логику для добавления DONE
if (!_planeStorages.ContainsKey(name))
if(!_planeStorages.ContainsKey(new PlaneCollectionInfo(name, string.Empty)))
{
_planeStorages.Add(name, new PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>(_pictureWidth, _pictureHeight));
_planeStorages.Add(new PlaneCollectionInfo(name, string.Empty),
new PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>(_pictureWidth, _pictureHeight));
}
}
/// <summary>
@ -67,10 +69,11 @@ namespace AirBomber
public void DelSet(string name)
{
// TODO Прописать логику для удаления DONE
if (_planeStorages.ContainsKey(name))
if (!_planeStorages.ContainsKey(new PlaneCollectionInfo(name, string.Empty)))
{
_planeStorages.Remove(name);
return;
}
_planeStorages.Remove(new PlaneCollectionInfo(name, string.Empty));
}
/// <summary>
/// Доступ к набору
@ -83,9 +86,9 @@ namespace AirBomber
get
{
// TODO Продумать логику получения набора DONE
if (_planeStorages.ContainsKey(ind))
if (_planeStorages.ContainsKey(new PlaneCollectionInfo(ind, string.Empty)))
{
return _planeStorages[ind];
return _planeStorages[new PlaneCollectionInfo(ind, string.Empty)];
}
return null;
}
@ -102,7 +105,7 @@ namespace AirBomber
File.Delete(filename);
}
StringBuilder data = new();
foreach (KeyValuePair<string, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>record in _planeStorages)
foreach (KeyValuePair<PlaneCollectionInfo, PlanesGenericCollection<DrawningAirPlane, DrawningObjectAirPlane>>record in _planeStorages)
{
StringBuilder records = new();
foreach (DrawningAirPlane? elem in record.Value.GetPlanes)
@ -169,7 +172,7 @@ namespace AirBomber
DrawningAirPlane? plane = elem?.CreateDrawningAirPlane(_separatorForObject, _pictureWidth, _pictureHeight);
if (plane != null)
{
if (!(collection + plane))
if ((collection + plane) == -1)
{
try
{
@ -186,7 +189,7 @@ namespace AirBomber
}
}
}
_planeStorages.Add(record[0], collection);
_planeStorages.Add(new PlaneCollectionInfo(record[0], string.Empty), collection);
}
return true;
}

View File

@ -5,7 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using AirBomber.Exceptions;
namespace AirBomber.Generics
namespace AirBomber
{
internal class SetGeneric<T>
where T : class
@ -37,9 +37,19 @@ namespace AirBomber.Generics
/// </summary>
/// <param name="plane">Добавляемый самолет</param>
/// <returns></returns>
public bool Insert(T plane, IEqualityComparer<T?>? equal = null)
public int Insert(T plane, IEqualityComparer<T?>? equal = null)
{
return Insert(plane, 0, equal);
if (equal != null)
{
foreach (var secondLoco in _places)
{
if (equal.Equals(plane, secondLoco))
{
throw new Exception("Такой объект уже есть в коллекции");
}
}
}
return Insert(plane, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -47,19 +57,23 @@ namespace AirBomber.Generics
/// <param name="plane">Добавляемый самолет</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
public int Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
{
if (position < 0 || position >= _maxCount)
throw new StorageOverflowException("Невозможно добавить");
if (Count >= _maxCount)
if (_places.Count >= _maxCount)
throw new StorageOverflowException(_maxCount);
if (equal != null && _places.Contains(plane, equal))
throw new ArgumentException("Такой объект уже есть в коллекции");
if (position < 0 || position >= _maxCount)
{
return -1;
}
_places.Insert(0, plane);
return true;
if (equal != null)
{
if (_places.Contains(plane, equal))
throw new ArgumentException(("Такой объект уже есть в коллекции"));
}
_places.Insert(position, plane);
return position;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции