ManualPressCommandViewModel.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. using Aitex.Core.RT.SCCore;
  2. using Caliburn.Micro;
  3. using Caliburn.Micro.Core;
  4. using MECF.Framework.Common.DataCenter;
  5. using MECF.Framework.Common.RecipeCenter;
  6. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using FurnaceUI.Models;
  15. using FurnaceUI.Views.Parameter;
  16. using FurnaceUI.Views.Recipes;
  17. using System.Windows.Controls;
  18. using System.Windows.Media;
  19. using Aitex.Core.Util;
  20. using Aitex.Core.Common.DeviceData;
  21. namespace FurnaceUI.Views.Editors
  22. {
  23. public class ManualPressCommandViewModel : FurnaceUIViewModelBase
  24. {
  25. private Dictionary<string, string> boatCmd = new Dictionary<string, string>();
  26. [Subscription("PM1.APC.DeviceData")]
  27. public AITAPCData APCData { get; set; }
  28. public bool IsSave { get; set; }
  29. public bool IsCommandButtonEnable => true;
  30. public string SelectedCmd { get; set; }
  31. public bool SetRecipeProcessEditViewEnable { get; set; } = true;
  32. private string _description = "";
  33. public string Description
  34. {
  35. get => _description;
  36. set
  37. {
  38. _description = value;
  39. NotifyOfPropertyChange(nameof(Description));
  40. }
  41. }
  42. private ManualPressCommandView _view;
  43. public string ReturnString { get; set; } = "";
  44. public string DefaultUnit { get; set; } = "Torr";
  45. public ManualPressCommandViewModel()
  46. {
  47. //CreateRadioButton();
  48. }
  49. public void RdoChecked(string cmd, object sender)
  50. {
  51. if (sender is RadioButton)
  52. {
  53. DefaultUnit = (string)QueryDataClient.Instance.Service.GetConfig($"PM1.APC.PressureUnit");
  54. ReturnString = cmd;
  55. switch (cmd)
  56. {
  57. case "Slow Vac":
  58. DefaultUnit = $"{DefaultUnit}/S";
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. }
  65. //private void CreateRadioButton()
  66. //{
  67. // boatCmd.Clear();
  68. // boatCmd.Add("Boat Load", "The boat is loaded in the furnace.(Speed set avai lable)");
  69. // boatCmd.Add("Boat Unload", "The boat is unloaded f rom the furnace.(Speed set available)");
  70. // boatCmd.Add("Boat Loader Home", "Boat Loader ismoved to the home position.");
  71. // boatCmd.Add("Boat Rotate", "The boat is rotated.");
  72. // boatCmd.Add("Boat Rotate Stop", "The rotat ion of the boat is stopped and R-axis is moved to the home position.");
  73. // boatCmd.Add("Boat CAP2", "Boat Loader is moved to CAP2 position.(CAP2 : CAP position in condition to not seal the reactor)");
  74. // boatCmd.Add("Stop(Include R-axis)", "Boat Loader is stopped. (Include R-axis.");
  75. //}
  76. public void RdoChecked(object sender)
  77. {
  78. Description = boatCmd[(string)((RadioButton)sender).Content];
  79. if ((bool)((RadioButton)sender).IsChecked)
  80. {
  81. ReturnString = (string)((RadioButton)sender).Content;
  82. }
  83. }
  84. public bool IsEnable
  85. {
  86. get
  87. {
  88. if (SetRecipeProcessEditViewEnable)
  89. {
  90. return CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  91. }
  92. else
  93. {
  94. return true;
  95. }
  96. }
  97. }
  98. public string RecipeType { get; set; }
  99. protected override void OnViewLoaded(object view)
  100. {
  101. base.OnViewLoaded(view);
  102. LoadData(view);
  103. }
  104. private void LoadData(object view)
  105. {
  106. if (!string.IsNullOrEmpty(SelectedCmd))
  107. {
  108. _view = ((GetView() as Window).Content) as ManualPressCommandView;
  109. string selectedCmd = SelectedCmd.Replace(" ", "");
  110. var control = _view.FindName(selectedCmd);
  111. if (control is null)
  112. return;
  113. RadioButton radioButton = control as RadioButton;
  114. radioButton.IsChecked = true;
  115. }
  116. ReturnString = SelectedCmd;
  117. }
  118. /// <summary>
  119. /// 查找子控件
  120. /// </summary>
  121. /// <typeparam name="T">子控件的类型</typeparam>
  122. /// <param name="obj">要找的是obj的子控件</param>
  123. /// <param name="name">想找的子控件的Name属性</param>
  124. /// <returns>目标子控件</returns>
  125. public static T GetChildObject<T>(DependencyObject obj, string name) where T : FrameworkElement
  126. {
  127. DependencyObject child = null;
  128. T grandChild = null;
  129. for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
  130. {
  131. child = VisualTreeHelper.GetChild(obj, i);
  132. if (child is T && (((T)child).Name == name | string.IsNullOrEmpty(name)))
  133. {
  134. return (T)child;
  135. }
  136. else
  137. {
  138. // 在下一级中没有找到指定名字的子控件,就再往下一级找
  139. grandChild = GetChildObject<T>(child, name);
  140. if (grandChild != null)
  141. return grandChild;
  142. }
  143. }
  144. return null;
  145. }
  146. public void TempSetSave()
  147. {
  148. IsSave = true;
  149. ((Window)GetView()).DialogResult = true;
  150. }
  151. public void TempSetCancel()
  152. {
  153. IsSave = false;
  154. ((Window)GetView()).DialogResult = false;
  155. }
  156. }
  157. }