laba4
This commit is contained in:
parent
5a00ca2c70
commit
fc2676cfef
@ -1,10 +1,9 @@
|
|||||||
|
using RPP.DrawningObjects;
|
||||||
using RPP.DrawningObjects;
|
|
||||||
using RPP.MovementStrategy;
|
using RPP.MovementStrategy;
|
||||||
|
|
||||||
namespace RPP.Generics
|
namespace RPP.Generics
|
||||||
{
|
{
|
||||||
public class AirbusGenericCollection<T,U>
|
public class AirbusGenericCollection<T, U>
|
||||||
where T : DrawningAirbus
|
where T : DrawningAirbus
|
||||||
where U : IMoveableObject
|
where U : IMoveableObject
|
||||||
{
|
{
|
||||||
@ -28,31 +27,31 @@ namespace RPP.Generics
|
|||||||
_collection = new SetGeneric<T>(width * height);
|
_collection = new SetGeneric<T>(width * height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int? operator +(AirbusGenericCollection<T, U> collect, T? obj)
|
public static bool operator +(AirbusGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect?._collection.Insert(obj);
|
return (bool)collect?._collection.Insert(obj);
|
||||||
}
|
|
||||||
|
|
||||||
public static bool operator -(AirbusGenericCollection<T, U> collect, int
|
|
||||||
pos)
|
|
||||||
{
|
|
||||||
T? obj = collect._collection.Get(pos);
|
|
||||||
if (obj != null)
|
|
||||||
{
|
|
||||||
return collect._collection.Remove(pos);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static T? operator -(AirbusGenericCollection<T, U> collect, int
|
||||||
|
pos)
|
||||||
|
{
|
||||||
|
T? obj = collect._collection[pos];
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
collect._collection.Remove(pos);
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap ShowCars()
|
public Bitmap ShowCars()
|
||||||
@ -85,17 +84,15 @@ namespace RPP.Generics
|
|||||||
{
|
{
|
||||||
int width = _pictureWidth / _placeSizeWidth;
|
int width = _pictureWidth / _placeSizeWidth;
|
||||||
int height = _pictureHeight / _placeSizeHeight;
|
int height = _pictureHeight / _placeSizeHeight;
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
int i = 0;
|
||||||
|
foreach (var airbus in _collection.GetAirbus())
|
||||||
{
|
{
|
||||||
|
if (airbus != null)
|
||||||
DrawningAirbus accept = _collection.Get(i);
|
{
|
||||||
if (accept == null) {
|
airbus.SetPosition((width - 1 - (i % width)) * _placeSizeWidth + 12, (height - 1 - (i / width)) * _placeSizeHeight + 10);
|
||||||
continue;
|
airbus.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
accept.SetPosition((width - 1 - (i % width)) * _placeSizeWidth + 12, (height - 1 - (i / width)) * _placeSizeHeight + 10);
|
|
||||||
|
|
||||||
accept.DrawTransport(g);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
55
RPP/RPP/AirbusGenericStorage.cs
Normal file
55
RPP/RPP/AirbusGenericStorage.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using RPP.MovementStrategy;
|
||||||
|
using RPP.DrawningObjects;
|
||||||
|
|
||||||
|
|
||||||
|
namespace RPP.Generics
|
||||||
|
{
|
||||||
|
internal class AirbusGenericStorage
|
||||||
|
{
|
||||||
|
readonly Dictionary<string, AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>> _airbusStorages;
|
||||||
|
|
||||||
|
public List<string> Keys => _airbusStorages.Keys.ToList();
|
||||||
|
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
public AirbusGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_airbusStorages = new Dictionary<string,
|
||||||
|
AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для добавления
|
||||||
|
if (_airbusStorages.ContainsKey(name)) return;
|
||||||
|
_airbusStorages[name] = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
// TODO Прописать логику для удаления
|
||||||
|
if (!_airbusStorages.ContainsKey(name)) return;
|
||||||
|
_airbusStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>?
|
||||||
|
this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// TODO Продумать логику получения набора
|
||||||
|
if(_airbusStorages.ContainsKey(ind)) return _airbusStorages[ind];
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
134
RPP/RPP/FormAirbusCollection.Designer.cs
generated
134
RPP/RPP/FormAirbusCollection.Designer.cs
generated
@ -29,34 +29,109 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
panel1 = new Panel();
|
panel1 = new Panel();
|
||||||
|
panel2 = new Panel();
|
||||||
|
buttonDelObject = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
buttonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
label2 = new Label();
|
||||||
ButtonRefreshCollection = new Button();
|
ButtonRefreshCollection = new Button();
|
||||||
ButtonRemoveAirbus = new Button();
|
ButtonRemoveAirbus = new Button();
|
||||||
maskedTextBoxNumber = new TextBox();
|
maskedTextBoxNumber = new TextBox();
|
||||||
AddAirbusButton = new Button();
|
AddAirbusButton = new Button();
|
||||||
label = new Label();
|
label1 = new Label();
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
panel1.SuspendLayout();
|
panel1.SuspendLayout();
|
||||||
|
panel2.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// panel1
|
// panel1
|
||||||
//
|
//
|
||||||
|
panel1.Controls.Add(panel2);
|
||||||
panel1.Controls.Add(ButtonRefreshCollection);
|
panel1.Controls.Add(ButtonRefreshCollection);
|
||||||
panel1.Controls.Add(ButtonRemoveAirbus);
|
panel1.Controls.Add(ButtonRemoveAirbus);
|
||||||
panel1.Controls.Add(maskedTextBoxNumber);
|
panel1.Controls.Add(maskedTextBoxNumber);
|
||||||
panel1.Controls.Add(AddAirbusButton);
|
panel1.Controls.Add(AddAirbusButton);
|
||||||
panel1.Controls.Add(label);
|
panel1.Controls.Add(label1);
|
||||||
panel1.Dock = DockStyle.Right;
|
panel1.Dock = DockStyle.Right;
|
||||||
panel1.Location = new Point(600, 0);
|
panel1.Location = new Point(685, 0);
|
||||||
|
panel1.Margin = new Padding(3, 4, 3, 4);
|
||||||
panel1.Name = "panel1";
|
panel1.Name = "panel1";
|
||||||
panel1.Size = new Size(200, 450);
|
panel1.Size = new Size(229, 600);
|
||||||
panel1.TabIndex = 0;
|
panel1.TabIndex = 0;
|
||||||
//
|
//
|
||||||
|
// panel2
|
||||||
|
//
|
||||||
|
panel2.Controls.Add(buttonDelObject);
|
||||||
|
panel2.Controls.Add(listBoxStorages);
|
||||||
|
panel2.Controls.Add(buttonAddObject);
|
||||||
|
panel2.Controls.Add(textBoxStorageName);
|
||||||
|
panel2.Controls.Add(label2);
|
||||||
|
panel2.Location = new Point(3, 36);
|
||||||
|
panel2.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
panel2.Name = "panel2";
|
||||||
|
panel2.Size = new Size(219, 292);
|
||||||
|
panel2.TabIndex = 5;
|
||||||
|
panel2.Paint += panel2_Paint;
|
||||||
|
//
|
||||||
|
// buttonDelObject
|
||||||
|
//
|
||||||
|
buttonDelObject.Location = new Point(15, 240);
|
||||||
|
buttonDelObject.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonDelObject.Name = "buttonDelObject";
|
||||||
|
buttonDelObject.Size = new Size(197, 48);
|
||||||
|
buttonDelObject.TabIndex = 4;
|
||||||
|
buttonDelObject.Text = "Удалить набор";
|
||||||
|
buttonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelObject.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorages
|
||||||
|
//
|
||||||
|
listBoxStorages.FormattingEnabled = true;
|
||||||
|
listBoxStorages.ItemHeight = 20;
|
||||||
|
listBoxStorages.Location = new Point(15, 127);
|
||||||
|
listBoxStorages.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
|
listBoxStorages.Size = new Size(196, 104);
|
||||||
|
listBoxStorages.TabIndex = 3;
|
||||||
|
listBoxStorages.SelectedIndexChanged += ListBoxObjects_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// buttonAddObject
|
||||||
|
//
|
||||||
|
buttonAddObject.Location = new Point(15, 64);
|
||||||
|
buttonAddObject.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
buttonAddObject.Name = "buttonAddObject";
|
||||||
|
buttonAddObject.Size = new Size(197, 55);
|
||||||
|
buttonAddObject.TabIndex = 2;
|
||||||
|
buttonAddObject.Text = "Добавить набор";
|
||||||
|
buttonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(15, 25);
|
||||||
|
textBoxStorageName.Margin = new Padding(3, 4, 3, 4);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(196, 27);
|
||||||
|
textBoxStorageName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(17, 0);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(66, 20);
|
||||||
|
label2.TabIndex = 0;
|
||||||
|
label2.Text = "Наборы";
|
||||||
|
label2.Click += label2_Click;
|
||||||
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Location = new Point(5, 236);
|
ButtonRefreshCollection.Location = new Point(6, 543);
|
||||||
|
ButtonRefreshCollection.Margin = new Padding(3, 4, 3, 4);
|
||||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
ButtonRefreshCollection.Size = new Size(190, 40);
|
ButtonRefreshCollection.Size = new Size(217, 53);
|
||||||
ButtonRefreshCollection.TabIndex = 4;
|
ButtonRefreshCollection.TabIndex = 4;
|
||||||
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
ButtonRefreshCollection.Text = "Обновить коллекцию";
|
||||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
@ -64,9 +139,10 @@
|
|||||||
//
|
//
|
||||||
// ButtonRemoveAirbus
|
// ButtonRemoveAirbus
|
||||||
//
|
//
|
||||||
ButtonRemoveAirbus.Location = new Point(5, 154);
|
ButtonRemoveAirbus.Location = new Point(6, 436);
|
||||||
|
ButtonRemoveAirbus.Margin = new Padding(3, 4, 3, 4);
|
||||||
ButtonRemoveAirbus.Name = "ButtonRemoveAirbus";
|
ButtonRemoveAirbus.Name = "ButtonRemoveAirbus";
|
||||||
ButtonRemoveAirbus.Size = new Size(190, 40);
|
ButtonRemoveAirbus.Size = new Size(217, 53);
|
||||||
ButtonRemoveAirbus.TabIndex = 3;
|
ButtonRemoveAirbus.TabIndex = 3;
|
||||||
ButtonRemoveAirbus.Text = "Удалить аэробус";
|
ButtonRemoveAirbus.Text = "Удалить аэробус";
|
||||||
ButtonRemoveAirbus.UseVisualStyleBackColor = true;
|
ButtonRemoveAirbus.UseVisualStyleBackColor = true;
|
||||||
@ -74,51 +150,57 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(45, 125);
|
maskedTextBoxNumber.Location = new Point(46, 397);
|
||||||
|
maskedTextBoxNumber.Margin = new Padding(3, 4, 3, 4);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(98, 23);
|
maskedTextBoxNumber.Size = new Size(111, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 2;
|
maskedTextBoxNumber.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// AddAirbusButton
|
// AddAirbusButton
|
||||||
//
|
//
|
||||||
AddAirbusButton.Location = new Point(5, 36);
|
AddAirbusButton.Location = new Point(6, 336);
|
||||||
|
AddAirbusButton.Margin = new Padding(3, 4, 3, 4);
|
||||||
AddAirbusButton.Name = "AddAirbusButton";
|
AddAirbusButton.Name = "AddAirbusButton";
|
||||||
AddAirbusButton.Size = new Size(190, 40);
|
AddAirbusButton.Size = new Size(217, 53);
|
||||||
AddAirbusButton.TabIndex = 1;
|
AddAirbusButton.TabIndex = 1;
|
||||||
AddAirbusButton.Text = "Добавить аэробус";
|
AddAirbusButton.Text = "Добавить аэробус";
|
||||||
AddAirbusButton.UseVisualStyleBackColor = true;
|
AddAirbusButton.UseVisualStyleBackColor = true;
|
||||||
AddAirbusButton.Click += AddAirbusButton_Click;
|
AddAirbusButton.Click += AddAirbusButton_Click;
|
||||||
//
|
//
|
||||||
// label
|
// label1
|
||||||
//
|
//
|
||||||
label.AutoSize = true;
|
label1.AutoSize = true;
|
||||||
label.Location = new Point(5, 0);
|
label1.Location = new Point(6, 0);
|
||||||
label.Name = "label";
|
label1.Name = "label1";
|
||||||
label.Size = new Size(83, 15);
|
label1.Size = new Size(103, 20);
|
||||||
label.TabIndex = 0;
|
label1.TabIndex = 0;
|
||||||
label.Text = "Инструменты";
|
label1.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Dock = DockStyle.Fill;
|
pictureBoxCollection.Dock = DockStyle.Fill;
|
||||||
pictureBoxCollection.Location = new Point(0, 0);
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
|
pictureBoxCollection.Margin = new Padding(3, 4, 3, 4);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(600, 450);
|
pictureBoxCollection.Size = new Size(685, 600);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// FormAirbusCollection
|
// FormAirbusCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(914, 600);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(panel1);
|
Controls.Add(panel1);
|
||||||
|
Margin = new Padding(3, 4, 3, 4);
|
||||||
Name = "FormAirbusCollection";
|
Name = "FormAirbusCollection";
|
||||||
Text = "FormFlyAirbus";
|
Text = "FormFlyAirbus";
|
||||||
Load += FormFlyAirbus_Load;
|
Load += FormFlyAirbus_Load;
|
||||||
panel1.ResumeLayout(false);
|
panel1.ResumeLayout(false);
|
||||||
panel1.PerformLayout();
|
panel1.PerformLayout();
|
||||||
|
panel2.ResumeLayout(false);
|
||||||
|
panel2.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -127,10 +209,16 @@
|
|||||||
|
|
||||||
private Panel panel1;
|
private Panel panel1;
|
||||||
private Button AddAirbusButton;
|
private Button AddAirbusButton;
|
||||||
private Label label;
|
private Label label1;
|
||||||
private PictureBox pictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
private Button ButtonRefreshCollection;
|
private Button ButtonRefreshCollection;
|
||||||
private Button ButtonRemoveAirbus;
|
private Button ButtonRemoveAirbus;
|
||||||
private TextBox maskedTextBoxNumber;
|
private TextBox maskedTextBoxNumber;
|
||||||
|
private Panel panel2;
|
||||||
|
private Label label2;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonAddObject;
|
||||||
|
private Button buttonDelObject;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,19 +1,18 @@
|
|||||||
using RPP.DrawningObjects;
|
using RPP.DrawningObjects;
|
||||||
using RPP.MovementStrategy;
|
|
||||||
using RPP.Generics;
|
using RPP.Generics;
|
||||||
|
using RPP.MovementStrategy;
|
||||||
|
|
||||||
|
|
||||||
namespace RPP
|
namespace RPP
|
||||||
{
|
{
|
||||||
public partial class FormAirbusCollection : Form
|
public partial class FormAirbusCollection : Form
|
||||||
{
|
{
|
||||||
private readonly AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> _Airbus;
|
private readonly AirbusGenericStorage _storage;
|
||||||
|
|
||||||
public FormAirbusCollection()
|
public FormAirbusCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_Airbus = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormFlyAirbus_Load(object sender, EventArgs e)
|
private void FormFlyAirbus_Load(object sender, EventArgs e)
|
||||||
@ -23,33 +22,99 @@ namespace RPP
|
|||||||
|
|
||||||
private void AddAirbusButton_Click(object sender, EventArgs e)
|
private void AddAirbusButton_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormAirbus form = new();
|
FormAirbus form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_Airbus + form.SelectedAirbus > -1)
|
if (obj + form.SelectedAirbus)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _Airbus.ShowCars();
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorages.SelectedIndex;
|
||||||
|
listBoxStorages.Items.Clear();
|
||||||
|
foreach (var key in _storage.Keys)
|
||||||
|
{
|
||||||
|
listBoxStorages.Items.Add(key);
|
||||||
|
}
|
||||||
|
if (listBoxStorages.Items.Count > 0 && (index == -1 || index
|
||||||
|
>= listBoxStorages.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorages.Items.Count > 0 && index > -1 &&
|
||||||
|
index < listBoxStorages.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorages.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonAddObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxStorageName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не все данные заполнены", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxStorageName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
private void ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowCars();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorages.SelectedItem.ToString() ?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonRemoveAirbus_Click(object sender, EventArgs e)
|
private void ButtonRemoveAirbus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (_Airbus - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _Airbus.ShowCars();
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -59,7 +124,26 @@ namespace RPP
|
|||||||
|
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _Airbus.ShowCars();
|
if (listBoxStorages.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowCars();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void panel2_Paint(object sender, PaintEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void label2_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
<data name="Color1" type="System.Drawing.Color, System.Drawing"">Blue</data>
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -7,67 +7,81 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace RPP.Generics
|
namespace RPP.Generics
|
||||||
{
|
{
|
||||||
internal class SetGeneric<T> where T : class
|
public class SetGeneric<T> where T : class
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
private readonly int _maxCount;
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(_maxCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T airbus)
|
public bool Insert(T airbus)
|
||||||
{
|
{
|
||||||
return Insert(airbus, 0);
|
return Insert(airbus, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Insert(T airbus, int position)
|
public bool Insert(T airbus, int position)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(position < 0 && position > Count) {
|
if (position < 0 || position >= _maxCount)
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (_places[position] != null)
|
|
||||||
{
|
|
||||||
int d = 0;
|
|
||||||
for (int j = 1; j < Count - position; j++)
|
|
||||||
{
|
|
||||||
if (_places[position + j] == null)
|
|
||||||
{
|
|
||||||
d = position + j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (d == 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
for(int j = d; j > position; j--) {
|
|
||||||
_places[j] = _places[j - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_places[position] = airbus;
|
|
||||||
return position;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Remove(int position)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (position < 0 && position > Count)
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_places[position] = null;
|
if (Count >= _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.Insert(0, airbus);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? Get(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
return _places[position];
|
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (position >= Count)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_places.RemoveAt(position);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T? this[int position]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return null;
|
||||||
|
return _places[position];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (position < 0 || position > _maxCount)
|
||||||
|
return;
|
||||||
|
_places[position] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public IEnumerable<T?> GetAirbus(int? maxAirbus = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxAirbus.HasValue && i == maxAirbus.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user