123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- 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
- {
- /// <summary>
- /// AuthenticationUC.xaml 的互動邏輯
- /// </summary>
- 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();
- }
- }
- }
|