MainWindow.xaml.cs 11.1 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Shapes;
using System.Windows.Navigation;
using System.Windows.Media.Animation;

using Misc;

using FLY.Thick.Base.IService;
using FLY.Thick.Base.Client;
using FLY.Thick.Base.Common;
using System.Threading;
using ThickTcpUiInWindow;
using System.Globalization;
24
using System.Threading.Tasks;
潘栩锋's avatar
潘栩锋 committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

namespace FLY.Thick.BlowingScan.UI.Client
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>、
    public partial class MainWindow : NavigationWindow
    {
        #region 延时推送 MARKNO
        const int MARKNO_WARNING_RING = 1;
        #endregion

        TDGage gage;

        public MainWindow()
        {
            InitializeComponent();

            NavigationCommands.BrowseBack.InputGestures.Add(new KeyGesture(Key.Escape));
        }
        int autoscan_tip_id=-1;
46
         void mSysParam_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
潘栩锋's avatar
潘栩锋 committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
        {
            SysParam sysparam = sender as SysParam;
            if (e.PropertyName == "HaveOSK")
            {
                FLY.UI.OSK.KeyboardBehavior.Enable = sysparam.HaveOSK;
            }
            else if (e.PropertyName == "HaveOSK_mouse")
            {
                FLY.UI.OSK.KeyboardBehavior.EnableMouseDown = sysparam.HaveOSK_mouse;
            }
            else if (e.PropertyName == "Language")
            {
                UpdateCulture();
            }
        }


        LoadingProgress lp;
65 66
        PgMain pMain;
        async Task Init() 
潘栩锋's avatar
潘栩锋 committed
67
        {
68 69 70 71 72 73 74
            //---------------------------------------------------------
            // 创建 与服务器端 连接 
            gage = new TDGage();
            gage.mSysParam.Load();
            gage.mSysParam.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(mSysParam_PropertyChanged);
            FLY.UI.OSK.KeyboardBehavior.Enable = gage.mSysParam.HaveOSK;
            FLY.UI.OSK.KeyboardBehavior.EnableMouseDown = gage.mSysParam.HaveOSK_mouse;
潘栩锋's avatar
潘栩锋 committed
75

76
            UpdateCulture();
潘栩锋's avatar
潘栩锋 committed
77 78


79 80 81
            gage.Init2();
            //客户端,通过 LCUS 报警!!!!!
            gage.mWarningService.PropertyChanged += (s, e) =>
潘栩锋's avatar
潘栩锋 committed
82
            {
83
                if (e.PropertyName == "IsRinging")
潘栩锋's avatar
潘栩锋 committed
84
                {
85
                    if ((gage.mSysParam as SysParam).EnableLCUS1)
潘栩锋's avatar
潘栩锋 committed
86
                    {
87
                        if (gage.mWarningService.IsRinging)
潘栩锋's avatar
潘栩锋 committed
88
                        {
89
                            gage.mLCUS.On();
潘栩锋's avatar
潘栩锋 committed
90
                        }
91 92 93 94 95 96 97 98
                        else
                        {
                            gage.mLCUS.Off();
                        }
                    }
                }
            };

99 100
            Application.Current.Properties["ThickGage"]= gage;
            Application.Current.Properties["Password"] = gage.mPasswordService;
101
            Application.Current.Properties["NavigationService"]= NavigationService;
潘栩锋's avatar
潘栩锋 committed
102

103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
            Application.Current.Properties["DynArea"] = gage.mDynArea;
            Application.Current.Properties["IBlowing"] = gage.mRenZiJiaService;
            Application.Current.Properties["IBlowingDetect"] = gage.mBDetect;


            Application.Current.Properties["WindowSize"] = gage.mSysParam.WindowSize;
            //添加观察者,1分钟查一次WindowSize,修改了,就保存
            FObjBase.PollModule.Current.Poll_Config(FObjBase.PollModule.POLL_CONFIG.ADD, () =>
            {
                if (Application.Current.Properties["WindowSize"] is int)
                {
                    if ((int)Application.Current.Properties["WindowSize"] != gage.mSysParam.WindowSize)
                    {
                        gage.mSysParam.WindowSize = (int)Application.Current.Properties["WindowSize"];
                        gage.mSysParam.Save();
                    }
                }
            }, TimeSpan.FromMinutes(1));


123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
            gage.mDynArea.PropertyChanged += (s, e) =>
            {
                DynArea dynarea = s as DynArea;
                //if (e.PropertyName == "Hrs") //不需要在这里提示了, 时间不够,已经变成了一个报警。
                //{

                //    if (gage.mDynArea.Hrs < 48) 
                //    {
                //        FLY.ControlLibrary.Window_WarningTip.Show(
                //            "警告",
                //            "设备剩余时间 " + gage.mDynArea.Hrs + "小时,请联系枫莱尔公司",
                //            TimeSpan.FromSeconds(gage.mSysParam.WarningTipDuration),
                //            gage.mSysParam.WarningTipPath);
                //    }
                //}
                if (e.PropertyName == "ControllerState")
                {
                    if (gage.mDynArea.ControllerState != CTRL_STATE.AUTOSCAN)
                    {
                        if (autoscan_tip_id != -1)
潘栩锋's avatar
潘栩锋 committed
143
                        {
144 145
                            FLY.ControlLibrary.Window_WarningTip.Stop(autoscan_tip_id);
                            autoscan_tip_id = -1;
潘栩锋's avatar
潘栩锋 committed
146
                        }
147
                    }
潘栩锋's avatar
潘栩锋 committed
148

149 150 151 152 153 154 155
                    if (gage.mDynArea.ControllerState == CTRL_STATE.PAUSE)
                    {
                        FLY.ControlLibrary.Window_WarningTip.Show(
                            "通知",
                            "暂停扫描",
                            TimeSpan.MaxValue);
                    }
潘栩锋's avatar
潘栩锋 committed
156 157 158



159 160 161
                    //case CTRL_STATE.AUTOSCAN://这些不是报警!!!
                    //    FLY.ControlLibrary.Window_WarningTip.Show(
                    //        "通知",
潘栩锋's avatar
潘栩锋 committed
162

163 164 165 166 167 168 169 170 171
                    //        gage.mDynArea.AutoScanCounter + "秒后,开始扫描",
                    //        TimeSpan.MaxValue,
                    //        gage.mSysParam.WarningTipPath);
                    //    break;

                }
                else if (e.PropertyName == "AutoScanCounter")
                {
                    if (gage.mDynArea.ControllerState == CTRL_STATE.AUTOSCAN)
潘栩锋's avatar
潘栩锋 committed
172
                    {
173 174 175 176 177 178 179 180
                        autoscan_tip_id = FLY.ControlLibrary.Window_WarningTip.Show(
                            "通知",
                            gage.mDynArea.AutoScanCounter.ToString() + "秒后,开始扫描",
                            TimeSpan.FromSeconds(gage.mDynArea.AutoScanCounter),
                            null,
                            gage.mWarningService.Reset,
                            "取消",
                            new Action(delegate()
潘栩锋's avatar
潘栩锋 committed
181
                        {
182 183 184
                            gage.mTDGageService.StartP2(STARTP2_MODE.STOP);
                        })
                            );
潘栩锋's avatar
潘栩锋 committed
185
                    }
186 187 188 189 190
                }

            };
            lp.Progress += 10;
            await Task.Delay(10);
潘栩锋's avatar
潘栩锋 committed
191 192

            
193 194 195
            FObjBase.PollModule.Current.Start();
            lp.Progress += 10;
            await Task.Delay(10);
潘栩锋's avatar
潘栩锋 committed
196
        }
197 198

        private async void NavigationWindow_Loaded(object sender, RoutedEventArgs e)
潘栩锋's avatar
潘栩锋 committed
199 200 201 202
        {
            lp = new LoadingProgress();
            Application.Current.Properties.Add("LoadingProgress", lp);

203 204
            //---------------------------------------------------------
            //转到进度条页面
潘栩锋's avatar
潘栩锋 committed
205 206 207 208 209
            Page_Loading p = new Page_Loading();
            p.DataContext = lp;
            NavigationService.Navigate(p);


210 211 212
            //---------------------------------------------------------
            //初始化
            await Init();
潘栩锋's avatar
潘栩锋 committed
213

214 215 216 217 218
            //---------------------------------------------------------
            //转到主界面
            pMain = new PgMain();
            
            await pMain.Init(gage);
潘栩锋's avatar
潘栩锋 committed
219

220 221 222 223 224
            NavigationService.Navigate(pMain);
            pMain.Loaded += (s, e1) =>
            {
                NavigationService.RemoveBackEntry();
            };
潘栩锋's avatar
潘栩锋 committed
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
        }


        private void UpdateCulture()
        {
            CultureInfo info;
            if (gage.mSysParam.Language == "en-US")
            {
                info = new CultureInfo(gage.mSysParam.Language);
            }
            else
            {
                info = new CultureInfo("zh-CN");
            }
            if (CultureInfo.CurrentCulture.EnglishName == info.EnglishName)
                return;

            Thread.CurrentThread.CurrentCulture = info;
            Thread.CurrentThread.CurrentUICulture = info;

            ThickTcpUiInWindow.App.UpdateCulture(@"Culture/StringResource.");
            ThickTcpUiInWindow.App.UpdateCulture(@"/ThickTcpUiInWindow;component/Culture/StringResource.");
        }

        private void CommandBindingScan_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            
                if (gage.mDynArea.SecuteLock)
                {
                    FLY.ControlLibrary.Window_WarningTip.Show(
                        "警告",
                        "使用码到期,请联系枫莱尔公司",
                        TimeSpan.FromSeconds(5),
                        gage.mSysParam.WarningTipPath);
                }
                else {
                    gage.mTDGageService.StartP1();
                }
            
        }
        private void CommandBindingStop_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            gage.mTDGageService.StartP2(STARTP2_MODE.STOP);
        }
        private void CommandBindingForw_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            gage.mTDGageService.StartP2(STARTP2_MODE.FORW);
        }
        private void CommandBindingBackw_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            gage.mTDGageService.StartP2(STARTP2_MODE.BACKW);
        }
        private void CommandBindingOrg_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            gage.mTDGageService.StartP2(STARTP2_MODE.ORG);
        }
    }
    public static class GageCommands
    {
        static GageCommands()
        {
            scan.InputGestures.Add(new KeyGesture(Key.F1));
            org.InputGestures.Add(new KeyGesture(Key.F2));
            stop.InputGestures.Add(new KeyGesture(Key.F3));
            forward.InputGestures.Add(new KeyGesture(Key.F4));
            backward.InputGestures.Add(new KeyGesture(Key.F5));
        }
        private static RoutedUICommand scan = new RoutedUICommand("SCAN", "Scan", typeof(GageCommands));
        public static RoutedUICommand Scan { get { return scan; } }

        private static RoutedCommand org = new RoutedCommand("Org", typeof(GageCommands));
        public static RoutedCommand Org { get { return org; } }

        private static RoutedCommand stop = new RoutedCommand("Stop", typeof(GageCommands));
        public static RoutedCommand Stop { get { return stop; } }

        private static RoutedCommand forward = new RoutedCommand("Forward", typeof(GageCommands));
        public static RoutedCommand Forward { get { return forward; } }

        private static RoutedCommand backward = new RoutedCommand("Backward", typeof(GageCommands));
        public static RoutedCommand Backward { get { return backward; } }
    }
}