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
{
///
/// FirmwareVersionPanel.xaml 的互動邏輯
///
public partial class FirmwareVersionPanel : UserControl
{
public FirmwareVersionPanel()
{
InitializeComponent();
SetTitleByIndex(0);
}
private int _Index = 0;
public int Index
{
get => _Index;
set => SetTitleByIndex(value);
}
public List 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 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 GetVersionPairs()
{
var toReturn = new List();
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;
}
}
}