| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 | using System;using System.Windows;using System.Windows.Controls;using System.Windows.Input;using Aitex.Core.RT.Log;namespace Aitex.Core.UI.DeviceControl{    public partial class AITBoostPumpInputDialogBox : Window    {        public AITBoostPumpInputDialogBox()        {            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)                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(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));        public static readonly DependencyProperty DeviceIdProperty = DependencyProperty.Register(                                "DeviceId", typeof(string), typeof(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));        public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register(                                "MaxValue", typeof(double), typeof(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));        public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register(                                "Frequency", typeof(double), typeof(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.AffectsRender));        public static readonly DependencyProperty RealValueProperty = DependencyProperty.Register(                                "RealValue", typeof(string), typeof(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata("0.0", FrameworkPropertyMetadataOptions.AffectsRender));        public static readonly DependencyProperty UnitProperty = DependencyProperty.Register(                                "Unit", typeof(string), typeof(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.AffectsRender));        public static readonly DependencyProperty SetPointProperty = DependencyProperty.Register(                                "SetPoint", typeof(double), typeof(AITBoostPumpInputDialogBox),                                new FrameworkPropertyMetadata(0.0, 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 double Frequency        {            get            {                return (double)this.GetValue(FrequencyProperty);            }            set            {                this.SetValue(FrequencyProperty, value);            }        }        public string RealValue        {            get            {                return (string)this.GetValue(RealValueProperty);            }            set            {                this.SetValue(RealValueProperty, 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 Action<double> SetPressureCommandDelegate;        private void ButtonSet_Click(object sender, RoutedEventArgs e)        {            try            {                SetPressureCommandDelegate(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();        }     }}
 |