FirmwareVersionPanel.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using InitializerModel;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Animation;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace ConfigEditor.SubPage.EvseConfig
  18. {
  19. /// <summary>
  20. /// FirmwareVersionPanel.xaml 的互動邏輯
  21. /// </summary>
  22. public partial class FirmwareVersionPanel : UserControl
  23. {
  24. public FirmwareVersionPanel()
  25. {
  26. InitializeComponent();
  27. SetTitleByIndex(0);
  28. }
  29. private int _Index = 0;
  30. public int Index
  31. {
  32. get => _Index;
  33. set => SetTitleByIndex(value);
  34. }
  35. public List<FirmwareUpdateModel> VersionPairs
  36. {
  37. get => GetVersionPairs();
  38. set => SetVersionPairs(value);
  39. }
  40. public string FileFolderPath { get; internal set; }
  41. private void NewFrimware_Click(object sender, RoutedEventArgs e)
  42. {
  43. UIElement toInsert = CreateFrimwareItem();
  44. uxFrimwareItemStackPanel.Children.Add(toInsert);
  45. }
  46. private void FrimwareItem_OnDeleteClicked(object sender, EventArgs e)
  47. {
  48. uxFrimwareItemStackPanel.Children.Remove(sender as UIElement);
  49. }
  50. private void SetTitleByIndex(int index)
  51. {
  52. _Index = index;
  53. string title = "Version Information";
  54. if (index > 0)
  55. {
  56. title = $"Version Information Dispenser {index}";
  57. }
  58. uxTitleGb.Header = title;
  59. }
  60. private void SetVersionPairs(List<FirmwareUpdateModel> firmwareList)
  61. {
  62. if (firmwareList is null)
  63. {
  64. return;
  65. }
  66. uxFrimwareItemStackPanel.Children.Clear();
  67. foreach (var firmware in firmwareList)
  68. {
  69. UIElement toInsert = CreateFrimwareItem(firmware);
  70. uxFrimwareItemStackPanel.Children.Add(toInsert);
  71. }
  72. return;
  73. }
  74. private UIElement CreateFrimwareItem(FirmwareUpdateModel firmware)
  75. {
  76. var toReturn = new FirmwareVersionPaneltem(FileFolderPath, firmware, Index);
  77. toReturn.OnDeleteClicked += FrimwareItem_OnDeleteClicked;
  78. return toReturn;
  79. }
  80. private UIElement CreateFrimwareItem()
  81. {
  82. var toReturn = new FirmwareVersionPaneltem(FileFolderPath, Index);
  83. toReturn.OnDeleteClicked += FrimwareItem_OnDeleteClicked;
  84. return toReturn;
  85. }
  86. private List<FirmwareUpdateModel> GetVersionPairs()
  87. {
  88. var toReturn = new List<FirmwareUpdateModel>();
  89. foreach (var uiElement in uxFrimwareItemStackPanel.Children)
  90. {
  91. FirmwareVersionPaneltem versionPaneltem = uiElement as FirmwareVersionPaneltem;
  92. if (versionPaneltem is null)
  93. {
  94. continue;
  95. }
  96. var model = versionPaneltem.GetModel();
  97. if (model is null)
  98. {
  99. continue;
  100. }
  101. toReturn.Add(model);
  102. }
  103. return toReturn;
  104. }
  105. }
  106. }