using NEIntelligentControl2.Models; using NEIntelligentControl2.Models.Windturbine; using NEIntelligentControl2.Service.WebSocket; using NEIntelligentControl2.Service.Windturbine; using NEIntelligentControl2.Views.Basic; using NEIntelligentControl2.Views.Infos; 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.Controls.Primitives; 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 NEIntelligentControl2.Views.Matrix { /// /// 风机矩阵块(小) /// public partial class WindBlockSmall : UserControl, IOptional { // ----------依赖属性------------ public static DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(WindBlockSmall)); public static DependencyProperty TopValueProperty = DependencyProperty.Register("TopValue", typeof(string), typeof(WindBlockSmall)); public static DependencyProperty MiddleValueProperty = DependencyProperty.Register("MiddleValue", typeof(string), typeof(WindBlockSmall)); public static DependencyProperty BottomValueProperty = DependencyProperty.Register("BottomValue", typeof(string), typeof(WindBlockSmall)); public static DependencyProperty StateProperty = DependencyProperty.Register("State", typeof(int), typeof(WindBlockSmall)); public static DependencyProperty ToolTipValueProperty = DependencyProperty.Register("ToolTipValue", typeof(string), typeof(WindBlockSmall)); public static DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(WindBlockSmall)); /// /// 标题 /// public string Title { get => GetValue(TitleProperty) as string; set => SetValue(TitleProperty, value); } /// /// 顶部数值 /// public string TopValue { get => GetValue(TopValueProperty) as string; set => SetValue(TopValueProperty, value); } /// /// 中间数值 /// public string MiddleValue { get => GetValue(MiddleValueProperty) as string; set => SetValue(MiddleValueProperty, value); } /// /// 底部数值 /// public string BottomValue { get => GetValue(BottomValueProperty) as string; set => SetValue(BottomValueProperty, value); } /// /// 状态 /// public int State { get { var v = GetValue(StateProperty); return v == null ? -1 : (int)v; } set => SetValue(StateProperty, value); } /// /// 是否被选中 /// public bool IsSelected { get => (bool)GetValue(IsSelectedProperty); set => SetValue(IsSelectedProperty, value); } /// /// 状态改变时间 /// public DateTime StateChangedTime { get; set; } private long _Timestamp { get; set; }// 状态持续时长 /// /// 提示消息 /// public string ToolTipValue { get => GetValue(ToolTipValueProperty) as string; set => SetValue(ToolTipValueProperty, value); } /// /// 标签 /// public string Key { get; set; } /// /// 风机ID /// public string WindturbineId { get; set; } /// /// 被操作时间 /// public DateTime OperatedTime { get; set; } // 鼠标点击事件 public event SelectedEventHandler SelectedChanged; private WindturbineInfo _WindturbineInfo; // 风机数据 /// /// 风机数据 /// public WindturbineInfo WindturbineInfo { get => _WindturbineInfo; } /// /// 自定义挂牌信息 /// public CustomLockInfo CustomLockInfo { get; internal set; } private int _PopupInterval = 0; public WindBlockSmall(WindturbineInfo v) { InitializeComponent(); _WindturbineInfo = v; _PopupInterval = App.GetService().WindturbineDetailsInterval; InitToolTip(); } private void InitToolTip() { if (_PopupInterval <= 0) return; ToolTip tp = new ToolTip(); tp.Opened += ToolTipOpened; g.ToolTip = tp; ToolTipService.SetInitialShowDelay(g, _PopupInterval); } private void ToolTipOpened(object sender, RoutedEventArgs e) { ToolTip tp = sender as ToolTip; if (tp == null) return; if (tp.Content == null) { var wdv = new WindturbineDetailsView(WindturbineInfo) { ToolTipValue =this.ToolTipValue }; tp.Content = wdv; } (tp.Content as WindturbineDetailsView)?.RefreshData(); } internal void Update(WindturbineInfo ap) { _WindturbineInfo = ap; TopValue = $"{ap.WindSpeed.ToString("F2")} m/s"; MiddleValue = $"{ap.Power.ToString("F2")} kW"; var rs = ap.ModelId.ToLower().Contains("up105") ? ap.RollSpeed * 9.55 : ap.RollSpeed; BottomValue = $"{rs.ToString("F2")} rpm"; State = (int)ap.Status; _Timestamp = ap.Ts; string time = _Timestamp.GetTimeString(); string timespan = _Timestamp.GetTimeSpanString(); ToolTipValue = $"开始时间:{time} 时长:{timespan}分钟"; if (this.CustomLockInfo != null) { ToolTipValue += $"\n挂牌:{CustomLockInfo.Value} 挂牌时间:{CustomLockInfo.FollowTime.ToString("yyyy-MM-dd HH:mm:ss")}"; } else if (_WindturbineInfo.IsLocked) { ToolTipValue += $"\n挂牌:{((HungType)_WindturbineInfo.LockValue).GetStringValue()}"; } var v = (g.ToolTip as ToolTip)?.Content as WindturbineDetailsView; if (v == null) return; v.ToolTipValue = ToolTipValue; } private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var b = Keyboard.Modifiers == ModifierKeys.Shift; if (SelectedChanged == null) { IsSelected = !IsSelected; } else { SelectedChanged(this, b); } if (e.ClickCount <= 1 || _WindturbineInfo == null) return; Windows.WindturbineInfoWindow.ShowWindow(this.WindturbineInfo); //WinForms.WindtrubineInfoWindow.ShowWindow(_WindturbineInfo); //ShowForm.Show(_WindturbineInfo.StationId, _WindturbineInfo.ModelId, _WindturbineInfo.WindturbineId, Title); } } }