123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using NEIntelligentControl2.Models.AGC;
- using NEIntelligentControl2.Models.Messages;
- using NEIntelligentControl2.Service.AGC;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- 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 NEIntelligentControl2.Views.AGC
- {
-
-
-
- public partial class DynamicAGCCard : UserControl
- {
- private Dictionary<int, AGCCard2> _AGCCardsPairt;
- private AGCCard2 _CurrentCard;
- private int _CurrentIndex;
- private bool _IsActived;
- private AGCManager _AGCManager;
- private bool _IsLoaded;
- public DynamicAGCCard()
- {
- InitializeComponent();
- _AGCCardsPairt = new Dictionary<int, AGCCard2>();
- _AGCManager = App.ServiceProvider.GetService(typeof(AGCManager)) as AGCManager;
- }
- private void InitCard()
- {
- var agcInfos = _AGCManager.AGCInfos;
- if (agcInfos == null) return;
- int i = 0;
- foreach(var v in agcInfos)
- {
- AGCCard2 ac = new AGCCard2() { Info = v, Visibility = Visibility.Collapsed };
- _GDMain.Children.Add(ac);
- _AGCCardsPairt.Add(i, ac);
- ++i;
- }
- _DVMain.Count = agcInfos.Count;
- _DVMain.Check(0);
- }
-
-
-
- private void RefreshLineData()
- {
- _AGCManager.RefreshLineData(this);
- }
-
-
-
- private async void RefreshData()
- {
- while (_IsActived)
- {
- _AGCManager.RefreshData(this);
- await Task.Delay(2000);
- }
- }
-
-
-
- private async void AutoCheck()
- {
- while (_IsActived)
- {
- await Task.Delay(7000);
- Dispatcher.Invoke(() => Button_Click(_BTRight, null));
- }
- }
- public void ChangeCard(int index)
- {
- if (index < 0 || index >= _DVMain.Count) return;
- _CurrentIndex = index;
- _DVMain.Check(index);
- }
- private void Button_Click(object sender, RoutedEventArgs e)
- {
- int i = ((Control)sender).Tag as string == "leftbutton" ? -1 : 1;
- _CurrentIndex += i;
- if (_CurrentIndex < 0) _CurrentIndex = _DVMain.Count - 1;
- if (_CurrentIndex >= _DVMain.Count) _CurrentIndex = 0;
- _DVMain.Check(_CurrentIndex);
- }
-
-
-
- private void DotView_Changed(object sender, DotChangedRoutedEventArgs e)
- {
- if (_CurrentCard != null)
- {
- _CurrentCard.Visibility = Visibility.Collapsed;
- }
- if (_AGCCardsPairt.ContainsKey(e.Index))
- {
- _AGCCardsPairt[e.Index].Visibility = Visibility.Visible;
- _CurrentCard = _AGCCardsPairt[e.Index];
- _CurrentIndex = e.Index;
- }
- }
- private void UserControl_Unloaded(object sender, RoutedEventArgs e)
- {
- _IsActived = false;
- }
- private void UserControl_Loaded(object sender, RoutedEventArgs e)
- {
- _IsActived = true;
- if (!_IsLoaded)
- {
- InitCard();
- }
-
- _IsLoaded = true;
- Task.Factory.StartNew(RefreshData, TaskCreationOptions.LongRunning);
- Task.Factory.StartNew(RefreshLineData, TaskCreationOptions.LongRunning);
- }
- }
- }
|