Лабораторная работа №3

This commit is contained in:
alhimek17 2024-03-26 13:14:52 +04:00
parent 2bec551f18
commit 8f24090bdf
8 changed files with 180 additions and 118 deletions

View File

@ -1,33 +1,44 @@
using ProjectAirPlane.Drawnings; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAirPlane.Drawnings;
namespace ProjectAirPlane.CollectionGenericObjects; namespace ProjectAirPlane.CollectionGenericObjects;
public abstract class AbstractCompany public abstract class AbstractCompany
{ {
/// <summary> /// <summary>
/// Размер места (ширина) /// Размер места (ширина)
/// </summary> /// </summary>
protected readonly int _placeSizeWidth = 195; protected readonly int _placeSizeWidth = 210;
/// <summary> /// <summary>
/// Размер места (высота) /// Размер места (высота)
/// </summary> /// </summary>
protected readonly int _placeSizeHeight = 70; protected readonly int _placeSizeHeight = 80;
/// <summary> /// <summary>
/// Ширина окна /// Ширина окна
/// </summary> /// </summary>
protected readonly int _pictureWidth; protected readonly int _pictureWidth;
/// <summary> /// <summary>
/// Высота окна /// Высота окна
/// </summary> /// </summary>
protected readonly int _pictureHeight; protected readonly int _pictureHeight;
/// <summary> /// <summary>
/// Коллекция судов /// Коллекция автомобилей
/// </summary> /// </summary>
protected ICollectionGenericObjects<DrawningPlane>? _collection = null; protected ICollectionGenericObjects<DrawningPlane>? _collection = null;
/// <summary> /// <summary>
/// Вычисление максимального количества элементов, который можно разместить в окне /// Вычисление максимального количества элементов, который можно разместить в окне
/// </summary> /// </summary>
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight); private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -41,16 +52,18 @@ public abstract class AbstractCompany
_collection = collection; _collection = collection;
_collection.SetMaxCount = GetMaxCount; _collection.SetMaxCount = GetMaxCount;
} }
/// <summary> /// <summary>
/// Перегрузка оператора сложения для класса /// Перегрузка оператора сложения для класса
/// </summary> /// </summary>
/// <param name="company">Компания</param> /// <param name="company">Компания</param>
/// <param name="ship">Добавляемый объект</param> /// <param name="car">Добавляемый объект</param>
/// <returns></returns> /// <returns></returns>
public static int operator +(AbstractCompany company, DrawningPlane plane) public static int operator +(AbstractCompany company, DrawningPlane plane)
{ {
return company._collection.Insert(plane); return company._collection?.Insert(plane) ?? -1;
} }
/// <summary> /// <summary>
/// Перегрузка оператора удаления для класса /// Перегрузка оператора удаления для класса
/// </summary> /// </summary>
@ -59,8 +72,9 @@ public abstract class AbstractCompany
/// <returns></returns> /// <returns></returns>
public static DrawningPlane operator -(AbstractCompany company, int position) public static DrawningPlane operator -(AbstractCompany company, int position)
{ {
return company._collection?.Remove(position); return company._collection?.Remove(position) ?? null;
} }
/// <summary> /// <summary>
/// Получение случайного объекта из коллекции /// Получение случайного объекта из коллекции
/// </summary> /// </summary>
@ -70,6 +84,7 @@ public abstract class AbstractCompany
Random rnd = new(); Random rnd = new();
return _collection?.Get(rnd.Next(GetMaxCount)); return _collection?.Get(rnd.Next(GetMaxCount));
} }
/// <summary> /// <summary>
/// Вывод всей коллекции /// Вывод всей коллекции
/// </summary> /// </summary>
@ -79,22 +94,25 @@ public abstract class AbstractCompany
Bitmap bitmap = new(_pictureWidth, _pictureHeight); Bitmap bitmap = new(_pictureWidth, _pictureHeight);
Graphics graphics = Graphics.FromImage(bitmap); Graphics graphics = Graphics.FromImage(bitmap);
DrawBackgound(graphics); DrawBackgound(graphics);
SetObjectsPosition(); SetObjectsPosition();
for (int i = 0; i < (_collection?.Count ?? 0); ++i) for (int i = 0; i < (_collection?.Count ?? 0); ++i)
{ {
DrawningPlane? obj = _collection?.Get(i); DrawningPlane? obj = _collection?.Get(i);
obj?.DrawTransport(graphics); obj?.DrawTransport(graphics);
} }
return bitmap; return bitmap;
} }
/// <summary> /// <summary>
/// Вывод заднего фона /// Вывод заднего фона
/// </summary> /// </summary>
/// <param name="g"></param> /// <param name="g"></param>
protected abstract void DrawBackgound(Graphics g); protected abstract void DrawBackgound(Graphics g);
/// <summary> /// <summary>
/// Расстановка объектов /// Расстановка объектов
/// </summary> /// </summary>
protected abstract void SetObjectsPosition(); protected abstract void SetObjectsPosition();
} }

View File

@ -1,9 +1,11 @@
namespace ProjectAirPlane.CollectionGenericObjects; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirPlane.CollectionGenericObjects;
/// <summary>
/// Интерфейс описания действий для набора хранимых объектов
/// </summary>
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
public interface ICollectionGenericObjects<T> public interface ICollectionGenericObjects<T>
where T : class where T : class
{ {
@ -37,7 +39,7 @@ public interface ICollectionGenericObjects<T>
/// </summary> /// </summary>
/// <param name="position">Позиция</param> /// <param name="position">Позиция</param>
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns> /// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
T Remove(int position); T? Remove(int position);
/// <summary> /// <summary>
/// Получение объекта по позиции /// Получение объекта по позиции
@ -46,4 +48,3 @@ public interface ICollectionGenericObjects<T>
/// <returns>Объект</returns> /// <returns>Объект</returns>
T? Get(int position); T? Get(int position);
} }

View File

@ -1,27 +1,54 @@
namespace ProjectAirPlane.CollectionGenericObjects; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ProjectAirPlane.CollectionGenericObjects;
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T> public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
where T : class where T : class
{ {
/// <summary> /// <summary>
/// Массив объектов, которые храним /// Массив объектов, которые храним
/// </summary> /// </summary>
private T?[] _collection; private T?[] _collection;
public int Count => _collection.Length; public int Count => _collection.Length;
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
public int SetMaxCount
{
set
{
if (value > 0)
{
if (_collection.Length > 0)
{
Array.Resize(ref _collection, value);
}
else
{
_collection = new T?[value];
}
}
}
}
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public MassiveGenericObjects() public MassiveGenericObjects()
{ {
_collection = Array.Empty<T?>(); _collection = Array.Empty<T?>();
} }
public T? Get(int position) public T? Get(int position)
{ {
// TODO проверка позиции // TODO проверка позиции
if (position >= _collection.Length || position < 0) return null; if (position >= _collection.Length || position < 0) return null;
return _collection[position]; return _collection[position];
} }
public int Insert(T obj) public int Insert(T obj)
{ {
// TODO вставка в свободное место набора // TODO вставка в свободное место набора
@ -37,12 +64,13 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
return -1; return -1;
} }
public int Insert(T obj, int position) public int Insert(T obj, int position)
{ {
// TODO проверка позиции // TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда // ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до // если нет после, ищем до
// TODO вставка // TODO вставка
if (position >= _collection.Length || position < 0) if (position >= _collection.Length || position < 0)
return -1; return -1;
@ -73,14 +101,18 @@ public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
} }
return -1; return -1;
} }
public T Remove(int position) public T Remove(int position)
{ {
// TODO проверка позиции // TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null // TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= _collection.Length || position < 0) if (position >= _collection.Length || position < 0)
{
return null; return null;
}
T obj = _collection[position]; T obj = _collection[position];
_collection[position] = null; _collection[position] = null;
return obj; return obj;
} }
} }

View File

@ -1,29 +1,30 @@
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectAirPlane.Drawnings; using ProjectAirPlane.Drawnings;
namespace ProjectAirPlane.CollectionGenericObjects; namespace ProjectAirPlane.CollectionGenericObjects;
public class PlaneSharigService : AbstractCompany public class PlaneSharingService : AbstractCompany
{ {
public PlaneSharigService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningPlane> collection) : base(picWidth, picHeight, collection) public PlaneSharingService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningPlane> collection) : base(picWidth, picHeight, collection)
{ {
} }
protected override void DrawBackgound(Graphics g) protected override void DrawBackgound(Graphics g)
{ {
int width = _pictureWidth / _placeSizeWidth;
int height = _pictureHeight / _placeSizeHeight;
Pen pen = new(Color.Black, 3); Pen pen = new(Color.Black, 3);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) for (int i = 0; i < width; i++)
{ {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + for (int j = 0; j < height + 1; ++j)
1; ++j)
{ {
g.DrawLine(pen, i * _placeSizeWidth, j * g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 5, j * _placeSizeHeight);
_placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
_placeSizeHeight);
} }
g.DrawLine(pen, i * _placeSizeWidth, 0, i *
_placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
} }
} }
@ -40,7 +41,7 @@ public class PlaneSharigService : AbstractCompany
if (_collection.Get(i) != null) if (_collection.Get(i) != null)
{ {
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 4); _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 15, curHeight * _placeSizeHeight + 3);
} }
if (curWidth > 0) if (curWidth > 0)
curWidth--; curWidth--;

View File

@ -3,9 +3,8 @@ using ProjectAirPlane.MovementStrategy;
namespace ProjectAirPlane; namespace ProjectAirPlane;
/// <summary> /// <summary>
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Ñïîðòèâíûé àâòîìîáèëü" /// Ôîðìà ðàáîòû ñ îáúåêòîì "Êîíòåéíåðîâîç"
/// </summary> /// </summary>
public partial class FormAirPlane : Form public partial class FormAirPlane : Form
{ {
@ -15,11 +14,21 @@ public partial class FormAirPlane : Form
private DrawningPlane? _drawningPlane; private DrawningPlane? _drawningPlane;
/// <summary> /// <summary>
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ /// Ñòðàòåãèÿ ïåðåìåùåíèÿ
/// </summary> /// </summary>
private AbstractStrategy? _strategy; private AbstractStrategy? _strategy;
public DrawningPlane SetPlane { get; internal set; } public DrawningPlane SetPlane
{
set
{
_drawningPlane = value;
_drawningPlane.SetPictureSize(pictureBoxAirPlane.Width, pictureBoxAirPlane.Height);
comboBoxStrategy.Enabled = true;
_strategy = null;
Draw();
}
}
/// <summary> /// <summary>
/// Êîíñòðóêòîð ôîðìû /// Êîíñòðóêòîð ôîðìû
@ -31,7 +40,7 @@ public partial class FormAirPlane : Form
} }
/// <summary> /// <summary>
/// Ìåòîä ïðîðèñîâêè ìàøèíû /// Ìåòîä ïðîðèñîâêè êîíòåéíåðîâîçà
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
@ -83,11 +92,11 @@ public partial class FormAirPlane : Form
} }
/// <summary> /// <summary>
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã" ///
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonStrategyStep_Click(object sender, EventArgs e) private void ButtonStrategyStep_Click(object sender, EventArgs e)
{ {
if (_drawningPlane == null) return; if (_drawningPlane == null) return;
@ -121,6 +130,4 @@ public partial class FormAirPlane : Form
_strategy = null; _strategy = null;
} }
} }
} }

View File

@ -35,7 +35,7 @@
maskedTextBox = new MaskedTextBox(); maskedTextBox = new MaskedTextBox();
buttonAddAirPlane = new Button(); buttonAddAirPlane = new Button();
buttonAddPlane = new Button(); buttonAddPlane = new Button();
comboBoxSelectionCompany = new ComboBox(); comboBoxSelectorCompany = new ComboBox();
pictureBox = new PictureBox(); pictureBox = new PictureBox();
groupBoxTools.SuspendLayout(); groupBoxTools.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit(); ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
@ -49,11 +49,11 @@
groupBoxTools.Controls.Add(maskedTextBox); groupBoxTools.Controls.Add(maskedTextBox);
groupBoxTools.Controls.Add(buttonAddAirPlane); groupBoxTools.Controls.Add(buttonAddAirPlane);
groupBoxTools.Controls.Add(buttonAddPlane); groupBoxTools.Controls.Add(buttonAddPlane);
groupBoxTools.Controls.Add(comboBoxSelectionCompany); groupBoxTools.Controls.Add(comboBoxSelectorCompany);
groupBoxTools.Dock = DockStyle.Right; groupBoxTools.Dock = DockStyle.Right;
groupBoxTools.Location = new Point(726, 0); groupBoxTools.Location = new Point(686, 0);
groupBoxTools.Name = "groupBoxTools"; groupBoxTools.Name = "groupBoxTools";
groupBoxTools.Size = new Size(205, 557); groupBoxTools.Size = new Size(195, 513);
groupBoxTools.TabIndex = 0; groupBoxTools.TabIndex = 0;
groupBoxTools.TabStop = false; groupBoxTools.TabStop = false;
groupBoxTools.Text = "Инструменты"; groupBoxTools.Text = "Инструменты";
@ -61,20 +61,20 @@
// buttonRefresh // buttonRefresh
// //
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRefresh.Location = new Point(6, 484); buttonRefresh.Location = new Point(6, 417);
buttonRefresh.Name = "buttonRefresh"; buttonRefresh.Name = "buttonRefresh";
buttonRefresh.Size = new Size(186, 50); buttonRefresh.Size = new Size(177, 35);
buttonRefresh.TabIndex = 6; buttonRefresh.TabIndex = 6;
buttonRefresh.Text = "Обновить"; buttonRefresh.Text = "Обновить";
buttonRefresh.UseVisualStyleBackColor = true; buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click; buttonRefresh.Click += ButtonRefresh_Click;
// //
// buttonGoToCheck // buttonGoToCheck
// //
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonGoToCheck.Location = new Point(6, 397); buttonGoToCheck.Location = new Point(6, 320);
buttonGoToCheck.Name = "buttonGoToCheck"; buttonGoToCheck.Name = "buttonGoToCheck";
buttonGoToCheck.Size = new Size(186, 50); buttonGoToCheck.Size = new Size(177, 35);
buttonGoToCheck.TabIndex = 5; buttonGoToCheck.TabIndex = 5;
buttonGoToCheck.Text = "Передать на тесты"; buttonGoToCheck.Text = "Передать на тесты";
buttonGoToCheck.UseVisualStyleBackColor = true; buttonGoToCheck.UseVisualStyleBackColor = true;
@ -83,29 +83,30 @@
// buttonRemovePlane // buttonRemovePlane
// //
buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonRemovePlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonRemovePlane.Location = new Point(6, 310); buttonRemovePlane.Location = new Point(7, 255);
buttonRemovePlane.Name = "buttonRemovePlane"; buttonRemovePlane.Name = "buttonRemovePlane";
buttonRemovePlane.Size = new Size(186, 50); buttonRemovePlane.Size = new Size(177, 35);
buttonRemovePlane.TabIndex = 4; buttonRemovePlane.TabIndex = 4;
buttonRemovePlane.Text = "Удалить самолёта"; buttonRemovePlane.Text = "Удалить самолёт";
buttonRemovePlane.UseVisualStyleBackColor = true; buttonRemovePlane.UseVisualStyleBackColor = true;
buttonRemovePlane.Click += ButtonRemovePlane_Click; buttonRemovePlane.Click += ButtonRemovePlane_Click;
// //
// maskedTextBox // maskedTextBox
// //
maskedTextBox.Location = new Point(6, 281); maskedTextBox.Location = new Point(7, 207);
maskedTextBox.Mask = "00"; maskedTextBox.Mask = "00";
maskedTextBox.Name = "maskedTextBox"; maskedTextBox.Name = "maskedTextBox";
maskedTextBox.Size = new Size(186, 23); maskedTextBox.Size = new Size(180, 23);
maskedTextBox.TabIndex = 3; maskedTextBox.TabIndex = 3;
maskedTextBox.ValidatingType = typeof(int); maskedTextBox.ValidatingType = typeof(int);
maskedTextBox.MaskInputRejected += MaskedTextBox_MaskInputRejected;
// //
// buttonAddAirPlane // buttonAddAirPlane
// //
buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddAirPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddAirPlane.Location = new Point(6, 143); buttonAddAirPlane.Location = new Point(7, 135);
buttonAddAirPlane.Name = "buttonAddAirPlane"; buttonAddAirPlane.Name = "buttonAddAirPlane";
buttonAddAirPlane.Size = new Size(186, 50); buttonAddAirPlane.Size = new Size(177, 47);
buttonAddAirPlane.TabIndex = 2; buttonAddAirPlane.TabIndex = 2;
buttonAddAirPlane.Text = "Добавление самолёта с радаром"; buttonAddAirPlane.Text = "Добавление самолёта с радаром";
buttonAddAirPlane.UseVisualStyleBackColor = true; buttonAddAirPlane.UseVisualStyleBackColor = true;
@ -114,31 +115,32 @@
// buttonAddPlane // buttonAddPlane
// //
buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; buttonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
buttonAddPlane.Location = new Point(6, 87); buttonAddPlane.Location = new Point(6, 80);
buttonAddPlane.Name = "buttonAddPlane"; buttonAddPlane.Name = "buttonAddPlane";
buttonAddPlane.Size = new Size(186, 50); buttonAddPlane.Size = new Size(177, 37);
buttonAddPlane.TabIndex = 1; buttonAddPlane.TabIndex = 1;
buttonAddPlane.Text = "Добавление судна"; buttonAddPlane.Text = "Добавление самолёта";
buttonAddPlane.UseVisualStyleBackColor = true; buttonAddPlane.UseVisualStyleBackColor = true;
buttonAddPlane.Click += ButtonAddPlane_Click; buttonAddPlane.Click += ButtonAddPlane_Click;
// //
// comboBoxSelectionCompany // comboBoxSelectorCompany
// //
comboBoxSelectionCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectionCompany.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectionCompany.FormattingEnabled = true; comboBoxSelectorCompany.FormattingEnabled = true;
comboBoxSelectionCompany.Items.AddRange(new object[] { "Хранилище" }); comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
comboBoxSelectionCompany.Location = new Point(6, 22); comboBoxSelectorCompany.Location = new Point(6, 22);
comboBoxSelectionCompany.Name = "comboBoxSelectionCompany"; comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectionCompany.Size = new Size(186, 23); comboBoxSelectorCompany.Size = new Size(178, 23);
comboBoxSelectionCompany.TabIndex = 0; comboBoxSelectorCompany.TabIndex = 0;
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
// //
// pictureBox // pictureBox
// //
pictureBox.Dock = DockStyle.Fill; pictureBox.Dock = DockStyle.Fill;
pictureBox.Location = new Point(0, 0); pictureBox.Location = new Point(0, 0);
pictureBox.Name = "pictureBox"; pictureBox.Name = "pictureBox";
pictureBox.Size = new Size(726, 557); pictureBox.Size = new Size(686, 513);
pictureBox.TabIndex = 1; pictureBox.TabIndex = 1;
pictureBox.TabStop = false; pictureBox.TabStop = false;
// //
@ -146,7 +148,7 @@
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(931, 557); ClientSize = new Size(881, 513);
Controls.Add(pictureBox); Controls.Add(pictureBox);
Controls.Add(groupBoxTools); Controls.Add(groupBoxTools);
Name = "FormPlaneCollection"; Name = "FormPlaneCollection";
@ -157,15 +159,10 @@
ResumeLayout(false); ResumeLayout(false);
} }
private void ButtonAddPlane_Click1(object sender, EventArgs e)
{
throw new NotImplementedException();
}
#endregion #endregion
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
private ComboBox comboBoxSelectionCompany; private ComboBox comboBoxSelectorCompany;
private Button buttonAddPlane; private Button buttonAddPlane;
private Button buttonAddAirPlane; private Button buttonAddAirPlane;
private PictureBox pictureBox; private PictureBox pictureBox;

View File

@ -23,24 +23,24 @@ public partial class FormPlaneCollection : Form
private AbstractCompany? _company = null; private AbstractCompany? _company = null;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormPlaneCollection() public FormPlaneCollection()
{ {
InitializeComponent(); InitializeComponent();
} }
/// <summary> /// <summary>
/// Выбор компании /// Выбор компании
/// </summary> /// </summary>
/// <param name="sender"></param> /// <param name="sender"></param>
/// <param name="e"></param> /// <param name="e"></param>
private void ComboBoxSelectionCompany_SelectedIndexChanged(object sender, EventArgs e) private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
{ {
switch (comboBoxSelectionCompany.Text) switch (comboBoxSelectorCompany.Text)
{ {
case "Хранилище": case "Хранилище":
_company = new PlaneSharigService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningPlane>()); _company = new PlaneSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningPlane>());
break; break;
} }
} }
@ -51,22 +51,22 @@ public partial class FormPlaneCollection : Form
/// <param name="type">Тип создаваемого объекта</param> /// <param name="type">Тип создаваемого объекта</param>
private void CreateObject(string type) private void CreateObject(string type)
{ {
DrawningPlane drawningPlane;
if (_company == null) if (_company == null)
{ {
return; return;
} }
Random random = new(); Random random = new();
DrawningPlane drawningPlane;
switch (type) switch (type)
{ {
case nameof(DrawningPlane): case nameof(DrawningPlane):
drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
break; break;
case nameof(DrawningAirPlane): case nameof(DrawningAirPlane):
// TODO вызов диалогового окна для выбора цвета
drawningPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), drawningPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), GetColor(random), GetColor(random),
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
break; break;
default: default:
@ -83,12 +83,13 @@ public partial class FormPlaneCollection : Form
MessageBox.Show("Не удалось добавить объект"); MessageBox.Show("Не удалось добавить объект");
} }
} }
/// <summary> /// <summary>
/// Получение цвета /// Получение цвета
/// </summary> /// </summary>
/// <param name="random">Генератор случайных чисел</param> /// <param name="random">Генератор случайных чисел</param>
/// <returns></returns> /// <returns></returns>
private static Color GetColor(Random random) private static Color GetColor(Random random)
{ {
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)); Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
ColorDialog dialog = new(); ColorDialog dialog = new();
@ -96,29 +97,34 @@ public partial class FormPlaneCollection : Form
{ {
color = dialog.Color; color = dialog.Color;
} }
return color; return color;
} }
private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane)); private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
private void ButtonAddAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane)); private void ButtonAddAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane));
private void MaskedTextBox_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
{
}
/// <summary>
/// Удаление объекта
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonRemovePlane_Click(object sender, EventArgs e) private void ButtonRemovePlane_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
{ {
return; return;
} }
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
{ {
return; return;
} }
int pos = Convert.ToInt32(maskedTextBox.Text); int pos = Convert.ToInt32(maskedTextBox.Text);
if (_company - pos != null) if (_company - pos != null)
{ {
@ -131,17 +137,13 @@ public partial class FormPlaneCollection : Form
} }
} }
/// <summary>
/// Передача объекта в другую форму
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonGoToCheck_Click(object sender, EventArgs e) private void ButtonGoToCheck_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)
{ {
return; return;
} }
DrawningPlane? plane = null; DrawningPlane? plane = null;
int counter = 100; int counter = 100;
while (plane == null) while (plane == null)
@ -153,10 +155,12 @@ public partial class FormPlaneCollection : Form
break; break;
} }
} }
if (plane == null) if (plane == null)
{ {
return; return;
} }
FormAirPlane form = new() FormAirPlane form = new()
{ {
SetPlane = plane SetPlane = plane
@ -164,12 +168,13 @@ public partial class FormPlaneCollection : Form
form.ShowDialog(); form.ShowDialog();
} }
private void buttonRefresh_Click(object sender, EventArgs e) private void ButtonRefresh_Click(object sender, EventArgs e)
{ {
if (_company == null) if (_company == null)
{ {
return; return;
} }
pictureBox.Image = _company.Show(); pictureBox.Image = _company.Show();
} }
} }

View File

@ -12,6 +12,7 @@ namespace ProjectAirPlane
// see https://aka.ms/applicationconfiguration. // see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize(); ApplicationConfiguration.Initialize();
Application.Run(new FormPlaneCollection()); Application.Run(new FormPlaneCollection());
} }
} }
} }