123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using NEIntelligentControl2.Models.Datas;
- using NEIntelligentControl2.Models.Messages;
- using NEIntelligentControl2.Models.Windturbine;
- using NEIntelligentControl2.Service.Windturbine;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Configuration;
- using System.Linq;
- using System.Text;
- using System.Text.Json.Serialization;
- 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 NEIntelligentControl2.Views.Infos
- {
- /// <summary>
- /// 测点详情
- /// </summary>
- public partial class PointDetails : UserControl
- {
- private bool _IsActived;
- private List<PointInfo> _AIPoints;
- private List<PointInfo> _DIPoints;
- private InfoManager _InfoManager;
- public WindturbineInfo WindturbineInfo { get; set; }
- public PointDetails()
- {
- InitializeComponent();
- _InfoManager = App.ServiceProvider.GetService(typeof(InfoManager)) as InfoManager;
- }
- private void UserControl_Unloaded(object sender, RoutedEventArgs e)
- {
- _IsActived = false;
- }
- private async void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- _IsActived = true;
- await InitPointTags();
- Task.Run(RefreshData);
- }
- private async void RefreshData()
- {
- var aiks = _AIPoints.Select(p => p.TagName).ToArray();
- var diks = _DIPoints.Select(p => p.TagName).ToArray();
- while (_IsActived)
- {
- try
- {
- var vsai = _InfoManager.GetPointDatasByTags(aiks);
- var vsdi = _InfoManager.GetPointDatasByTags(diks);
- Dispatcher.Invoke(() =>
- {
- UpdateData(vsai, _AIPoints);
- UpdateData(vsdi, _DIPoints);
- });
- }
- catch (Exception e)
- {
- Console.WriteLine(e.ToString());
- }
- await Task.Delay(2000);
- }
- }
- private void UpdateData(Dictionary<string, TsData> vs, List<PointInfo> ps)
- {
- foreach(var v in ps)
- {
- if (!vs.ContainsKey(v.TagName)) continue;
- v.PointValue = vs[v.TagName].Value;
- }
- }
- private Task InitPointTags()
- {
- return Task.Run(() =>
- {
- if (_AIPoints != null && _AIPoints.Count > 0) return;
- try
- {
- _AIPoints = _InfoManager.GetAIPoints(WindturbineInfo.WindturbineId);
- _DIPoints = _InfoManager.GetDIPoints(WindturbineInfo.WindturbineId);
- Dispatcher.Invoke(() =>
- {
- _DGAI.ItemsSource = _AIPoints;
- _DGDI.ItemsSource = _DIPoints;
- });
- }
- catch { }
- });
- }
- private void TextBox_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Key != Key.Enter) return;
- Search();
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- switch (((Control)sender).Tag)
- {
- case "ok":
- Search();
- break;
- default:return;
- }
- }
- private void Search()
- {
- string s = _TBSerach.Text;
- if (string.IsNullOrWhiteSpace(s))
- {
- _DGAI.ItemsSource = _AIPoints;
- _DGDI.ItemsSource = _DIPoints;
- return;
- }
- Task.Run(() =>
- {
- var vs1 = _AIPoints.Where(p => p.PointName.Contains(s)).ToList();
- var vs2 = _DIPoints.Where(p => p.PointName.Contains(s)).ToList();
- Dispatcher.Invoke(() =>
- {
- _DGAI.ItemsSource = vs1;
- _DGDI.ItemsSource = vs2;
- });
- });
- }
- }
- }
|