ToDoInfoWindow.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. if (Title.Text.Trim() == "" || ExeTime.Text.Trim() == "")
  74. {
  75. Growl.Warning("任务标题 和 待办时间不能为空!");
  76. return;
  77. } else
  78. {
  79. try
  80. {
  81. Convert.ToDateTime(ExeTime.Text);
  82. } catch (Exception)
  83. {
  84. Growl.Warning("请输入正确的时间!");
  85. return;
  86. }
  87. }
  88. if (windowType == NEW_TODO)
  89. {
  90. info = new ToDoInfo
  91. {
  92. Title = Title.Text,
  93. Msg = Msg.Text,
  94. ExeTime = ExeTime.Text
  95. };
  96. appData.ToDoList.Add(info);
  97. } else
  98. {
  99. int index =appData.ToDoList.IndexOf(info);
  100. appData.ToDoList.Remove(info);
  101. info.Title = Title.Text;
  102. info.Msg = Msg.Text;
  103. info.ExeTime = ExeTime.Text;
  104. info.DoneTime = DoneTime.Text;
  105. appData.ToDoList.Insert(index, info);
  106. }
  107. CommonCode.SaveAppData(MainWindow.appData);
  108. this.Close();
  109. }
  110. private static System.Windows.Window window = null;
  111. public static void ShowNone()
  112. {
  113. if (window == null || !window.Activate())
  114. {
  115. window = new ToDoInfoWindow();
  116. }
  117. windowType = NEW_TODO;
  118. window.Show();
  119. }
  120. public static System.Windows.Window GetThis()
  121. {
  122. if (window == null || !window.Activate())
  123. {
  124. window = new ToDoInfoWindow();
  125. }
  126. windowType = NEW_TODO;
  127. return window;
  128. }
  129. private static System.Windows.Window window2 = null;
  130. public static void ShowDetail(ToDoInfo info)
  131. {
  132. if (window2 == null || !window2.Activate())
  133. {
  134. window2 = new ToDoInfoWindow(info);
  135. }
  136. windowType = DETAIL_TODO;
  137. window2.Show();
  138. }
  139. }
  140. }