лаб 4
This commit is contained in:
parent
eca2e72650
commit
d745ee3256
187
Airbus/FormAirbusCollection.Designer.cs
generated
187
Airbus/FormAirbusCollection.Designer.cs
generated
@ -28,88 +28,152 @@
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
buttonAdd=new Button();
|
||||
pictureBoxCollection=new PictureBox();
|
||||
labelInstruments=new Label();
|
||||
buttonUpdate=new Button();
|
||||
buttonDelete=new Button();
|
||||
colorDialog=new ColorDialog();
|
||||
maskedTextBoxNumber=new MaskedTextBox();
|
||||
buttonAddAirbus = new Button();
|
||||
pictureBoxCollection = new PictureBox();
|
||||
labelInstruments = new Label();
|
||||
buttonUpdate = new Button();
|
||||
buttonDeleteAirbus = new Button();
|
||||
colorDialog = new ColorDialog();
|
||||
maskedTextBoxNumber = new MaskedTextBox();
|
||||
label1 = new Label();
|
||||
listBoxStorages = new ListBox();
|
||||
buttonAddStorage = new Button();
|
||||
buttonDeleteStorage = new Button();
|
||||
textBoxStorageName = new TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// buttonAdd
|
||||
// buttonAddAirbus
|
||||
//
|
||||
buttonAdd.Anchor=AnchorStyles.Top|AnchorStyles.Right;
|
||||
buttonAdd.Location=new Point(457, 34);
|
||||
buttonAdd.Name="buttonAdd";
|
||||
buttonAdd.Size=new Size(137, 28);
|
||||
buttonAdd.TabIndex=0;
|
||||
buttonAdd.Text="Добавить самолёт";
|
||||
buttonAdd.UseVisualStyleBackColor=true;
|
||||
buttonAdd.Click+=buttonAdd_Click;
|
||||
buttonAddAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonAddAirbus.Location = new Point(572, 332);
|
||||
buttonAddAirbus.Name = "buttonAddAirbus";
|
||||
buttonAddAirbus.Size = new Size(137, 28);
|
||||
buttonAddAirbus.TabIndex = 0;
|
||||
buttonAddAirbus.Text = "Добавить самолёт";
|
||||
buttonAddAirbus.UseVisualStyleBackColor = true;
|
||||
buttonAddAirbus.Click += buttonAddAirbus_Click;
|
||||
//
|
||||
// pictureBoxCollection
|
||||
//
|
||||
pictureBoxCollection.Location=new Point(0, 0);
|
||||
pictureBoxCollection.Name="pictureBoxCollection";
|
||||
pictureBoxCollection.Size=new Size(424, 453);
|
||||
pictureBoxCollection.TabIndex=1;
|
||||
pictureBoxCollection.TabStop=false;
|
||||
pictureBoxCollection.Location = new Point(0, 0);
|
||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||
pictureBoxCollection.Size = new Size(552, 436);
|
||||
pictureBoxCollection.TabIndex = 1;
|
||||
pictureBoxCollection.TabStop = false;
|
||||
//
|
||||
// labelInstruments
|
||||
//
|
||||
labelInstruments.Anchor=AnchorStyles.Top|AnchorStyles.Right;
|
||||
labelInstruments.AutoSize=true;
|
||||
labelInstruments.Location=new Point(449, 9);
|
||||
labelInstruments.Name="labelInstruments";
|
||||
labelInstruments.Size=new Size(83, 15);
|
||||
labelInstruments.TabIndex=2;
|
||||
labelInstruments.Text="Инструменты";
|
||||
labelInstruments.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
labelInstruments.AutoSize = true;
|
||||
labelInstruments.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point);
|
||||
labelInstruments.Location = new Point(580, 0);
|
||||
labelInstruments.Name = "labelInstruments";
|
||||
labelInstruments.Size = new Size(108, 21);
|
||||
labelInstruments.TabIndex = 2;
|
||||
labelInstruments.Text = "Инструменты";
|
||||
//
|
||||
// buttonUpdate
|
||||
//
|
||||
buttonUpdate.Anchor=AnchorStyles.Top|AnchorStyles.Right;
|
||||
buttonUpdate.Location=new Point(457, 212);
|
||||
buttonUpdate.Name="buttonUpdate";
|
||||
buttonUpdate.Size=new Size(137, 28);
|
||||
buttonUpdate.TabIndex=3;
|
||||
buttonUpdate.Text="Обновить коллекцию";
|
||||
buttonUpdate.UseVisualStyleBackColor=true;
|
||||
buttonUpdate.Click+=buttonUpdate_Click;
|
||||
buttonUpdate.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonUpdate.Location = new Point(572, 130);
|
||||
buttonUpdate.Name = "buttonUpdate";
|
||||
buttonUpdate.Size = new Size(131, 25);
|
||||
buttonUpdate.TabIndex = 3;
|
||||
buttonUpdate.Text = "Обновить набор";
|
||||
buttonUpdate.UseVisualStyleBackColor = true;
|
||||
buttonUpdate.Click += buttonUpdate_Click;
|
||||
//
|
||||
// buttonDelete
|
||||
// buttonDeleteAirbus
|
||||
//
|
||||
buttonDelete.Anchor=AnchorStyles.Top|AnchorStyles.Right;
|
||||
buttonDelete.Location=new Point(457, 140);
|
||||
buttonDelete.Name="buttonDelete";
|
||||
buttonDelete.Size=new Size(137, 28);
|
||||
buttonDelete.TabIndex=4;
|
||||
buttonDelete.Text="Удалить самолёт";
|
||||
buttonDelete.UseVisualStyleBackColor=true;
|
||||
buttonDelete.Click+=buttonDelete_Click;
|
||||
buttonDeleteAirbus.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
buttonDeleteAirbus.Location = new Point(572, 392);
|
||||
buttonDeleteAirbus.Name = "buttonDeleteAirbus";
|
||||
buttonDeleteAirbus.Size = new Size(137, 28);
|
||||
buttonDeleteAirbus.TabIndex = 4;
|
||||
buttonDeleteAirbus.Text = "Удалить самолёт";
|
||||
buttonDeleteAirbus.UseVisualStyleBackColor = true;
|
||||
buttonDeleteAirbus.Click += buttonDeleteAirbus_Click;
|
||||
//
|
||||
// maskedTextBoxNumber
|
||||
//
|
||||
maskedTextBoxNumber.Anchor=AnchorStyles.Top|AnchorStyles.Right;
|
||||
maskedTextBoxNumber.Location=new Point(457, 111);
|
||||
maskedTextBoxNumber.Name="maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size=new Size(100, 23);
|
||||
maskedTextBoxNumber.TabIndex=5;
|
||||
maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
maskedTextBoxNumber.Location = new Point(572, 365);
|
||||
maskedTextBoxNumber.Mask = "00";
|
||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||
maskedTextBoxNumber.Size = new Size(138, 23);
|
||||
maskedTextBoxNumber.TabIndex = 5;
|
||||
maskedTextBoxNumber.ValidatingType = typeof(int);
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(572, 38);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(52, 15);
|
||||
label1.TabIndex = 7;
|
||||
label1.Text = "Наборы";
|
||||
//
|
||||
// listBoxStorages
|
||||
//
|
||||
listBoxStorages.FormattingEnabled = true;
|
||||
listBoxStorages.ItemHeight = 15;
|
||||
listBoxStorages.Location = new Point(572, 160);
|
||||
listBoxStorages.Margin = new Padding(3, 2, 3, 2);
|
||||
listBoxStorages.Name = "listBoxStorages";
|
||||
listBoxStorages.Size = new Size(132, 109);
|
||||
listBoxStorages.TabIndex = 8;
|
||||
listBoxStorages.SelectedIndexChanged += listBoxObjects_SelectedIndexChanged;
|
||||
//
|
||||
// buttonAddStorage
|
||||
//
|
||||
buttonAddStorage.Location = new Point(572, 102);
|
||||
buttonAddStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonAddStorage.Name = "buttonAddStorage";
|
||||
buttonAddStorage.Size = new Size(131, 25);
|
||||
buttonAddStorage.TabIndex = 9;
|
||||
buttonAddStorage.Text = "Добавить набор";
|
||||
buttonAddStorage.UseVisualStyleBackColor = true;
|
||||
buttonAddStorage.Click += buttonAddStorage_Click;
|
||||
//
|
||||
// buttonDeleteStorage
|
||||
//
|
||||
buttonDeleteStorage.Location = new Point(572, 273);
|
||||
buttonDeleteStorage.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonDeleteStorage.Name = "buttonDeleteStorage";
|
||||
buttonDeleteStorage.Size = new Size(131, 25);
|
||||
buttonDeleteStorage.TabIndex = 10;
|
||||
buttonDeleteStorage.Text = "Удалить набор";
|
||||
buttonDeleteStorage.UseVisualStyleBackColor = true;
|
||||
buttonDeleteStorage.Click += buttonDeleteStorage_Click;
|
||||
//
|
||||
// textBoxStorageName
|
||||
//
|
||||
textBoxStorageName.Location = new Point(572, 77);
|
||||
textBoxStorageName.Margin = new Padding(3, 2, 3, 2);
|
||||
textBoxStorageName.Name = "textBoxStorageName";
|
||||
textBoxStorageName.Size = new Size(132, 23);
|
||||
textBoxStorageName.TabIndex = 11;
|
||||
//
|
||||
// FormAirbusCollection
|
||||
//
|
||||
AutoScaleDimensions=new SizeF(7F, 15F);
|
||||
AutoScaleMode=AutoScaleMode.Font;
|
||||
ClientSize=new Size(607, 455);
|
||||
Controls.Add(buttonAdd);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(724, 443);
|
||||
Controls.Add(textBoxStorageName);
|
||||
Controls.Add(buttonDeleteStorage);
|
||||
Controls.Add(buttonAddStorage);
|
||||
Controls.Add(listBoxStorages);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonAddAirbus);
|
||||
Controls.Add(maskedTextBoxNumber);
|
||||
Controls.Add(buttonDelete);
|
||||
Controls.Add(buttonDeleteAirbus);
|
||||
Controls.Add(buttonUpdate);
|
||||
Controls.Add(labelInstruments);
|
||||
Controls.Add(pictureBoxCollection);
|
||||
Name="FormAirbusCollection";
|
||||
Text="Набор самолётов";
|
||||
Name = "FormAirbusCollection";
|
||||
Text = "Набор самолётов";
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
@ -117,12 +181,17 @@
|
||||
|
||||
#endregion
|
||||
|
||||
private Button buttonAdd;
|
||||
private Button buttonAddAirbus;
|
||||
private PictureBox pictureBoxCollection;
|
||||
private Label labelInstruments;
|
||||
private Button buttonUpdate;
|
||||
private Button buttonDelete;
|
||||
private Button buttonDeleteAirbus;
|
||||
private ColorDialog colorDialog;
|
||||
private MaskedTextBox maskedTextBoxNumber;
|
||||
private Label label1;
|
||||
private ListBox listBoxStorages;
|
||||
private Button buttonAddStorage;
|
||||
private Button buttonDeleteStorage;
|
||||
private TextBox textBoxStorageName;
|
||||
}
|
||||
}
|
@ -16,24 +16,86 @@ namespace ProjectAirbus
|
||||
public partial class FormAirbusCollection : Form
|
||||
{
|
||||
// Набор объектов
|
||||
private readonly AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus> _airbus;
|
||||
private readonly AirbusGenericStorage _storage;
|
||||
|
||||
public FormAirbusCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
_airbus = new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
_storage = new AirbusGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||
}
|
||||
|
||||
// добавить в набор
|
||||
private void buttonAdd_Click(object sender, EventArgs e)
|
||||
// заполнение лист бокс
|
||||
private void ReloadObjects()
|
||||
{
|
||||
int index = listBoxStorages.SelectedIndex;
|
||||
listBoxStorages.Items.Clear();
|
||||
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||
{
|
||||
listBoxStorages.Items.Add(_storage.Keys[i]);
|
||||
}
|
||||
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 buttonAddStorage_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]?.ShowAirbus();
|
||||
}
|
||||
|
||||
// удалить набор
|
||||
private void buttonDeleteStorage_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 buttonAddAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
MessageBox.Show("Не выбран набор");
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormPlane form = new();
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (_airbus + form.SelectedAirbus != -1)
|
||||
if (obj + form.SelectedAirbus != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = _airbus.ShowAirbus();
|
||||
pictureBoxCollection.Image = obj.ShowAirbus();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -42,9 +104,18 @@ namespace ProjectAirbus
|
||||
}
|
||||
}
|
||||
|
||||
// удалить
|
||||
private void buttonDelete_Click(object sender, EventArgs e)
|
||||
// удалить самолёт
|
||||
private void buttonDeleteAirbus_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
@ -56,13 +127,13 @@ namespace ProjectAirbus
|
||||
}
|
||||
catch
|
||||
{
|
||||
MessageBox.Show("Ошибка ввода данных");
|
||||
MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (_airbus - pos)
|
||||
if (obj - pos)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBoxCollection.Image = _airbus.ShowAirbus();
|
||||
pictureBoxCollection.Image = obj.ShowAirbus();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -70,10 +141,19 @@ namespace ProjectAirbus
|
||||
}
|
||||
}
|
||||
|
||||
// обновить
|
||||
// обновить рисунок по набору
|
||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
pictureBoxCollection.Image = _airbus.ShowAirbus();
|
||||
if (listBoxStorages.SelectedIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||
if (obj == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
pictureBoxCollection.Image = obj.ShowAirbus();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, 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="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
@ -61,6 +121,6 @@
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>79</value>
|
||||
<value>36</value>
|
||||
</metadata>
|
||||
</root>
|
@ -39,7 +39,7 @@ namespace ProjectAirbus.Generics
|
||||
}
|
||||
public static bool operator -(AirbusGenericCollection<T, U> collect, int pos)
|
||||
{
|
||||
if (collect._collection.Get(pos) == null)
|
||||
if (collect._collection.GetAirbus(pos) == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -49,7 +49,7 @@ namespace ProjectAirbus.Generics
|
||||
// получение объекта IMoveableObjecr
|
||||
public U? GetU(int pos)
|
||||
{
|
||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
||||
return (U?)_collection[pos]?.GetMoveableObject;
|
||||
}
|
||||
|
||||
// вывод всего набора
|
||||
@ -81,30 +81,21 @@ namespace ProjectAirbus.Generics
|
||||
private void DrawObjects(Graphics g)
|
||||
{
|
||||
// координаты
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int x = _pictureWidth / _placeSizeWidth - 1;
|
||||
int y = _pictureHeight / _placeSizeHeight - 1;
|
||||
|
||||
for (int i = 0; i <= _collection.Count; ++i)
|
||||
foreach (var airbus in _collection.GetAirbus())
|
||||
{
|
||||
DrawningAirbus _airbus = _collection.Get(i);
|
||||
if (_airbus == null)
|
||||
if (airbus != null)
|
||||
{
|
||||
++x;
|
||||
if (x >= _pictureWidth / _placeSizeWidth)
|
||||
if (x < 0)
|
||||
{
|
||||
x = 0;
|
||||
++y;
|
||||
x = _pictureWidth / _placeSizeWidth - 1;
|
||||
--y;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
_airbus.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
||||
_airbus.DrawTransport(g);
|
||||
++x;
|
||||
// новая строка
|
||||
if (x >= _pictureWidth / _placeSizeWidth)
|
||||
{
|
||||
x = 0;
|
||||
++y;
|
||||
airbus.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
|
||||
airbus.DrawTransport(g);
|
||||
--x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
72
Airbus/Generics/AirbusGenericStorage.cs
Normal file
72
Airbus/Generics/AirbusGenericStorage.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using ProjectAirbus.Drawnings;
|
||||
using ProjectAirbus.MovementStrategy;
|
||||
|
||||
namespace ProjectAirbus.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 Прописать логику для добавления
|
||||
// проверка, что нет набора с таким именем
|
||||
foreach (string nameStorage in Keys)
|
||||
{
|
||||
if (nameStorage == name)
|
||||
{
|
||||
MessageBox.Show("Набор с заданным именем уже существует", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_airbusStorages.Add(name, new AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
|
||||
// Удаление набора
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
if ( _airbusStorages.ContainsKey(name))
|
||||
{
|
||||
_airbusStorages.Remove(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Доступ к набору
|
||||
public AirbusGenericCollection<DrawningAirbus, DrawningObjectAirbus>? this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
if (_airbusStorages.ContainsKey(ind))
|
||||
{
|
||||
return _airbusStorages[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -9,97 +9,89 @@ namespace ProjectAirbus.Generics
|
||||
internal class SetGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
// список объекторв
|
||||
private readonly T?[] _places;
|
||||
// список объектов
|
||||
private readonly List<T?> _places;
|
||||
// кол-во объектов
|
||||
public int Count => _places.Length - 1;
|
||||
public int Count => _places.Count;
|
||||
// максимальное количество
|
||||
private readonly int _maxCount;
|
||||
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_places = new T?[count];
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(count);
|
||||
}
|
||||
|
||||
// Добавление объекта в набор
|
||||
// Добавление объекта в начало набора
|
||||
public int Insert(T airbus)
|
||||
{
|
||||
// проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
int pos = Count - 1;
|
||||
if (_places[Count] != null)
|
||||
if (_places.Count >= _maxCount)
|
||||
{
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
for (int i = pos; i > 0; --i)
|
||||
{
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// сдвиг всех объектов, находящихся слева от позиции до первого пустого элемента
|
||||
for (int i = pos + 1; i <= Count; ++i)
|
||||
{
|
||||
_places[i - 1] = _places[i];
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
_places[Count] = airbus;
|
||||
return pos;
|
||||
|
||||
_places.Insert(0, airbus);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Добавление объекта в набор на конкретную позицию
|
||||
public bool Insert(T airbus, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position < 0 || position > Count)
|
||||
if (Count >= _maxCount || position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
if (_places[Count] != null)
|
||||
{
|
||||
// проверка, что после вставляемого элемента в массиве есть пустой элемент
|
||||
int pos = Count;
|
||||
for (int i = Count; i > 0; --i)
|
||||
{
|
||||
|
||||
if (_places[i] == null)
|
||||
{
|
||||
pos = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// сдвиг всех объектов, находящихся слева от позиции до первого пустого элемента
|
||||
for (int i = Count; i >= pos; --i)
|
||||
{
|
||||
_places[i - 1] = _places[i];
|
||||
}
|
||||
}
|
||||
_places[Count] = airbus;
|
||||
_places.Insert(position, airbus);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Удаление объекта из набора с конкретной позиции
|
||||
public bool Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position < 0 || position > Count)
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// удалить объект из массива, присвоив элементу массива значение null
|
||||
_places[position] = null;
|
||||
_places.RemoveAt(position);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Получение объекта из набора по позиции
|
||||
public T? Get(int position)
|
||||
public T? this[int position]
|
||||
{
|
||||
// проверка позиции
|
||||
if (position < 0 || position > Count)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
if (position < 0 || position >= Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (position < 0 || Count >= _maxCount)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_places.Insert(position, value);
|
||||
}
|
||||
return _places[position];
|
||||
}
|
||||
|
||||
// Проход по списку
|
||||
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…
Reference in New Issue
Block a user