RecipeLoadControl.xaml.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using MECF.Framework.Common.RecipeCenter;
  2. using PunkHPX8_Core;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Collections.ObjectModel;
  6. using System.Diagnostics;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace PunkHPX8_Themes.UserControls
  20. {
  21. /// <summary>
  22. /// RecipeLoad.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class RecipeLoadControl : UserControl
  25. {
  26. public RecipeLoadControl()
  27. {
  28. InitializeComponent();
  29. }
  30. public static readonly DependencyProperty SelectedRecipeNodeProperty = DependencyProperty.Register( "SelectedRecipeNode", typeof(RecipeNode), typeof(RecipeLoadControl),
  31. new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
  32. /// <summary>
  33. /// 当前选中recipe节点
  34. /// </summary>
  35. public RecipeNode SelectedRecipeNode
  36. {
  37. get
  38. {
  39. return (RecipeNode)this.GetValue(SelectedRecipeNodeProperty);
  40. }
  41. set
  42. {
  43. this.SetValue(SelectedRecipeNodeProperty, value);
  44. }
  45. }
  46. public static readonly DependencyProperty RecipeTypeProperty = DependencyProperty.Register(
  47. "RecipeType", typeof(string), typeof(RecipeLoadControl),new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  48. /// <summary>
  49. /// recipe类型
  50. /// </summary>
  51. public string RecipeType
  52. {
  53. get
  54. {
  55. return (string)this.GetValue(RecipeTypeProperty);
  56. }
  57. set
  58. {
  59. this.SetValue(RecipeTypeProperty, value);
  60. }
  61. }
  62. public static readonly DependencyProperty RecipeNodesProperty = DependencyProperty.
  63. Register("RecipeNodes", typeof(ObservableCollection<RecipeNode>), typeof(RecipeLoadControl));
  64. public ObservableCollection<RecipeNode> RecipeNodes
  65. {
  66. get { return (ObservableCollection<RecipeNode>)this.GetValue(RecipeNodesProperty); }
  67. set { this.SetValue(RecipeNodesProperty, value); }
  68. }
  69. private void Self_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  70. {
  71. if (e.NewValue != null)
  72. {
  73. bool result = (bool)e.NewValue;
  74. if (result)
  75. {
  76. if (!string.IsNullOrEmpty(RecipeType))
  77. {
  78. RecipeNodes = RecipeClient.Instance.Service.GetRecipesByType(RecipeType);
  79. if ("dep".Equals(RecipeType))
  80. {
  81. ObservableCollection<RecipeNode> DqdrRecipeNodes = RecipeClient.Instance.Service.GetRecipesByType("dqdr");
  82. if (DqdrRecipeNodes != null)
  83. {
  84. foreach(var item in DqdrRecipeNodes)
  85. {
  86. RecipeNodes.Add(item);
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. }
  94. public static readonly DependencyProperty IsEngineeringModeProperty = DependencyProperty.Register(
  95. "IsEngineeringMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  96. /// <summary>
  97. /// IsEngineeringMode
  98. /// </summary>
  99. public bool IsEngineeringMode
  100. {
  101. get
  102. {
  103. return (bool)this.GetValue(IsEngineeringModeProperty);
  104. }
  105. set
  106. {
  107. this.SetValue(IsEngineeringModeProperty, value);
  108. }
  109. }
  110. public static readonly DependencyProperty IsProductionModeProperty = DependencyProperty.Register(
  111. "IsProductionMode", typeof(bool), typeof(RecipeLoadControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  112. /// <summary>
  113. /// IsProductionMode
  114. /// </summary>
  115. public bool IsProductionMode
  116. {
  117. get
  118. {
  119. return (bool)this.GetValue(IsProductionModeProperty);
  120. }
  121. set
  122. {
  123. this.SetValue(IsProductionModeProperty, value);
  124. }
  125. }
  126. private void TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
  127. {
  128. RecipeNode recipeNode = (RecipeNode)e.NewValue;
  129. if (recipeNode != null)
  130. {
  131. if(recipeNode.NodeType== RecipeNodeType.File)
  132. {
  133. SelectedRecipeNode = recipeNode;
  134. }
  135. else
  136. {
  137. SelectedRecipeNode = null;
  138. }
  139. }
  140. else
  141. {
  142. SelectedRecipeNode = null;
  143. }
  144. }
  145. }
  146. }