using Aitex.Core.Common;
using LiveCharts;
using MECF.Framework.Common.OperationCenter;
using System;
using System.Collections.Generic;
using System.Linq;
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
{
///
/// TemperatureControllerControl.xaml 的交互逻辑
///
public partial class TemperatureControllerControl : UserControl
{
#region 属性
public static readonly DependencyProperty ModuleNameProperty = DependencyProperty.Register(
"ModuleName", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 模块名称
///
public string ModuleName
{
get
{
return (string)this.GetValue(ModuleNameProperty);
}
set
{
this.SetValue(ModuleNameProperty, value);
}
}
public static readonly DependencyProperty ModuleTitleProperty = DependencyProperty.Register(
"ModuleTitle", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 标题
///
public string ModuleTitle
{
get
{
return (string)this.GetValue(ModuleTitleProperty);
}
set
{
this.SetValue(ModuleTitleProperty, value);
}
}
public static readonly DependencyProperty DisableStatusProperty = DependencyProperty.Register(
"DisableStatus", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 可用性状态
///
public string DisableStatus
{
get
{
return (string)this.GetValue(DisableStatusProperty);
}
set
{
this.SetValue(DisableStatusProperty, value);
}
}
public static readonly DependencyProperty IsEnableProperty = DependencyProperty.Register(
"IsEnable", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
///IsEnable
///
public bool IsEnable
{
get
{
return (bool)this.GetValue(IsEnableProperty);
}
set
{
this.SetValue(IsEnableProperty, value);
}
}
public static readonly DependencyProperty IsApplyEnableProperty = DependencyProperty.Register(
"IsApplyEnable", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
///IsApplyEnable
///
public bool IsApplyEnable
{
get
{
return (bool)this.GetValue(IsApplyEnableProperty);
}
set
{
this.SetValue(IsApplyEnableProperty, value);
}
}
public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(
"Status", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("Normal", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 状态
///
public string Status
{
get
{
return (string)this.GetValue(StatusProperty);
}
set
{
this.SetValue(StatusProperty, value);
}
}
public static readonly DependencyProperty AutoStatusProperty = DependencyProperty.Register(
"AutoStatus", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata("Auto", FrameworkPropertyMetadataOptions.AffectsRender));
///
/// 自动性状态
///
public string AutoStatus
{
get
{
return (string)this.GetValue(AutoStatusProperty);
}
set
{
this.SetValue(AutoStatusProperty, value);
}
}
public static readonly DependencyProperty IsConnectedProperty = DependencyProperty.Register(
"IsConnected", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// IsConnected
///
public bool IsConnected
{
get
{
return (bool)this.GetValue(IsConnectedProperty);
}
set
{
this.SetValue(IsConnectedProperty, value);
}
}
public static readonly DependencyProperty TemperatureReachedProperty = DependencyProperty.Register(
"TemperatureReached", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// TemperatureReached
///
public bool TemperatureReached
{
get
{
return (bool)this.GetValue(TemperatureReachedProperty);
}
set
{
this.SetValue(TemperatureReachedProperty, value);
}
}
public static readonly DependencyProperty DeltaExceededProperty = DependencyProperty.Register(
"DeltaExceeded", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// DeltaExceeded
///
public bool DeltaExceeded
{
get
{
return (bool)this.GetValue(DeltaExceededProperty);
}
set
{
this.SetValue(DeltaExceededProperty, value);
}
}
#region Alarm
public static readonly DependencyProperty AlarmDataProperty = DependencyProperty.Register(
"AlarmData", typeof(string), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(AlarmDataChanged)));
///
/// AlarmData
///
public string AlarmData
{
get
{
return (string)this.GetValue(AlarmDataProperty);
}
set
{
this.SetValue(AlarmDataProperty, value);
}
}
private static void AlarmDataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != null)
{
string alarm = (string)e.NewValue;
string[] strAry = alarm.Split('-');
int result = 0;
if (strAry.Length == 12)
{
result += SetAlarmProperty(d, HighTempCutoffProperty, strAry[3] == "1");
result += SetAlarmProperty(d, LowTempCutoffProperty, strAry[2] == "1");
result += SetAlarmProperty(d, FanProperty, strAry[1] == "1");
result += SetAlarmProperty(d, OutputFailureProperty, strAry[0] == "1");
result += SetAlarmProperty(d, TempLimitWarnProperty, strAry[7] == "1");
result += SetAlarmProperty(d, RemoteOffProperty, strAry[6] == "1");
result += SetAlarmProperty(d, ThermostatProperty, strAry[5] == "1");
result += SetAlarmProperty(d, PowerFailureProperty, strAry[4] == "1");
result += SetAlarmProperty(d, ExtSensorFailureProperty, strAry[11] == "1");
result += SetAlarmProperty(d, IntSensorFailureProperty, strAry[10] == "1");
result += SetAlarmProperty(d, AutoTuningProperty, strAry[9] == "1");
result += SetAlarmProperty(d, LeakProperty, strAry[8] == "1");
//if (result == 0)
//{
// d.SetValue(StatusProperty, "Normal");
//}
//else
//{
// d.SetValue(StatusProperty, "Error");
//}
}
}
}
private static int SetAlarmProperty(DependencyObject d,DependencyProperty dependency, bool value)
{
d.SetValue(dependency, value);
return value ? 1 : 0;
}
public static readonly DependencyProperty AutoTuningProperty = DependencyProperty.Register(
"AutoTuning", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// AutoTuning
///
public bool AutoTuning
{
get
{
return (bool)this.GetValue(AutoTuningProperty);
}
set
{
this.SetValue(AutoTuningProperty, value);
}
}
public static readonly DependencyProperty FanProperty = DependencyProperty.Register(
"Fan", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// Fan
///
public bool Fan
{
get
{
return (bool)this.GetValue(FanProperty);
}
set
{
this.SetValue(FanProperty, value);
}
}
public static readonly DependencyProperty RemoteOffProperty = DependencyProperty.Register(
"RemoteOff", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// RemoteOff
///
public bool RemoteOff
{
get
{
return (bool)this.GetValue(RemoteOffProperty);
}
set
{
this.SetValue(RemoteOffProperty, value);
}
}
public static readonly DependencyProperty ExtSensorFailureProperty = DependencyProperty.Register(
"ExtSensorFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// ExtSensorFailure
///
public bool ExtSensorFailure
{
get
{
return (bool)this.GetValue(ExtSensorFailureProperty);
}
set
{
this.SetValue(ExtSensorFailureProperty, value);
}
}
public static readonly DependencyProperty HighTempCutoffProperty = DependencyProperty.Register(
"HighTempCutoff", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// HighTempCutoff
///
public bool HighTempCutoff
{
get
{
return (bool)this.GetValue(HighTempCutoffProperty);
}
set
{
this.SetValue(HighTempCutoffProperty, value);
}
}
public static readonly DependencyProperty LowTempCutoffProperty = DependencyProperty.Register(
"LowTempCutoff", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// LowTempCutoff
///
public bool LowTempCutoff
{
get
{
return (bool)this.GetValue(LowTempCutoffProperty);
}
set
{
this.SetValue(LowTempCutoffProperty, value);
}
}
public static readonly DependencyProperty OutputFailureProperty = DependencyProperty.Register(
"OutputFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// OutputFailure
///
public bool OutputFailure
{
get
{
return (bool)this.GetValue(OutputFailureProperty);
}
set
{
this.SetValue(OutputFailureProperty, value);
}
}
public static readonly DependencyProperty IntSensorFailureProperty = DependencyProperty.Register(
"IntSensorFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// IntSensorFailure
///
public bool IntSensorFailure
{
get
{
return (bool)this.GetValue(IntSensorFailureProperty);
}
set
{
this.SetValue(IntSensorFailureProperty, value);
}
}
public static readonly DependencyProperty TempLimitWarnProperty = DependencyProperty.Register(
"TempLimitWarn", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// TempLimitWarn
///
public bool TempLimitWarn
{
get
{
return (bool)this.GetValue(TempLimitWarnProperty);
}
set
{
this.SetValue(TempLimitWarnProperty, value);
}
}
public static readonly DependencyProperty PowerFailureProperty = DependencyProperty.Register(
"PowerFailure", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// PowerFailure
///
public bool PowerFailure
{
get
{
return (bool)this.GetValue(PowerFailureProperty);
}
set
{
this.SetValue(PowerFailureProperty, value);
}
}
public static readonly DependencyProperty LeakProperty = DependencyProperty.Register(
"Leak", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// Leak
///
public bool Leak
{
get
{
return (bool)this.GetValue(LeakProperty);
}
set
{
this.SetValue(LeakProperty, value);
}
}
public static readonly DependencyProperty ThermostatProperty = DependencyProperty.Register(
"Thermostat", typeof(bool), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// Thermostat
///
public bool Thermostat
{
get
{
return (bool)this.GetValue(ThermostatProperty);
}
set
{
this.SetValue(ThermostatProperty, value);
}
}
#endregion
public static readonly DependencyProperty SetPointValueProperty = DependencyProperty.Register(
"SetPointValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// SetPointValue
///
public double SetPointValue
{
get
{
return (double)this.GetValue(SetPointValueProperty);
}
set
{
this.SetValue(SetPointValueProperty, value);
}
}
public static readonly DependencyProperty SetPointMinValueProperty = DependencyProperty.Register(
"SetPointMinValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// SetPointMinValue
///
public double SetPointMinValue
{
get
{
return (double)this.GetValue(SetPointMinValueProperty);
}
set
{
this.SetValue(SetPointMinValueProperty, value);
}
}
public static readonly DependencyProperty SetPointMaxValueProperty = DependencyProperty.Register(
"SetPointMaxValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// SetPointMaxValue
///
public double SetPointMaxValue
{
get
{
return (double)this.GetValue(SetPointMaxValueProperty);
}
set
{
this.SetValue(SetPointMaxValueProperty, value);
}
}
public static readonly DependencyProperty TargetTemperatureValueProperty = DependencyProperty.Register(
"TargetTemperatureValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// TargetTemperatureValue
///
public double TargetTemperatureValue
{
get
{
return (double)this.GetValue(TargetTemperatureValueProperty);
}
set
{
this.SetValue(TargetTemperatureValueProperty, value);
}
}
public static readonly DependencyProperty ReserviorValueProperty = DependencyProperty.Register(
"ReserviorValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// ReserviorValue
///
public double ReserviorValue
{
get
{
return (double)this.GetValue(ReserviorValueProperty);
}
set
{
this.SetValue(ReserviorValueProperty, value);
}
}
public static readonly DependencyProperty HeatExchangerValueProperty = DependencyProperty.Register(
"HeatExchangerValue", typeof(double), typeof(TemperatureControllerControl), new FrameworkPropertyMetadata((double)0, FrameworkPropertyMetadataOptions.AffectsRender));
///
/// HeatExchangerValue
///
public double HeatExchangerValue
{
get
{
return (double)this.GetValue(HeatExchangerValueProperty);
}
set
{
this.SetValue(HeatExchangerValueProperty, value);
}
}
#region 曲线
public static readonly DependencyProperty ReserviorSeriesProperty = DependencyProperty.Register("ReserviorSeries", typeof(ChartValues), typeof(TemperatureControllerControl),
new FrameworkPropertyMetadata(new ChartValues(), FrameworkPropertyMetadataOptions.AffectsRender));
///
/// ReserviorSeries
///
public ChartValues ReserviorSeries
{
get
{
return (ChartValues)this.GetValue(ReserviorSeriesProperty);
}
set
{
this.SetValue(ReserviorSeriesProperty, value);
}
}
public static readonly DependencyProperty HeatExchangerSeriesProperty = DependencyProperty.Register("HeatExchangerSeries", typeof(ChartValues), typeof(TemperatureControllerControl),
new FrameworkPropertyMetadata(new ChartValues(), FrameworkPropertyMetadataOptions.AffectsRender));
///
/// HeatExchangerSeries
///
public ChartValues HeatExchangerSeries
{
get
{
return (ChartValues)this.GetValue(HeatExchangerSeriesProperty);
}
set
{
this.SetValue(HeatExchangerSeriesProperty, value);
}
}
public static readonly DependencyProperty LabelSeriesProperty = DependencyProperty.Register("LabelSeries", typeof(ChartValues), typeof(TemperatureControllerControl),
new FrameworkPropertyMetadata(new ChartValues(), FrameworkPropertyMetadataOptions.AffectsRender));
///
/// LabelSeries
///
public ChartValues LabelSeries
{
get
{
return (ChartValues)this.GetValue(LabelSeriesProperty);
}
set
{
this.SetValue(LabelSeriesProperty, value);
}
}
#endregion
#endregion
///
/// 构造函数
///
public TemperatureControllerControl()
{
InitializeComponent();
}
#region Button Click
private void Disable_Click(object sender, RoutedEventArgs e)
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Disable");
}
private void Enable_Click(object sender, RoutedEventArgs e)
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Enable");
}
private void Apply_Click(object sender, RoutedEventArgs e)
{
InvokeClient.Instance.Service.DoOperation($"{ModuleName}.Apply", SetPointValue, SetPointMinValue,SetPointMaxValue);
}
#endregion
}
}