using Aitex.Core.UI.MVVM;
using Aitex.Core.Utilities;
using MECF.Framework.Common.Equipment;
using MECF.Framework.Common.OperationCenter;
using MECF.Framework.Common.Persistent.Prewet;
using MECF.Framework.Common.Persistent.SRD;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace CyberX8_Themes.UserControls
{
///
/// OperatingModeControl.xaml 的交互逻辑
///
public partial class OperatingModeControl : UserControl
{
public OperatingModeControl()
{
InitializeComponent();
}
public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
"ModuleName", typeof(string), typeof(OperatingModeControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 模块名称
///
public string ModuleName
{
get
{
return (string)this.GetValue(ModuleNameProperty);
}
set
{
this.SetValue(ModuleNameProperty, value);
}
}
public static readonly DependencyProperty SubModuleNameProperty = DependencyProperty.Register(
"SubModuleName", typeof(string), typeof(OperatingModeControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// SubModuleName
///
public string SubModuleName
{
get
{
return (string)this.GetValue(SubModuleNameProperty);
}
set
{
this.SetValue(SubModuleNameProperty, value);
}
}
public static readonly DependencyProperty IsDisabledProperty = DependencyProperty.Register(
"IsDisabled", typeof(bool), typeof(OperatingModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// IsDisabled
///
public bool IsDisabled
{
get
{
return (bool)this.GetValue(IsDisabledProperty);
}
set
{
this.SetValue(IsDisabledProperty, value);
}
}
public static readonly DependencyProperty IsManualProperty = DependencyProperty.Register(
"IsManual", typeof(bool), typeof(OperatingModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// IsManual
///
public bool IsManual
{
get
{
return (bool)this.GetValue(IsManualProperty);
}
set
{
this.SetValue(IsManualProperty, value);
}
}
public static readonly DependencyProperty IsAutoProperty = DependencyProperty.Register(
"IsAuto", typeof(bool), typeof(OperatingModeControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// IsAuto
///
public bool IsAuto
{
get
{
return (bool)this.GetValue(IsAutoProperty);
}
set
{
this.SetValue(IsAutoProperty, value);
}
}
public static readonly DependencyProperty OperationModeValueProperty = DependencyProperty.Register(
"OperationModeValue", typeof(string), typeof(OperatingModeControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnItemsSourceChanged)));
///
/// OpertationModeValue
///
public string OperationModeValue
{
get
{
return (string)this.GetValue(OperationModeValueProperty);
}
set
{
this.SetValue(OperationModeValueProperty, value);
}
}
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
string moduleName = (string)d.GetValue(ModuleNameProperty);
OperatingModeControl control = (OperatingModeControl)d;
if (e.NewValue != null)
{
string currentMode = (string)e.NewValue;
switch (currentMode)
{
case "Disabled":
d.SetValue(IsDisabledProperty, true);
d.SetValue(IsManualProperty, false);
d.SetValue(IsAutoProperty, false); break;
case "Manual":
d.SetValue(IsDisabledProperty, false);
d.SetValue(IsManualProperty, true);
d.SetValue(IsAutoProperty, false); break;
case "Auto":
d.SetValue(IsDisabledProperty, false);
d.SetValue(IsManualProperty, false);
d.SetValue(IsAutoProperty, true); break;
default:
break;
}
}
}
private void Disabled_Click(object sender, RoutedEventArgs e)
{
if (SubModuleName == "DosingSystem")
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.DisabledAction", true);
}
else
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.DisabledAction");
}
}
private void Manual_Click(object sender, RoutedEventArgs e)
{
if(SubModuleName == "DosingSystem")
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ManualAction", true);
}
else
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.ManualAction");
}
}
private void Automatic_Click(object sender, RoutedEventArgs e)
{
if (SubModuleName == "DosingSystem")
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.AutoAction", true);
}
else
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.AutoAction");
}
}
}
}