using IOTContainer.Common; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading; 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.Shapes; using System.Windows.Threading; namespace IOTContainer.View { /// /// ExitPwd.xaml 的交互逻辑 /// public partial class ExitPwd : Window { public ExitPwd() { InitializeComponent(); Countdown_timer(); } //倒计时模块 private DispatcherTimer pageTimer = null; public TimeCount Time = new TimeCount(); private void Countdown_timer() { this.DataContext = Time; pageTimer = new DispatcherTimer() { IsEnabled = true, Interval = TimeSpan.FromSeconds(1), }; pageTimer.Tick += new EventHandler((sender, e) => { FocusManager.SetFocusedElement(this, textBox); if (--Time.Countdown <= 0) { this.Hide(); Thread.Sleep(300); this.Close(); } }); } private void Keypad_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; textBox.Text += button.Tag.ToString(); } private void KeyBoard_Click(object sender, RoutedEventArgs e) { Button button = sender as Button; switch (button.Tag.ToString()) { case "KeyBoard": button.Tag = "keyboard"; KeyPad1.Visibility = Visibility.Hidden; KeyPad2.Visibility = Visibility.Visible; KeyBoard.Content = "大写"; break; case "keyboard": button.Tag = "KeyBoard"; KeyPad1.Visibility = Visibility.Visible; KeyPad2.Visibility = Visibility.Hidden; KeyBoard.Content = "小写"; break; default: break; } } private void Delete_Click(object sender, RoutedEventArgs e) { if (textBox.Text.Length > 0) { textBox.Text = textBox.Text.Substring(0, textBox.Text.Length - 1); } } private void Clear_Click(object sender, RoutedEventArgs e) { textBox.Text = ""; } private void Image_MouseDown(object sender, MouseButtonEventArgs e) { pageTimer.IsEnabled = false; this.Hide(); Thread.Sleep(300); this.Close(); } private void Exit_Click(object sender, RoutedEventArgs e) { var dt = DateTime.Now; if (textBox.Text.Length == 0) { errorMsg.Content = "请先输入密码!"; } else if (textBox.Text == dt.ToString("dd") + "0" + dt.DayOfWeek.ToString("D") + dt.ToString("MM")) { ExternalCall.CheckStartExplorer(); Environment.Exit(0); } else if (dt.DayOfWeek.ToString("D") == "0" && textBox.Text == dt.ToString("dd") + "07" + dt.ToString("MM")) { ExternalCall.CheckStartExplorer(); Environment.Exit(0); } else { errorMsg.Content = "密码错误!"; } } } public class TimeCount : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private int countdown = 59; public int Countdown { get { return countdown; } set { countdown = value; if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs("Countdown")); } } } } }