AskDate.xaml.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Windows;
  3. namespace DeviceCenter
  4. {
  5. /// <summary>
  6. /// AskDate.xaml 的交互逻辑
  7. /// </summary>
  8. public partial class AskDate : Window
  9. {
  10. public DateTime start;
  11. public DateTime end;
  12. public AskDate()
  13. {
  14. InitializeComponent();
  15. DateTime now = DateTime.Now;
  16. DateTime start = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0);
  17. DateTime end = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);
  18. tb_start.Text = start.ToString("yyyy-MM-dd HH:mm:ss");
  19. tb_end.Text = end.ToString("yyyy-MM-dd HH:mm:ss");
  20. }
  21. private void Button_Click(object sender, RoutedEventArgs e)
  22. {
  23. try
  24. {
  25. start = DateTime.ParseExact(tb_start.Text, "yyyy-MM-dd HH:mm:ss", null);
  26. end = DateTime.ParseExact(tb_end.Text, "yyyy-MM-dd HH:mm:ss", null);
  27. DialogResult = true;
  28. }
  29. catch (Exception ex)
  30. {
  31. MessageBox.Show(ex.Message); DialogResult = false;
  32. }
  33. }
  34. }
  35. }