lab 4 complete

This commit is contained in:
NikGapon 2022-12-07 21:26:37 +04:00
parent f3fb6e9fec
commit 9ccb83c58d
7 changed files with 62 additions and 6 deletions

View File

@ -133,4 +133,4 @@ namespace Airbus
} }
} }
} }

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Airbus namespace Airbus
{ {
internal class DrawningObjectAirplane : IDrawningObject public class DrawningObjectAirplane : IDrawningObject
{ {
private DrawningAirplane _airplane = null; private DrawningAirplane _airplane = null;
@ -31,5 +31,6 @@ namespace Airbus
{ {
_airplane?.SetPosition(x, y, width, height); _airplane?.SetPosition(x, y, width, height);
} }
public static explicit operator DrawningAirplane(DrawningObjectAirplane drawningObject) => drawningObject._airplane;
} }
} }

View File

@ -16,9 +16,15 @@ namespace Airbus
private DrawningAirplane airplane; private DrawningAirplane airplane;
public DrawningAirplane SelectedAirplane { get; private set; } public DrawningAirplane SelectedAirplane { get; private set; }
public FormAirplane() public FormAirplane(DrawningAirplane? goairplane = null)
{ {
airplane = goairplane;
InitializeComponent(); InitializeComponent();
if (goairplane != null)
{
SetData();
Draw();
}
} }
private void Draw() private void Draw()

View File

@ -46,6 +46,7 @@
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAirplane = new System.Windows.Forms.Button(); this.buttonAddAirplane = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox(); this.pictureBox = new System.Windows.Forms.PictureBox();
this.buttonRemoveFromTrashcan = new System.Windows.Forms.Button();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout(); this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
@ -53,6 +54,7 @@
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.buttonRemoveFromTrashcan);
this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.buttonAddAirplaneWithPar); this.groupBoxTools.Controls.Add(this.buttonAddAirplaneWithPar);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
@ -195,7 +197,7 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(62, 370); this.buttonShowOnMap.Location = new System.Drawing.Point(60, 399);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(75, 23); this.buttonShowOnMap.Size = new System.Drawing.Size(75, 23);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
@ -205,7 +207,7 @@
// //
// buttonStorage // buttonStorage
// //
this.buttonStorage.Location = new System.Drawing.Point(6, 399); this.buttonStorage.Location = new System.Drawing.Point(6, 428);
this.buttonStorage.Name = "buttonStorage"; this.buttonStorage.Name = "buttonStorage";
this.buttonStorage.Size = new System.Drawing.Size(188, 23); this.buttonStorage.Size = new System.Drawing.Size(188, 23);
this.buttonStorage.TabIndex = 4; this.buttonStorage.TabIndex = 4;
@ -250,6 +252,16 @@
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
// buttonRemoveFromTrashcan
//
this.buttonRemoveFromTrashcan.Location = new System.Drawing.Point(6, 370);
this.buttonRemoveFromTrashcan.Name = "buttonRemoveFromTrashcan";
this.buttonRemoveFromTrashcan.Size = new System.Drawing.Size(182, 23);
this.buttonRemoveFromTrashcan.TabIndex = 11;
this.buttonRemoveFromTrashcan.Text = "Вернуть с корзины";
this.buttonRemoveFromTrashcan.UseVisualStyleBackColor = true;
this.buttonRemoveFromTrashcan.Click += new System.EventHandler(this.buttonRemoveFromTrashcan_Click);
//
// FormMapWithSetAirplane // FormMapWithSetAirplane
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -286,5 +298,6 @@
private Button buttonDelMap; private Button buttonDelMap;
private Button buttonAddMap; private Button buttonAddMap;
private TextBox textBoxNewMapName; private TextBox textBoxNewMapName;
private Button buttonRemoveFromTrashcan;
} }
} }

View File

@ -22,6 +22,7 @@ namespace Airbus
/// Объект от коллекции карт /// Объект от коллекции карт
/// </summary> /// </summary>
private readonly MapsCollection _mapsCollection; private readonly MapsCollection _mapsCollection;
private LinkedList<DrawningObjectAirplane> trashcan;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
@ -30,6 +31,7 @@ namespace Airbus
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height); _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear(); comboBoxSelectorMap.Items.Clear();
trashcan = new();
foreach (var elem in _mapsDict) foreach (var elem in _mapsDict)
{ {
comboBoxSelectorMap.Items.Add(elem.Key); comboBoxSelectorMap.Items.Add(elem.Key);
@ -144,8 +146,11 @@ namespace Airbus
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
var delObject = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty, pos];
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
trashcan.AddLast(delObject);
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
@ -233,5 +238,28 @@ namespace Airbus
} }
} }
} }
private void buttonRemoveFromTrashcan_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1 || trashcan.Count == 0)
{
return;
}
FormAirplane form = new((DrawningAirplane)trashcan.First());
trashcan.RemoveFirst();
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectAirplane airplane = new(form.SelectedAirplane);
if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane > -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
MessageBox.Show("Не удалось добавить объект");
}
}
}
} }
} }

View File

@ -29,7 +29,7 @@ namespace Airbus
/// <summary> /// <summary>
/// Набор объектов /// Набор объектов
/// </summary> /// </summary>
private readonly SetAirplaneGeneric<T> _setAirplane; public SetAirplaneGeneric<T> _setAirplane { get; private set; }
/// <summary> /// <summary>
/// Карта /// Карта
/// </summary> /// </summary>

View File

@ -67,5 +67,13 @@ namespace Airbus
return null; return null;
} }
} }
public DrawningObjectAirplane this[string ind, int indDrawningObject]
{
get
{
_mapStorages.TryGetValue(ind, out var returnAirplane);
return returnAirplane?._setAirplane[indDrawningObject];
}
}
} }
} }