полуготовая лаба4
This commit is contained in:
parent
6be2956699
commit
88833f3f18
@ -43,24 +43,22 @@ namespace AircraftCarrier.Generics
|
|||||||
return collect._collection.Insert(obj);
|
return collect._collection.Insert(obj);
|
||||||
}
|
}
|
||||||
/// Перегрузка оператора вычитания
|
/// Перегрузка оператора вычитания
|
||||||
public static T? operator -(AircraftsGenericCollection<T, U> collect, int pos)
|
public static bool operator -(AircraftsGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection[pos];
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
collect._collection.Remove(pos);
|
return collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return obj;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Получение объекта IMoveableObject
|
/// Получение объекта IMoveableObject
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection[pos]?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Вывод всего набора объектов
|
/// Вывод всего набора объектов
|
||||||
public Bitmap ShowAircraft()
|
public Bitmap ShowAircrafts()
|
||||||
{
|
{
|
||||||
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
Bitmap bmp = new(_pictureWidth, _pictureHeight);
|
||||||
Graphics gr = Graphics.FromImage(bmp);
|
Graphics gr = Graphics.FromImage(bmp);
|
||||||
@ -89,15 +87,18 @@ namespace AircraftCarrier.Generics
|
|||||||
/// Метод прорисовки объектов
|
/// Метод прорисовки объектов
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
foreach (var car in _collection.GetAircrafts())
|
int Width = _pictureWidth / _placeSizeWidth;
|
||||||
|
int Height = _pictureHeight / _placeSizeHeight;
|
||||||
|
int i = 0;
|
||||||
|
foreach (var aircraft in _collection.GetAircrafts())
|
||||||
{
|
{
|
||||||
if (car != null)
|
if (aircraft != null)
|
||||||
{
|
{
|
||||||
// TODO получение объекта
|
|
||||||
// TODO установка позиции
|
aircraft.SetPosition(i % Width * _placeSizeWidth + 3, 600);
|
||||||
// TODO прорисовка объекта
|
aircraft.DrawTransport(g);
|
||||||
car.DrawTransport(g);
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,18 @@ namespace AircraftCarrier.Generics
|
|||||||
/// Добавление набора
|
/// Добавление набора
|
||||||
public void AddSet(string name)
|
public void AddSet(string name)
|
||||||
{
|
{
|
||||||
// TODO Прописать логику для добавления
|
if (!_AircraftStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_AircraftStorages.Add(name, new AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Удаление набора
|
/// Удаление набора
|
||||||
public void DelSet(string name)
|
public void DelSet(string name)
|
||||||
{
|
{
|
||||||
// TODO Прописать логику для удаления
|
if (_AircraftStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
_AircraftStorages.Remove(name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// Доступ к набору
|
/// Доступ к набору
|
||||||
public AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>?
|
public AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>?
|
||||||
@ -43,7 +49,10 @@ namespace AircraftCarrier.Generics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO Продумать логику получения набора
|
if (_AircraftStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _AircraftStorages[ind];
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,6 @@ namespace AircraftCarrier
|
|||||||
}
|
}
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCreateAircraft_Click(object sender, EventArgs e)
|
private void ButtonCreateAircraft_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
@ -67,7 +66,6 @@ namespace AircraftCarrier
|
|||||||
100));
|
100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e)
|
private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
Random random = new();
|
Random random = new();
|
||||||
@ -90,7 +88,6 @@ namespace AircraftCarrier
|
|||||||
_drawingAircraft.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
_drawingAircraft.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||||
Draw();
|
Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonStep_Click(object sender, EventArgs e)
|
private void buttonStep_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_drawingAircraft == null)
|
if (_drawingAircraft == null)
|
||||||
|
@ -28,31 +28,31 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
PictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
PanelTools = new Panel();
|
PanelTools = new Panel();
|
||||||
|
labelTools = new Label();
|
||||||
PanelSets = new Panel();
|
PanelSets = new Panel();
|
||||||
|
ButtonRemoveObject = new Button();
|
||||||
|
listBoxStorage = new ListBox();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
labelSets = new Label();
|
||||||
ButtonRefreshCollection = new Button();
|
ButtonRefreshCollection = new Button();
|
||||||
ButtonRemoveAircraft = new Button();
|
ButtonRemoveAircraft = new Button();
|
||||||
MaskedTextBoxNumber = new MaskedTextBox();
|
MaskedTextBoxNumber = new MaskedTextBox();
|
||||||
ButtonAddAircraft = new Button();
|
ButtonAddAircraft = new Button();
|
||||||
labelTools = new Label();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
labelSets = new Label();
|
|
||||||
textBoxStorageName = new TextBox();
|
|
||||||
ButtonAddObject = new Button();
|
|
||||||
listBoxStorage = new ListBox();
|
|
||||||
ButtonRemoveObject = new Button();
|
|
||||||
((System.ComponentModel.ISupportInitialize)PictureBoxCollection).BeginInit();
|
|
||||||
PanelTools.SuspendLayout();
|
PanelTools.SuspendLayout();
|
||||||
PanelSets.SuspendLayout();
|
PanelSets.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// PictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
PictureBoxCollection.Location = new Point(0, 0);
|
pictureBoxCollection.Location = new Point(0, 0);
|
||||||
PictureBoxCollection.Name = "PictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
PictureBoxCollection.Size = new Size(768, 651);
|
pictureBoxCollection.Size = new Size(793, 724);
|
||||||
PictureBoxCollection.TabIndex = 0;
|
pictureBoxCollection.TabIndex = 0;
|
||||||
PictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
// PanelTools
|
// PanelTools
|
||||||
//
|
//
|
||||||
@ -63,11 +63,20 @@
|
|||||||
PanelTools.Controls.Add(ButtonRemoveAircraft);
|
PanelTools.Controls.Add(ButtonRemoveAircraft);
|
||||||
PanelTools.Controls.Add(MaskedTextBoxNumber);
|
PanelTools.Controls.Add(MaskedTextBoxNumber);
|
||||||
PanelTools.Controls.Add(ButtonAddAircraft);
|
PanelTools.Controls.Add(ButtonAddAircraft);
|
||||||
PanelTools.Location = new Point(774, 12);
|
PanelTools.Location = new Point(799, 12);
|
||||||
PanelTools.Name = "PanelTools";
|
PanelTools.Name = "PanelTools";
|
||||||
PanelTools.Size = new Size(232, 639);
|
PanelTools.Size = new Size(232, 712);
|
||||||
PanelTools.TabIndex = 1;
|
PanelTools.TabIndex = 1;
|
||||||
//
|
//
|
||||||
|
// labelTools
|
||||||
|
//
|
||||||
|
labelTools.AutoSize = true;
|
||||||
|
labelTools.Location = new Point(16, -4);
|
||||||
|
labelTools.Name = "labelTools";
|
||||||
|
labelTools.Size = new Size(103, 20);
|
||||||
|
labelTools.TabIndex = 5;
|
||||||
|
labelTools.Text = "Инструменты";
|
||||||
|
//
|
||||||
// PanelSets
|
// PanelSets
|
||||||
//
|
//
|
||||||
PanelSets.Controls.Add(ButtonRemoveObject);
|
PanelSets.Controls.Add(ButtonRemoveObject);
|
||||||
@ -80,6 +89,52 @@
|
|||||||
PanelSets.Size = new Size(204, 339);
|
PanelSets.Size = new Size(204, 339);
|
||||||
PanelSets.TabIndex = 4;
|
PanelSets.TabIndex = 4;
|
||||||
//
|
//
|
||||||
|
// ButtonRemoveObject
|
||||||
|
//
|
||||||
|
ButtonRemoveObject.Location = new Point(20, 286);
|
||||||
|
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
||||||
|
ButtonRemoveObject.Size = new Size(168, 41);
|
||||||
|
ButtonRemoveObject.TabIndex = 4;
|
||||||
|
ButtonRemoveObject.Text = "Удалить набор";
|
||||||
|
ButtonRemoveObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveObject.Click += ButtonRemoveObject_Click;
|
||||||
|
//
|
||||||
|
// listBoxStorage
|
||||||
|
//
|
||||||
|
listBoxStorage.FormattingEnabled = true;
|
||||||
|
listBoxStorage.ItemHeight = 20;
|
||||||
|
listBoxStorage.Location = new Point(29, 147);
|
||||||
|
listBoxStorage.Name = "listBoxStorage";
|
||||||
|
listBoxStorage.Size = new Size(150, 124);
|
||||||
|
listBoxStorage.TabIndex = 3;
|
||||||
|
listBoxStorage.SelectedIndexChanged += listBoxStorage_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Location = new Point(20, 83);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(168, 41);
|
||||||
|
ButtonAddObject.TabIndex = 2;
|
||||||
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(41, 41);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(125, 27);
|
||||||
|
textBoxStorageName.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelSets
|
||||||
|
//
|
||||||
|
labelSets.AutoSize = true;
|
||||||
|
labelSets.Location = new Point(11, 9);
|
||||||
|
labelSets.Name = "labelSets";
|
||||||
|
labelSets.Size = new Size(55, 20);
|
||||||
|
labelSets.TabIndex = 0;
|
||||||
|
labelSets.Text = "Набор";
|
||||||
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Location = new Point(36, 572);
|
ButtonRefreshCollection.Location = new Point(36, 572);
|
||||||
@ -118,68 +173,16 @@
|
|||||||
ButtonAddAircraft.UseVisualStyleBackColor = true;
|
ButtonAddAircraft.UseVisualStyleBackColor = true;
|
||||||
ButtonAddAircraft.Click += ButtonAddAircraft_Click;
|
ButtonAddAircraft.Click += ButtonAddAircraft_Click;
|
||||||
//
|
//
|
||||||
// labelTools
|
|
||||||
//
|
|
||||||
labelTools.AutoSize = true;
|
|
||||||
labelTools.Location = new Point(16, -4);
|
|
||||||
labelTools.Name = "labelTools";
|
|
||||||
labelTools.Size = new Size(103, 20);
|
|
||||||
labelTools.TabIndex = 5;
|
|
||||||
labelTools.Text = "Инструменты";
|
|
||||||
//
|
|
||||||
// labelSets
|
|
||||||
//
|
|
||||||
labelSets.AutoSize = true;
|
|
||||||
labelSets.Location = new Point(11, 9);
|
|
||||||
labelSets.Name = "labelSets";
|
|
||||||
labelSets.Size = new Size(55, 20);
|
|
||||||
labelSets.TabIndex = 0;
|
|
||||||
labelSets.Text = "Набор";
|
|
||||||
//
|
|
||||||
// textBoxStorageName
|
|
||||||
//
|
|
||||||
textBoxStorageName.Location = new Point(41, 41);
|
|
||||||
textBoxStorageName.Name = "textBoxStorageName";
|
|
||||||
textBoxStorageName.Size = new Size(125, 27);
|
|
||||||
textBoxStorageName.TabIndex = 1;
|
|
||||||
//
|
|
||||||
// ButtonAddObject
|
|
||||||
//
|
|
||||||
ButtonAddObject.Location = new Point(20, 83);
|
|
||||||
ButtonAddObject.Name = "ButtonAddObject";
|
|
||||||
ButtonAddObject.Size = new Size(168, 41);
|
|
||||||
ButtonAddObject.TabIndex = 2;
|
|
||||||
ButtonAddObject.Text = "Добавить набор";
|
|
||||||
ButtonAddObject.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// listBoxStorage
|
|
||||||
//
|
|
||||||
listBoxStorage.FormattingEnabled = true;
|
|
||||||
listBoxStorage.ItemHeight = 20;
|
|
||||||
listBoxStorage.Location = new Point(29, 147);
|
|
||||||
listBoxStorage.Name = "listBoxStorage";
|
|
||||||
listBoxStorage.Size = new Size(150, 124);
|
|
||||||
listBoxStorage.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// ButtonRemoveObject
|
|
||||||
//
|
|
||||||
ButtonRemoveObject.Location = new Point(20, 286);
|
|
||||||
ButtonRemoveObject.Name = "ButtonRemoveObject";
|
|
||||||
ButtonRemoveObject.Size = new Size(168, 41);
|
|
||||||
ButtonRemoveObject.TabIndex = 4;
|
|
||||||
ButtonRemoveObject.Text = "Удалить набор";
|
|
||||||
ButtonRemoveObject.UseVisualStyleBackColor = true;
|
|
||||||
//
|
|
||||||
// FormAircraftCollection
|
// FormAircraftCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(1007, 651);
|
ClientSize = new Size(1033, 724);
|
||||||
Controls.Add(PanelTools);
|
Controls.Add(PanelTools);
|
||||||
Controls.Add(PictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Name = "FormAircraftCollection";
|
Name = "FormAircraftCollection";
|
||||||
Text = "FormAircraftCollection";
|
Text = "FormAircraftCollection";
|
||||||
((System.ComponentModel.ISupportInitialize)PictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
PanelTools.ResumeLayout(false);
|
PanelTools.ResumeLayout(false);
|
||||||
PanelTools.PerformLayout();
|
PanelTools.PerformLayout();
|
||||||
PanelSets.ResumeLayout(false);
|
PanelSets.ResumeLayout(false);
|
||||||
@ -189,7 +192,7 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private PictureBox PictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
private Panel PanelTools;
|
private Panel PanelTools;
|
||||||
private MaskedTextBox MaskedTextBoxNumber;
|
private MaskedTextBox MaskedTextBoxNumber;
|
||||||
private Button ButtonAddAircraft;
|
private Button ButtonAddAircraft;
|
||||||
|
@ -14,40 +14,107 @@ namespace AircraftCarrier
|
|||||||
{
|
{
|
||||||
public partial class FormAircraftCollection : Form
|
public partial class FormAircraftCollection : Form
|
||||||
{
|
{
|
||||||
private readonly AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft> _Aircrafts;
|
private readonly AircraftsGenericStorage _storage;
|
||||||
public FormAircraftCollection()
|
public FormAircraftCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_Aircrafts = new AircraftsGenericCollection<DrawningAircraft, DrawningObjectAircraft>(PictureBoxCollection.Width, PictureBoxCollection.Height);
|
_storage = new AircraftsGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
|
}
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxStorage.SelectedIndex;
|
||||||
|
listBoxStorage.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxStorage.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
if (listBoxStorage.Items.Count > 0 && (index == -1 || index >= listBoxStorage.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxStorage.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
else if (listBoxStorage.Items.Count > 0 && index > -1 && index < listBoxStorage.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxStorage.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 listBoxStorage_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowAircrafts();
|
||||||
|
}
|
||||||
|
private void ButtonRemoveObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект{listBoxStorage.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxStorage.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private void ButtonAddAircraft_Click(object sender, EventArgs e)
|
private void ButtonAddAircraft_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FormAircraftCarrier form = new();
|
FormAircraftCarrier form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_Aircrafts + form.SelectedAircraft != -1)
|
if (obj + form.SelectedAircraft != -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
PictureBoxCollection.Image = _Aircrafts.ShowAircraft();
|
pictureBoxCollection.Image = obj.ShowAircrafts();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
private void ButtonRemoveAircraft_Click(object sender, EventArgs e)
|
private void ButtonRemoveAircraft_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.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 (_Aircrafts - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
PictureBoxCollection.Image = _Aircrafts.ShowAircraft();
|
pictureBoxCollection.Image = obj.ShowAircrafts();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -56,9 +123,17 @@ namespace AircraftCarrier
|
|||||||
}
|
}
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
PictureBoxCollection.Image = _Aircrafts.ShowAircraft();
|
if (listBoxStorage.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxStorage.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowAircrafts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,25 +21,25 @@ namespace AircraftCarrier.Generics
|
|||||||
_places = new List<T?>(count);
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
/// Добавление объекта в набор
|
/// Добавление объекта в набор
|
||||||
public bool Insert(T Aircraft)
|
public int Insert(T Aircraft)
|
||||||
{
|
{
|
||||||
// TODO вставка в начало набора
|
return Insert(Aircraft, 0);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
/// Добавление объекта в набор на конкретную позицию
|
/// Добавление объекта в набор на конкретную позицию
|
||||||
public bool Insert(T Aircraft, int position)
|
public int Insert(T Aircraft, int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position < 0 || position > Count || Count >= _maxCount)
|
||||||
// TODO проверка, что есть место для вставки
|
return -1;
|
||||||
// TODO вставка по позиции
|
|
||||||
_places[position] = Aircraft;
|
_places.Insert(position, Aircraft);
|
||||||
return true;
|
return position;
|
||||||
}
|
}
|
||||||
/// Удаление объекта из набора с конкретной позиции
|
/// Удаление объекта из набора с конкретной позиции
|
||||||
public bool Remove(int position)
|
public bool Remove(int position)
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position < 0 || position >= Count)
|
||||||
// TODO удаление объекта из списка
|
return false;
|
||||||
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// Получение объекта из набора по позиции
|
/// Получение объекта из набора по позиции
|
||||||
@ -47,14 +47,16 @@ namespace AircraftCarrier.Generics
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position < 0 || position >= Count)
|
||||||
|
return null;
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
// TODO проверка позиции
|
if (position < 0 || position > Count || Count >= _maxCount)
|
||||||
// TODO проверка свободных мест в списке
|
return;
|
||||||
// TODO вставка в список по позиции
|
|
||||||
|
_places.Insert(position, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Проход по списку
|
/// Проход по списку
|
||||||
|
Loading…
Reference in New Issue
Block a user