123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- using InitializerModel;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Animation;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ConfigEditor.SubPage.EvseConfig
- {
- /// <summary>
- /// FirmwareVersionPanel.xaml 的互動邏輯
- /// </summary>
- public partial class FirmwareVersionPanel : UserControl
- {
- public FirmwareVersionPanel()
- {
- InitializeComponent();
- SetTitleByIndex(0);
- }
- private int _Index = 0;
- public int Index
- {
- get => _Index;
- set => SetTitleByIndex(value);
- }
- public List<FirmwareUpdateModel> VersionPairs
- {
- get => GetVersionPairs();
- set => SetVersionPairs(value);
- }
- public string FileFolderPath { get; internal set; }
- private void NewFrimware_Click(object sender, RoutedEventArgs e)
- {
- UIElement toInsert = CreateFrimwareItem();
- uxFrimwareItemStackPanel.Children.Add(toInsert);
- }
- private void FrimwareItem_OnDeleteClicked(object sender, EventArgs e)
- {
- uxFrimwareItemStackPanel.Children.Remove(sender as UIElement);
- }
- private void SetTitleByIndex(int index)
- {
- _Index = index;
- string title = "Version Information";
- if (index > 0)
- {
- title = $"Version Information Dispenser {index}";
- }
- uxTitleGb.Header = title;
- }
- private void SetVersionPairs(List<FirmwareUpdateModel> firmwareList)
- {
- if (firmwareList is null)
- {
- return;
- }
- uxFrimwareItemStackPanel.Children.Clear();
- foreach (var firmware in firmwareList)
- {
- UIElement toInsert = CreateFrimwareItem(firmware);
- uxFrimwareItemStackPanel.Children.Add(toInsert);
- }
- return;
- }
- private UIElement CreateFrimwareItem(FirmwareUpdateModel firmware)
- {
- var toReturn = new FirmwareVersionPaneltem(FileFolderPath, firmware, Index);
- toReturn.OnDeleteClicked += FrimwareItem_OnDeleteClicked;
- return toReturn;
- }
- private UIElement CreateFrimwareItem()
- {
- var toReturn = new FirmwareVersionPaneltem(FileFolderPath, Index);
- toReturn.OnDeleteClicked += FrimwareItem_OnDeleteClicked;
- return toReturn;
- }
- private List<FirmwareUpdateModel> GetVersionPairs()
- {
- var toReturn = new List<FirmwareUpdateModel>();
- foreach (var uiElement in uxFrimwareItemStackPanel.Children)
- {
- FirmwareVersionPaneltem versionPaneltem = uiElement as FirmwareVersionPaneltem;
- if (versionPaneltem is null)
- {
- continue;
- }
- var model = versionPaneltem.GetModel();
- if (model is null)
- {
- continue;
- }
- toReturn.Add(model);
- }
- return toReturn;
- }
- }
- }
|