diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs index 4fbb3ae..bbabd0c 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.Designer.cs @@ -42,6 +42,8 @@ ButtonAddObject = new Button(); ButtonRemoveObject = new Button(); Instruments = new GroupBox(); + buttonSortByType = new Button(); + buttonSortByColor = new Button(); menuStrip1 = new MenuStrip(); файлToolStripMenuItem = new ToolStripMenuItem(); SaveToolStripMenuItem = new ToolStripMenuItem(); @@ -59,17 +61,18 @@ // maskedTextBoxNumber // maskedTextBoxNumber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - maskedTextBoxNumber.Location = new Point(38, 342); + maskedTextBoxNumber.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); + maskedTextBoxNumber.Location = new Point(38, 417); maskedTextBoxNumber.Mask = "00"; maskedTextBoxNumber.Name = "maskedTextBoxNumber"; - maskedTextBoxNumber.Size = new Size(156, 27); + maskedTextBoxNumber.Size = new Size(156, 26); maskedTextBoxNumber.TabIndex = 4; // // ButtonRefreshCollection // ButtonRefreshCollection.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonRefreshCollection.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); - ButtonRefreshCollection.Location = new Point(38, 412); + ButtonRefreshCollection.Location = new Point(38, 518); ButtonRefreshCollection.Name = "ButtonRefreshCollection"; ButtonRefreshCollection.Size = new Size(150, 29); ButtonRefreshCollection.TabIndex = 2; @@ -80,7 +83,7 @@ // ButtonRemoveLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonRemoveLocomotive.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); - ButtonRemoveLocomotive.Location = new Point(37, 375); + ButtonRemoveLocomotive.Location = new Point(38, 481); ButtonRemoveLocomotive.Name = "ButtonRemoveLocomotive"; ButtonRemoveLocomotive.Size = new Size(150, 31); ButtonRemoveLocomotive.TabIndex = 1; @@ -92,7 +95,7 @@ // ButtonAddLocomotive.Anchor = AnchorStyles.Top; ButtonAddLocomotive.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); - ButtonAddLocomotive.Location = new Point(38, 306); + ButtonAddLocomotive.Location = new Point(38, 381); ButtonAddLocomotive.Name = "ButtonAddLocomotive"; ButtonAddLocomotive.Size = new Size(150, 30); ButtonAddLocomotive.TabIndex = 0; @@ -103,32 +106,30 @@ // pictureBoxCollections // pictureBoxCollections.Anchor = AnchorStyles.Left; - pictureBoxCollections.Location = new Point(-1, 31); + pictureBoxCollections.Location = new Point(0, 31); pictureBoxCollections.Name = "pictureBoxCollections"; - pictureBoxCollections.Size = new Size(303, 409); + pictureBoxCollections.Size = new Size(303, 523); pictureBoxCollections.TabIndex = 1; pictureBoxCollections.TabStop = false; // // textBoxStorageName // textBoxStorageName.Location = new Point(31, 28); - textBoxStorageName.Margin = new Padding(3, 4, 3, 4); textBoxStorageName.Name = "textBoxStorageName"; textBoxStorageName.Size = new Size(149, 27); textBoxStorageName.TabIndex = 5; // // groupBox1 // - groupBox1.Anchor = AnchorStyles.None; groupBox1.Controls.Add(listBoxStorage); groupBox1.Controls.Add(ButtonAddObject); groupBox1.Controls.Add(ButtonRemoveObject); groupBox1.Controls.Add(textBoxStorageName); - groupBox1.Location = new Point(7, 29); - groupBox1.Margin = new Padding(3, 4, 3, 4); + groupBox1.Location = new Point(7, 18); + //groupBox1.Margin = new Padding(3, 4, 3, 4); groupBox1.Name = "groupBox1"; - groupBox1.Padding = new Padding(3, 4, 3, 4); - groupBox1.Size = new Size(216, 270); + //groupBox1.Padding = new Padding(3, 4, 3, 4); + groupBox1.Size = new Size(216, 280); groupBox1.TabIndex = 5; groupBox1.TabStop = false; groupBox1.Text = "Наборы"; @@ -160,7 +161,7 @@ // ButtonRemoveObject.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; ButtonRemoveObject.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); - ButtonRemoveObject.Location = new Point(31, 228); + ButtonRemoveObject.Location = new Point(31, 238); ButtonRemoveObject.Name = "ButtonRemoveObject"; ButtonRemoveObject.Size = new Size(149, 31); ButtonRemoveObject.TabIndex = 8; @@ -171,20 +172,46 @@ // Instruments // Instruments.Anchor = AnchorStyles.Right; + Instruments.Controls.Add(buttonSortByType); + Instruments.Controls.Add(buttonSortByColor); Instruments.Controls.Add(ButtonRefreshCollection); Instruments.Controls.Add(groupBox1); Instruments.Controls.Add(maskedTextBoxNumber); Instruments.Controls.Add(ButtonAddLocomotive); Instruments.Controls.Add(ButtonRemoveLocomotive); - Instruments.Location = new Point(302, -1); + Instruments.Location = new Point(302, 0); Instruments.Margin = new Padding(3, 4, 3, 4); Instruments.Name = "Instruments"; Instruments.Padding = new Padding(3, 4, 3, 4); - Instruments.Size = new Size(236, 448); + Instruments.Size = new Size(236, 554); Instruments.TabIndex = 6; Instruments.TabStop = false; Instruments.Text = "Инструменты"; // + // buttonSortByType + // + buttonSortByType.Anchor = AnchorStyles.Top; + buttonSortByType.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonSortByType.Location = new Point(44, 305); + buttonSortByType.Name = "buttonSortByType"; + buttonSortByType.Size = new Size(150, 30); + buttonSortByType.TabIndex = 7; + buttonSortByType.Text = "Сортировать по типу"; + buttonSortByType.UseVisualStyleBackColor = true; + buttonSortByType.Click += buttonSortByType_Click; + // + // buttonSortByColor + // + buttonSortByColor.Anchor = AnchorStyles.Top; + buttonSortByColor.Font = new Font("Candara Light", 9F, FontStyle.Regular, GraphicsUnit.Point); + buttonSortByColor.Location = new Point(25, 341); + buttonSortByColor.Name = "buttonSortByColor"; + buttonSortByColor.Size = new Size(181, 30); + buttonSortByColor.TabIndex = 6; + buttonSortByColor.Text = "Сортировать по цвету"; + buttonSortByColor.UseVisualStyleBackColor = true; + buttonSortByColor.Click += buttonSortByColor_Click; + // // menuStrip1 // menuStrip1.ImageScalingSize = new Size(20, 20); @@ -229,7 +256,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(538, 443); + ClientSize = new Size(538, 554); Controls.Add(Instruments); Controls.Add(pictureBoxCollections); Controls.Add(menuStrip1); @@ -249,6 +276,11 @@ PerformLayout(); } + private void ButtonSortByColor_Click(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + #endregion private Button ButtonRefreshCollection; private Button ButtonRemoveLocomotive; @@ -269,5 +301,7 @@ private ToolStripMenuItem LoadToolStripMenuItem; private SaveFileDialog saveFileDialog; private OpenFileDialog openFileDialog; + private Button buttonSortByType; + private Button buttonSortByColor; } } \ No newline at end of file diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs index 1332dc1..060b842 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/FormLocomotiveCollections.cs @@ -61,7 +61,7 @@ namespace ProjectElectricLocomotive _logger.LogWarning("Неудачная попытка. Коллекция не добавлена, не все данные заполнены"); return; } - _storage.AddSet(textBoxStorageName.Text); + _storage.AddSet(textBoxStorageName.Text.ToString()); ReloadObjects(); _logger.LogInformation($"Добавлен набор: {textBoxStorageName.Text}"); @@ -115,7 +115,8 @@ namespace ProjectElectricLocomotive MessageBox.Show("Объект добавлен"); pictureBoxCollections.Image = obj.ShowLocomotives(); _logger.LogInformation($"Добавлен объект {obj}"); -; } + ; + } else { MessageBox.Show("Не удалось добавить объект"); @@ -219,5 +220,20 @@ namespace ProjectElectricLocomotive } } } + + private void buttonSortByType_Click(object sender, EventArgs e) => CompareLocos(new LocoCompareByType()); + + private void buttonSortByColor_Click(object sender, EventArgs e) => CompareLocos(new LocoCompareByColor()); + + public void CompareLocos(IComparer comparer) + { + if (listBoxStorage.SelectedIndex == -1) return; + + var obj = _storage[listBoxStorage.SelectedItem.ToString() ?? string.Empty]; + if(obj == null) return; + + obj.Sort(comparer); + pictureBoxCollections.Image = obj.ShowLocomotives(); + } } } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs index e137d59..b55136c 100644 --- a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocomotiveGenericStorage.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Xml.Linq; using ProjectElectricLocomotive.DrawingObjects; using ProjectElectricLocomotive.MovementStrategy; @@ -15,12 +16,12 @@ namespace ProjectElectricLocomotive.Generics /// /// Словарь (хранилище) /// - readonly Dictionary> _locomotivesStorage; + readonly Dictionary> _locomotivesStorage; /// /// Возвращение списка названий наборов /// - public List Keys => _locomotivesStorage.Keys.ToList(); + public List Keys => _locomotivesStorage.Keys.ToList(); private readonly int _pictureWidth; @@ -34,7 +35,7 @@ namespace ProjectElectricLocomotive.Generics /// public LocomotiveGenericStorage(int pictureWidth, int pictureHeight) { - _locomotivesStorage = new Dictionary>(); + _locomotivesStorage = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -44,9 +45,10 @@ namespace ProjectElectricLocomotive.Generics /// Название набора public void AddSet(string name) { - if (!_locomotivesStorage.ContainsKey(name)) + if (!_locomotivesStorage.ContainsKey(new LocosCollectionInfo(name, ""))) { - _locomotivesStorage.Add(name, new LocomotiveGenericCollection(_pictureWidth, _pictureHeight)); + _locomotivesStorage.Add(new LocosCollectionInfo(name, ""), + new LocomotiveGenericCollection(_pictureWidth, _pictureHeight)); } } @@ -56,9 +58,9 @@ namespace ProjectElectricLocomotive.Generics /// Название набора public void DelSet(string name) { - if (_locomotivesStorage.ContainsKey(name)) + if (_locomotivesStorage.ContainsKey(new LocosCollectionInfo(name, ""))) { - _locomotivesStorage.Remove(name); + _locomotivesStorage.Remove(new LocosCollectionInfo(name, "")); } } @@ -73,9 +75,9 @@ namespace ProjectElectricLocomotive.Generics { get { - if (_locomotivesStorage.ContainsKey(ind)) + if (_locomotivesStorage.ContainsKey(new LocosCollectionInfo(ind, ""))) { - return _locomotivesStorage[ind]; + return _locomotivesStorage[new LocosCollectionInfo(ind, "")]; } return null; } @@ -106,7 +108,7 @@ namespace ProjectElectricLocomotive.Generics File.Delete(filename); } StringBuilder data = new(); - foreach (KeyValuePair> record in _locomotivesStorage) + foreach (KeyValuePair> record in _locomotivesStorage) { StringBuilder records = new(); foreach (DrawingLocomotive? elem in record.Value.GetLocomotives) @@ -173,7 +175,7 @@ namespace ProjectElectricLocomotive.Generics } LocomotiveGenericCollection collection = new(_pictureWidth, _pictureHeight); string[] set = record[1].Split(_separatorRecords, StringSplitOptions.RemoveEmptyEntries); - foreach (string elem in set) + foreach (string elem in set/*.Reverse()*/) { DrawingLocomotive? loco = elem?.CreateDrawingLocomotive(_separatorForObject, _pictureWidth, _pictureHeight); if (loco != null) @@ -184,7 +186,8 @@ namespace ProjectElectricLocomotive.Generics } } } - _locomotivesStorage.Add(record[0], collection); + _locomotivesStorage.Add(new LocosCollectionInfo(record[0], string.Empty), collection); + } return; } diff --git a/ProjectElectricLocomotive/ProjectElectricLocomotive/LocosCollectionInfo.cs b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocosCollectionInfo.cs new file mode 100644 index 0000000..0b5a8ce --- /dev/null +++ b/ProjectElectricLocomotive/ProjectElectricLocomotive/LocosCollectionInfo.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectElectricLocomotive +{ + public class LocosCollectionInfo : IEquatable + { + public string Name { get; private set; } + public string Description { get; private set; } + public LocosCollectionInfo(string name, string description) + { + Name = name; + Description = description; + } + + public bool Equals(LocosCollectionInfo other) + { + if (Name != other?.Name) + //throw new NotImplementedException(nameof(Name)); + return false; + return true; + } + + public override int GetHashCode() + { + return Name.GetHashCode(); + } + + public override string ToString() + { + return Name; + } + } +}