Пример #1
0
        /// <summary>
        /// 最小化到通知栏
        /// </summary>
        private void ToolIcon()
        {
            string path = Path.GetFullPath(@"Resources\favicon.ico");

            if (this.notifyIcon != null)
            {
                this.notifyIcon.Dispose();
                this.notifyIcon = null;
            }
            this.notifyIcon = new NotifyIcon
            {
                BalloonTipText = LocaleUtil.GetString("MsgBubble"),   //设置程序启动时显示的文本
                Text           = LocaleUtil.GetString("ServiceName"), //最小化到托盘时,鼠标点击时显示的文本
                Icon           = new System.Drawing.Icon(path),       //程序图标
                Visible        = true
            };
            //右键菜单--打开菜单项
            System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem(LocaleUtil.GetString("Open"));
            open.Click += new EventHandler(ShowWindow);
            //右键菜单--退出菜单项
            System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem(LocaleUtil.GetString("Exit"));
            exit.Click += new EventHandler(CloseWindow);
            //关联托盘控件
            System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { open, exit };
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);

            notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
            //this.notifyIcon.ShowBalloonTip(1000);
        }
Пример #2
0
        public override string FormatErrorMessage(string name)
        {
            string labelKey = LocaleUtil.GetString("Label" + name);
            string msgKey   = LocaleUtil.GetString("RequireMsg");

            return(labelKey + msgKey);
        }
Пример #3
0
        /// <summary>
        /// 关闭窗口时提示窗口
        /// </summary>
        private async void ShowTipDialogOnClose()
        {
            MetroDialogSettings settings = new MetroDialogSettings
            {
                NegativeButtonText    = LocaleUtil.GetString("No"),
                AffirmativeButtonText = LocaleUtil.GetString("Yes")
            };
            MessageDialogResult clickresult = await this.ShowMessageAsync(LocaleUtil.GetString("MsgLvlNotice"), LocaleUtil.GetString("MsgExit"), MessageDialogStyle.AffirmativeAndNegative, settings);

            if (clickresult == MessageDialogResult.Negative)
            {
                Hide();
                notifyIcon.ShowBalloonTip(1000);
            }
            else
            {
                System.Windows.Application.Current.Shutdown();
            }
        }
Пример #4
0
        /// <summary>
        /// 后台线程,轮询获取拣货单
        /// </summary>
        public void PollNotify()
        {
            Thread thread = new Thread(start: () =>
            {
                SpeechSynthesizer synth = new SpeechSynthesizer
                {
                    Volume = 100
                };
                MetroDialogSettings settings = new MetroDialogSettings
                {
                    AnimateHide = true
                };
                while (true)
                {
                    bool isNewOn   = Convert.ToBoolean(ConfigurationManager.AppSettings["IsNew"]);
                    bool isDelayOn = Convert.ToBoolean(ConfigurationManager.AppSettings["IsDelay"]);
                    // 新拣货任务开关打开
                    if (isNewOn)
                    {
                        ResponseModel model = HttpUtil.FetchNewTask(Convert.ToString(App.CurrentWh));
                        if ("1".Equals(model.RtnStatus))
                        {
                            grid.ShowDialog(model.RtnMsg);
                        }
                        else
                        {
                            bool hasTask = Convert.ToBoolean(model.Data);
                            if (hasTask)
                            {
                                synth.SpeakAsync(LocaleUtil.GetString("TipNewMsg"));
                                grid.ShowDialog("TipNewMsg");
                            }
                        }
                    }
                    if (isDelayOn)
                    {
                        ResponseModel model = HttpUtil.FetchDelayTask(Convert.ToString(App.CurrentWh));
                        if ("1".Equals(model.RtnStatus))
                        {
                            grid.ShowDialog(model.RtnMsg);
                        }
                        else
                        {
                            bool hasTask = Convert.ToBoolean(model.Data);
                            if (hasTask)
                            {
                                synth.SpeakAsync(LocaleUtil.GetString("TipDelayMsg"));
                                grid.ShowDialog("TipDelayMsg");
                            }
                        }
                    }
                    Thread.Sleep(INTERVAL);
                }
            })
            {
                // 设置为true,关闭窗口后才会自动关闭线程
                IsBackground = true
            };

            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
        }