AlarmtableParameterViewModel.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. using Aitex.Core.RT.Event;
  2. using Caliburn.Micro.Core;
  3. using MECF.Framework.Common.Alarms;
  4. using MECF.Framework.Common.OperationCenter;
  5. using MECF.Framework.UI.Client.CenterViews.Alarms;
  6. using MECF.Framework.UI.Client.CenterViews.Configs.SystemConfig;
  7. using MECF.Framework.UI.Client.ClientBase;
  8. using OpenSEMI.ClientBase;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. namespace MECF.Framework.UI.Client.CenterViews.Parameter
  17. {
  18. public class AlarmtableParameterViewModel : ModuleUiViewModelBase
  19. {
  20. public bool IsPermission { get => this.Permission == 3; }
  21. private AlarmProvider _alarmProvider = new AlarmProvider();
  22. public ObservableCollection<AlarmParameterOperation> AlarmParameterOperations { get; set; } = new ObservableCollection<AlarmParameterOperation>();
  23. public ObservableCollection<string> AlarmGroups { get; set; } = new ObservableCollection<string>();
  24. public ObservableCollection<string> TableList { get; set; } = new ObservableCollection<string>();
  25. private int _alarmGroupsWidth = 285;
  26. public string SelectedAlarmGroup { get; set; }
  27. public int AlarmGroupsWidth
  28. {
  29. get => _alarmGroupsWidth;
  30. set
  31. {
  32. _alarmGroupsWidth = value;
  33. NotifyOfPropertyChange("AlarmGroupsWidth");
  34. }
  35. }
  36. private List<string> _groupNames = new List<string>
  37. (new string[] {
  38. "Group1",
  39. "Group2",
  40. "Group3",
  41. "Group4",
  42. "Group5",
  43. "Group6",
  44. "Group7",
  45. "Group8",
  46. "Group9",
  47. "Group10"
  48. });
  49. public Dictionary<string, Dictionary<string, EventItem>> AllGroupAlarmList = new Dictionary<string, Dictionary<string, EventItem>>();
  50. public List<string> GroupNames
  51. {
  52. get => _groupNames;
  53. set
  54. {
  55. _groupNames = value;
  56. NotifyOfPropertyChange("GroupNames");
  57. }
  58. }
  59. public int SelectedAlarmTableIndex = 0;
  60. public string EntryValue;
  61. public Visibility _alarmTableVisibility = Visibility.Collapsed;
  62. public Visibility AlarmTableVisibility
  63. {
  64. get => _alarmTableVisibility;
  65. set
  66. {
  67. _alarmTableVisibility = value;
  68. NotifyOfPropertyChange("AlarmTableVisibility");
  69. }
  70. }
  71. public Visibility _alarmGroupsVisibility = Visibility.Collapsed;
  72. public Visibility AlarmGroupsVisibility
  73. {
  74. get => _alarmGroupsVisibility;
  75. set
  76. {
  77. _alarmGroupsVisibility = value;
  78. if (_alarmGroupsVisibility == Visibility.Visible)
  79. { AlarmGroupsWidth = 235; }
  80. else
  81. {
  82. AlarmGroupsWidth = 0;
  83. }
  84. NotifyOfPropertyChange("AlarmGroupsVisibility");
  85. }
  86. }
  87. protected override void OnViewLoaded(object view)
  88. {
  89. base.OnViewLoaded(view);
  90. var alarmDict = _alarmProvider.GetXmlAlarmList();
  91. AllGroupAlarmList = alarmDict;
  92. SetVisibility();
  93. }
  94. private void SetVisibility()
  95. {
  96. if (AllGroupAlarmList != null)
  97. {
  98. if (AllGroupAlarmList.Count < 2)
  99. {
  100. AlarmTableVisibility = Visibility.Collapsed;
  101. if (AllGroupAlarmList.Count != 0)
  102. {
  103. AlarmParameterOperations.Clear();
  104. foreach (var subitem in AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()].Keys)
  105. {
  106. AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()][subitem]));
  107. }
  108. }
  109. }
  110. else
  111. {
  112. AlarmTableVisibility = Visibility.Visible;
  113. TableList.Clear();
  114. foreach (var item in AllGroupAlarmList.Keys)
  115. {
  116. TableList.Add(item);
  117. }
  118. AlarmParameterOperations.Clear();
  119. foreach (var subitem in AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()].Keys)
  120. {
  121. AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()][subitem]));
  122. }
  123. }
  124. SetAlarmGroup(AllGroupAlarmList.Keys.FirstOrDefault());
  125. }
  126. else
  127. {
  128. AlarmTableVisibility = Visibility.Hidden;
  129. }
  130. }
  131. public void AlarmTableSelected(string index)
  132. {
  133. SaveAlarmGroup();
  134. int tempValue = int.Parse(index);
  135. SelectedAlarmTableIndex = tempValue;
  136. SelectedAlarmGroup = string.Empty;
  137. AlarmParameterOperations.Clear();
  138. SetAlarmGroup(index);
  139. }
  140. private void SetAlarmGroup(string index)
  141. {
  142. AlarmGroups.Clear();
  143. var categoryList = AllGroupAlarmList[index].Values.Select(x => x.Category);
  144. foreach (var item in categoryList)
  145. {
  146. if (!AlarmGroups.Contains(item))
  147. {
  148. AlarmGroups.Add(item);
  149. }
  150. }
  151. if (AlarmGroups.Count < 2)
  152. {
  153. AlarmGroupsVisibility = Visibility.Collapsed;
  154. AlarmParameterOperations.Clear();
  155. foreach (var subitem in AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()].Keys)
  156. {
  157. AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[AllGroupAlarmList.Keys.FirstOrDefault()][subitem]));
  158. }
  159. }
  160. else
  161. {
  162. AlarmGroupsVisibility = Visibility.Visible;
  163. AlarmParameterOperations.Clear();
  164. foreach (var subitem in AllGroupAlarmList[index].Keys)
  165. {
  166. AlarmParameterOperations.Add(new AlarmParameterOperation(subitem, AllGroupAlarmList[index][subitem]));
  167. }
  168. }
  169. }
  170. private void SaveAlarmGroup()
  171. {
  172. foreach (var item in AlarmParameterOperations)
  173. {
  174. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Id = item.ID;
  175. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Source = item.Source;
  176. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Description = item.Description;
  177. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Solution = item.Solution;
  178. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Explaination = item.Explaination;
  179. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Bypass = item.Bypass;
  180. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Group = (EventGroup)Enum.Parse(typeof(EventGroup), item.Group);
  181. AllGroupAlarmList[SelectedAlarmTableIndex.ToString()][item.AlarmName].Editable = item.IsEdit;
  182. }
  183. }
  184. public void AlarmTableSave()
  185. {
  186. SaveAlarmGroup();
  187. InvokeClient.Instance.Service.DoOperation($"System.UpdateAlarmTable", AllGroupAlarmList);
  188. }
  189. /// <summary>
  190. /// 按照Id号或者Alarm文本查找
  191. /// </summary>
  192. /// <param name="alarmId"></param>
  193. /// <param name="alarmText"></param>
  194. public void AlarmValueFind(string alarmId, string alarmText)
  195. {
  196. if (!string.IsNullOrWhiteSpace(alarmId) || !string.IsNullOrWhiteSpace(alarmText))
  197. {
  198. AlarmParameterOperations.Clear();
  199. bool b1, b2, b3, b4;
  200. if (!string.IsNullOrEmpty(SelectedAlarmGroup))
  201. {
  202. foreach(var alarmOperation in AllGroupAlarmList[SelectedAlarmTableIndex.ToString()])
  203. {
  204. b1 = alarmOperation.Value.Category == SelectedAlarmGroup;
  205. b2 = string.IsNullOrWhiteSpace(alarmId) && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower());
  206. b3 = string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId;
  207. b4 = !string.IsNullOrWhiteSpace(alarmId) && !string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower());
  208. if (b1 && (b2 || b3 || b4))
  209. {
  210. AlarmParameterOperations.Add(new AlarmParameterOperation(alarmOperation.Key, alarmOperation.Value));
  211. }
  212. }
  213. }
  214. else
  215. {
  216. foreach (var alarmOperation in AllGroupAlarmList[SelectedAlarmTableIndex.ToString()])
  217. {
  218. b2 = string.IsNullOrWhiteSpace(alarmId) && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower());
  219. b3 = string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId;
  220. b4 = !string.IsNullOrWhiteSpace(alarmId) && !string.IsNullOrWhiteSpace(alarmText) && alarmOperation.Value.Id.ToString() == alarmId && alarmOperation.Value.Description.ToLower().Contains(alarmText.ToLower());
  221. if (b2 || b3 || b4)
  222. {
  223. AlarmParameterOperations.Add(new AlarmParameterOperation(alarmOperation.Key, alarmOperation.Value));
  224. }
  225. }
  226. }
  227. }
  228. else
  229. {
  230. DialogBox.ShowWarning("Please input condition!");
  231. }
  232. }
  233. public void AlarmTableAllOn()
  234. {
  235. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, "Whether all switches are turned on?") == DialogButton.Yes)
  236. {
  237. EntryValue = "AllOn";
  238. GetAlarmParameterOperations();
  239. }
  240. }
  241. public void AlarmTableAllOff()
  242. {
  243. if (DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No, DialogType.CONFIRM, "Whether all switches are turned off?") == DialogButton.Yes)
  244. {
  245. EntryValue = "AllOff";
  246. GetAlarmParameterOperations();
  247. }
  248. }
  249. public void AlarmTableCancel()
  250. {
  251. }
  252. public void GetAlarmParameterOperations()
  253. {
  254. if (AllGroupAlarmList == null || AllGroupAlarmList.Count == 0) return;
  255. foreach (var item in AllGroupAlarmList[SelectedAlarmTableIndex.ToString()])
  256. {
  257. if (AlarmGroups.Count < 2)
  258. {
  259. if (EntryValue == "AllOn")
  260. item.Value.Bypass = true;
  261. else if (EntryValue == "AllOff")
  262. item.Value.Bypass = false;
  263. }
  264. else
  265. {
  266. if (SelectedAlarmGroup != null)
  267. {
  268. if (item.Value.Category == SelectedAlarmGroup)
  269. {
  270. if (EntryValue == "AllOn")
  271. item.Value.Bypass = true;
  272. else if (EntryValue == "AllOff")
  273. item.Value.Bypass = false;
  274. }
  275. }
  276. }
  277. }
  278. AlarmParameterOperations.Clear();
  279. IEnumerable<KeyValuePair<string, EventItem>> findGroupAlarm;
  280. if (SelectedAlarmGroup != null)
  281. {
  282. findGroupAlarm = AllGroupAlarmList[SelectedAlarmTableIndex.ToString()].Where(x => x.Value.Category == SelectedAlarmGroup);
  283. }
  284. else
  285. {
  286. findGroupAlarm = AllGroupAlarmList[SelectedAlarmTableIndex.ToString()];
  287. }
  288. foreach (var item in findGroupAlarm)
  289. {
  290. AlarmParameterOperations.Add(new AlarmParameterOperation(item.Key, item.Value));
  291. }
  292. }
  293. public void AlarmTypeSelected(object obj)
  294. {
  295. var tempobj = obj;
  296. var selectedAlarmGroup = (string)tempobj;
  297. SelectedAlarmGroup = selectedAlarmGroup;
  298. SaveAlarmGroup();
  299. AlarmParameterOperations.Clear();
  300. var findGroupAlarm = AllGroupAlarmList[SelectedAlarmTableIndex.ToString()].Where(x => x.Value.Category == selectedAlarmGroup);
  301. foreach (var item in findGroupAlarm)
  302. {
  303. AlarmParameterOperations.Add(new AlarmParameterOperation(item.Key, item.Value));
  304. }
  305. }
  306. public class AlarmParameterOperation : PropertyChangedBase
  307. {
  308. public AlarmParameterOperation()
  309. { }
  310. private string _alarmName;
  311. public string AlarmName
  312. {
  313. get => _alarmName;
  314. set
  315. {
  316. _alarmName = value;
  317. NotifyOfPropertyChange("AlarmName");
  318. }
  319. }
  320. private string _source;
  321. public string Source
  322. {
  323. get => _source;
  324. set
  325. {
  326. _source = value;
  327. NotifyOfPropertyChange("Source");
  328. }
  329. }
  330. private long _id;
  331. public long ID
  332. {
  333. get => _id;
  334. set
  335. {
  336. _id = value;
  337. NotifyOfPropertyChange("ID");
  338. }
  339. }
  340. private string _description;
  341. public string Description
  342. {
  343. get => _description;
  344. set
  345. {
  346. _description = value;
  347. NotifyOfPropertyChange("Description");
  348. }
  349. }
  350. private string _solution;
  351. public string Solution
  352. {
  353. get => _solution;
  354. set
  355. {
  356. _solution = value;
  357. NotifyOfPropertyChange("Solution");
  358. }
  359. }
  360. private string _explaination;
  361. public string Explaination
  362. {
  363. get => _explaination;
  364. set
  365. {
  366. _explaination = value;
  367. NotifyOfPropertyChange("Explaination");
  368. }
  369. }
  370. private bool _bypass;
  371. public bool Bypass
  372. {
  373. get => _bypass;
  374. set
  375. {
  376. _bypass = value;
  377. NotifyOfPropertyChange("Bypass");
  378. }
  379. }
  380. private string _group;
  381. public string Group
  382. {
  383. get => _group;
  384. set
  385. {
  386. _group = value;
  387. NotifyOfPropertyChange("Group");
  388. }
  389. }
  390. private bool _isEdit;
  391. public bool IsEdit
  392. {
  393. get => _isEdit;
  394. set
  395. {
  396. _isEdit = value;
  397. NotifyOfPropertyChange("IsEdit");
  398. }
  399. }
  400. private int _selectedIndex;
  401. public int SelectedIndex
  402. {
  403. get => _selectedIndex;
  404. set
  405. {
  406. _selectedIndex = value;
  407. NotifyOfPropertyChange("SelectedIndex");
  408. }
  409. }
  410. public AlarmParameterOperation(string key, EventItem eventItem)
  411. {
  412. AlarmName = key;
  413. if (eventItem != null)
  414. {
  415. ID = eventItem.Id;
  416. Source = eventItem.Source;
  417. Description = eventItem.Description;
  418. Solution = eventItem.Solution;
  419. Explaination = eventItem.Explaination;
  420. Bypass = eventItem.Bypass;
  421. if (eventItem.Group == EventGroup.Group0)
  422. eventItem.Group = EventGroup.Group1;
  423. Group = eventItem.Group.ToString();
  424. IsEdit = eventItem.Editable;
  425. }
  426. }
  427. public AlarmParameterOperation(string alarmParameterStr)
  428. {
  429. if (alarmParameterStr != null)
  430. {
  431. var alarmPar = alarmParameterStr.Split(',');
  432. if (alarmPar != null && alarmPar.Length > 0)
  433. {
  434. _id = int.Parse(alarmPar[0]);
  435. //_isSave = bool.Parse(alarmPar[1]);
  436. _group = alarmPar[2];
  437. _isEdit = bool.Parse(alarmPar[3]);
  438. }
  439. }
  440. }
  441. public override string ToString()
  442. {
  443. string rtnString = $"{_id},{_group},{_isEdit}";
  444. return rtnString;
  445. }
  446. }
  447. public class ShowAlarmGroup : PropertyChangedBase
  448. {
  449. private string _name;
  450. public string Name
  451. {
  452. get => _name; set
  453. {
  454. _name = value;
  455. NotifyOfPropertyChange("Name");
  456. }
  457. }
  458. private string _display;
  459. public string Display
  460. {
  461. get => _display; set
  462. {
  463. _display = value;
  464. NotifyOfPropertyChange("Display");
  465. }
  466. }
  467. private bool _bvalue = false;
  468. public bool AlarmBoolValue
  469. {
  470. get { return _bvalue; }
  471. set { _bvalue = value; NotifyOfPropertyChange("AlarmBoolValue"); }
  472. }
  473. }
  474. }
  475. }