| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437 | 
							- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- 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;
 
- using System.Globalization;
 
- using Aitex.Core.RT.Log;
 
- namespace Aitex.Core.UI.DeviceControl
 
- {
 
-     public class DoubleConverter : IValueConverter
 
-     {
 
-         public DoubleConverter()
 
-         {
 
-         }
 
-         // Summary:
 
-         //     Converts a value.
 
-         //
 
-         // Parameters:
 
-         //   value:
 
-         //     The value produced by the binding source.
 
-         //
 
-         //   targetType:
 
-         //     The type of the binding target property.
 
-         //
 
-         //   parameter:
 
-         //     The converter parameter to use.
 
-         //
 
-         //   culture:
 
-         //     The culture to use in the converter.
 
-         //
 
-         // Returns:
 
-         //     A converted value. If the method returns null, the valid null value is used.
 
-         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 
-         {
 
-             return value.ToString();
 
-         }
 
-         //
 
-         // Summary:
 
-         //     Converts a value.
 
-         //
 
-         // Parameters:
 
-         //   value:
 
-         //     The value that is produced by the binding target.
 
-         //
 
-         //   targetType:
 
-         //     The type to convert to.
 
-         //
 
-         //   parameter:
 
-         //     The converter parameter to use.
 
-         //
 
-         //   culture:
 
-         //     The culture to use in the converter.
 
-         //
 
-         // Returns:
 
-         //     A converted value. If the method returns null, the valid null value is used.
 
-         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
 
-         {
 
-             string input = (string)value;
 
-             double result = 0;
 
-             if (double.TryParse(input, out result))
 
-             {
 
-                 return result;
 
-             }
 
-             return DependencyProperty.UnsetValue;
 
-         }
 
-     }
 
-     public class InputDialogValidationRule : ValidationRule
 
-     {
 
-         double minInput;
 
-         double maxInput;
 
-         public double MinInput
 
-         {
 
-             get
 
-             {
 
-                 return this.minInput;
 
-             }
 
-             set
 
-             {
 
-                 this.minInput = value;
 
-             }
 
-         }
 
-         public double MaxInput
 
-         {
 
-             get
 
-             {
 
-                 return this.maxInput;
 
-             }
 
-             set
 
-             {
 
-                 this.maxInput = value;
 
-             }
 
-         }
 
-         public InputDialogValidationRule()
 
-         {
 
-         }
 
-         public override ValidationResult Validate(object value, CultureInfo cultureInfo)
 
-         {
 
-             double result;
 
-             // Is a number?
 
-             if (!double.TryParse((string)value, out result))
 
-             {
 
-                 string msg = string.Format("‘{0}’不是一个数。", value);
 
-                 return new ValidationResult(false, msg);
 
-             }
 
-             // Is in range?
 
-             if ((result < this.minInput) || (result > this.maxInput))
 
-             {
 
-                 string msg = string.Format("输入值必须在‘{0}’与‘{1}’之间。", this.minInput, this.maxInput);
 
-                 return new ValidationResult(false, msg);
 
-             }
 
-             // Number is valid
 
-             return new ValidationResult(true, null);
 
-         }
 
-     }
 
-     /// <summary>
 
-     /// Interaction logic for InputDialogBox.xaml
 
-     /// </summary>
 
-     public partial class AITHeaterInputDialogBox : Window
 
-     {
 
-         public AITHeaterInputDialogBox()
 
-         {
 
-             InitializeComponent();
 
-             DataContext = this;
 
-             WindowStartupLocation = WindowStartupLocation.CenterOwner;
 
-         }
 
-         public void FocasAll()
 
-         {
 
-             inputBox.Text = Math.Round(SetPoint, 2).ToString();
 
-             inputBox.Focus();
 
-             inputBox.SelectAll();
 
-         }
 
-         /// <summary>
 
-         /// Vilidate input range
 
-         /// </summary>
 
-         /// <param name="sender"></param>
 
-         /// <param name="e"></param>
 
-         private void InputTextBox_TextChanged(object sender, TextChangedEventArgs e)
 
-         {
 
-             double input;
 
-             if (!double.TryParse(inputBox.Text, out input))
 
-                 btnSet.IsEnabled = false;
 
-             else if (input < 0 || input > MaxValue || input < MinValue)
 
-                 btnSet.IsEnabled = false;
 
-             else
 
-                 btnSet.IsEnabled = true;
 
-             inputBox.Foreground = btnSet.IsEnabled ?
 
-                 System.Windows.Media.Brushes.Black : System.Windows.Media.Brushes.Red;
 
-         }
 
-         public static readonly DependencyProperty DeviceNameProperty = DependencyProperty.Register(
 
-                                 "DeviceName", typeof(string), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty DeviceIdProperty = DependencyProperty.Register(
 
-                                 "DeviceId", typeof(string), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register(
 
-                                 "MaxValue", typeof(double), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty MinValueProperty = DependencyProperty.Register(
 
-                                 "MinValue", typeof(double), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register(
 
-                                 "DefaultValue", typeof(double), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty RealValueProperty = DependencyProperty.Register(
 
-                                 "RealValue", typeof(string), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata("0.0", FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty HeaterOnProperty = DependencyProperty.Register(
 
-                                 "HeaterOn", typeof(string), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata("0.0", FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty HeaterOffProperty = DependencyProperty.Register(
 
-                                 "HeaterOff", typeof(string), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata("0.0", FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty UnitProperty = DependencyProperty.Register(
 
-                                 "Unit", typeof(string), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(
 
-                                 "SetPoint", typeof(double), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));
 
-         public static readonly DependencyProperty IsHeaterOnProperty = DependencyProperty.Register(
 
-                                 "IsHeaterOn", typeof(bool), typeof(AITHeaterInputDialogBox),
 
-                                 new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));
 
-         /// <summary>
 
-         /// 是否百分比显示
 
-         /// </summary>
 
-         public bool IsPercent
 
-         {
 
-             get;
 
-             set;
 
-         }
 
-         public string DeviceName
 
-         {
 
-             get
 
-             {
 
-                 return (string)this.GetValue(DeviceNameProperty);
 
-             }
 
-             set
 
-             {
 
-                 if (!string.IsNullOrEmpty(value) && !value.StartsWith("_"))
 
-                     value = "_" + value;
 
-                 this.SetValue(DeviceNameProperty, value);
 
-             }
 
-         }
 
-         public string DeviceId
 
-         {
 
-             get
 
-             {
 
-                 return (string)this.GetValue(DeviceIdProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(DeviceIdProperty, value);
 
-             }
 
-         }
 
-         public double MaxValue
 
-         {
 
-             get
 
-             {
 
-                 return (double)this.GetValue(MaxValueProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(MaxValueProperty, value);
 
-                 // validationRule.MaxInput = value;
 
-             }
 
-         }
 
-         public int MinValueHeight
 
-         {
 
-             get
 
-             {
 
-                 if (DeviceId == "Chiller") return 30;
 
-                 else return 0;
 
-             }
 
-         }
 
-         public double MinValue
 
-         {
 
-             get
 
-             {
 
-                 return (double)this.GetValue(MinValueProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(MinValueProperty, value);
 
-                 // validationRule.MaxInput = value;
 
-             }
 
-         }
 
-         public double DefaultValue
 
-         {
 
-             get
 
-             {
 
-                 return (double)this.GetValue(DefaultValueProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(DefaultValueProperty, value);
 
-             }
 
-         }
 
-         public string RealValue
 
-         {
 
-             get
 
-             {
 
-                 return (string)this.GetValue(RealValueProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(RealValueProperty, value);
 
-             }
 
-         }
 
-         public string HeaterOnName
 
-         {
 
-             get
 
-             {
 
-                 return (string)this.GetValue(HeaterOnProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(HeaterOnProperty, value);
 
-             }
 
-         }
 
-         public string HeaterOffName
 
-         {
 
-             get
 
-             {
 
-                 return (string)this.GetValue(HeaterOffProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(HeaterOffProperty, value);
 
-             }
 
-         }
 
-         public string Unit
 
-         {
 
-             get
 
-             {
 
-                 return (string)this.GetValue(UnitProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(UnitProperty, value);
 
-             }
 
-         }
 
-         public double SetPoint
 
-         {
 
-             get
 
-             {
 
-                 return (double)this.GetValue(SetPointProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(SetPointProperty, value);
 
-             }
 
-         }
 
-         public bool IsHeaterOn
 
-         {
 
-             get
 
-             {
 
-                 return (bool)this.GetValue(IsHeaterOnProperty);
 
-             }
 
-             set
 
-             {
 
-                 this.SetValue(IsHeaterOnProperty, value);
 
-                 btnHeaterOff.IsEnabled = value;
 
-                 btnHeaterOn.IsEnabled = !value;
 
-             }
 
-         }
 
-         public Action<bool> SetHeaterPowerOnOffCommandDelegate;
 
-         public Action<double> SetHeaterValueCommandDelegate;
 
-         private void ButtonSet_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             try
 
-             {
 
-                 SetHeaterValueCommandDelegate(Convert.ToDouble(inputBox.Text));
 
-                 
 
-                 Close();
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 LOG.WriteExeption(ex);
 
-             }
 
-         }
 
-         private void OnEnterKeyIsHit(object sender, KeyEventArgs e)
 
-         {
 
-             try
 
-             {
 
-                 if (!btnSet.IsEnabled)
 
-                     return;
 
-                 if (e.Key == Key.Return)
 
-                 {
 
-                     ButtonSet_Click(null, null);
 
-                 }
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 LOG.WriteExeption(ex);
 
-             }
 
-         }
 
-         private void ButtonCancel_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             Close();
 
-         }
 
-         private void ButtonHeaterOn_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             try
 
-             {
 
-                 if (SetHeaterPowerOnOffCommandDelegate != null)
 
-                 {
 
-                     SetHeaterPowerOnOffCommandDelegate(true);
 
-                 }
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 LOG.WriteExeption(ex);
 
-             }
 
-         }
 
-         private void ButtonHeaterOff_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             try
 
-             {
 
-                 if (SetHeaterPowerOnOffCommandDelegate != null)
 
-                 {
 
-                     SetHeaterPowerOnOffCommandDelegate(false);
 
-                 }
 
-             }
 
-             catch (Exception ex)
 
-             {
 
-                 LOG.WriteExeption(ex);
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |