using System; using System.Collections.Generic; using System.IO; 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.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Microsoft.WindowsAPICodePack.Dialogs; namespace Phihong_EVSE_UI_Tool { /// /// AuthenticationUC.xaml 的互動邏輯 /// public partial class AuthenticationUC : UserControl { private Properties.Settings mySettings = Properties.Settings.Default; private string verifyCustomImgPath; private string verifyOkCustomImgPath; private string verifyFailCustomImgPath; public AuthenticationUC() { InitializeComponent(); verifyCustomImgPath = mySettings.VerifyCustomImgPath; uxVerifyDefaultRadioButton.IsChecked = mySettings.IsVerifyDefault; uxVerifyCustomRadioButton.IsChecked = !mySettings.IsVerifyDefault; uxVerifyExploreTextBox.Text = mySettings.VerifyCustomImgPath_org; verifyOkCustomImgPath = mySettings.VerifyOkCustomImgPath; uxVerifyOkDefaultRadioButton.IsChecked = mySettings.IsVerifyOkDefault; uxVerifyOkCustomRadioButton.IsChecked = !mySettings.IsVerifyOkDefault; uxVerifyOkExploreTextBox.Text = mySettings.VerifyOkCustomImgPath_org; verifyFailCustomImgPath = mySettings.VerifyFailCustomImgPath; uxVerifyFailDefaultRadioButton.IsChecked = mySettings.IsVerifyFailDefault; uxVerifyFailCustomRadioButton.IsChecked = !mySettings.IsVerifyFailDefault; uxVerifyFailExploreTextBox.Text = mySettings.VerifyFailCustomImgPath_org; } private void uxDefaultRadioButton_Checked(object sender, RoutedEventArgs e) { Uri srcPath; RadioButton rb = e.Source as RadioButton; if (rb is null) { return; } switch (rb.Tag.ToString()) { case "Verify": srcPath = new Uri(Utility.BG_PARENTFOLDER + Utility.BG_VERIFY, UriKind.Relative); uxVerifyImage.Source = new BitmapImage(srcPath); Utility.CopyFileFromResource(srcPath, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFY); mySettings.IsVerifyDefault = true; break; case "VerifyOk": srcPath = new Uri(Utility.BG_PARENTFOLDER + Utility.BG_VERIFYOK, UriKind.Relative); uxVerifyOkImage.Source = new BitmapImage(srcPath); Utility.CopyFileFromResource(srcPath, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFYOK); mySettings.IsVerifyOkDefault = true; break; case "VerifyFail": srcPath = new Uri(Utility.BG_PARENTFOLDER + Utility.BG_VERIFYFAIL, UriKind.Relative); uxVerifyFailImage.Source = new BitmapImage(srcPath); Utility.CopyFileFromResource(srcPath, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFYFAIL); mySettings.IsVerifyFailDefault = true; break; default: return; } mySettings.Save(); } private void uxCustomRadioButton_Checked(object sender, RoutedEventArgs e) { RadioButton rb = e.Source as RadioButton; if (rb is null) { return; } switch (rb.Tag.ToString()) { case "Verify": if (File.Exists(verifyCustomImgPath)) { Utility.LoadImageFromPath(uxVerifyImage, verifyCustomImgPath); File.Copy(verifyCustomImgPath, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFY, true); mySettings.IsVerifyDefault = false; } break; case "VerifyOk": if (File.Exists(verifyOkCustomImgPath)) { Utility.LoadImageFromPath(uxVerifyOkImage, verifyOkCustomImgPath); File.Copy(verifyOkCustomImgPath, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFYOK, true); mySettings.IsVerifyOkDefault = false; } break; case "VerifyFail": if (File.Exists(verifyFailCustomImgPath)) { Utility.LoadImageFromPath(uxVerifyFailImage, verifyFailCustomImgPath); File.Copy(verifyFailCustomImgPath, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFYFAIL, true); mySettings.IsVerifyFailDefault = false; } break; default: return; } mySettings.Save(); } private void uxBrowseButton_Click(object sender, RoutedEventArgs e) { Button btn = e.Source as Button; if (btn is null) { return; } var dlg = new CommonOpenFileDialog() { EnsureFileExists = true, Title = "Select an image file", }; dlg.Filters.Add(new CommonFileDialogFilter("BMP images", "*.bmp")); if (dlg.ShowDialog() == CommonFileDialogResult.Ok) { if (!Utility.IsBackgroundImageSizeQualified(dlg.FileName)) { MessageBox.Show(dlg.FileName + "\r\n" + "The resolution of the image must be 800x480", "Incorrect Resolution", MessageBoxButton.OK, MessageBoxImage.Error); return; } switch (btn.Tag.ToString()) { case "Verify": uxVerifyExploreTextBox.Text = dlg.FileName; verifyCustomImgPath = Utility.CUSTOM_DIRECTORY + Utility.BG_VERIFY; File.Copy(dlg.FileName, verifyCustomImgPath, true); File.Copy(dlg.FileName, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFY, true); Utility.LoadImageFromPath(uxVerifyImage, verifyCustomImgPath); mySettings.IsVerifyDefault = false; mySettings.VerifyCustomImgPath = verifyCustomImgPath; mySettings.VerifyCustomImgPath_org = uxVerifyExploreTextBox.Text; break; case "VerifyOk": uxVerifyOkExploreTextBox.Text = dlg.FileName; verifyOkCustomImgPath = Utility.CUSTOM_DIRECTORY + Utility.BG_VERIFYOK; File.Copy(dlg.FileName, verifyOkCustomImgPath, true); File.Copy(dlg.FileName, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFYOK, true); Utility.LoadImageFromPath(uxVerifyOkImage, verifyOkCustomImgPath); mySettings.IsVerifyOkDefault = false; mySettings.VerifyOkCustomImgPath = verifyOkCustomImgPath; mySettings.VerifyOkCustomImgPath_org = uxVerifyOkExploreTextBox.Text; break; case "VerifyFail": uxVerifyFailExploreTextBox.Text = dlg.FileName; verifyFailCustomImgPath = Utility.CUSTOM_DIRECTORY + Utility.BG_VERIFYFAIL; File.Copy(dlg.FileName, verifyFailCustomImgPath, true); File.Copy(dlg.FileName, Utility.OUTPUT_DIRECTORY + Utility.BG_VERIFYFAIL, true); Utility.LoadImageFromPath(uxVerifyFailImage, verifyFailCustomImgPath); mySettings.IsVerifyFailDefault = false; mySettings.VerifyFailCustomImgPath = verifyFailCustomImgPath; mySettings.VerifyFailCustomImgPath_org = uxVerifyFailExploreTextBox.Text; break; default: break; } } mySettings.Save(); } } }