diff --git a/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
index 3879f89..a8bdfd8 100644
--- a/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
+++ b/ElectricLocomotive/FormLocomotiveCollection.Designer.cs
@@ -176,6 +176,7 @@
buttonAddLocomotive.TabIndex = 0;
buttonAddLocomotive.Text = "Добавить локомотив";
buttonAddLocomotive.UseVisualStyleBackColor = true;
+ buttonAddLocomotive.Click += buttonAddLocomotive_Click;
//
// FormLocomotiveCollection
//
diff --git a/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/FormLocomotiveCollection.cs
index 60aefa7..5b3fab0 100644
--- a/ElectricLocomotive/FormLocomotiveCollection.cs
+++ b/ElectricLocomotive/FormLocomotiveCollection.cs
@@ -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);
diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs
index 8351883..a77769e 100644
--- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs
+++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs
@@ -142,10 +142,8 @@ namespace ProjectElectricLocomotive.Generics
{
locomotive.SetPosition((pos % ColumnCount) * _placeSizeWidth, ((RowsCount - pos / ColumnCount - 1) * _placeSizeHeight));
locomotive.DrawTransport(g);
- }
-
-
-
+ ++pos;
+ }
}
}
}
diff --git a/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs b/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs
index fabb576..e7b044b 100644
--- a/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs
+++ b/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs
@@ -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
/// Название набора
public void AddSet(string name)
{
-
+ if (Keys.Contains(name))
+ {
+ return;
+ };
+ _locomotiveStorage.Add(name,
+ new LocomotivesGenericCollection<
+ DrawningLocomotive, DrawningObjectLocomotive>(
+ _pictureWidth, _pictureHeight));
}
///
/// Удаление набора
@@ -62,7 +70,10 @@ namespace ProjectElectricLocomotive.Generics
/// Название набора
public void DelSet(string name)
{
- // TODO Прописать логику для удаления
+ if (Keys.Contains(name))
+ {
+ _locomotiveStorage.Remove(name);
+ }
}
///
/// Доступ к набору
@@ -74,10 +85,12 @@ namespace ProjectElectricLocomotive.Generics
{
get
{
- // TODO Продумать логику получения набора
+ if (Keys.Contains(ind))
+ {
+ return _locomotiveStorage[ind];
+ }
return null;
}
-
}
}
}
diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs
index a39d3fe..faa123f 100644
--- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs
+++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs
@@ -97,73 +97,17 @@ namespace ProjectElectricLocomotive
ReloadObjects();
}
}
-
- ///
- /// Заполнение listBoxObjects
- ///
- 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 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 ListBoxObjects_SelectedIndexChanged(object sender, EventArgs e)
- {
- pictureBoxCollection.Image = _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowLocomotives();
- }
- ///
- /// Удаление набора
- ///
- ///
- ///
- 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();
- }
- }
///
/// Добавление объекта в набор