RecipePressCommandViewModel.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. namespace FurnaceUI.Views.Editors
  20. {
  21. public class RecipePressCommandViewModel : FurnaceUIViewModelBase
  22. {
  23. private Dictionary<string, string> boatCmd = new Dictionary<string, string>();
  24. public bool IsSave { get; set; }
  25. public string SelectedCmd { get; set; }
  26. private string _description = "";
  27. public string Description
  28. {
  29. get => _description;
  30. set
  31. {
  32. _description = value;
  33. NotifyOfPropertyChange(nameof(Description));
  34. }
  35. }
  36. public string ReturnString { get; set; } = "";
  37. public RecipePressCommandViewModel()
  38. {
  39. //CreateRadioButton();
  40. }
  41. public void RdoChecked(string cmd, object sender)
  42. {
  43. if (sender is RadioButton)
  44. {
  45. ReturnString = cmd;
  46. //switch (cmd)
  47. //{
  48. // default:
  49. // break;
  50. //}
  51. }
  52. }
  53. //private void CreateRadioButton()
  54. //{
  55. // boatCmd.Clear();
  56. // boatCmd.Add("Boat Load", "The boat is loaded in the furnace.(Speed set avai lable)");
  57. // boatCmd.Add("Boat Unload", "The boat is unloaded f rom the furnace.(Speed set available)");
  58. // boatCmd.Add("Boat Loader Home", "Boat Loader ismoved to the home position.");
  59. // boatCmd.Add("Boat Rotate", "The boat is rotated.");
  60. // boatCmd.Add("Boat Rotate Stop", "The rotat ion of the boat is stopped and R-axis is moved to the home position.");
  61. // boatCmd.Add("Boat CAP2", "Boat Loader is moved to CAP2 position.(CAP2 : CAP position in condition to not seal the reactor)");
  62. // boatCmd.Add("Stop(Include R-axis)", "Boat Loader is stopped. (Include R-axis.");
  63. //}
  64. public void RdoChecked(object sender)
  65. {
  66. Description = boatCmd[(string)((RadioButton)sender).Content];
  67. if ((bool)((RadioButton)sender).IsChecked)
  68. {
  69. ReturnString = (string)((RadioButton)sender).Content;
  70. }
  71. }
  72. public bool IsEnable => CGlobal.RecipeProcessEditViewEnable;//是否是View模式
  73. public string RecipeType { get; set; }
  74. protected override void OnViewLoaded(object view)
  75. {
  76. base.OnViewLoaded(view);
  77. LoadData(view);
  78. }
  79. private void LoadData(object view)
  80. {
  81. if (!string.IsNullOrEmpty(SelectedCmd) )
  82. {
  83. var pressCmdView = (RecipePressCommandView)view;
  84. RadioButton radioButton = GetChildObject<RadioButton>(pressCmdView, SelectedCmd.Replace(" ",""));
  85. if (radioButton != null)
  86. {
  87. radioButton.IsChecked = true;
  88. }
  89. }
  90. ReturnString = SelectedCmd;
  91. }
  92. /// <summary>
  93. /// 查找子控件
  94. /// </summary>
  95. /// <typeparam name="T">子控件的类型</typeparam>
  96. /// <param name="obj">要找的是obj的子控件</param>
  97. /// <param name="name">想找的子控件的Name属性</param>
  98. /// <returns>目标子控件</returns>
  99. public static T GetChildObject<T>(DependencyObject obj, string name) where T : FrameworkElement
  100. {
  101. DependencyObject child = null;
  102. T grandChild = null;
  103. for (int i = 0; i <= VisualTreeHelper.GetChildrenCount(obj) - 1; i++)
  104. {
  105. child = VisualTreeHelper.GetChild(obj, i);
  106. if (child is T && (((T)child).Name == name | string.IsNullOrEmpty(name)))
  107. {
  108. return (T)child;
  109. }
  110. else
  111. {
  112. // 在下一级中没有找到指定名字的子控件,就再往下一级找
  113. grandChild = GetChildObject<T>(child, name);
  114. if (grandChild != null)
  115. return grandChild;
  116. }
  117. }
  118. return null;
  119. }
  120. public void TempSetSave()
  121. {
  122. IsSave = true;
  123. ((Window)GetView()).DialogResult = true;
  124. }
  125. public void TempSetCancel()
  126. {
  127. IsSave = false;
  128. ((Window)GetView()).DialogResult = false;
  129. }
  130. }
  131. }