Добавления.

This commit is contained in:
Андрей Байгулов 2023-10-29 21:15:03 +04:00
parent 1f66a0689b
commit e5619197bc
2 changed files with 181 additions and 51 deletions

View File

@ -29,13 +29,19 @@
private void InitializeComponent()
{
panelLocomotiveCollection = new Panel();
groupBoxSets = new GroupBox();
textBoxSetName = new TextBox();
buttonDeleteSet = new Button();
listBoxStorages = new ListBox();
buttonAddSet = new Button();
LabelOnPanel = new Label();
maskedTextBoxNumber = new MaskedTextBox();
ButtonRefreshCollection = new Button();
ButtonRemoveLocomotive = new Button();
ButtonAddLocomotive = new Button();
pictureBoxCollection = new PictureBox();
LabelOnPanel = new Label();
panelLocomotiveCollection.SuspendLayout();
groupBoxSets.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
SuspendLayout();
//
@ -43,62 +49,68 @@
//
panelLocomotiveCollection.AccessibleDescription = "";
panelLocomotiveCollection.AccessibleName = "";
panelLocomotiveCollection.Controls.Add(groupBoxSets);
panelLocomotiveCollection.Controls.Add(LabelOnPanel);
panelLocomotiveCollection.Controls.Add(maskedTextBoxNumber);
panelLocomotiveCollection.Controls.Add(ButtonRefreshCollection);
panelLocomotiveCollection.Controls.Add(ButtonRemoveLocomotive);
panelLocomotiveCollection.Controls.Add(ButtonAddLocomotive);
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.Size = new Size(208, 448);
panelLocomotiveCollection.Size = new Size(248, 584);
panelLocomotiveCollection.TabIndex = 0;
panelLocomotiveCollection.Tag = "Инструменты";
//
// maskedTextBoxNumber
// groupBoxSets
//
maskedTextBoxNumber.Location = new Point(40, 74);
maskedTextBoxNumber.Name = "maskedTextBoxNumber";
maskedTextBoxNumber.Size = new Size(123, 23);
maskedTextBoxNumber.TabIndex = 3;
groupBoxSets.Controls.Add(textBoxSetName);
groupBoxSets.Controls.Add(buttonDeleteSet);
groupBoxSets.Controls.Add(listBoxStorages);
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);
ButtonRefreshCollection.Name = "ButtonRefreshCollection";
ButtonRefreshCollection.Size = new Size(194, 43);
ButtonRefreshCollection.TabIndex = 2;
ButtonRefreshCollection.Text = " Обновить коллекцию";
ButtonRefreshCollection.UseVisualStyleBackColor = true;
ButtonRefreshCollection.Click += ButtonRefreshCollection_Click;
textBoxSetName.Location = new Point(6, 38);
textBoxSetName.Name = "textBoxSetName";
textBoxSetName.Size = new Size(226, 23);
textBoxSetName.TabIndex = 3;
//
// ButtonRemoveLocomotive
// buttonDeleteSet
//
ButtonRemoveLocomotive.Location = new Point(3, 138);
ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive";
ButtonRemoveLocomotive.Size = new Size(194, 39);
ButtonRemoveLocomotive.TabIndex = 1;
ButtonRemoveLocomotive.Text = "Удалить локомотив";
ButtonRemoveLocomotive.UseVisualStyleBackColor = true;
ButtonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
buttonDeleteSet.Location = new Point(6, 216);
buttonDeleteSet.Name = "buttonDeleteSet";
buttonDeleteSet.Size = new Size(226, 45);
buttonDeleteSet.TabIndex = 2;
buttonDeleteSet.Text = "Удалить набор";
buttonDeleteSet.UseVisualStyleBackColor = true;
buttonDeleteSet.Click += buttonDeleteSet_Click;
//
// ButtonAddLocomotive
// listBoxStorages
//
ButtonAddLocomotive.Location = new Point(3, 15);
ButtonAddLocomotive.Name = "ButtonAddLocomotive";
ButtonAddLocomotive.Size = new Size(194, 39);
ButtonAddLocomotive.TabIndex = 0;
ButtonAddLocomotive.Text = "Добавить локомотив";
ButtonAddLocomotive.UseVisualStyleBackColor = true;
ButtonAddLocomotive.Click += ButtonAddLocomotive_Click;
listBoxStorages.FormattingEnabled = true;
listBoxStorages.ItemHeight = 15;
listBoxStorages.Location = new Point(6, 116);
listBoxStorages.Name = "listBoxStorages";
listBoxStorages.Size = new Size(226, 94);
listBoxStorages.TabIndex = 1;
listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
//
// pictureBoxCollection
// buttonAddSet
//
pictureBoxCollection.Location = new Point(2, 2);
pictureBoxCollection.Name = "pictureBoxCollection";
pictureBoxCollection.Size = new Size(589, 448);
pictureBoxCollection.TabIndex = 1;
pictureBoxCollection.TabStop = false;
buttonAddSet.Location = new Point(6, 67);
buttonAddSet.Name = "buttonAddSet";
buttonAddSet.Size = new Size(226, 34);
buttonAddSet.TabIndex = 0;
buttonAddSet.Text = "Добавить набор";
buttonAddSet.UseVisualStyleBackColor = true;
buttonAddSet.Click += buttonAddSet_Click;
//
// LabelOnPanel
//
@ -109,17 +121,64 @@
LabelOnPanel.TabIndex = 4;
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
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
ClientSize = new Size(909, 587);
Controls.Add(pictureBoxCollection);
Controls.Add(panelLocomotiveCollection);
Name = "FormLocomotiveCollection";
Text = "Набор локомотивов";
panelLocomotiveCollection.ResumeLayout(false);
panelLocomotiveCollection.PerformLayout();
groupBoxSets.ResumeLayout(false);
groupBoxSets.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
ResumeLayout(false);
}
@ -132,5 +191,10 @@
private PictureBox pictureBoxCollection;
private MaskedTextBox maskedTextBoxNumber;
private Label LabelOnPanel;
private GroupBox groupBoxSets;
private Button buttonDeleteSet;
private ListBox listBoxStorages;
private Button buttonAddSet;
private TextBox textBoxSetName;
}
}

View File

@ -16,21 +16,47 @@ namespace ProjectElectricLocomotive
{
public partial class FormLocomotiveCollection : Form
{
private readonly LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive> _locomotives;
private readonly LocomotivesGenericStorage _storage;
public FormLocomotiveCollection()
{
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();
if (form.ShowDialog() == DialogResult.OK)
{
if (_locomotives + form.SelectedLocomotive != -1)
//проверяем, удалось ли нам загрузить объект
if (obj + form.SelectedLocomotive > -1)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
pictureBoxCollection.Image = obj.ShowLocomotives();
}
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("Удалить объект?", "Удаление",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
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;
}
int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
if (_locomotives - pos != null)
if (obj - pos != null)
{
MessageBox.Show("Объект удален");
pictureBoxCollection.Image = _locomotives.ShowLocomotives();
pictureBoxCollection.Image = obj.ShowLocomotives();
pictureBoxCollection.Image = obj.ShowLocomotives();
}
else
{
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();
}
}
}
}