From d2e990ba5a72c3d7209f9929ad60a4cb0c8a1a65 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Tue, 24 Oct 2023 14:59:56 +0400 Subject: [PATCH 1/7] =?UTF-8?q?=D0=BD=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BA=D0=BE=D1=80=D0=BA=D0=BA=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ElectricLocomotive/DrawningObjects/DrawningLocomotive.cs | 2 +- ElectricLocomotive/Generics/LocomotivesGenericCollection.cs | 2 +- ElectricLocomotive/LogicFormLocomotiveCollection.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ElectricLocomotive/DrawningObjects/DrawningLocomotive.cs b/ElectricLocomotive/DrawningObjects/DrawningLocomotive.cs index 16842eb..8a91dc8 100644 --- a/ElectricLocomotive/DrawningObjects/DrawningLocomotive.cs +++ b/ElectricLocomotive/DrawningObjects/DrawningLocomotive.cs @@ -56,7 +56,7 @@ namespace ProjectElectricLocomotive.DrawningObjects public int GetHeight => _locomotiveHeight; /// - /// Получение объекта IMoveableObject из объекта DrawningCar + /// Получение объекта IMoveableObject из объекта DrawningLocomotive /// public IMoveableObject GetMoveableObject => new DrawningObjectLocomotive(this); diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs index 6bb2849..2b0644b 100644 --- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs @@ -95,7 +95,7 @@ namespace ProjectElectricLocomotive.Generics /// Вывод всего набора объектов /// /// - public Bitmap ShowCars() + public Bitmap ShowLocomotives() { Bitmap bmp = new(_pictureWidth, _pictureHeight); Graphics gr = Graphics.FromImage(bmp); diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index f2cb6ac..ca624f5 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -44,7 +44,7 @@ namespace ProjectElectricLocomotive if (_locomotives + form.SelectedLocomotive) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _locomotives.ShowCars(); + pictureBoxCollection.Image = _locomotives.ShowLocomotives(); } else { @@ -69,7 +69,7 @@ namespace ProjectElectricLocomotive if (_locomotives - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _locomotives.ShowCars(); + pictureBoxCollection.Image = _locomotives.ShowLocomotives(); } else { @@ -83,7 +83,7 @@ namespace ProjectElectricLocomotive /// private void ButtonRefreshCollection_Click(object sender, EventArgs e) { - pictureBoxCollection.Image = _locomotives.ShowCars(); + pictureBoxCollection.Image = _locomotives.ShowLocomotives(); } } } -- 2.25.1 From 7880fc1215749760758f1524a23414e44a1fda93 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 09:06:28 +0400 Subject: [PATCH 2/7] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ElectricLocomotive/Generics/LocomotivesGenericCollection.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs index 2b0644b..7e21c74 100644 --- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs @@ -138,8 +138,9 @@ namespace ProjectElectricLocomotive.Generics continue; } - int widthCount = _pictureHeight / _placeSizeHeight; - drawningLocomotive.SetPosition((i / widthCount) * _placeSizeWidth, (i % widthCount) * _placeSizeHeight); + int ColumnCount = _pictureWidth / _placeSizeWidth; + int RowsCount = _pictureHeight / _placeSizeHeight; + drawningLocomotive.SetPosition((i % ColumnCount) * _placeSizeWidth, ((RowsCount - i / ColumnCount - 1) * _placeSizeHeight)); drawningLocomotive.DrawTransport(g); } } -- 2.25.1 From ddcceff03f4d8329a1163010d2aca0b8a97e1c6c Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 09:50:26 +0400 Subject: [PATCH 3/7] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B3=D1=80=D1=83?= =?UTF-8?q?=D0=B7=D0=BA=D0=B0=20=D1=81=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B8=20=D0=B2=D1=8B=D1=87=D0=B8=D1=82=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Generics/LocomotivesGenericCollection.cs | 19 +++++++++++-------- .../LogicFormLocomotiveCollection.cs | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs index 7e21c74..182f1f0 100644 --- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs @@ -56,14 +56,17 @@ namespace ProjectElectricLocomotive.Generics /// /// /// - public static bool operator +(LocomotivesGenericCollection collect, T? - obj) + public static int operator +(LocomotivesGenericCollection collect, T? obj) { if (obj == null) { - return false; + return 0; } - return collect?._collection.Insert(obj) ?? false; + if (collect?._collection.Insert(obj) ?? false) + { + return collect._collection.Count; + } + return 0; } /// /// Перегрузка оператора вычитания @@ -71,15 +74,15 @@ namespace ProjectElectricLocomotive.Generics /// /// /// - public static T? operator -(LocomotivesGenericCollection collect, int + public static int operator -(LocomotivesGenericCollection collect, int pos) { T? obj = collect._collection.Get(pos); - if (obj != null) + if (obj != null && collect._collection.Remove(pos)) { - collect._collection.Remove(pos); + return collect._collection.Count; } - return obj; + return -1; } /// /// Получение объекта IMoveableObject diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index ca624f5..065adab 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -41,7 +41,7 @@ namespace ProjectElectricLocomotive FormLocomotive form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_locomotives + form.SelectedLocomotive) + if (_locomotives + form.SelectedLocomotive > 0) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = _locomotives.ShowLocomotives(); @@ -66,7 +66,7 @@ namespace ProjectElectricLocomotive return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_locomotives - pos != null) + if (_locomotives - pos != -1) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = _locomotives.ShowLocomotives(); -- 2.25.1 From 74ad5870623c9a6def2f127f8d15f024d66f8d2e Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 10:25:50 +0400 Subject: [PATCH 4/7] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=BC=D0=B5=D0=B6=D1=83?= =?UTF-8?q?=D1=82=D0=BE=D1=87=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B5=D0=B7=D1=83?= =?UTF-8?q?=D0=BB=D1=8C=D1=82=D0=B0=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.Designer.cs | 74 ++++++++++-- .../Generics/LocomotivesGenericCollection.cs | 11 +- ElectricLocomotive/Generics/SetGeneric.cs | 72 ++++++++---- .../LogicFormLocomotiveCollection.cs | 108 ++++++++++++++++-- 4 files changed, 224 insertions(+), 41 deletions(-) diff --git a/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index 792d6cd..388d09e 100644 --- a/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -31,13 +31,19 @@ tableLayoutPanel1 = new TableLayoutPanel(); pictureBoxCollection = new PictureBox(); groupBox1 = new GroupBox(); + groupBox2 = new GroupBox(); + listBoxStorages = new ListBox(); + button1 = new Button(); + textBoxStorageName = new TextBox(); maskedTextBoxNumber = new MaskedTextBox(); buttonRefreshCollection = new Button(); buttonRemoveLocomotive = new Button(); buttonAddLocomotive = new Button(); + button2 = new Button(); tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); groupBox1.SuspendLayout(); + groupBox2.SuspendLayout(); SuspendLayout(); // // tableLayoutPanel1 @@ -69,7 +75,7 @@ // groupBox1 // groupBox1.Anchor = AnchorStyles.Top | AnchorStyles.Right; - groupBox1.AutoSize = true; + groupBox1.Controls.Add(groupBox2); groupBox1.Controls.Add(maskedTextBoxNumber); groupBox1.Controls.Add(buttonRefreshCollection); groupBox1.Controls.Add(buttonRemoveLocomotive); @@ -78,14 +84,52 @@ groupBox1.MaximumSize = new Size(200, 1000000); groupBox1.MinimumSize = new Size(200, 200); groupBox1.Name = "groupBox1"; - groupBox1.Size = new Size(200, 220); + groupBox1.Size = new Size(200, 444); groupBox1.TabIndex = 0; groupBox1.TabStop = false; groupBox1.Text = "Инструменты"; // + // groupBox2 + // + groupBox2.Controls.Add(button2); + groupBox2.Controls.Add(listBoxStorages); + groupBox2.Controls.Add(button1); + groupBox2.Controls.Add(textBoxStorageName); + groupBox2.Location = new Point(6, 26); + groupBox2.Name = "groupBox2"; + groupBox2.Size = new Size(188, 244); + groupBox2.TabIndex = 5; + groupBox2.TabStop = false; + groupBox2.Text = "Наборы"; + // + // listBoxStorages + // + listBoxStorages.FormattingEnabled = true; + listBoxStorages.ItemHeight = 20; + listBoxStorages.Location = new Point(6, 94); + listBoxStorages.Name = "listBoxStorages"; + listBoxStorages.Size = new Size(174, 104); + listBoxStorages.TabIndex = 2; + // + // button1 + // + button1.Location = new Point(4, 59); + button1.Name = "button1"; + button1.Size = new Size(176, 29); + button1.TabIndex = 1; + button1.Text = "Добавить набор"; + button1.UseVisualStyleBackColor = true; + // + // textBoxStorageName + // + textBoxStorageName.Location = new Point(6, 26); + textBoxStorageName.Name = "textBoxStorageName"; + textBoxStorageName.Size = new Size(176, 27); + textBoxStorageName.TabIndex = 0; + // // maskedTextBoxNumber // - maskedTextBoxNumber.Location = new Point(6, 97); + maskedTextBoxNumber.Location = new Point(10, 328); maskedTextBoxNumber.Mask = "00000"; maskedTextBoxNumber.Name = "maskedTextBoxNumber"; maskedTextBoxNumber.Size = new Size(184, 27); @@ -94,7 +138,7 @@ // // buttonRefreshCollection // - buttonRefreshCollection.Location = new Point(6, 165); + buttonRefreshCollection.Location = new Point(10, 396); buttonRefreshCollection.Name = "buttonRefreshCollection"; buttonRefreshCollection.Size = new Size(184, 29); buttonRefreshCollection.TabIndex = 3; @@ -104,7 +148,7 @@ // // buttonRemoveLocomotive // - buttonRemoveLocomotive.Location = new Point(6, 130); + buttonRemoveLocomotive.Location = new Point(10, 361); buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; buttonRemoveLocomotive.Size = new Size(184, 29); buttonRemoveLocomotive.TabIndex = 2; @@ -114,13 +158,21 @@ // // buttonAddLocomotive // - buttonAddLocomotive.Location = new Point(6, 26); + buttonAddLocomotive.Location = new Point(10, 293); buttonAddLocomotive.Name = "buttonAddLocomotive"; buttonAddLocomotive.Size = new Size(184, 29); buttonAddLocomotive.TabIndex = 0; buttonAddLocomotive.Text = "Добавить локомотив"; buttonAddLocomotive.UseVisualStyleBackColor = true; - buttonAddLocomotive.Click += buttonAddLocomotive_Click; + // + // button2 + // + button2.Location = new Point(4, 204); + button2.Name = "button2"; + button2.Size = new Size(176, 29); + button2.TabIndex = 3; + button2.Text = "Добавить набор"; + button2.UseVisualStyleBackColor = true; // // FormLocomotiveCollection // @@ -132,10 +184,11 @@ Name = "FormLocomotiveCollection"; Text = "FormLocomotiveCollection"; tableLayoutPanel1.ResumeLayout(false); - tableLayoutPanel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); groupBox1.ResumeLayout(false); groupBox1.PerformLayout(); + groupBox2.ResumeLayout(false); + groupBox2.PerformLayout(); ResumeLayout(false); PerformLayout(); } @@ -149,5 +202,10 @@ private Button buttonRemoveLocomotive; private Button buttonRefreshCollection; private MaskedTextBox maskedTextBoxNumber; + private GroupBox groupBox2; + private TextBox textBoxStorageName; + private Button button1; + private ListBox listBoxStorages; + private Button button2; } } \ No newline at end of file diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs index 182f1f0..5cd4d0a 100644 --- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs @@ -91,7 +91,7 @@ namespace ProjectElectricLocomotive.Generics /// public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } /// @@ -133,12 +133,13 @@ namespace ProjectElectricLocomotive.Generics /// private void DrawObjects(Graphics g) { - for (int i = 0; i < _collection.Count; i++) + foreach (var locomotive in _collection.GetLocomotives()) { - DrawningLocomotive drawningLocomotive = _collection.Get(i); - if (drawningLocomotive == null) + if (locomotive != null) { - continue; + //int widthCount = _pictureHeight / _placeSizeHeight; + //locomotive.SetPosition((i / widthCount) * _placeSizeWidth, (i % widthCount) * _placeSizeHeight); + locomotive.DrawTransport(g); } int ColumnCount = _pictureWidth / _placeSizeWidth; diff --git a/ElectricLocomotive/Generics/SetGeneric.cs b/ElectricLocomotive/Generics/SetGeneric.cs index 0750fd2..c944c32 100644 --- a/ElectricLocomotive/Generics/SetGeneric.cs +++ b/ElectricLocomotive/Generics/SetGeneric.cs @@ -14,20 +14,25 @@ namespace ProjectElectricLocomotive.Generics where T : class { /// - /// Массив объектов, которые храним + /// Список объектов, которые храним /// - private readonly T?[] _places; + private readonly List _places; /// /// Количество объектов в массиве /// - public int Count => _places.Length; + public int Count => _places.Count; + /// + /// Максимальное количество объектов в списке + /// + private readonly int _maxCount; /// /// Конструктор /// /// public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } /// @@ -36,11 +41,11 @@ namespace ProjectElectricLocomotive.Generics /// Первый элемент /// Второй элемент /// - private void swap(ref T first, ref T second) + private void swap(int index1, int index2) { - T temp = first; - first = second; - second = temp; + T temp = _places[index1]; + _places[index1] = _places[index2]; + _places[index2] = temp; } /// @@ -50,8 +55,8 @@ namespace ProjectElectricLocomotive.Generics /// public bool Insert(T locomotive) { - int end = _places.Length; - for (int i = 0; i < _places.Length; ++i) + int end = Count; + for (int i = 0; i < Count; ++i) { if (_places[i] == null) { @@ -59,7 +64,7 @@ namespace ProjectElectricLocomotive.Generics break; } } - if (end == _places.Length) + if (end == Count) { return false; } @@ -78,7 +83,7 @@ namespace ProjectElectricLocomotive.Generics /// public bool Insert(T locomotive, int position) { - if (position >= _places.Length || position < 0) + if (position >= Count || position < 0) { return false; } @@ -87,8 +92,8 @@ namespace ProjectElectricLocomotive.Generics _places[position] = locomotive; return true; } - int end = _places.Length; - for (int i = position; i < _places.Length; ++i) + int end = Count; + for (int i = position; i < Count; ++i) { if (_places[i] == null) { @@ -96,14 +101,14 @@ namespace ProjectElectricLocomotive.Generics break; } } - if (end == _places.Length) + if (end == Count) { return false; } _places[end] = locomotive; for (int i = position; i < end; ++i) { - swap(ref _places[i], ref _places[end]); + swap(i, end); } return true; } @@ -114,7 +119,7 @@ namespace ProjectElectricLocomotive.Generics /// public bool Remove(int position) { - if (position >= _places.Length || position < 0) + if (position >= Count || position < 0) { return false; } @@ -128,13 +133,38 @@ namespace ProjectElectricLocomotive.Generics /// /// /// - public T? Get(int position) + public T? this[int position] { - if (position >= _places.Length || position < 0) + get { - return null; + if (position >= Count || position < 0) + { + return null; + } + return _places[position]; + } + set + { + // TODO проверка позиции + // TODO проверка свободных мест в списке + // TODO вставка в список по позиции + } + } + + /// + /// Проход по списку + /// + /// + public IEnumerable GetLocomotives(int? maxLocomotives = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxLocomotives.HasValue && i == maxLocomotives.Value) + { + yield break; + } } - return _places[position]; } } diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index 065adab..a81861f 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -18,19 +18,88 @@ namespace ProjectElectricLocomotive /// /// Набор объектов /// - private readonly LocomotivesGenericCollection< - DrawningLocomotive, DrawningObjectLocomotive> _locomotives; + private readonly LocomotivesGenericStorage _storage; /// /// Конструктор /// public FormLocomotiveCollection() { InitializeComponent(); - _locomotives = new LocomotivesGenericCollection( - pictureBoxCollection.Width, pictureBoxCollection.Height + _storage = new LocomotivesGenericStorage( + pictureBoxCollection.Width, + pictureBoxCollection.Height ); } + /// + /// Заполнение 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(); + } + } + /// /// Добавление объекта в набор /// @@ -38,13 +107,23 @@ namespace ProjectElectricLocomotive /// 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; + } + FormLocomotive form = new(); if (form.ShowDialog() == DialogResult.OK) { if (_locomotives + form.SelectedLocomotive > 0) { MessageBox.Show("Объект добавлен"); - pictureBoxCollection.Image = _locomotives.ShowLocomotives(); + pictureBoxCollection.Image = obj.ShowLocomotives(); } else { @@ -59,6 +138,15 @@ namespace ProjectElectricLocomotive /// private void ButtonRemoveLocomotive_Click(object sender, EventArgs e) { + 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) @@ -69,7 +157,7 @@ namespace ProjectElectricLocomotive if (_locomotives - pos != -1) { MessageBox.Show("Объект удален"); - pictureBoxCollection.Image = _locomotives.ShowLocomotives(); + pictureBoxCollection.Image = obj.ShowLocomotives(); } else { @@ -83,7 +171,13 @@ namespace ProjectElectricLocomotive /// 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]; + + pictureBoxCollection.Image = obj.ShowLocomotives(); } } } -- 2.25.1 From 0d25d56f0f98b6f6db32b14b23d46e5fe7a3b719 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 10:36:16 +0400 Subject: [PATCH 5/7] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.Designer.cs | 47 ++++++----- .../FormLocomotiveCollection.cs | 20 ++++- .../Generics/LocomotivesGenericCollection.cs | 16 ++-- .../Generics/LocomotivesGenericStorage.cs | 83 +++++++++++++++++++ ElectricLocomotive/Generics/SetGeneric.cs | 66 ++------------- .../LogicFormLocomotiveCollection.cs | 10 +-- 6 files changed, 145 insertions(+), 97 deletions(-) create mode 100644 ElectricLocomotive/Generics/LocomotivesGenericStorage.cs diff --git a/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index 388d09e..3879f89 100644 --- a/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -32,14 +32,14 @@ pictureBoxCollection = new PictureBox(); groupBox1 = new GroupBox(); groupBox2 = new GroupBox(); + buttonDelObject = new Button(); listBoxStorages = new ListBox(); - button1 = new Button(); + buttonAddObject = new Button(); textBoxStorageName = new TextBox(); maskedTextBoxNumber = new MaskedTextBox(); buttonRefreshCollection = new Button(); buttonRemoveLocomotive = new Button(); buttonAddLocomotive = new Button(); - button2 = new Button(); tableLayoutPanel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); groupBox1.SuspendLayout(); @@ -91,9 +91,9 @@ // // groupBox2 // - groupBox2.Controls.Add(button2); + groupBox2.Controls.Add(buttonDelObject); groupBox2.Controls.Add(listBoxStorages); - groupBox2.Controls.Add(button1); + groupBox2.Controls.Add(buttonAddObject); groupBox2.Controls.Add(textBoxStorageName); groupBox2.Location = new Point(6, 26); groupBox2.Name = "groupBox2"; @@ -102,6 +102,16 @@ groupBox2.TabStop = false; groupBox2.Text = "Наборы"; // + // buttonDelObject + // + buttonDelObject.Location = new Point(4, 204); + buttonDelObject.Name = "buttonDelObject"; + buttonDelObject.Size = new Size(176, 29); + buttonDelObject.TabIndex = 3; + buttonDelObject.Text = "Удалить набор"; + buttonDelObject.UseVisualStyleBackColor = true; + buttonDelObject.Click += buttonDelObject_Click; + // // listBoxStorages // listBoxStorages.FormattingEnabled = true; @@ -110,15 +120,17 @@ listBoxStorages.Name = "listBoxStorages"; listBoxStorages.Size = new Size(174, 104); listBoxStorages.TabIndex = 2; + listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged; // - // button1 + // buttonAddObject // - button1.Location = new Point(4, 59); - button1.Name = "button1"; - button1.Size = new Size(176, 29); - button1.TabIndex = 1; - button1.Text = "Добавить набор"; - button1.UseVisualStyleBackColor = true; + buttonAddObject.Location = new Point(4, 59); + buttonAddObject.Name = "buttonAddObject"; + buttonAddObject.Size = new Size(176, 29); + buttonAddObject.TabIndex = 1; + buttonAddObject.Text = "Добавить набор"; + buttonAddObject.UseVisualStyleBackColor = true; + buttonAddObject.Click += buttonAddObject_Click; // // textBoxStorageName // @@ -165,15 +177,6 @@ buttonAddLocomotive.Text = "Добавить локомотив"; buttonAddLocomotive.UseVisualStyleBackColor = true; // - // button2 - // - button2.Location = new Point(4, 204); - button2.Name = "button2"; - button2.Size = new Size(176, 29); - button2.TabIndex = 3; - button2.Text = "Добавить набор"; - button2.UseVisualStyleBackColor = true; - // // FormLocomotiveCollection // AutoScaleDimensions = new SizeF(8F, 20F); @@ -204,8 +207,8 @@ private MaskedTextBox maskedTextBoxNumber; private GroupBox groupBox2; private TextBox textBoxStorageName; - private Button button1; + private Button buttonAddObject; private ListBox listBoxStorages; - private Button button2; + private Button buttonDelObject; } } \ No newline at end of file diff --git a/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/FormLocomotiveCollection.cs index 3ce62d8..8c29ce8 100644 --- a/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/FormLocomotiveCollection.cs @@ -12,10 +12,7 @@ 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) { @@ -26,5 +23,20 @@ namespace ProjectElectricLocomotive { ButtonRefreshCollection_Click(sender, e); } + + private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) + { + ListBoxObjects_SelectedIndexChanged(sender, e); + } + + private void buttonAddObject_Click(object sender, EventArgs e) + { + ButtonAddObject_Click(sender, e); + } + + private void buttonDelObject_Click(object sender, EventArgs e) + { + ButtonDelObject_Click(sender, e); + } } } diff --git a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs index 5cd4d0a..8351883 100644 --- a/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/Generics/LocomotivesGenericCollection.cs @@ -62,7 +62,7 @@ namespace ProjectElectricLocomotive.Generics { return 0; } - if (collect?._collection.Insert(obj) ?? false) + if (collect?._collection.Insert(obj) ?? false) { return collect._collection.Count; } @@ -77,7 +77,7 @@ namespace ProjectElectricLocomotive.Generics public static int operator -(LocomotivesGenericCollection collect, int pos) { - T? obj = collect._collection.Get(pos); + T? obj = collect._collection[pos]; if (obj != null && collect._collection.Remove(pos)) { return collect._collection.Count; @@ -133,19 +133,19 @@ namespace ProjectElectricLocomotive.Generics /// private void DrawObjects(Graphics g) { + int ColumnCount = _pictureWidth / _placeSizeWidth; + int RowsCount = _pictureHeight / _placeSizeHeight; + int pos = 0; foreach (var locomotive in _collection.GetLocomotives()) { if (locomotive != null) { - //int widthCount = _pictureHeight / _placeSizeHeight; - //locomotive.SetPosition((i / widthCount) * _placeSizeWidth, (i % widthCount) * _placeSizeHeight); + locomotive.SetPosition((pos % ColumnCount) * _placeSizeWidth, ((RowsCount - pos / ColumnCount - 1) * _placeSizeHeight)); locomotive.DrawTransport(g); } - int ColumnCount = _pictureWidth / _placeSizeWidth; - int RowsCount = _pictureHeight / _placeSizeHeight; - drawningLocomotive.SetPosition((i % ColumnCount) * _placeSizeWidth, ((RowsCount - i / ColumnCount - 1) * _placeSizeHeight)); - drawningLocomotive.DrawTransport(g); + + } } } diff --git a/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs b/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs new file mode 100644 index 0000000..fabb576 --- /dev/null +++ b/ElectricLocomotive/Generics/LocomotivesGenericStorage.cs @@ -0,0 +1,83 @@ +using ProjectElectricLocomotive.DrawningObjects; +using ProjectElectricLocomotive.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive.Generics +{ + /// + /// Класс для хранения коллекции + /// + internal class LocomotivesGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary + > _locomotiveStorage; + + /// + /// Возвращение списка названий наборов + /// + public List Keys => _locomotiveStorage.Keys.ToList(); + + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + + /// + /// Конструктор + /// + /// + /// + public LocomotivesGenericStorage(int pictureWidth, int pictureHeight) + { + _locomotiveStorage = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + + } + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + // TODO Прописать логику для удаления + } + /// + /// Доступ к набору + /// + /// + /// + public LocomotivesGenericCollection? this[string ind] + { + get + { + // TODO Продумать логику получения набора + return null; + } + + } + } +} diff --git a/ElectricLocomotive/Generics/SetGeneric.cs b/ElectricLocomotive/Generics/SetGeneric.cs index c944c32..6ca43f5 100644 --- a/ElectricLocomotive/Generics/SetGeneric.cs +++ b/ElectricLocomotive/Generics/SetGeneric.cs @@ -35,19 +35,6 @@ namespace ProjectElectricLocomotive.Generics _places = new List(count); } - /// - /// обмен двух элементов - /// - /// Первый элемент - /// Второй элемент - /// - private void swap(int index1, int index2) - { - T temp = _places[index1]; - _places[index1] = _places[index2]; - _places[index2] = temp; - } - /// /// Добавление объекта в набор /// @@ -55,24 +42,10 @@ namespace ProjectElectricLocomotive.Generics /// public bool Insert(T locomotive) { - int end = Count; - for (int i = 0; i < Count; ++i) - { - if (_places[i] == null) - { - end = i; - break; - } - } - if (end == Count) - { + if (_places.Count >= _maxCount) { return false; } - for (int i = end; i >= 1; --i) - { - _places[i] = _places[i - 1]; - } - _places[0] = locomotive; + _places.Insert(0, locomotive); return true; } /// @@ -83,33 +56,11 @@ namespace ProjectElectricLocomotive.Generics /// public bool Insert(T locomotive, int position) { - if (position >= Count || position < 0) + if (_places.Count >= _maxCount || position >= 0 || position <= _places.Count) { return false; } - if (_places[position] == null) - { - _places[position] = locomotive; - return true; - } - int end = Count; - for (int i = position; i < Count; ++i) - { - if (_places[i] == null) - { - end = i; - break; - } - } - if (end == Count) - { - return false; - } - _places[end] = locomotive; - for (int i = position; i < end; ++i) - { - swap(i, end); - } + _places.Insert(position, locomotive); return true; } /// @@ -124,7 +75,7 @@ namespace ProjectElectricLocomotive.Generics return false; } - _places[position] = null; + _places.RemoveAt(position); return true; } @@ -145,9 +96,10 @@ namespace ProjectElectricLocomotive.Generics } set { - // TODO проверка позиции - // TODO проверка свободных мест в списке - // TODO вставка в список по позиции + if (position < Count || position >= 0) + { + _places[position] = value; + } } } diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index a81861f..5acfa68 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -42,13 +42,11 @@ namespace ProjectElectricLocomotive { listBoxStorages.Items.Add(_storage.Keys[i]); } - if (listBoxStorages.Items.Count > 0 && (index == -1 || index - >= listBoxStorages.Items.Count)) + 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) + else if (listBoxStorages.Items.Count > 0 && index > -1 && index < listBoxStorages.Items.Count) { listBoxStorages.SelectedIndex = index; } @@ -120,7 +118,7 @@ namespace ProjectElectricLocomotive FormLocomotive form = new(); if (form.ShowDialog() == DialogResult.OK) { - if (_locomotives + form.SelectedLocomotive > 0) + if (obj + form.SelectedLocomotive > 0) { MessageBox.Show("Объект добавлен"); pictureBoxCollection.Image = obj.ShowLocomotives(); @@ -154,7 +152,7 @@ namespace ProjectElectricLocomotive return; } int pos = Convert.ToInt32(maskedTextBoxNumber.Text); - if (_locomotives - pos != -1) + if (obj - pos != -1) { MessageBox.Show("Объект удален"); pictureBoxCollection.Image = obj.ShowLocomotives(); -- 2.25.1 From 85704d9e33cf6aa3768406a1400d8adea44ad18c Mon Sep 17 00:00:00 2001 From: bekodeg Date: Wed, 25 Oct 2023 11:03:02 +0400 Subject: [PATCH 6/7] =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=204=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.cs | 10 +-- .../LogicFormLocomotiveCollection.cs | 72 ++++++++++++++++++- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/FormLocomotiveCollection.cs index 8c29ce8..60aefa7 100644 --- a/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/FormLocomotiveCollection.cs @@ -24,11 +24,6 @@ namespace ProjectElectricLocomotive ButtonRefreshCollection_Click(sender, e); } - private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) - { - ListBoxObjects_SelectedIndexChanged(sender, e); - } - private void buttonAddObject_Click(object sender, EventArgs e) { ButtonAddObject_Click(sender, e); @@ -38,5 +33,10 @@ namespace ProjectElectricLocomotive { ButtonDelObject_Click(sender, e); } + + private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e) + { + ListBoxObjects_SelectedIndexChanged(sender, e); + } } } diff --git a/ElectricLocomotive/LogicFormLocomotiveCollection.cs b/ElectricLocomotive/LogicFormLocomotiveCollection.cs index 5acfa68..a39d3fe 100644 --- a/ElectricLocomotive/LogicFormLocomotiveCollection.cs +++ b/ElectricLocomotive/LogicFormLocomotiveCollection.cs @@ -98,6 +98,73 @@ namespace ProjectElectricLocomotive } } + /// + /// Заполнение 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(); + } + } + /// /// Добавление объекта в набор /// @@ -174,7 +241,10 @@ namespace ProjectElectricLocomotive return; } var obj = _storage[listBoxStorages.SelectedItem.ToString() ?? string.Empty]; - + if (obj == null) + { + return; + } pictureBoxCollection.Image = obj.ShowLocomotives(); } } -- 2.25.1 From c6059a9dfadcc1a7b78b2c5234b22faf1af83a37 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Sat, 4 Nov 2023 11:34:17 +0400 Subject: [PATCH 7/7] =?UTF-8?q?4=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=84=D0=B8=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.Designer.cs | 1 + .../FormLocomotiveCollection.cs | 6 +- .../Generics/LocomotivesGenericCollection.cs | 6 +- .../Generics/LocomotivesGenericStorage.cs | 21 +++++-- .../LogicFormLocomotiveCollection.cs | 56 ------------------- 5 files changed, 24 insertions(+), 66 deletions(-) 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(); - } - } /// /// Добавление объекта в набор -- 2.25.1