PIbd-21 Bakalskaya E.D. LabWork04 Base #6

Closed
ekallin wants to merge 4 commits from LabWork04 into LabWork03
7 changed files with 368 additions and 175 deletions

View File

@ -47,7 +47,7 @@
this.pictureBoxElectricLocomotive.Location = new System.Drawing.Point(0, 0);
this.pictureBoxElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.pictureBoxElectricLocomotive.Name = "pictureBoxElectricLocomotive";
this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(994, 520);
this.pictureBoxElectricLocomotive.Size = new System.Drawing.Size(870, 572);
this.pictureBoxElectricLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
this.pictureBoxElectricLocomotive.TabIndex = 0;
this.pictureBoxElectricLocomotive.TabStop = false;
@ -56,10 +56,10 @@
//
this.buttonCreateElectricLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateElectricLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(13, 442);
this.buttonCreateElectricLocomotive.Location = new System.Drawing.Point(11, 514);
this.buttonCreateElectricLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateElectricLocomotive.Name = "buttonCreateElectricLocomotive";
this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateElectricLocomotive.Size = new System.Drawing.Size(191, 48);
this.buttonCreateElectricLocomotive.TabIndex = 1;
this.buttonCreateElectricLocomotive.Text = "Создать электролокомотив";
this.buttonCreateElectricLocomotive.UseVisualStyleBackColor = true;
@ -70,10 +70,10 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonLeft.Location = new System.Drawing.Point(878, 481);
this.buttonLeft.Location = new System.Drawing.Point(768, 543);
this.buttonLeft.Margin = new System.Windows.Forms.Padding(2);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(24, 24);
this.buttonLeft.Size = new System.Drawing.Size(21, 18);
this.buttonLeft.TabIndex = 2;
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click);
@ -83,10 +83,10 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowUP;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(915, 442);
this.buttonUp.Location = new System.Drawing.Point(801, 514);
this.buttonUp.Margin = new System.Windows.Forms.Padding(2);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(24, 24);
this.buttonUp.Size = new System.Drawing.Size(21, 18);
this.buttonUp.TabIndex = 3;
this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
@ -96,10 +96,10 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(950, 481);
this.buttonRight.Location = new System.Drawing.Point(831, 543);
this.buttonRight.Margin = new System.Windows.Forms.Padding(2);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(24, 24);
this.buttonRight.Size = new System.Drawing.Size(21, 18);
this.buttonRight.TabIndex = 4;
this.buttonRight.UseVisualStyleBackColor = true;
this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
@ -109,10 +109,10 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectElectricLocomotive.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonDown.Location = new System.Drawing.Point(915, 481);
this.buttonDown.Location = new System.Drawing.Point(801, 543);
this.buttonDown.Margin = new System.Windows.Forms.Padding(2);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(24, 24);
this.buttonDown.Size = new System.Drawing.Size(21, 18);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
@ -125,20 +125,20 @@
this.comboBoxStrategy.Items.AddRange(new object[] {
"MoveToCenter",
"MoveToRightCorner"});
this.comboBoxStrategy.Location = new System.Drawing.Point(846, 10);
this.comboBoxStrategy.Location = new System.Drawing.Point(740, 8);
this.comboBoxStrategy.Margin = new System.Windows.Forms.Padding(2);
this.comboBoxStrategy.Name = "comboBoxStrategy";
this.comboBoxStrategy.Size = new System.Drawing.Size(129, 28);
this.comboBoxStrategy.Size = new System.Drawing.Size(113, 23);
this.comboBoxStrategy.TabIndex = 6;
//
// buttonCreateLocomotive
//
this.buttonCreateLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.buttonCreateLocomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonCreateLocomotive.Location = new System.Drawing.Point(266, 442);
this.buttonCreateLocomotive.Location = new System.Drawing.Point(233, 514);
this.buttonCreateLocomotive.Margin = new System.Windows.Forms.Padding(2);
this.buttonCreateLocomotive.Name = "buttonCreateLocomotive";
this.buttonCreateLocomotive.Size = new System.Drawing.Size(218, 64);
this.buttonCreateLocomotive.Size = new System.Drawing.Size(191, 48);
this.buttonCreateLocomotive.TabIndex = 7;
this.buttonCreateLocomotive.Text = "Создать локомотив";
this.buttonCreateLocomotive.UseVisualStyleBackColor = true;
@ -148,10 +148,10 @@
//
this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonStep.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.buttonStep.Location = new System.Drawing.Point(863, 52);
this.buttonStep.Location = new System.Drawing.Point(755, 39);
this.buttonStep.Margin = new System.Windows.Forms.Padding(2);
this.buttonStep.Name = "buttonStep";
this.buttonStep.Size = new System.Drawing.Size(100, 45);
this.buttonStep.Size = new System.Drawing.Size(88, 34);
this.buttonStep.TabIndex = 8;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
@ -161,10 +161,10 @@
//
this.ButtonSelect_Locomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonSelect_Locomotive.Font = new System.Drawing.Font("Candara Light", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonSelect_Locomotive.Location = new System.Drawing.Point(863, 113);
this.ButtonSelect_Locomotive.Location = new System.Drawing.Point(755, 85);
this.ButtonSelect_Locomotive.Margin = new System.Windows.Forms.Padding(2);
this.ButtonSelect_Locomotive.Name = "ButtonSelect_Locomotive";
this.ButtonSelect_Locomotive.Size = new System.Drawing.Size(100, 61);
this.ButtonSelect_Locomotive.Size = new System.Drawing.Size(88, 46);
this.ButtonSelect_Locomotive.TabIndex = 9;
this.ButtonSelect_Locomotive.Text = "Выбор локо";
this.ButtonSelect_Locomotive.UseVisualStyleBackColor = true;
@ -172,9 +172,9 @@
//
// FormElectricLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(994, 520);
this.ClientSize = new System.Drawing.Size(870, 572);
this.Controls.Add(this.ButtonSelect_Locomotive);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateLocomotive);

View File

@ -28,56 +28,55 @@
/// </summary>
private void InitializeComponent()
{
this.Instruments = new System.Windows.Forms.Panel();
this.components = new System.ComponentModel.Container();
this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
this.ButtonRefreshCollection = new System.Windows.Forms.Button();
this.ButtonRemoveLocomotive = new System.Windows.Forms.Button();
this.ButtonAddLocomotive = new System.Windows.Forms.Button();
this.pictureBoxCollections = new System.Windows.Forms.PictureBox();
this.Instruments.SuspendLayout();
this.textBoxStorageName = new System.Windows.Forms.TextBox();
this.bindingSource1 = new System.Windows.Forms.BindingSource(this.components);
this.bindingSource2 = new System.Windows.Forms.BindingSource(this.components);
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.listBoxStorage = new System.Windows.Forms.ListBox();
this.ButtonAddObject = new System.Windows.Forms.Button();
this.ButtonRemoveObject = new System.Windows.Forms.Button();
this.Instruments = new System.Windows.Forms.GroupBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource2)).BeginInit();
this.groupBox1.SuspendLayout();
this.Instruments.SuspendLayout();
this.SuspendLayout();
//
// Instruments
//
this.Instruments.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.Instruments.AutoSize = true;
this.Instruments.Controls.Add(this.maskedTextBoxNumber);
this.Instruments.Controls.Add(this.ButtonRefreshCollection);
this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
this.Instruments.Controls.Add(this.ButtonAddLocomotive);
this.Instruments.Location = new System.Drawing.Point(435, -40);
this.Instruments.Name = "Instruments";
this.Instruments.Size = new System.Drawing.Size(191, 451);
this.Instruments.TabIndex = 0;
//
// maskedTextBoxNumber
//
this.maskedTextBoxNumber.Location = new System.Drawing.Point(42, 123);
this.maskedTextBoxNumber.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.maskedTextBoxNumber.Location = new System.Drawing.Point(38, 532);
this.maskedTextBoxNumber.Mask = "0";
this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
this.maskedTextBoxNumber.Size = new System.Drawing.Size(149, 27);
this.maskedTextBoxNumber.TabIndex = 4;
//
// ButtonRefreshCollection
//
this.ButtonRefreshCollection.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ButtonRefreshCollection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonRefreshCollection.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRefreshCollection.Location = new System.Drawing.Point(29, 249);
this.ButtonRefreshCollection.Location = new System.Drawing.Point(38, 665);
this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 36);
this.ButtonRefreshCollection.Size = new System.Drawing.Size(150, 41);
this.ButtonRefreshCollection.TabIndex = 2;
this.ButtonRefreshCollection.Text = "Обновить все";
this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
//
// ButtonRemoveLocomotive
//
this.ButtonRemoveLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Right;
this.ButtonRemoveLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonRemoveLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(29, 179);
this.ButtonRemoveLocomotive.Location = new System.Drawing.Point(38, 592);
this.ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 36);
this.ButtonRemoveLocomotive.Size = new System.Drawing.Size(150, 44);
this.ButtonRemoveLocomotive.TabIndex = 1;
this.ButtonRemoveLocomotive.Text = "Удалить локо";
this.ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
@ -85,11 +84,11 @@
//
// ButtonAddLocomotive
//
this.ButtonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonAddLocomotive.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.ButtonAddLocomotive.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonAddLocomotive.Location = new System.Drawing.Point(29, 52);
this.ButtonAddLocomotive.Location = new System.Drawing.Point(38, 461);
this.ButtonAddLocomotive.Name = "ButtonAddLocomotive";
this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 36);
this.ButtonAddLocomotive.Size = new System.Drawing.Size(150, 39);
this.ButtonAddLocomotive.TabIndex = 0;
this.ButtonAddLocomotive.Text = "Добавить локо";
this.ButtonAddLocomotive.UseVisualStyleBackColor = true;
@ -97,37 +96,122 @@
//
// pictureBoxCollections
//
this.pictureBoxCollections.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.pictureBoxCollections.Location = new System.Drawing.Point(-3, -2);
this.pictureBoxCollections.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.pictureBoxCollections.Location = new System.Drawing.Point(-1, 5);
this.pictureBoxCollections.Name = "pictureBoxCollections";
this.pictureBoxCollections.Size = new System.Drawing.Size(458, 373);
this.pictureBoxCollections.Size = new System.Drawing.Size(798, 721);
this.pictureBoxCollections.TabIndex = 1;
this.pictureBoxCollections.TabStop = false;
//
// textBoxStorageName
//
this.textBoxStorageName.Location = new System.Drawing.Point(31, 43);
this.textBoxStorageName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxStorageName.Name = "textBoxStorageName";
this.textBoxStorageName.Size = new System.Drawing.Size(149, 27);
this.textBoxStorageName.TabIndex = 5;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.listBoxStorage);
this.groupBox1.Controls.Add(this.ButtonAddObject);
this.groupBox1.Controls.Add(this.ButtonRemoveObject);
this.groupBox1.Controls.Add(this.textBoxStorageName);
this.groupBox1.Location = new System.Drawing.Point(7, 29);
this.groupBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBox1.Size = new System.Drawing.Size(216, 395);
this.groupBox1.TabIndex = 5;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Наборы";
//
// listBoxStorage
//
this.listBoxStorage.FormattingEnabled = true;
this.listBoxStorage.ItemHeight = 20;
this.listBoxStorage.Location = new System.Drawing.Point(31, 163);
this.listBoxStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.listBoxStorage.Name = "listBoxStorage";
this.listBoxStorage.Size = new System.Drawing.Size(149, 124);
this.listBoxStorage.TabIndex = 9;
this.listBoxStorage.SelectedIndexChanged += new System.EventHandler(this.listBoxStorage_SelectedIndexChanged);
//
// ButtonAddObject
//
this.ButtonAddObject.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.ButtonAddObject.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonAddObject.Location = new System.Drawing.Point(31, 96);
this.ButtonAddObject.Name = "ButtonAddObject";
this.ButtonAddObject.Size = new System.Drawing.Size(150, 39);
this.ButtonAddObject.TabIndex = 7;
this.ButtonAddObject.Text = "Добавить набор";
this.ButtonAddObject.UseVisualStyleBackColor = true;
this.ButtonAddObject.Click += new System.EventHandler(this.ButtonAddObject_Click);
//
// ButtonRemoveObject
//
this.ButtonRemoveObject.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.ButtonRemoveObject.Font = new System.Drawing.Font("Candara Light", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
this.ButtonRemoveObject.Location = new System.Drawing.Point(31, 325);
this.ButtonRemoveObject.Name = "ButtonRemoveObject";
this.ButtonRemoveObject.Size = new System.Drawing.Size(150, 44);
this.ButtonRemoveObject.TabIndex = 8;
this.ButtonRemoveObject.Text = "Удалить набор";
this.ButtonRemoveObject.UseVisualStyleBackColor = true;
this.ButtonRemoveObject.Click += new System.EventHandler(this.ButtonRemoveObject_Click);
//
// Instruments
//
this.Instruments.Controls.Add(this.ButtonRefreshCollection);
this.Instruments.Controls.Add(this.groupBox1);
this.Instruments.Controls.Add(this.maskedTextBoxNumber);
this.Instruments.Controls.Add(this.ButtonAddLocomotive);
this.Instruments.Controls.Add(this.ButtonRemoveLocomotive);
this.Instruments.Location = new System.Drawing.Point(797, 5);
this.Instruments.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Instruments.Name = "Instruments";
this.Instruments.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Instruments.Size = new System.Drawing.Size(229, 721);
this.Instruments.TabIndex = 6;
this.Instruments.TabStop = false;
this.Instruments.Text = "Инструменты";
//
// FormLocomotiveCollections
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(626, 370);
this.Controls.Add(this.pictureBoxCollections);
this.ClientSize = new System.Drawing.Size(1033, 724);
this.Controls.Add(this.Instruments);
this.Controls.Add(this.pictureBoxCollections);
this.Name = "FormLocomotiveCollections";
this.Text = "Набор локомотивов";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bindingSource2)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.Instruments.ResumeLayout(false);
this.Instruments.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollections)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Panel Instruments;
private Button ButtonRefreshCollection;
private Button ButtonRemoveLocomotive;
private Button ButtonAddLocomotive;
private PictureBox pictureBoxCollections;
private MaskedTextBox maskedTextBoxNumber;
private GroupBox groupBox1;
private TextBox textBoxStorageName;
private BindingSource bindingSource1;
private BindingSource bindingSource2;
private ListBox listBoxStorage;
private Button ButtonAddObject;
private Button ButtonRemoveObject;
private GroupBox Instruments;
}
}

View File

@ -17,25 +17,85 @@ namespace ProjectElectricLocomotive
{
public partial class FormLocomotiveCollections : Form
{
private readonly LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
private readonly LocomotiveGenericStorage _storage;
//private readonly LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
public FormLocomotiveCollections()
{
InitializeComponent();
_locomotives = new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(pictureBoxCollections.Width,
pictureBoxCollections.Height);
_storage = new LocomotiveGenericStorage(pictureBoxCollections.Width, pictureBoxCollections.Height);
}
/// <summary>
/// Заполнение listBoxObjects
/// </summary>
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)
{
pictureBoxCollections.Image = _storage[listBoxStorage.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives();
}
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 ButtonAddLocomotive_Click(object sender, EventArgs e)
{
if (_locomotives == null) return;
if (listBoxStorage.SelectedIndex == -1) return;
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
FormElectricLocomotive form = new();
if (form.ShowDialog() == DialogResult.OK)
{
//проверяем, удалось ли нам загрузить объект
if (_locomotives + form.SelectedLocomotive != -1)
if (obj + form.SelectedLocomotive > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
pictureBoxCollections.Image = obj.ShowLocomotives();
}
else
{
@ -46,15 +106,22 @@ namespace ProjectElectricLocomotive
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
{
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;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_locomotives - pos != null)
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
pictureBoxCollections.Image = obj.ShowLocomotives();
}
else
{
@ -64,7 +131,13 @@ namespace ProjectElectricLocomotive
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
{
pictureBoxCollections.Image = _locomotives.ShowLocomotives();
if (listBoxStorage.SelectedIndex == -1) return;
var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty];
if (obj == null)
{
return;
}
pictureBoxCollections.Image = obj.ShowLocomotives();
}
}
}

View File

@ -1,64 +1,4 @@
<?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.
-->
<root>
<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">
@ -117,4 +57,13 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bindingSource1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="bindingSource2.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>154, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>25</value>
</metadata>
</root>

View File

@ -32,7 +32,7 @@ namespace ProjectElectricLocomotive.Generics
}
/// Перегрузка оператора сложения
public static int operator +(LocomotiveGenericCollection<T, U> collect, T loco)
public static int operator +(LocomotiveGenericCollection<T, U> collect, T? loco)
{
if (loco == null)
{
@ -42,15 +42,20 @@ namespace ProjectElectricLocomotive.Generics
}
/// Перегрузка оператора вычитания
public static T operator -(LocomotiveGenericCollection<T, U> collect, int pos)
public static T? operator -(LocomotiveGenericCollection<T, U> collect, int pos)
{
return collect._collection.Remove(pos);
T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
return obj;
}
// получение объекта imoveableObj
public U? GetU(int pos)
{
return (U?)_collection.Get(pos)?.GetMoveableObject;
return (U?)_collection[pos]?.GetMoveableObject;
}
/// Вывод всего набора объектов
@ -82,13 +87,12 @@ namespace ProjectElectricLocomotive.Generics
int WidthObjCount = _pictureWidth / _placeSizeWidth;
for (int i = 0; i < _collection.Count; i++)
{
T? type = _collection.Get(i);
T? type = _collection[i];
if (type != null)
{
type.SetPosition(
(int)(i / HeightObjCount * _placeSizeWidth),
(HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight)
);
(HeightObjCount - 1) * _placeSizeHeight - (int)(i % HeightObjCount * _placeSizeHeight));
type?.DrawTransport(g);
}
}

View File

@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectElectricLocomotive.DrawingObjects;
using ProjectElectricLocomotive.MovementStrategy;
namespace ProjectElectricLocomotive.Generics
{
internal class LocomotiveGenericStorage
{
/// <summary>
/// Словарь (хранилище)
/// </summary>
readonly Dictionary<string, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotivesStorage;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<string> Keys => _locomotivesStorage.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
/// <summary>
/// Конструктор
/// </summary>
/// <param name="pictureWidth"></param>
/// <param name="pictureHeight"></param>
public LocomotiveGenericStorage(int pictureWidth, int pictureHeight)
{
_locomotivesStorage = new Dictionary<string, LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление набора
/// </summary>
/// <param name="name">Название набора</param>
public void AddSet(string name)
{
if (!_locomotivesStorage.ContainsKey(name))
{
_locomotivesStorage.Add(name, new LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
}
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="name">Название набора</param>
public void DelSet(string name)
{
if (_locomotivesStorage.ContainsKey(name))
{
_locomotivesStorage.Remove(name);
}
}
/// <summary>
/// Доступ к набору
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public LocomotiveGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>?
this[string ind]
{
get
{
// TODO Продумать логику получения набора
if (_locomotivesStorage.ContainsKey(ind))
{
return _locomotivesStorage[ind];
}
return null;
}
}
}
}

View File

@ -8,11 +8,17 @@ namespace ProjectElectricLocomotive.Generics
{
internal class SetGeneric<T> where T : class
{
private readonly T[] _places;
public int Count => _places.Length;
private readonly List<T?> _places;
public int Count => _places.Count;
/// Максимальное количество объектов в списке
private readonly int _maxCount;
public SetGeneric(int count)
{
_places = new T[count];
_maxCount = count;
_places = new List<T?>(count);
}
/// Добавление объекта в набор
@ -23,54 +29,48 @@ namespace ProjectElectricLocomotive.Generics
public int Insert(T loco, int position)
{
int NoEmpty = 0, temp = 0;
for (int i = position; i < Count; i++)
{
if (_places[i] != null) NoEmpty++;
}
if (NoEmpty == Count - position - 1) return -1;
if (position < Count && position >= 0)
{
for (int j = position; j < Count; j++)
{
if (_places[j] == null)
{
temp = j;
break;
}
}
// shift right
for (int i = temp; i > position; i--)
{
_places[i] = _places[i - 1];
}
_places[position] = loco;
return position;
}
return -1;
// TODO проверка позиции
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// проверка, что после вставляемого элемента в массиве есть пустой элемент //
if (position < 0 || position >= _maxCount) return -1;
_places.Insert(position, loco);
return position;
}
public T Remove(int position)
public T? Remove(int position)
{
// TODO проверка позиции
// TODO удаление объекта из массива, присвоив элементу массива значение null
if (position >= Count || position < 0)
return null;
T tmp = _places[position];
T? tmp = _places[position];
_places[position] = null;
return tmp;
}
//Получение объекта из набора по позиции
public T Get(int position)
public T? this[int position]
{
// TODO проверка позиции
if (position < 0 || position >= Count) return null;
return _places[position];
get
{
if (position < 0 || position >= Count) return null;
return _places[position];
}
set
{
if (position < 0 || position >= Count || Count == _maxCount) return;
_places.Insert(position, value);
}
}
/// <summary>
/// Проход по списку
/// </summary>
/// <returns></returns>
public IEnumerable<T?> GetLocomotives(int? maxLocos = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxLocos.HasValue && i == maxLocos.Value)
{
yield break;
}
}
}
}
}