ToDoInfoWindow.xaml.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using GeekDesk.Util;
  2. using GeekDesk.ViewModel;
  3. using HandyControl.Controls;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace GeekDesk.Control.Windows
  18. {
  19. /// <summary>
  20. /// BacklogInfoWindow.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class ToDoInfoWindow
  23. {
  24. private static int windowType = -1;
  25. private static readonly int NEW_TODO = 1;
  26. private static readonly int DETAIL_TODO = 2;
  27. private AppData appData = MainWindow.appData;
  28. private ToDoInfo info;
  29. private ToDoInfoWindow()
  30. {
  31. InitializeComponent();
  32. ExeTime.SelectedDateTime = DateTime.Now.AddMinutes(10);
  33. this.Topmost = true;
  34. }
  35. private ToDoInfoWindow(ToDoInfo info)
  36. {
  37. InitializeComponent();
  38. this.Topmost = true;
  39. Title.Text = info.Title;
  40. Msg.Text = info.Msg;
  41. ExeTime.Text = info.ExeTime;
  42. DoneTime.Text = info.DoneTime;
  43. this.info = info;
  44. }
  45. /// <summary>
  46. /// 点击关闭按钮
  47. /// </summary>
  48. /// <param name="sender"></param>
  49. /// <param name="e"></param>
  50. private void Close_Button_Click(object sender, RoutedEventArgs e)
  51. {
  52. this.Close();
  53. }
  54. /// <summary>
  55. /// 移动窗口
  56. /// </summary>
  57. /// <param name="sender"></param>
  58. /// <param name="e"></param>
  59. private void DragMove(object sender, System.Windows.Input.MouseButtonEventArgs e)
  60. {
  61. if (e.LeftButton == MouseButtonState.Pressed)
  62. {
  63. DragMove();
  64. }
  65. }
  66. /// <summary>
  67. /// 保存待办
  68. /// </summary>
  69. /// <param name="sender"></param>
  70. /// <param name="e"></param>
  71. private void Save_Button_Click(object sender, RoutedEventArgs e)
  72. {
  73. DateTime dt;
  74. if (Title.Text.Trim() == "" || ExeTime.Text.Trim() == "")
  75. {
  76. Growl.Warning("任务标题 和 待办时间不能为空!");
  77. return;
  78. } else
  79. {
  80. try
  81. {
  82. dt = Convert.ToDateTime(ExeTime.Text);
  83. } catch (Exception)
  84. {
  85. Growl.Warning("请输入正确的时间!");
  86. return;
  87. }
  88. }
  89. if (windowType == NEW_TODO)
  90. {
  91. info = new ToDoInfo
  92. {
  93. Title = Title.Text,
  94. Msg = Msg.Text,
  95. ExeTime = ExeTime.Text
  96. };
  97. appData.ToDoList.Add(info);
  98. } else
  99. {
  100. appData.HiToDoList.Remove(info);
  101. info.Title = Title.Text;
  102. info.Msg = Msg.Text;
  103. info.ExeTime = ExeTime.Text;
  104. info.DoneTime = null;
  105. appData.ToDoList.Add(info);
  106. }
  107. DateTime dtNow = DateTime.Now;
  108. TimeSpan ts = dt.Subtract(dtNow);
  109. int minutes = (int)Math.Ceiling(ts.TotalMinutes);
  110. if (minutes < 0)
  111. {
  112. minutes = 0;
  113. }
  114. if (minutes > 60)
  115. {
  116. int m = minutes % 60;
  117. int h = minutes / 60;
  118. Growl.SuccessGlobal("设置待办任务成功, 系统将在 " + h + " 小时零 " + m + " 分钟后提醒您!");
  119. } else
  120. {
  121. Growl.SuccessGlobal("设置待办任务成功, 系统将在 " + minutes + " 分钟后提醒您!");
  122. }
  123. CommonCode.SaveAppData(MainWindow.appData);
  124. this.Close();
  125. }
  126. private static System.Windows.Window window = null;
  127. public static void ShowNone()
  128. {
  129. if (window == null || !window.Activate())
  130. {
  131. window = new ToDoInfoWindow();
  132. window.Show();
  133. }
  134. windowType = NEW_TODO;
  135. window.Visibility = Visibility.Visible;
  136. }
  137. public static System.Windows.Window GetThis()
  138. {
  139. if (window == null || !window.Activate())
  140. {
  141. window = new ToDoInfoWindow();
  142. window.Show();
  143. }
  144. window.Visibility = Visibility.Collapsed;
  145. windowType = NEW_TODO;
  146. return window;
  147. }
  148. private static System.Windows.Window window2 = null;
  149. public static void ShowDetail(ToDoInfo info)
  150. {
  151. if (window2 == null || !window2.Activate())
  152. {
  153. window2 = new ToDoInfoWindow(info);
  154. }
  155. windowType = DETAIL_TODO;
  156. window2.Show();
  157. }
  158. }
  159. }