RecipeModeControl.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using MECF.Framework.Common.OperationCenter;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace PunkHPX8_Themes.UserControls
  17. {
  18. /// <summary>
  19. /// RecipeModeControl.xaml 的交互逻辑
  20. /// </summary>
  21. public partial class RecipeModeControl : UserControl
  22. {
  23. public RecipeModeControl()
  24. {
  25. InitializeComponent();
  26. }
  27. public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
  28. "ModuleName", typeof(string), typeof(RecipeModeControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
  29. /// <summary>
  30. /// 模块名称
  31. /// </summary>
  32. public string ModuleName
  33. {
  34. get
  35. {
  36. return (string)this.GetValue(ModuleNameProperty);
  37. }
  38. set
  39. {
  40. this.SetValue(ModuleNameProperty, value);
  41. }
  42. }
  43. public static readonly DependencyProperty IsEngineeringProperty = DependencyProperty.Register(
  44. "IsEngineering", typeof(bool), typeof(RecipeModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  45. /// <summary>
  46. /// IsEngineering
  47. /// </summary>
  48. public bool IsEngineering
  49. {
  50. get
  51. {
  52. return (bool)this.GetValue(IsEngineeringProperty);
  53. }
  54. set
  55. {
  56. this.SetValue(IsEngineeringProperty, value);
  57. }
  58. }
  59. public static readonly DependencyProperty IsProductionProperty = DependencyProperty.Register(
  60. "IsProduction", typeof(bool), typeof(RecipeModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
  61. /// <summary>
  62. /// IsProduction
  63. /// </summary>
  64. public bool IsProduction
  65. {
  66. get
  67. {
  68. return (bool)this.GetValue(IsProductionProperty);
  69. }
  70. set
  71. {
  72. this.SetValue(IsProductionProperty, value);
  73. }
  74. }
  75. public static readonly DependencyProperty RecipeModeValueProperty = DependencyProperty.Register(
  76. "RecipeModeValue", typeof(string), typeof(RecipeModeControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnRecipeModeValueChanged)));
  77. /// <summary>
  78. /// RecipeModeValue
  79. /// </summary>
  80. public string RecipeModeValue
  81. {
  82. get
  83. {
  84. return (string)this.GetValue(RecipeModeValueProperty);
  85. }
  86. set
  87. {
  88. this.SetValue(RecipeModeValueProperty, value);
  89. }
  90. }
  91. private static void OnRecipeModeValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  92. {
  93. string moduleName = (string)d.GetValue(ModuleNameProperty);
  94. RecipeModeControl control = (RecipeModeControl)d;
  95. if (e.NewValue != null)
  96. {
  97. string currentMode = (string)e.NewValue;
  98. switch (currentMode)
  99. {
  100. case "Engineering":
  101. d.SetValue(IsEngineeringProperty, true);
  102. d.SetValue(IsProductionProperty, false);
  103. break;
  104. case "Production":
  105. d.SetValue(IsEngineeringProperty, false);
  106. d.SetValue(IsProductionProperty, true);
  107. break;
  108. default:
  109. break;
  110. }
  111. }
  112. }
  113. private void Engineering_Click(object sender, RoutedEventArgs e)
  114. {
  115. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.EngineeringModeAction");
  116. }
  117. private void Production_Click(object sender, RoutedEventArgs e)
  118. {
  119. InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ProductionModeAction");
  120. }
  121. }
  122. }