4 работа финал

This commit is contained in:
bekodeg 2023-11-04 11:34:17 +04:00
parent 85704d9e33
commit c6059a9dfa
5 changed files with 24 additions and 66 deletions

View File

@ -176,6 +176,7 @@
buttonAddLocomotive.TabIndex = 0;
buttonAddLocomotive.Text = "Добавить локомотив";
buttonAddLocomotive.UseVisualStyleBackColor = true;
buttonAddLocomotive.Click += buttonAddLocomotive_Click;
//
// FormLocomotiveCollection
//

View File

@ -12,8 +12,10 @@ namespace ProjectElectricLocomotive
{
public partial class FormLocomotiveCollection
{
private void buttonAddLocomotive_Click(object sender, EventArgs e)
{
ButtonAddLocomotive_Click(sender, e);
}
private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
{
ButtonRemoveLocomotive_Click(sender, e);

View File

@ -142,10 +142,8 @@ namespace ProjectElectricLocomotive.Generics
{
locomotive.SetPosition((pos % ColumnCount) * _placeSizeWidth, ((RowsCount - pos / ColumnCount - 1) * _placeSizeHeight));
locomotive.DrawTransport(g);
}
++pos;
}
}
}
}

View File

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace ProjectElectricLocomotive.Generics
{
@ -54,7 +55,14 @@ namespace ProjectElectricLocomotive.Generics
/// <param name="name">Название набора</param>
public void AddSet(string name)
{
if (Keys.Contains(name))
{
return;
};
_locomotiveStorage.Add(name,
new LocomotivesGenericCollection<
DrawningLocomotive, DrawningObjectLocomotive>(
_pictureWidth, _pictureHeight));
}
/// <summary>
/// Удаление набора
@ -62,7 +70,10 @@ namespace ProjectElectricLocomotive.Generics
/// <param name="name">Название набора</param>
public void DelSet(string name)
{
// TODO Прописать логику для удаления
if (Keys.Contains(name))
{
_locomotiveStorage.Remove(name);
}
}
/// <summary>
/// Доступ к набору
@ -74,10 +85,12 @@ namespace ProjectElectricLocomotive.Generics
{
get
{
// TODO Продумать логику получения набора
if (Keys.Contains(ind))
{
return _locomotiveStorage[ind];
}
return null;
}
}
}
}

View File

@ -97,73 +97,17 @@ namespace ProjectElectricLocomotive
ReloadObjects();
}
}
/// <summary>
/// Заполнение listBoxObjects
/// </summary>
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;
}
}
/// <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[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives();
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButtonDelObject_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();
}
}
/// <summary>
/// Добавление объекта в набор