예제 #1
0
        /// <summary>
        /// 主界面按键捕获
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void main_focus_KeyDown(object sender, KeyEventArgs e)
        {
            //MessageBox.Show(e.KeyValue.ToString(),"KEY_VALUE");
            //statusBar1.Text = e.KeyValue.ToString();

            switch (e.KeyCode)
            {
            case Keys.D0:
                quitFlag                  = 0;
                textBox1.Text             = "\r\n按(1-9)更新程序\r\n按ESC返回主界面";
                tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(update);
                _nowControlModule         = PROGRESS;
                PROGRESS.Focus();
                break;

            case Keys.D9:
                quitFlag                  = 0;
                tb_testMsg.BackColor      = Color.Gray;
                tb_testMsg.Text           = "\r\n\r\n                测试界面\r\n\r\n          按1开始自动检测\r\n\r\n          按ESC返回主界面";
                tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(test);
                _nowControlModule         = tb_test_focus;
                _nowControlModule.Focus();
                break;

            case Keys.Escape:
                if (quitFlag > 5 && quitFlag < 90)
                {
                    quitFlag = 0;
                    Quit();
                }
                else if (quitFlag > 90)
                {
                    quitFlag = 0;
                }
                break;

            case Keys.Back:
                if (quitFlag < 6)
                {
                    quitFlag++;
                }
                break;

            case Keys.Space:
                tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(test);
                _nowControlModule         = null;
                break;
            }

            if ((e.KeyValue > 48) && (e.KeyValue < (49 + _applicationCount)))
            {
                string msg;
                if (!WifiCtrl.GetInstance().isConnectWifi(_IpAddress, out msg))
                {
                    _outStr = msg;
                    return;
                }
                if (quitFlag == 99)
                {
                    return;
                }
                quitFlag = 99;
                CheckAppVersion(e.KeyValue - 49);
                SwitchApp(e.KeyValue - 49);
            }
        }
예제 #2
0
        /// <summary>
        /// 配置文件更新
        /// </summary>
        private void UpdateConfig()
        {
            textBox1.Text             = "正在更新配置文件\r\n请等待。。。";
            tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(update);
            _nowControlModule         = PROGRESS;
            PROGRESS.Focus();
            //if (m_socketClient != null)
            //{
            //this.Disconnect();
            //}

            /*
             * bool isConnect=this.Connect();
             * while (!isConnect)
             * {
             *  if (_serverPort < _lastPort)
             *  {
             *      _serverPort += 1;
             *
             *      this.Disconnect();
             *
             *      isConnect = this.Connect();
             *  }
             *  else
             *  {
             *      _serverPort = _firstPort;
             *      MessageBox.Show("更新配置文件失败!");
             *      tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(main);
             *      _nowControlModule = main_focus;
             *      main_focus.Focus();
             *      return;
             *  }
             * }
             * */
            //this.Connect();

            //_codeStr = listView1.Items[0].SubItems[1].Text + "|" + listView1.Items[0].SubItems[2].Text;
            _codeStr = "UpdateConfig";
            _pFlag   = 98;
            //SendOneDatagram();
            //NewTransmit();
            byte[] tmp = DownLoadFile();

            if (tmp != null)
            {
                try
                {
                    FileStream MyFileStream = new FileStream("\\Program Files\\CONFIG.XML", FileMode.Create, FileAccess.Write);
                    MyFileStream.Write(tmp, 0, tmp.Length);
                    MyFileStream.Close();
                    MessageBox.Show("更新完成!", "提示");
                }
                catch
                {
                    MessageBox.Show("更新失败!", "提示");
                }
            }
            else
            {
                MessageBox.Show("接收失败!", "提示");
            }
            tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(main);
            _nowControlModule         = main_focus;
            main_focus.Focus();

            //todo update xml config

            /*
             * XmlDocument xml = new XmlDocument();
             * try
             * {
             *  xml.LoadXml(_outStr);
             *  //MessageBox.Show(_outStr,"xml");
             *  xml.Save("\\Program Files\\CONFIG.XML");
             * }
             * catch (Exception e)
             * {
             *  MessageBox.Show(e.Message,"错误");
             *  tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(main);
             *  _nowControlModule = main_focus;
             *  main_focus.Focus();
             *  return;
             * }
             * // MessageBox.Show("success","ok");
             *
             * listView1.Items.Clear();
             * try
             * {
             *  //openFileDialog1.ShowDialog();
             *  //string path = openFileDialog1.FileName;
             *  xml.Load("\\Program Files\\CONFIG.XML");
             *  XmlNodeList Application = xml.SelectSingleNode("Root/Applications").ChildNodes;
             *  foreach (XmlNode app in Application)
             *  {
             *      //MessageBox.Show(app.SelectSingleNode("name").InnerText,"app");
             *      AddListviewItem(app.SelectSingleNode("name").InnerText, app.Name, app.SelectSingleNode("version").InnerText
             *          , app.SelectSingleNode("wince_path").InnerText, app.SelectSingleNode("pc_path").InnerText);
             *
             *  }
             *  MessageBox.Show("更新完成!", "提示");
             *
             * }
             * catch (Exception ee)
             * {
             *  MessageBox.Show(ee.Message, "错误");
             *  //UpdateConfig();
             * }
             * finally
             * {
             *  if (m_socketClient != null)
             *  {
             *      this.Disconnect();
             *  }
             *  tabControl1.SelectedIndex = tabControl1.TabPages.IndexOf(main);
             *  _nowControlModule = main_focus;
             *  main_focus.Focus();
             * }
             * */
        }