AlarmHistoryView.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using ivf_tl_CustomControls;
  2. using ivf_tl_Entity.Entity.Alarm;
  3. using ivf_tl_Entity.Entity.balance;
  4. using ivf_tl_Manage.Converts;
  5. using ivf_tl_Manage.ViewModels;
  6. using ivf_tl_Manage.Win;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Controls;
  15. using System.Windows.Data;
  16. using System.Windows.Documents;
  17. using System.Windows.Input;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Imaging;
  20. using System.Windows.Navigation;
  21. using System.Windows.Shapes;
  22. namespace ivf_tl_Manage.Views
  23. {
  24. /// <summary>
  25. /// AlarmHistoryView.xaml 的交互逻辑
  26. /// </summary>
  27. public partial class AlarmHistoryView : UserControl
  28. {
  29. private AlarmHistoryViewModel vm;
  30. public AlarmHistoryView()
  31. {
  32. InitializeComponent();
  33. bool isStop = false;
  34. Loaded += (s, e) =>
  35. {
  36. vm = (AlarmHistoryViewModel)this.DataContext;
  37. if (vm == null) return;
  38. this._tlName_ComBox.SelectedItem = vm.CurrentTlInfo;
  39. Task.Run(() =>
  40. {
  41. Dispatcher.Invoke(() =>
  42. {
  43. vm.Init();
  44. });
  45. return;
  46. List<AlarmHistoryEntity> lista = new List<AlarmHistoryEntity>();
  47. while (true)
  48. {
  49. if (vm == null) return;
  50. if (isStop) return;
  51. lista.Clear();
  52. lista = vm.Updata1();
  53. Dispatcher.Invoke(() =>
  54. {
  55. vm.AlarmHistoryList.Clear();
  56. foreach (var item in lista)
  57. {
  58. vm.AlarmHistoryList.Add(item);
  59. }
  60. });
  61. Thread.Sleep(5000);
  62. }
  63. });
  64. };
  65. Unloaded += (s, e) =>
  66. {
  67. isStop = true;
  68. vm = null;
  69. this.rootCanvas.Children.Clear();
  70. };
  71. }
  72. public void MessageShow(string message)
  73. {
  74. new ToastMessageWindow(AppData.Instance.MainWindow, 1920, 65, message).Show();
  75. }
  76. private void test_SelectionChanged(object sender, SelectionChangedEventArgs e)
  77. {
  78. string ss = "";
  79. }
  80. private void test_DropDownClosed(object sender, EventArgs e)
  81. {
  82. }
  83. private void TLSN_DropDownClosed(object sender, EventArgs e)
  84. {
  85. if (vm == null) return;
  86. if (!(sender is ComBoxCustom2 source)) return;
  87. if (!source.IsLoaded) return;
  88. if(source.SelectedItem == null)
  89. {
  90. vm.SetCurrentTlInfo(null);
  91. return;
  92. }
  93. vm.SetCurrentTlInfo((TLInfo)source.SelectedItem);
  94. }
  95. private void House_DropDownClosed(object sender, EventArgs e)
  96. {
  97. if (vm == null) return;
  98. if (!(sender is ComBoxCustom2 source)) return;
  99. if (!source.IsLoaded) return;
  100. if (source.SelectedItem == null)
  101. {
  102. vm.SetCurrentHouse(-1);
  103. return;
  104. }
  105. vm.SetCurrentHouse((int)source.SelectedItem);
  106. }
  107. private void AlarmType_DropDownClosed(object sender, EventArgs e)
  108. {
  109. if (vm == null) return;
  110. if (!(sender is ComBoxCustom2 source)) return;
  111. if (!source.IsLoaded) return;
  112. if (source.SelectedItem == null)
  113. {
  114. vm.SetCurrentAlarmType(null);
  115. return;
  116. }
  117. vm.SetCurrentAlarmType((AlarmTypeEntity)source.SelectedItem);
  118. }
  119. private void RadioButtonMarkSetting_Checked(object sender, RoutedEventArgs e)
  120. {
  121. if (vm == null) return;
  122. if (!(sender is RadioButtonMarkSetting source)) return;
  123. if (!source.IsLoaded) return;
  124. vm.SetSelectedType(source.Tag.ToString());
  125. }
  126. private void PaginationUserControl_PageChangedEvent(UserControls.PaginationUserControl arg1, int arg2)
  127. {
  128. if (vm == null) return;
  129. if (!arg1.IsLoaded) return;
  130. NoUp = true;
  131. this._all_CheckBox1.IsChecked = false;
  132. this._all_CheckBox2.IsChecked = true;
  133. NoUp = false;
  134. vm.SetPageCurrent(arg2);
  135. }
  136. private void canvasItemsControl_MouseDown(object sender, MouseButtonEventArgs e)
  137. {
  138. }
  139. private void Detail_Click(object sender, RoutedEventArgs e)
  140. {
  141. if (!(sender is ButtonImage source)) return;
  142. if (!(source.Tag is AlarmHistoryEntity alarmHistoryEntity)) return;
  143. AppData.Instance.MainWindowViewModel.MaskVisibility = true;
  144. new AlarmDetailWindow(alarmHistoryEntity, AppData.Instance.MainWindow).ShowDialog();
  145. AppData.Instance.MainWindowViewModel.MaskVisibility = false;
  146. }
  147. private void All_Checked(object sender, RoutedEventArgs e)
  148. {
  149. if (vm == null || NoUp || !this.IsLoaded) return;
  150. foreach (var item in vm.AlarmHistoryList)
  151. {
  152. item.IsCheck = true;
  153. }
  154. }
  155. private void All_UnChecked(object sender, RoutedEventArgs e)
  156. {
  157. if (vm == null || NoUp || !this.IsLoaded) return;
  158. foreach (var item in vm.AlarmHistoryList)
  159. {
  160. item.IsCheck = false;
  161. }
  162. }
  163. bool NoUp = false;
  164. private void Detail_Checked(object sender, RoutedEventArgs e)
  165. {
  166. if (vm == null || !this.IsLoaded) return;
  167. if (vm.AlarmHistoryList.FirstOrDefault(x => !x.IsCheck) == null)
  168. {
  169. NoUp = true;
  170. this._all_CheckBox1.IsChecked = true;
  171. NoUp = false;
  172. }
  173. }
  174. private void Detail_Unchecked(object sender, RoutedEventArgs e)
  175. {
  176. if (vm == null || !this.IsLoaded) return;
  177. NoUp = true;
  178. this._all_CheckBox1.IsChecked = false;
  179. NoUp = false;
  180. }
  181. bool isNotifyChanged = false;
  182. private void Notify_Checked(object sender, RoutedEventArgs e)
  183. {
  184. if (isNotifyChanged || vm == null || !this.IsLoaded) return;
  185. if (!(sender is CheckBox checkBox)) return;
  186. if (!checkBox.IsLoaded) return;
  187. AlarmHistoryEntity alarmHistoryEntity = checkBox.Tag as AlarmHistoryEntity;
  188. if (alarmHistoryEntity == null) return;
  189. if (alarmHistoryEntity.type == 1)
  190. {
  191. //MessageShow("报警已结束");
  192. MessageShow(KeyToStringConvert.GetLanguageStringByKey("0544"));
  193. isNotifyChanged = true;
  194. checkBox.IsChecked = false;
  195. isNotifyChanged = false;
  196. return;
  197. }
  198. if (!vm.EditAlarmNotify(alarmHistoryEntity))
  199. {
  200. isNotifyChanged = true;
  201. checkBox.IsChecked = false;
  202. isNotifyChanged = false;
  203. }
  204. }
  205. private void Notify_Unchecked(object sender, RoutedEventArgs e)
  206. {
  207. if (isNotifyChanged || vm == null || !this.IsLoaded) return;
  208. if (!(sender is CheckBox checkBox)) return;
  209. if (!checkBox.IsLoaded) return;
  210. AlarmHistoryEntity alarmHistoryEntity = checkBox.Tag as AlarmHistoryEntity;
  211. if (alarmHistoryEntity == null) return;
  212. if (alarmHistoryEntity.type == 1)
  213. {
  214. MessageShow(KeyToStringConvert.GetLanguageStringByKey("0544"));
  215. isNotifyChanged = true;
  216. checkBox.IsChecked = true;
  217. isNotifyChanged = false;
  218. return;
  219. }
  220. if (!vm.EditAlarmNotify(alarmHistoryEntity))
  221. {
  222. isNotifyChanged = true;
  223. checkBox.IsChecked = true;
  224. isNotifyChanged = false;
  225. }
  226. }
  227. private void AllDetail_Unchecked(object sender, RoutedEventArgs e)
  228. {
  229. if (vm == null || !this.IsLoaded || NoUp) return;
  230. var list = vm.AlarmHistoryList.Where(x => x.IsCheck && x.notify == 1);
  231. foreach (AlarmHistoryEntity alarm in list)
  232. {
  233. if (vm.EditAlarmNotify(alarm.id, 0))
  234. {
  235. alarm.notify = 0;
  236. }
  237. else
  238. {
  239. NoUp = true;
  240. this._all_CheckBox2.IsChecked = true;
  241. NoUp = false;
  242. break;
  243. }
  244. }
  245. }
  246. private void AllDetail_Checked(object sender, RoutedEventArgs e)
  247. {
  248. if (vm == null || !this.IsLoaded || NoUp) return;
  249. var list = vm.AlarmHistoryList.Where(x => x.IsCheck && x.notify == 0);
  250. foreach (AlarmHistoryEntity alarm in list)
  251. {
  252. if (alarm.type == 1)
  253. {
  254. MessageShow(KeyToStringConvert.GetLanguageStringByKey("0544"));
  255. NoUp = true;
  256. this._all_CheckBox2.IsChecked = false;
  257. NoUp = false;
  258. break;
  259. }
  260. if (vm.EditAlarmNotify(alarm.id, 1))
  261. {
  262. alarm.notify = 1;
  263. }
  264. else
  265. {
  266. NoUp = true;
  267. this._all_CheckBox2.IsChecked = false;
  268. NoUp = false;
  269. break;
  270. }
  271. }
  272. }
  273. }
  274. }