InterlockItemViewModel.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using MECF.Framework.Common.CommonData;
  2. using MECF.Framework.Common.DataCenter;
  3. using MECF.Framework.Common.IOCore;
  4. using OpenSEMI.ClientBase;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using FurnaceUI.Models;
  13. namespace FurnaceUI.Views.Operations
  14. {
  15. public class InterlockItemViewModel : FurnaceUIViewModelBase
  16. {
  17. public string ItemType { get; set; }
  18. public ObservableCollection<InterlockItem> InterlockItems { get; set; } = new ObservableCollection<InterlockItem>();
  19. private InterlockItem _interlockSelectedItem;
  20. public InterlockItem InterlockSelectedItem
  21. {
  22. get => _interlockSelectedItem;
  23. set
  24. {
  25. _interlockSelectedItem = value;
  26. NotifyOfPropertyChange(nameof(InterlockSelectedItem));
  27. }
  28. }
  29. private string _selectedItem;
  30. public string SelectedItem
  31. {
  32. get => _selectedItem;
  33. set
  34. {
  35. _selectedItem = value;
  36. NotifyOfPropertyChange(nameof(SelectedItem));
  37. }
  38. }
  39. private string _searchKey;
  40. public string SearchKey
  41. {
  42. get => _searchKey;
  43. set
  44. {
  45. _searchKey = value;
  46. NotifyOfPropertyChange(nameof(SearchKey));
  47. }
  48. }
  49. public InterlockItemViewModel(string itemType)
  50. {
  51. ItemType = itemType;
  52. }
  53. protected override void OnInitialize()
  54. {
  55. InitItem();
  56. base.OnInitialize();
  57. }
  58. private void InitItem()
  59. {
  60. if (ItemType == "Action")
  61. {
  62. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  63. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1");
  64. for (int i = 0; i < notifiableIoItems.Count; i++)
  65. {
  66. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  67. }
  68. }
  69. else
  70. {
  71. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  72. notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.PM1");
  73. for (int i = 0; i < notifiableIoItems.Count; i++)
  74. {
  75. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  76. }
  77. notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.PM1");
  78. for (int i = 0; i < notifiableIoItems.Count; i++)
  79. {
  80. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  81. }
  82. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1");
  83. for (int i = 0; i < notifiableIoItems.Count; i++)
  84. {
  85. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  86. }
  87. }
  88. }
  89. public void SearchItem()
  90. {
  91. if (!string.IsNullOrEmpty(SearchKey))
  92. {
  93. InterlockItems.Clear();
  94. if (ItemType == "Action")
  95. {
  96. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  97. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1");
  98. for (int i = 0; i < notifiableIoItems.Count; i++)
  99. {
  100. if (notifiableIoItems[i].Name.Contains(SearchKey))
  101. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  102. }
  103. }
  104. else
  105. {
  106. List<NotifiableIoItem> notifiableIoItems = new List<NotifiableIoItem>();
  107. notifiableIoItems = QueryDataClient.Instance.Service.GetDiList($"System.PM1");
  108. for (int i = 0; i < notifiableIoItems.Count; i++)
  109. {
  110. if (notifiableIoItems[i].Name.Contains(SearchKey))
  111. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  112. }
  113. notifiableIoItems = QueryDataClient.Instance.Service.GetAiList($"System.PM1");
  114. for (int i = 0; i < notifiableIoItems.Count; i++)
  115. {
  116. if (notifiableIoItems[i].Name.Contains(SearchKey))
  117. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  118. }
  119. notifiableIoItems = QueryDataClient.Instance.Service.GetDoList($"System.PM1");
  120. for (int i = 0; i < notifiableIoItems.Count; i++)
  121. {
  122. if (notifiableIoItems[i].Name.Contains(SearchKey))
  123. InterlockItems.Add(new InterlockItem() { ItemName = notifiableIoItems[i].Name });
  124. }
  125. }
  126. }
  127. else
  128. {
  129. DialogBox.ShowWarning("Please input search key!");
  130. }
  131. }
  132. public void SelectItem()
  133. {
  134. if (InterlockSelectedItem == null)
  135. SelectedItem = "";
  136. else
  137. SelectedItem = InterlockSelectedItem.ItemName;
  138. }
  139. public void SaveCmd()
  140. {
  141. if (string.IsNullOrEmpty(SelectedItem))
  142. {
  143. DialogBox.ShowWarning("SelectedItem is empty!");
  144. return;
  145. }
  146. ((Window)GetView()).DialogResult = true;
  147. }
  148. public void CloseCmd()
  149. {
  150. ((Window)GetView()).DialogResult = false;
  151. }
  152. }
  153. public class InterlockItem : NotifiableItem
  154. {
  155. private string _itemName;
  156. public string ItemName
  157. {
  158. get => _itemName;
  159. set
  160. {
  161. _itemName = value;
  162. InvokePropertyChanged(nameof(ItemName));
  163. }
  164. }
  165. }
  166. }