using Microsoft.WindowsAPICodePack.Dialogs; using System; using System.IO; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; 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(Path.Combine(Utility.BG_PARENTFOLDER, Utility.BG_VERIFY), UriKind.Relative); uxVerifyImage.Source = new BitmapImage(srcPath); Utility.CopyFileFromResource(srcPath, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFY)); Utility.ChangedFiles[Utility.BG_VERIFY] = true; mySettings.IsVerifyDefault = true; break; case "VerifyOk": srcPath = new Uri(Path.Combine(Utility.BG_PARENTFOLDER, Utility.BG_VERIFYOK), UriKind.Relative); uxVerifyOkImage.Source = new BitmapImage(srcPath); Utility.CopyFileFromResource(srcPath, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFYOK)); Utility.ChangedFiles[Utility.BG_VERIFYOK] = true; mySettings.IsVerifyOkDefault = true; break; case "VerifyFail": srcPath = new Uri(Path.Combine(Utility.BG_PARENTFOLDER, Utility.BG_VERIFYFAIL), UriKind.Relative); uxVerifyFailImage.Source = new BitmapImage(srcPath); Utility.CopyFileFromResource(srcPath, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFYFAIL)); Utility.ChangedFiles[Utility.BG_VERIFYFAIL] = true; 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, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFY), true); Utility.ChangedFiles[Utility.BG_VERIFY] = true; mySettings.IsVerifyDefault = false; } break; case "VerifyOk": if (File.Exists(verifyOkCustomImgPath)) { Utility.LoadImageFromPath(uxVerifyOkImage, verifyOkCustomImgPath); File.Copy(verifyOkCustomImgPath, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFYOK), true); Utility.ChangedFiles[Utility.BG_VERIFYOK] = true; mySettings.IsVerifyOkDefault = false; } break; case "VerifyFail": if (File.Exists(verifyFailCustomImgPath)) { Utility.LoadImageFromPath(uxVerifyFailImage, verifyFailCustomImgPath); File.Copy(verifyFailCustomImgPath, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFYFAIL), true); Utility.ChangedFiles[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 = Path.Combine(Utility.CUSTOM_DIRECTORY, Utility.BG_VERIFY); File.Copy(dlg.FileName, verifyCustomImgPath, true); File.Copy(dlg.FileName, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFY), true); Utility.LoadImageFromPath(uxVerifyImage, verifyCustomImgPath); Utility.ChangedFiles[Utility.BG_VERIFY] = true; mySettings.IsVerifyDefault = false; mySettings.VerifyCustomImgPath = verifyCustomImgPath; mySettings.VerifyCustomImgPath_org = uxVerifyExploreTextBox.Text; break; case "VerifyOk": uxVerifyOkExploreTextBox.Text = dlg.FileName; verifyOkCustomImgPath = Path.Combine(Utility.CUSTOM_DIRECTORY, Utility.BG_VERIFYOK); File.Copy(dlg.FileName, verifyOkCustomImgPath, true); File.Copy(dlg.FileName, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFYOK), true); Utility.LoadImageFromPath(uxVerifyOkImage, verifyOkCustomImgPath); Utility.ChangedFiles[Utility.BG_VERIFYOK] = true; mySettings.IsVerifyOkDefault = false; mySettings.VerifyOkCustomImgPath = verifyOkCustomImgPath; mySettings.VerifyOkCustomImgPath_org = uxVerifyOkExploreTextBox.Text; break; case "VerifyFail": uxVerifyFailExploreTextBox.Text = dlg.FileName; verifyFailCustomImgPath = Path.Combine(Utility.CUSTOM_DIRECTORY, Utility.BG_VERIFYFAIL); File.Copy(dlg.FileName, verifyFailCustomImgPath, true); File.Copy(dlg.FileName, Path.Combine(Utility.OUTPUT_DIRECTORY, Utility.BG_VERIFYFAIL), true); Utility.LoadImageFromPath(uxVerifyFailImage, verifyFailCustomImgPath); Utility.ChangedFiles[Utility.BG_VERIFYFAIL] = true; mySettings.IsVerifyFailDefault = false; mySettings.VerifyFailCustomImgPath = verifyFailCustomImgPath; mySettings.VerifyFailCustomImgPath_org = uxVerifyFailExploreTextBox.Text; break; default: break; } } mySettings.Save(); } } }