export
This commit is contained in:
parent
34ea93003f
commit
2dbfb4694f
@ -28,32 +28,98 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
toolsLabel = new Panel();
|
toolsPanel = new Panel();
|
||||||
|
panelSets = new Panel();
|
||||||
|
textBoxStorageName = new TextBox();
|
||||||
|
listBoxObjects = new ListBox();
|
||||||
|
ButtonAddObject = new Button();
|
||||||
|
ButtonDelObject = new Button();
|
||||||
|
SetsLabel = new Label();
|
||||||
ButtonRefreshCollection = new Button();
|
ButtonRefreshCollection = new Button();
|
||||||
ButtonDeleteBus = new Button();
|
ButtonDeleteBus = new Button();
|
||||||
maskedTextBoxNumber = new TextBox();
|
maskedTextBoxNumber = new TextBox();
|
||||||
addBus = new Button();
|
ButtonAddBus = new Button();
|
||||||
label1 = new Label();
|
LabelTools = new Label();
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
toolsLabel.SuspendLayout();
|
toolsPanel.SuspendLayout();
|
||||||
|
panelSets.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// toolsLabel
|
// toolsPanel
|
||||||
//
|
//
|
||||||
toolsLabel.Controls.Add(ButtonRefreshCollection);
|
toolsPanel.Controls.Add(panelSets);
|
||||||
toolsLabel.Controls.Add(ButtonDeleteBus);
|
toolsPanel.Controls.Add(ButtonRefreshCollection);
|
||||||
toolsLabel.Controls.Add(maskedTextBoxNumber);
|
toolsPanel.Controls.Add(ButtonDeleteBus);
|
||||||
toolsLabel.Controls.Add(addBus);
|
toolsPanel.Controls.Add(maskedTextBoxNumber);
|
||||||
toolsLabel.Controls.Add(label1);
|
toolsPanel.Controls.Add(ButtonAddBus);
|
||||||
toolsLabel.Location = new Point(678, -2);
|
toolsPanel.Controls.Add(LabelTools);
|
||||||
toolsLabel.Name = "toolsLabel";
|
toolsPanel.Location = new Point(662, -2);
|
||||||
toolsLabel.Size = new Size(221, 451);
|
toolsPanel.Name = "toolsPanel";
|
||||||
toolsLabel.TabIndex = 0;
|
toolsPanel.Size = new Size(221, 504);
|
||||||
|
toolsPanel.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// panelSets
|
||||||
|
//
|
||||||
|
panelSets.Controls.Add(textBoxStorageName);
|
||||||
|
panelSets.Controls.Add(listBoxObjects);
|
||||||
|
panelSets.Controls.Add(ButtonAddObject);
|
||||||
|
panelSets.Controls.Add(ButtonDelObject);
|
||||||
|
panelSets.Controls.Add(SetsLabel);
|
||||||
|
panelSets.Location = new Point(8, 20);
|
||||||
|
panelSets.Name = "panelSets";
|
||||||
|
panelSets.Size = new Size(210, 208);
|
||||||
|
panelSets.TabIndex = 6;
|
||||||
|
//
|
||||||
|
// textBoxStorageName
|
||||||
|
//
|
||||||
|
textBoxStorageName.Location = new Point(10, 27);
|
||||||
|
textBoxStorageName.Name = "textBoxStorageName";
|
||||||
|
textBoxStorageName.Size = new Size(190, 27);
|
||||||
|
textBoxStorageName.TabIndex = 12;
|
||||||
|
//
|
||||||
|
// listBoxObjects
|
||||||
|
//
|
||||||
|
listBoxObjects.FormattingEnabled = true;
|
||||||
|
listBoxObjects.ItemHeight = 20;
|
||||||
|
listBoxObjects.Location = new Point(10, 99);
|
||||||
|
listBoxObjects.Name = "listBoxObjects";
|
||||||
|
listBoxObjects.Size = new Size(190, 64);
|
||||||
|
listBoxObjects.TabIndex = 11;
|
||||||
|
listBoxObjects.SelectedIndexChanged += listBoxObjects_SelectedIndexChanged;
|
||||||
|
//
|
||||||
|
// ButtonAddObject
|
||||||
|
//
|
||||||
|
ButtonAddObject.Location = new Point(10, 60);
|
||||||
|
ButtonAddObject.Name = "ButtonAddObject";
|
||||||
|
ButtonAddObject.Size = new Size(191, 33);
|
||||||
|
ButtonAddObject.TabIndex = 8;
|
||||||
|
ButtonAddObject.Text = "Добавить набор";
|
||||||
|
ButtonAddObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddObject.Click += ButtonAddObject_Click;
|
||||||
|
//
|
||||||
|
// ButtonDelObject
|
||||||
|
//
|
||||||
|
ButtonDelObject.Location = new Point(10, 169);
|
||||||
|
ButtonDelObject.Name = "ButtonDelObject";
|
||||||
|
ButtonDelObject.Size = new Size(192, 33);
|
||||||
|
ButtonDelObject.TabIndex = 7;
|
||||||
|
ButtonDelObject.Text = "Удалить набор\r\n";
|
||||||
|
ButtonDelObject.UseVisualStyleBackColor = true;
|
||||||
|
ButtonDelObject.Click += ButtonDelObject_Click;
|
||||||
|
//
|
||||||
|
// SetsLabel
|
||||||
|
//
|
||||||
|
SetsLabel.AutoSize = true;
|
||||||
|
SetsLabel.Location = new Point(3, 4);
|
||||||
|
SetsLabel.Name = "SetsLabel";
|
||||||
|
SetsLabel.Size = new Size(66, 20);
|
||||||
|
SetsLabel.TabIndex = 0;
|
||||||
|
SetsLabel.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// ButtonRefreshCollection
|
// ButtonRefreshCollection
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Location = new Point(10, 194);
|
ButtonRefreshCollection.Location = new Point(8, 452);
|
||||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
ButtonRefreshCollection.Size = new Size(197, 41);
|
ButtonRefreshCollection.Size = new Size(197, 41);
|
||||||
ButtonRefreshCollection.TabIndex = 4;
|
ButtonRefreshCollection.TabIndex = 4;
|
||||||
@ -63,7 +129,7 @@
|
|||||||
//
|
//
|
||||||
// ButtonDeleteBus
|
// ButtonDeleteBus
|
||||||
//
|
//
|
||||||
ButtonDeleteBus.Location = new Point(10, 121);
|
ButtonDeleteBus.Location = new Point(8, 379);
|
||||||
ButtonDeleteBus.Name = "ButtonDeleteBus";
|
ButtonDeleteBus.Name = "ButtonDeleteBus";
|
||||||
ButtonDeleteBus.Size = new Size(197, 41);
|
ButtonDeleteBus.Size = new Size(197, 41);
|
||||||
ButtonDeleteBus.TabIndex = 3;
|
ButtonDeleteBus.TabIndex = 3;
|
||||||
@ -73,35 +139,35 @@
|
|||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// maskedTextBoxNumber
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(50, 88);
|
maskedTextBoxNumber.Location = new Point(48, 346);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
maskedTextBoxNumber.Size = new Size(125, 27);
|
maskedTextBoxNumber.Size = new Size(125, 27);
|
||||||
maskedTextBoxNumber.TabIndex = 2;
|
maskedTextBoxNumber.TabIndex = 2;
|
||||||
//
|
//
|
||||||
// addBus
|
// ButtonAddBus
|
||||||
//
|
//
|
||||||
addBus.Location = new Point(10, 26);
|
ButtonAddBus.Location = new Point(8, 284);
|
||||||
addBus.Name = "addBus";
|
ButtonAddBus.Name = "ButtonAddBus";
|
||||||
addBus.Size = new Size(197, 41);
|
ButtonAddBus.Size = new Size(197, 41);
|
||||||
addBus.TabIndex = 1;
|
ButtonAddBus.TabIndex = 1;
|
||||||
addBus.Text = "Добавить автобус";
|
ButtonAddBus.Text = "Добавить автобус";
|
||||||
addBus.UseVisualStyleBackColor = true;
|
ButtonAddBus.UseVisualStyleBackColor = true;
|
||||||
addBus.Click += ButtonAddBus_Click;
|
ButtonAddBus.Click += ButtonAddBus_Click;
|
||||||
//
|
//
|
||||||
// label1
|
// LabelTools
|
||||||
//
|
//
|
||||||
label1.AutoSize = true;
|
LabelTools.AutoSize = true;
|
||||||
label1.Location = new Point(5, 0);
|
LabelTools.Location = new Point(5, 0);
|
||||||
label1.Name = "label1";
|
LabelTools.Name = "LabelTools";
|
||||||
label1.Size = new Size(103, 20);
|
LabelTools.Size = new Size(103, 20);
|
||||||
label1.TabIndex = 0;
|
LabelTools.TabIndex = 0;
|
||||||
label1.Text = "Инструменты";
|
LabelTools.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// pictureBoxCollection
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(1, -2);
|
pictureBoxCollection.Location = new Point(1, -2);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
pictureBoxCollection.Size = new Size(676, 451);
|
pictureBoxCollection.Size = new Size(663, 504);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
pictureBoxCollection.TabIndex = 1;
|
||||||
pictureBoxCollection.TabStop = false;
|
pictureBoxCollection.TabStop = false;
|
||||||
//
|
//
|
||||||
@ -109,25 +175,33 @@
|
|||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(900, 450);
|
ClientSize = new Size(882, 510);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(toolsLabel);
|
Controls.Add(toolsPanel);
|
||||||
Name = "FormBusCollection";
|
Name = "FormBusCollection";
|
||||||
Text = "Набор автобусов";
|
Text = "Набор автобусов";
|
||||||
toolsLabel.ResumeLayout(false);
|
toolsPanel.ResumeLayout(false);
|
||||||
toolsLabel.PerformLayout();
|
toolsPanel.PerformLayout();
|
||||||
|
panelSets.ResumeLayout(false);
|
||||||
|
panelSets.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Panel toolsLabel;
|
private Panel toolsPanel;
|
||||||
private Label label1;
|
private Label LabelTools;
|
||||||
private Button ButtonDeleteBus;
|
private Button ButtonDeleteBus;
|
||||||
private Button addBus;
|
private Button ButtonAddBus;
|
||||||
private Button ButtonRefreshCollection;
|
private Button ButtonRefreshCollection;
|
||||||
private PictureBox pictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
public TextBox maskedTextBoxNumber;
|
public TextBox maskedTextBoxNumber;
|
||||||
|
private Panel panelSets;
|
||||||
|
private Label SetsLabel;
|
||||||
|
private Button ButtonDelObject;
|
||||||
|
private Button ButtonAddObject;
|
||||||
|
private ListBox listBoxObjects;
|
||||||
|
private TextBox textBoxStorageName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -21,7 +21,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Набор объектов
|
/// Набор объектов
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly TheBusesGenericCollection<DrawningBus, DrawningObjectBus> _theBuses;
|
private readonly TheBusesGenericStorage _storage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -29,8 +29,77 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
|||||||
public FormBusCollection()
|
public FormBusCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_theBuses = new TheBusesGenericCollection<DrawningBus, DrawningObjectBus>
|
_storage = new TheBusesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Заполнение listBoxObjects
|
||||||
|
/// </summary>
|
||||||
|
private void ReloadObjects()
|
||||||
|
{
|
||||||
|
int index = listBoxObjects.SelectedIndex;
|
||||||
|
|
||||||
|
listBoxObjects.Items.Clear();
|
||||||
|
for (int i = 0; i < _storage.Keys.Count; i++)
|
||||||
|
{
|
||||||
|
listBoxObjects.Items.Add(_storage.Keys[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listBoxObjects.Items.Count > 0 && (index == -1 || index >= listBoxObjects.Items.Count))
|
||||||
|
{
|
||||||
|
listBoxObjects.SelectedIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (listBoxObjects.Items.Count > 0 && index > -1 && index < listBoxObjects.Items.Count)
|
||||||
|
{
|
||||||
|
listBoxObjects.SelectedIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора в коллекцию
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Выбор набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void listBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxObjects.SelectedItem?.ToString() ?? string.Empty]?.ShowTheBuses();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void ButtonDelObject_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxObjects.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (MessageBox.Show($"Удалить объект{listBoxObjects.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo,
|
||||||
|
MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_storage.DelSet(listBoxObjects.SelectedItem.ToString()
|
||||||
|
?? string.Empty);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -40,19 +109,29 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonAddBus_Click(object sender, EventArgs e)
|
private void ButtonAddBus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
|
if (listBoxObjects.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxObjects.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormDoubleDeckerBus form = new();
|
FormDoubleDeckerBus form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_theBuses + form.SelectedBus != -1)
|
if (obj + form.SelectedBus)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _theBuses.ShowTheBuses();
|
pictureBoxCollection.Image = obj.ShowTheBuses();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,17 +141,26 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonDeleteBus_Click(object sender, EventArgs e)
|
private void ButtonDeleteBus_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
if (listBoxObjects.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxObjects.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 (obj - pos != null)
|
||||||
if (_theBuses - pos != true)
|
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _theBuses.ShowTheBuses();
|
pictureBoxCollection.Image = obj.ShowTheBuses();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -87,7 +175,17 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base
|
|||||||
/// <param name="e"></param>
|
/// <param name="e"></param>
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _theBuses.ShowTheBuses();
|
if (listBoxObjects.SelectedIndex == -1)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var obj = _storage[listBoxObjects.SelectedItem.ToString() ??
|
||||||
|
string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowTheBuses();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,19 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
where T : class
|
where T : class
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly T?[] _places;
|
private readonly List<T?> _places;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Количество объектов в массиве
|
/// Количество объектов в cписке
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Count => _places.Length;
|
public int Count => _places.Count;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Максимальное количество объектов в cписке
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _maxCount;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Конструктор
|
/// Конструктор
|
||||||
@ -29,7 +34,8 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// <param name="count"></param>
|
/// <param name="count"></param>
|
||||||
public SetGeneric(int count)
|
public SetGeneric(int count)
|
||||||
{
|
{
|
||||||
_places = new T?[count];
|
_maxCount = count;
|
||||||
|
_places = new List<T?>(count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -37,9 +43,15 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="bus">Добавляемый автобус</param>
|
/// <param name="bus">Добавляемый автобус</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T bus)
|
public bool Insert(T bus)
|
||||||
{
|
{
|
||||||
return Insert(bus, 0);
|
if (_places.Count == _maxCount)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Insert(bus, 0);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -48,36 +60,15 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// <param name="bus">Добавляемый автобус</param>
|
/// <param name="bus">Добавляемый автобус</param>
|
||||||
/// <param name="position">Позиция</param>
|
/// <param name="position">Позиция</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T bus, int position)
|
public bool Insert(T bus, int position)
|
||||||
{
|
{
|
||||||
int nullIndex = -1, i;
|
if (!(position >= 0 && position <= Count && _places.Count < _maxCount))
|
||||||
|
|
||||||
if (position < 0 || position >= Count)
|
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = position; i < Count; i++)
|
_places.Insert(position, bus);
|
||||||
{
|
return true;
|
||||||
if (_places[i] == null)
|
|
||||||
{
|
|
||||||
nullIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (nullIndex < 0)
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = nullIndex; i > position; i--)
|
|
||||||
{
|
|
||||||
_places[i] = _places[i - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
_places[position] = bus;
|
|
||||||
return position;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -92,7 +83,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_places[position] = null;
|
_places.RemoveAt(position);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,14 +92,43 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="position"></param>
|
/// <param name="position"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public T? Get(int position)
|
public T? this[int position]
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= Count)
|
get
|
||||||
|
{
|
||||||
|
if (position < 0 || position >= _maxCount)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return _places[position];
|
return _places[position];
|
||||||
}
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (!(position >= 0 && position < Count && _places.Count < _maxCount))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_places.Insert(position, value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Проход по списку
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<T?> GetTheBuses(int? maxTheBuses = null)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _places.Count; ++i)
|
||||||
|
{
|
||||||
|
yield return _places[i];
|
||||||
|
if (maxTheBuses.HasValue && i == maxTheBuses.Value)
|
||||||
|
{
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -63,13 +63,14 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int operator +(TheBusesGenericCollection<T, U> collect, T? obj)
|
public static bool operator +(TheBusesGenericCollection<T, U> collect, T? obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
if (obj == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return false;
|
||||||
}
|
}
|
||||||
return collect._collection.Insert(obj);
|
|
||||||
|
return collect?._collection.Insert(obj) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -78,14 +79,15 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// <param name="collect"></param>
|
/// <param name="collect"></param>
|
||||||
/// <param name="pos"></param>
|
/// <param name="pos"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static bool operator -(TheBusesGenericCollection<T, U> collect, int pos)
|
public static T? operator -(TheBusesGenericCollection<T, U> collect, int pos)
|
||||||
{
|
{
|
||||||
T? obj = collect._collection.Get(pos);
|
T? obj = collect._collection[pos];
|
||||||
if (obj != null)
|
if (obj != null)
|
||||||
{
|
{
|
||||||
collect._collection.Remove(pos);
|
collect._collection.Remove(pos);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -95,7 +97,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public U? GetU(int pos)
|
public U? GetU(int pos)
|
||||||
{
|
{
|
||||||
return (U?)_collection.Get(pos)?.GetMoveableObject;
|
return (U?)_collection[pos]?.GetMoveableObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -136,16 +138,16 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
|||||||
/// <param name="g"></param>
|
/// <param name="g"></param>
|
||||||
private void DrawObjects(Graphics g)
|
private void DrawObjects(Graphics g)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _collection.Count; i++)
|
int i = 0;
|
||||||
|
foreach (var bus in _collection.GetTheBuses())
|
||||||
{
|
{
|
||||||
DrawningBus bus = _collection.Get(i);
|
|
||||||
|
|
||||||
if (bus != null)
|
if (bus != null)
|
||||||
{
|
{
|
||||||
int inRow = _pictureWidth / _placeSizeWidth;
|
int inRow = _pictureWidth / _placeSizeWidth;
|
||||||
bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
|
bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, i / inRow * _placeSizeHeight);
|
||||||
bus.DrawTransport(g);
|
bus.DrawTransport(g);
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects;
|
||||||
|
using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Класс для хранения коллекции
|
||||||
|
/// </summary>
|
||||||
|
internal class TheBusesGenericStorage
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Словарь (хранилище)
|
||||||
|
/// </summary>
|
||||||
|
readonly Dictionary<string, TheBusesGenericCollection<DrawningBus,
|
||||||
|
DrawningObjectBus>> _busStorages;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращение списка названий наборов
|
||||||
|
/// </summary>
|
||||||
|
public List<string> Keys => _busStorages.Keys.ToList();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ширина окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureWidth;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Высота окна отрисовки
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _pictureHeight;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Конструктор
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="pictureWidth"></param>
|
||||||
|
/// <param name="pictureHeight"></param>
|
||||||
|
public TheBusesGenericStorage(int pictureWidth, int pictureHeight)
|
||||||
|
{
|
||||||
|
_busStorages = new Dictionary<string, TheBusesGenericCollection<DrawningBus, DrawningObjectBus>>();
|
||||||
|
_pictureWidth = pictureWidth;
|
||||||
|
_pictureHeight = pictureHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void AddSet(string name)
|
||||||
|
{
|
||||||
|
_busStorages.Add(name, new TheBusesGenericCollection<DrawningBus, DrawningObjectBus>(_pictureWidth, _pictureHeight));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удаление набора
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">Название набора</param>
|
||||||
|
public void DelSet(string name)
|
||||||
|
{
|
||||||
|
if (!_busStorages.ContainsKey(name))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_busStorages.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Доступ к набору
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ind"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public TheBusesGenericCollection<DrawningBus, DrawningObjectBus>? this[string ind]
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_busStorages.ContainsKey(ind))
|
||||||
|
{
|
||||||
|
return _busStorages[ind];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user