MainWindow.xaml.cs 4.09 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2
using FLY.DownBlowing.Server;
using System;
3
using System.Collections.Generic;
4
using System.Globalization;
5 6 7 8 9 10 11 12 13 14 15 16 17
using System.Linq;
using System.Reflection;
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;
18
using System.Windows.Threading;
19 20 21 22 23 24

namespace FLY.DownBlowing.UI.Server
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
25
    public partial class MainWindow : NavigationWindow
26 27 28 29 30 31 32
    {
        FLY.AppHelper.WindowNotifyIconHelper notifyiconhelper;
        FLY.DownBlowing.Server.TDGage gage;
        FLY.DownBlowing.Server.OBJProxy.OBJProxy objProxy;
        public MainWindow()
        {
            InitializeComponent();
潘栩锋's avatar
潘栩锋 committed
33 34
            PgLoading p = new PgLoading();
            this.Navigate(p);
35 36 37 38 39

            this.Title = (new Misc.Ver() { SrcType = typeof(MainWindow) }).ToString();

            notifyiconhelper = new AppHelper.WindowNotifyIconHelper(this, this.Title);

潘栩锋's avatar
潘栩锋 committed
40 41
            //DebugInit();
        }
42

潘栩锋's avatar
潘栩锋 committed
43 44 45 46
        private async void NavigationWindow_Loaded(object sender, RoutedEventArgs _e)
        {
            gage = new TDGage("Gage1");
            await gage.Init();
47

潘栩锋's avatar
潘栩锋 committed
48
            objProxy = new DownBlowing.Server.OBJProxy.OBJProxy(0, gage);
49

潘栩锋's avatar
潘栩锋 committed
50
            FObjBase.PollModule.Current.Start();
51

潘栩锋's avatar
潘栩锋 committed
52 53 54 55 56
            this.Hide();
            PgMain p = new PgMain();
            p.Init(gage);
            this.Navigate(p);
            this.NavigationService.RemoveBackEntry();
57 58 59 60 61 62 63 64
        }

        private void btnSetupClick(object sender, RoutedEventArgs e)
        {
            WdSetup w = new WdSetup();
            w.Owner = this;
            w.ShowDialog();
        }
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116

        DispatcherTimer timer;

        void DebugInit() 
        {
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(0.5);
            timer.Tick += Timer_Tick;
            timer.Start();
        }

        private void Timer_Tick(object sender, EventArgs e)
        {
            Random r = new Random();
            for (int i = 0; i < gage.mData.TAreas.Count(); i++) {

                gage.mData.TAreas[i].TempPV1 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempPV2 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempPV3 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempPV4 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempPV5 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempPV6 = (float)(r.NextDouble() * 3 + 100);

                gage.mData.TAreas[i].TempSV1 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempSV2 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempSV3 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempSV4 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempSV5 = (float)(r.NextDouble() * 3 + 100);
                gage.mData.TAreas[i].TempSV6 = (float)(r.NextDouble() * 3 + 100);


                gage.mData.TAreas[i].IsHeatingSet1 = !gage.mData.TAreas[i].IsHeatingSet1;
                gage.mData.TAreas[i].IsHeating1 = gage.mData.TAreas[i].IsHeating1 == 0 ? 1 : 0;
                gage.mData.TAreas[i].IsSelfAdjusting1 = gage.mData.TAreas[i].IsSelfAdjusting1 == 0 ? 1 : 0;
                gage.mData.TAreas[i].IsCooling1 = gage.mData.TAreas[i].IsCooling1 == 0 ? 1 : 0;
            }

        }
    }
    public class TimeSpan2msConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is TimeSpan))
                return null;
            return (int)(((TimeSpan)value).TotalMilliseconds);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
117 118
    }
}