Добавления.
This commit is contained in:
parent
1f66a0689b
commit
e5619197bc
@ -29,13 +29,19 @@
|
|||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
panelLocomotiveCollection = new Panel();
|
panelLocomotiveCollection = new Panel();
|
||||||
|
groupBoxSets = new GroupBox();
|
||||||
|
textBoxSetName = new TextBox();
|
||||||
|
buttonDeleteSet = new Button();
|
||||||
|
listBoxStorages = new ListBox();
|
||||||
|
buttonAddSet = new Button();
|
||||||
|
LabelOnPanel = new Label();
|
||||||
maskedTextBoxNumber = new MaskedTextBox();
|
maskedTextBoxNumber = new MaskedTextBox();
|
||||||
ButtonRefreshCollection = new Button();
|
ButtonRefreshCollection = new Button();
|
||||||
ButtonRemoveLocomotive = new Button();
|
ButtonRemoveLocomotive = new Button();
|
||||||
ButtonAddLocomotive = new Button();
|
ButtonAddLocomotive = new Button();
|
||||||
pictureBoxCollection = new PictureBox();
|
pictureBoxCollection = new PictureBox();
|
||||||
LabelOnPanel = new Label();
|
|
||||||
panelLocomotiveCollection.SuspendLayout();
|
panelLocomotiveCollection.SuspendLayout();
|
||||||
|
groupBoxSets.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -43,62 +49,68 @@
|
|||||||
//
|
//
|
||||||
panelLocomotiveCollection.AccessibleDescription = "";
|
panelLocomotiveCollection.AccessibleDescription = "";
|
||||||
panelLocomotiveCollection.AccessibleName = "";
|
panelLocomotiveCollection.AccessibleName = "";
|
||||||
|
panelLocomotiveCollection.Controls.Add(groupBoxSets);
|
||||||
panelLocomotiveCollection.Controls.Add(LabelOnPanel);
|
panelLocomotiveCollection.Controls.Add(LabelOnPanel);
|
||||||
panelLocomotiveCollection.Controls.Add(maskedTextBoxNumber);
|
panelLocomotiveCollection.Controls.Add(maskedTextBoxNumber);
|
||||||
panelLocomotiveCollection.Controls.Add(ButtonRefreshCollection);
|
panelLocomotiveCollection.Controls.Add(ButtonRefreshCollection);
|
||||||
panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive);
|
panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive);
|
||||||
panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive);
|
panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive);
|
||||||
panelLocomotiveCollection.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
panelLocomotiveCollection.Font = new Font("Segoe UI", 9F, FontStyle.Regular, GraphicsUnit.Point);
|
||||||
panelLocomotiveCollection.Location = new Point(594, 2);
|
panelLocomotiveCollection.Location = new Point(660, 2);
|
||||||
panelLocomotiveCollection.Name = "panelLocomotiveCollection";
|
panelLocomotiveCollection.Name = "panelLocomotiveCollection";
|
||||||
panelLocomotiveCollection.Size = new Size(208, 448);
|
panelLocomotiveCollection.Size = new Size(248, 584);
|
||||||
panelLocomotiveCollection.TabIndex = 0;
|
panelLocomotiveCollection.TabIndex = 0;
|
||||||
panelLocomotiveCollection.Tag = "Инструменты";
|
panelLocomotiveCollection.Tag = "Инструменты";
|
||||||
//
|
//
|
||||||
// maskedTextBoxNumber
|
// groupBoxSets
|
||||||
//
|
//
|
||||||
maskedTextBoxNumber.Location = new Point(40, 74);
|
groupBoxSets.Controls.Add(textBoxSetName);
|
||||||
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
groupBoxSets.Controls.Add(buttonDeleteSet);
|
||||||
maskedTextBoxNumber.Size = new Size(123, 23);
|
groupBoxSets.Controls.Add(listBoxStorages);
|
||||||
maskedTextBoxNumber.TabIndex = 3;
|
groupBoxSets.Controls.Add(buttonAddSet);
|
||||||
|
groupBoxSets.Location = new Point(3, 15);
|
||||||
|
groupBoxSets.Name = "groupBoxSets";
|
||||||
|
groupBoxSets.Size = new Size(242, 324);
|
||||||
|
groupBoxSets.TabIndex = 5;
|
||||||
|
groupBoxSets.TabStop = false;
|
||||||
|
groupBoxSets.Text = "Наборы";
|
||||||
//
|
//
|
||||||
// ButtonRefreshCollection
|
// textBoxSetName
|
||||||
//
|
//
|
||||||
ButtonRefreshCollection.Location = new Point(3, 194);
|
textBoxSetName.Location = new Point(6, 38);
|
||||||
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
textBoxSetName.Name = "textBoxSetName";
|
||||||
ButtonRefreshCollection.Size = new Size(194, 43);
|
textBoxSetName.Size = new Size(226, 23);
|
||||||
ButtonRefreshCollection.TabIndex = 2;
|
textBoxSetName.TabIndex = 3;
|
||||||
ButtonRefreshCollection.Text = " Обновить коллекцию";
|
|
||||||
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
|
||||||
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
|
|
||||||
//
|
//
|
||||||
// ButtonRemoveLocomotive
|
// buttonDeleteSet
|
||||||
//
|
//
|
||||||
ButtonRemoveLocomotive.Location = new Point(3, 138);
|
buttonDeleteSet.Location = new Point(6, 216);
|
||||||
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
|
buttonDeleteSet.Name = "buttonDeleteSet";
|
||||||
ButtonRemoveLocomotive.Size = new Size(194, 39);
|
buttonDeleteSet.Size = new Size(226, 45);
|
||||||
ButtonRemoveLocomotive.TabIndex = 1;
|
buttonDeleteSet.TabIndex = 2;
|
||||||
ButtonRemoveLocomotive.Text = "Удалить локомотив";
|
buttonDeleteSet.Text = "Удалить набор";
|
||||||
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
|
buttonDeleteSet.UseVisualStyleBackColor = true;
|
||||||
ButtonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
|
buttonDeleteSet.Click += buttonDeleteSet_Click;
|
||||||
//
|
//
|
||||||
// ButtonAddLocomotive
|
// listBoxStorages
|
||||||
//
|
//
|
||||||
ButtonAddLocomotive.Location = new Point(3, 15);
|
listBoxStorages.FormattingEnabled = true;
|
||||||
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
|
listBoxStorages.ItemHeight = 15;
|
||||||
ButtonAddLocomotive.Size = new Size(194, 39);
|
listBoxStorages.Location = new Point(6, 116);
|
||||||
ButtonAddLocomotive.TabIndex = 0;
|
listBoxStorages.Name = "listBoxStorages";
|
||||||
ButtonAddLocomotive.Text = "Добавить локомотив";
|
listBoxStorages.Size = new Size(226, 94);
|
||||||
ButtonAddLocomotive.UseVisualStyleBackColor = true;
|
listBoxStorages.TabIndex = 1;
|
||||||
ButtonAddLocomotive.Click += ButtonAddLocomotive_Click;
|
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
// pictureBoxCollection
|
// buttonAddSet
|
||||||
//
|
//
|
||||||
pictureBoxCollection.Location = new Point(2, 2);
|
buttonAddSet.Location = new Point(6, 67);
|
||||||
pictureBoxCollection.Name = "pictureBoxCollection";
|
buttonAddSet.Name = "buttonAddSet";
|
||||||
pictureBoxCollection.Size = new Size(589, 448);
|
buttonAddSet.Size = new Size(226, 34);
|
||||||
pictureBoxCollection.TabIndex = 1;
|
buttonAddSet.TabIndex = 0;
|
||||||
pictureBoxCollection.TabStop = false;
|
buttonAddSet.Text = "Добавить набор";
|
||||||
|
buttonAddSet.UseVisualStyleBackColor = true;
|
||||||
|
buttonAddSet.Click += buttonAddSet_Click;
|
||||||
//
|
//
|
||||||
// LabelOnPanel
|
// LabelOnPanel
|
||||||
//
|
//
|
||||||
@ -109,17 +121,64 @@
|
|||||||
LabelOnPanel.TabIndex = 4;
|
LabelOnPanel.TabIndex = 4;
|
||||||
LabelOnPanel.Text = "Инструменты";
|
LabelOnPanel.Text = "Инструменты";
|
||||||
//
|
//
|
||||||
|
// maskedTextBoxNumber
|
||||||
|
//
|
||||||
|
maskedTextBoxNumber.Location = new Point(35, 408);
|
||||||
|
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
|
||||||
|
maskedTextBoxNumber.Size = new Size(176, 23);
|
||||||
|
maskedTextBoxNumber.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// ButtonRefreshCollection
|
||||||
|
//
|
||||||
|
ButtonRefreshCollection.Location = new Point(3, 530);
|
||||||
|
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
|
||||||
|
ButtonRefreshCollection.Size = new Size(242, 43);
|
||||||
|
ButtonRefreshCollection.TabIndex = 2;
|
||||||
|
ButtonRefreshCollection.Text = " Обновить коллекцию";
|
||||||
|
ButtonRefreshCollection.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRefreshCollection.Click += buttonRefreshCollection_Click;
|
||||||
|
//
|
||||||
|
// ButtonRemoveLocomotive
|
||||||
|
//
|
||||||
|
ButtonRemoveLocomotive.Location = new Point(3, 460);
|
||||||
|
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
|
||||||
|
ButtonRemoveLocomotive.Size = new Size(242, 39);
|
||||||
|
ButtonRemoveLocomotive.TabIndex = 1;
|
||||||
|
ButtonRemoveLocomotive.Text = "Удалить локомотив";
|
||||||
|
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonRemoveLocomotive.Click += buttonRemoveLocomotive_Click;
|
||||||
|
//
|
||||||
|
// ButtonAddLocomotive
|
||||||
|
//
|
||||||
|
ButtonAddLocomotive.Location = new Point(3, 345);
|
||||||
|
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
|
||||||
|
ButtonAddLocomotive.Size = new Size(242, 39);
|
||||||
|
ButtonAddLocomotive.TabIndex = 0;
|
||||||
|
ButtonAddLocomotive.Text = "Добавить локомотив";
|
||||||
|
ButtonAddLocomotive.UseVisualStyleBackColor = true;
|
||||||
|
ButtonAddLocomotive.Click += buttonAddLocomotive_Click;
|
||||||
|
//
|
||||||
|
// pictureBoxCollection
|
||||||
|
//
|
||||||
|
pictureBoxCollection.Location = new Point(2, 2);
|
||||||
|
pictureBoxCollection.Name = "pictureBoxCollection";
|
||||||
|
pictureBoxCollection.Size = new Size(655, 584);
|
||||||
|
pictureBoxCollection.TabIndex = 1;
|
||||||
|
pictureBoxCollection.TabStop = false;
|
||||||
|
//
|
||||||
// FormLocomotiveCollection
|
// FormLocomotiveCollection
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(909, 587);
|
||||||
Controls.Add(pictureBoxCollection);
|
Controls.Add(pictureBoxCollection);
|
||||||
Controls.Add(panelLocomotiveCollection);
|
Controls.Add(panelLocomotiveCollection);
|
||||||
Name = "FormLocomotiveCollection";
|
Name = "FormLocomotiveCollection";
|
||||||
Text = "Набор локомотивов";
|
Text = "Набор локомотивов";
|
||||||
panelLocomotiveCollection.ResumeLayout(false);
|
panelLocomotiveCollection.ResumeLayout(false);
|
||||||
panelLocomotiveCollection.PerformLayout();
|
panelLocomotiveCollection.PerformLayout();
|
||||||
|
groupBoxSets.ResumeLayout(false);
|
||||||
|
groupBoxSets.PerformLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
@ -132,5 +191,10 @@
|
|||||||
private PictureBox pictureBoxCollection;
|
private PictureBox pictureBoxCollection;
|
||||||
private MaskedTextBox maskedTextBoxNumber;
|
private MaskedTextBox maskedTextBoxNumber;
|
||||||
private Label LabelOnPanel;
|
private Label LabelOnPanel;
|
||||||
|
private GroupBox groupBoxSets;
|
||||||
|
private Button buttonDeleteSet;
|
||||||
|
private ListBox listBoxStorages;
|
||||||
|
private Button buttonAddSet;
|
||||||
|
private TextBox textBoxSetName;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,21 +16,47 @@ namespace ProjectElectricLocomotive
|
|||||||
{
|
{
|
||||||
public partial class FormLocomotiveCollection : Form
|
public partial class FormLocomotiveCollection : Form
|
||||||
{
|
{
|
||||||
private readonly LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
|
private readonly LocomotivesGenericStorage _storage;
|
||||||
public FormLocomotiveCollection()
|
public FormLocomotiveCollection()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_locomotives = new LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
_storage = new LocomotivesGenericStorage(pictureBoxCollection.Width, pictureBoxCollection.Height);
|
||||||
}
|
}
|
||||||
private void ButtonAddLocomotive_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 buttonAddLocomotive_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
FormElectricLocomotive form = new();
|
FormElectricLocomotive form = new();
|
||||||
if (form.ShowDialog() == DialogResult.OK)
|
if (form.ShowDialog() == DialogResult.OK)
|
||||||
{
|
{
|
||||||
if (_locomotives + form.SelectedLocomotive != -1)
|
//проверяем, удалось ли нам загрузить объект
|
||||||
|
if (obj + form.SelectedLocomotive > -1)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект добавлен");
|
MessageBox.Show("Объект добавлен");
|
||||||
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
|
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -38,27 +64,67 @@ namespace ProjectElectricLocomotive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
|
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (MessageBox.Show("Удалить объект?", "Удаление",
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
|
||||||
if (_locomotives - pos != null)
|
if (obj - pos != null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Объект удален");
|
MessageBox.Show("Объект удален");
|
||||||
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
|
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||||
|
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MessageBox.Show("Не удалось удалить объект");
|
MessageBox.Show("Не удалось удалить объект");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void ButtonRefreshCollection_Click(object sender, EventArgs e)
|
private void buttonRefreshCollection_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
|
if (listBoxStorages.SelectedIndex == -1) return;
|
||||||
|
var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty];
|
||||||
|
if (obj == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pictureBoxCollection.Image = obj.ShowLocomotives();
|
||||||
|
}
|
||||||
|
private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives();
|
||||||
|
}
|
||||||
|
private void buttonAddSet_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxSetName.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Не всё заполнено", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_storage.AddSet(textBoxSetName.Text);
|
||||||
|
ReloadObjects();
|
||||||
|
}
|
||||||
|
private void buttonDeleteSet_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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user