From ebf367ef84966e0946cc4702c06416d15341d7cf Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 29 Oct 2023 19:02:01 +0400 Subject: [PATCH 1/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20SetGeneri?= =?UTF-8?q?c=20(=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=204=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D1=8B).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ElectricLocomotive/SetGeneric.cs | 129 ++++++++++++------ 1 file changed, 84 insertions(+), 45 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 60c65ce..223eb4d 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -7,59 +7,98 @@ using System.Threading.Tasks; namespace ProjectElectricLocomotive.Generics { internal class SetGeneric - where T : class + where T : class { - private readonly T?[] _places; - public int Count => _places.Length; + /// + /// Список объектов, которые храним + /// + private readonly List _places; + /// + /// Количество объектов в массиве + /// + public int Count => _places.Count; + /// + /// Максимальное количество объектов в списке + /// + private readonly int _maxCount; + /// + /// Конструктор + /// + /// public SetGeneric(int count) { - _places = new T?[count]; + _maxCount = count; + _places = new List(count); } - public int Insert(T locomotive) + /// + /// Добавление объекта в набор + /// + /// Добавляемый автомобиль + /// + public bool Insert(T car) { - return Insert(locomotive, 0); - } - public int Insert(T locomotive, int position) - { - int Full = 0; - int temp = 0; - for (int i = position; i < Count; i++) - { - if (_places[i] != null) Full++; - } - if (Full == Count - position - 1) - return -1; - if (position < Count && position >= 0) - { - for (int j = position; j < Count; j++) - { - if (_places[j] == null) - { - temp = j; - break; - } - } - for (int i = temp; i > position; i--) - { - _places[i] = _places[i - 1]; - } - _places[position] = locomotive; - return position; - } - return -1; - } - public bool Remove(int position) - { - if (position >= Count || position < 0) - if (!(position >= 0 && position < Count) || _places[position] == null) - return false; - _places[position] = null; + // TODO вставка в начало набора return true; } - public T Get(int position) + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автомобиль + /// Позиция + /// + public bool Insert(T car, int position) { - if (position < 0 || position >= Count) return null; - return _places[position]; + // TODO проверка позиции + // TODO проверка, что есть место для вставки + // TODO вставка по позиции + _places[position] = car; + return true; + } + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из списка + return true; + } + /// + /// Получение объекта из набора по позиции + /// + /// + /// + public T? this[int position] + { + get + { + // TODO проверка позиции + return _places[position]; + } + set + { + // TODO проверка позиции + // TODO проверка свободных мест в списке + // TODO вставка в список по позиции + } + } + /// + /// Проход по списку + /// + /// + public IEnumerable GetCars(int? maxCars = null) + { + for (int i = 0; i < _places.Count; ++i) + { + yield return _places[i]; + if (maxCars.HasValue && i == maxCars.Value) + { + yield break; + } + } } } + } -- 2.25.1 From 93037118d634cf81bec4d2c93fbcef501002c271 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 29 Oct 2023 19:18:46 +0400 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B2=20CarsGenericCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocomotivesGenericCollection.cs | 18 +++---- .../ElectricLocomotive/SetGeneric.cs | 48 ++----------------- 2 files changed, 15 insertions(+), 51 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index aaa36a9..e1f05ad 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -31,18 +31,20 @@ namespace ProjectElectricLocomotive.Generics { return -1; } - return collect?._collection.Insert(locomotive) ?? -1; + return collect._collection.Insert(locomotive); } - public static bool operator -(LocomotivesGenericCollection collect, int pos) + public static T? operator -(LocomotivesGenericCollection collect, int pos) { - T? locomotive = collect._collection.Get(pos); - if (locomotive != null) - return collect._collection.Remove(pos); - return false; + T? obj = collect._collection[pos]; + if (obj != null) + { + collect._collection.Remove(pos); + } + return obj; } public U? GetU(int pos) { - return (U?)_collection.Get(pos)?.GetMoveableObject; + return (U?)_collection[pos]?.GetMoveableObject; } public Bitmap ShowLocomotives() { @@ -74,7 +76,7 @@ namespace ProjectElectricLocomotive.Generics int Wloco = _pictureWidth / _placeSizeWidth; for (int i = 0; i < _collection.Count; i++) { - T? type = _collection.Get(i); + T? type = _collection[i]; if (type != null) { type.SetPosition( diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 223eb4d..89b6709 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -9,67 +9,33 @@ namespace ProjectElectricLocomotive.Generics internal class SetGeneric where T : class { - /// - /// Список объектов, которые храним - /// private readonly List _places; - /// - /// Количество объектов в массиве - /// public int Count => _places.Count; - /// - /// Максимальное количество объектов в списке - /// private readonly int _maxCount; - /// - /// Конструктор - /// - /// public SetGeneric(int count) { _maxCount = count; _places = new List(count); } - /// - /// Добавление объекта в набор - /// - /// Добавляемый автомобиль - /// - public bool Insert(T car) + public bool Insert(T locomotive) { // TODO вставка в начало набора return true; } - /// - /// Добавление объекта в набор на конкретную позицию - /// - /// Добавляемый автомобиль - /// Позиция - /// - public bool Insert(T car, int position) + public bool Insert(T locomotive, int position) { // TODO проверка позиции // TODO проверка, что есть место для вставки // TODO вставка по позиции - _places[position] = car; + _places[position] = locomotive; return true; } - /// - /// Удаление объекта из набора с конкретной позиции - /// - /// - /// public bool Remove(int position) { // TODO проверка позиции // TODO удаление объекта из списка return true; } - /// - /// Получение объекта из набора по позиции - /// - /// - /// public T? this[int position] { get @@ -84,16 +50,12 @@ namespace ProjectElectricLocomotive.Generics // TODO вставка в список по позиции } } - /// - /// Проход по списку - /// - /// - public IEnumerable GetCars(int? maxCars = null) + public IEnumerable GetLocos(int? maxLocos = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; - if (maxCars.HasValue && i == maxCars.Value) + if (maxLocos.HasValue && i == maxLocos.Value) { yield break; } -- 2.25.1 From c9b0d52c9f03bf79606d64a0051ce415f10760d7 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 29 Oct 2023 19:23:13 +0400 Subject: [PATCH 3/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20LocomotivesGene?= =?UTF-8?q?ricStorage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocomotivesGenericStorage.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs new file mode 100644 index 0000000..97e93ff --- /dev/null +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs @@ -0,0 +1,72 @@ +using ProjectElectricLocomotive.DrawingObjects; +using ProjectElectricLocomotive.Generics; +using ProjectElectricLocomotive.MovementStrategy; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive +{ + internal class LocomotivesGenericStorage + { + /// + /// Словарь (хранилище) + /// + readonly Dictionary> _locomotivesStorage; + /// Возвращение списка названий наборов + /// + public List Keys => _locomotivesStorage.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// + public LocomotivesGenericStorage(int pictureWidth, int pictureHeight) + { + _locomotivesStorage = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление набора + /// + /// Название набора + public void AddSet(string name) + { + // TODO Прописать логику для добавления + } + /// + /// Удаление набора + /// + /// Название набора + public void DelSet(string name) + { + // TODO Прописать логику для удаления + } + /// + /// Доступ к набору + /// + /// + /// + public LocomotivesGenericCollection? + this[string ind] + { + get + { + // TODO Продумать логику получения набора + return null; + } + } + + } +} -- 2.25.1 From 1f66a0689be9fa0ba60694061131995c5d8f62e2 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 29 Oct 2023 19:44:58 +0400 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9D=D0=B5=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=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 --- .../FormElectricLocomotive.Designer.cs | 2 - .../FormElectricLocomotive.cs | 11 ------ .../FormLocomotiveCollection.Designer.cs | 4 -- .../FormLocomotiveCollection.cs | 11 ------ .../ElectricLocomotive/SetGeneric.cs | 38 +++++++++---------- 5 files changed, 19 insertions(+), 47 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.Designer.cs index a44ff89..e0ab159 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.Designer.cs @@ -132,7 +132,6 @@ namespace ElectricLocomotive comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(151, 23); comboBoxStrategy.TabIndex = 6; - comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged; // // buttonCreateLocomotive // @@ -189,7 +188,6 @@ namespace ElectricLocomotive Name = "FormElectricLocomotive"; StartPosition = FormStartPosition.CenterScreen; Text = "ElectricLocomotive"; - Load += ElectricLocomotive_Load; ((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).EndInit(); ResumeLayout(false); PerformLayout(); diff --git a/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.cs b/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.cs index cee1fea..3f4d731 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormElectricLocomotive.cs @@ -123,17 +123,6 @@ namespace ElectricLocomotive _abstractStrategy = null; } } - private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e) - { - - } - private void pictureBoxElectricLocomotive_Click(object sender, EventArgs e) - { - - } - private void ElectricLocomotive_Load(object sender, EventArgs e) - { - } private void ButtonSelectLocomotive_Click(object sender, EventArgs e) { SelectedLocomotive = _drawingLocomotive; diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index e829010..fc46811 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -54,7 +54,6 @@ panelLocomotiveCollection.Size = new Size(208, 448); panelLocomotiveCollection.TabIndex = 0; panelLocomotiveCollection.Tag = "Инструменты"; - panelLocomotiveCollection.Paint += panelLocomotiveCollection_Paint; // // maskedTextBoxNumber // @@ -109,7 +108,6 @@ LabelOnPanel.Size = new Size(83, 15); LabelOnPanel.TabIndex = 4; LabelOnPanel.Text = "Инструменты"; - LabelOnPanel.Click += LabelOnPanel_Click; // // FormLocomotiveCollection // @@ -120,13 +118,11 @@ Controls.Add(panelLocomotiveCollection); Name = "FormLocomotiveCollection"; Text = "Набор локомотивов"; - Load += FormLocomotiveCollection_Load; panelLocomotiveCollection.ResumeLayout(false); panelLocomotiveCollection.PerformLayout(); ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); ResumeLayout(false); } - #endregion private Panel panelLocomotiveCollection; diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index cda95cd..37e92c1 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -60,16 +60,5 @@ namespace ProjectElectricLocomotive { pictureBoxCollection.Image = _locomotives.ShowLocomotives(); } - private void FormLocomotiveCollection_Load(object sender, EventArgs e) - { - } - private void LabelOnPanel_Click(object sender, EventArgs e) - { - - } - private void panelLocomotiveCollection_Paint(object sender, PaintEventArgs e) - { - - } } } diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 89b6709..7ce9c5b 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -17,45 +17,45 @@ namespace ProjectElectricLocomotive.Generics _maxCount = count; _places = new List(count); } - public bool Insert(T locomotive) + public int Insert(T locomotive) { - // TODO вставка в начало набора - return true; + return Insert(locomotive, 0); } - public bool Insert(T locomotive, int position) + public int Insert(T locomotive, int position) { - // TODO проверка позиции - // TODO проверка, что есть место для вставки - // TODO вставка по позиции - _places[position] = locomotive; - return true; + if (position < 0 || position >= _maxCount) return -1; + _places.Insert(position, locomotive); + return position; } - public bool Remove(int position) + public T? Remove(int position) { - // TODO проверка позиции - // TODO удаление объекта из списка - return true; + if (position >= Count || position < 0) + { + return null; + } + T? tmp = _places[position]; + _places[position] = null; + return tmp; } public T? this[int position] { get { - // TODO проверка позиции + if (position < 0 || position >= Count) return null; return _places[position]; } set { - // TODO проверка позиции - // TODO проверка свободных мест в списке - // TODO вставка в список по позиции + if (position < 0 || position >= Count || Count == _maxCount) return; + _places.Insert(position, value); } } - public IEnumerable GetLocos(int? maxLocos = null) + public IEnumerable GetLocomotives(int? maxLocomotives = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; - if (maxLocos.HasValue && i == maxLocos.Value) + if (maxLocomotives.HasValue && i == maxLocomotives.Value) { yield break; } -- 2.25.1 From e5619197bc6b3520b2f69f12035dbf09bfe72ac5 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 29 Oct 2023 21:15:03 +0400 Subject: [PATCH 5/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormLocomotiveCollection.Designer.cs | 142 +++++++++++++----- .../FormLocomotiveCollection.cs | 90 +++++++++-- 2 files changed, 181 insertions(+), 51 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs index fc46811..1b467de 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs index 37e92c1..ae6a12f 100644 --- a/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/FormLocomotiveCollection.cs @@ -16,21 +16,47 @@ namespace ProjectElectricLocomotive { public partial class FormLocomotiveCollection : Form { - private readonly LocomotivesGenericCollection _locomotives; + private readonly LocomotivesGenericStorage _storage; public FormLocomotiveCollection() { InitializeComponent(); - _locomotives = new LocomotivesGenericCollection(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(); + } } } } -- 2.25.1 From 275b551026da74f30aa6b355081381cb617318a8 Mon Sep 17 00:00:00 2001 From: tellsense Date: Sun, 29 Oct 2023 21:27:26 +0400 Subject: [PATCH 6/6] =?UTF-8?q?4=20=D0=BB=D0=B0=D0=B1=D0=B0=20=D0=B3=D0=BE?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocomotivesGenericCollection.cs | 2 +- .../LocomotivesGenericStorage.cs | 31 +++++++++++++------ .../ElectricLocomotive/SetGeneric.cs | 28 +++++++++++------ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index e1f05ad..51de520 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -15,7 +15,7 @@ namespace ProjectElectricLocomotive.Generics private readonly int _pictureWidth; private readonly int _pictureHeight; private readonly int _placeSizeWidth = 200; - private readonly int _placeSizeHeight = 90; + private readonly int _placeSizeHeight = 120; private readonly SetGeneric _collection; public LocomotivesGenericCollection(int picWidth, int picHeight) { diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs index 97e93ff..f29cdff 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs @@ -15,17 +15,17 @@ namespace ProjectElectricLocomotive /// Словарь (хранилище) /// readonly Dictionary> _locomotivesStorage; + + /// /// Возвращение списка названий наборов /// public List Keys => _locomotivesStorage.Keys.ToList(); - /// - /// Ширина окна отрисовки - /// + + private readonly int _pictureWidth; - /// - /// Высота окна отрисовки - /// + private readonly int _pictureHeight; + /// /// Конструктор /// @@ -43,16 +43,25 @@ namespace ProjectElectricLocomotive /// Название набора public void AddSet(string name) { - // TODO Прописать логику для добавления + if (!_locomotivesStorage.ContainsKey(name)) + { + _locomotivesStorage.Add(name, new LocomotivesGenericCollection(_pictureWidth, _pictureHeight)); + } } + /// /// Удаление набора /// /// Название набора public void DelSet(string name) { - // TODO Прописать логику для удаления + if (_locomotivesStorage.ContainsKey(name)) + { + _locomotivesStorage.Remove(name); + } } + + /// /// Доступ к набору /// @@ -63,10 +72,12 @@ namespace ProjectElectricLocomotive { get { - // TODO Продумать логику получения набора + if (_locomotivesStorage.ContainsKey(ind)) + { + return _locomotivesStorage[ind]; + } return null; } } - } } diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 7ce9c5b..7b52791 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -10,33 +10,40 @@ namespace ProjectElectricLocomotive.Generics where T : class { private readonly List _places; + public int Count => _places.Count; + + /// Максимальное количество объектов в списке private readonly int _maxCount; public SetGeneric(int count) { _maxCount = count; _places = new List(count); } - public int Insert(T locomotive) + + /// Добавление объекта в набор + public int Insert(T loco) { - return Insert(locomotive, 0); + return Insert(loco, 0); } - public int Insert(T locomotive, int position) + + public int Insert(T loco, int position) { if (position < 0 || position >= _maxCount) return -1; - _places.Insert(position, locomotive); + _places.Insert(position, loco); return position; } + public T? Remove(int position) { if (position >= Count || position < 0) - { return null; - } + T? tmp = _places[position]; _places[position] = null; return tmp; } + public T? this[int position] { get @@ -50,17 +57,20 @@ namespace ProjectElectricLocomotive.Generics _places.Insert(position, value); } } - public IEnumerable GetLocomotives(int? maxLocomotives = null) + /// + /// Проход по списку + /// + /// + public IEnumerable GetLocomotives(int? maxLocos = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; - if (maxLocomotives.HasValue && i == maxLocomotives.Value) + if (maxLocos.HasValue && i == maxLocos.Value) { yield break; } } } } - } -- 2.25.1