예제 #1
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (thread.IsAlive)
     {
         var confirm = MessageBox.Show("是否断开收费网络?", "退出确认", MessageBoxButtons.YesNoCancel);
         if (confirm == DialogResult.Yes)
         {
             thread.Abort();
             IPGW.IPGW_connect(IPGW.FREE, this.userName.Text, this.passWord.Text);
             return;
         }
         else if (confirm == DialogResult.No)
         {
             thread.Abort();
             return;
         }
         else if (confirm == DialogResult.Cancel)
         {
             e.Cancel = true;    //cancel closing.
         }
         else
         {
             throw new Exception("Dialog result unexpected");
         }
     }
 }
예제 #2
0
        private void Func()
        {
            int hour   = 0;
            int minute = 0;
            int second = 0;

            try
            {
                minute = Convert.ToInt32(this.textBox1.Text);
            }
            catch (Exception e)
            {
                MessageBox.Show("时间输入错误:\n" + e.Message);
                return;
            }
            Console.WriteLine(minute);
            if (minute == 0)
            {
                return;
            }
            if (minute > 60)
            {
                hour   = minute / 60;
                minute = minute % 60;
            }
            while (hour > 0 || minute > 0 || second > 0)
            {
                this.Invoke((EventHandler) delegate
                {
                    if (second < 0)
                    {
                        second = 59;
                        minute--;
                    }
                    if (minute < 0)
                    {
                        minute = 59;
                        hour--;
                    }
                    this.connInfo.Show();
                    this.connInfo.Text = "Disconnect in\n" + hour.ToString() + ": " + minute.ToString() + ": " + second.ToString();
                });
                Thread.Sleep(1000);
                second--;
            }
            try
            {
                this.connInfo.Hide();
            }
            catch (Exception ex)
            {
            }
            IPGW.IPGW_connect(IPGW.FREE, this.userName.Text, this.passWord.Text);
            this.notifyIcon1.ShowBalloonTip(1000, "提示", IPGW.parseCode[IPGW.lastResultCode], ToolTipIcon.Info);
        }
예제 #3
0
 private void button4_Click(object sender, EventArgs e)
 {
     IPGW.saveUserInfo(userName.Text, passWord.Text);
     IPGW.IPGW_connect(IPGW.DIS_ALL, this.userName.Text, this.passWord.Text);
     MessageBox.Show(IPGW.parseCode[IPGW.lastResultCode]);
     if (thread.IsAlive)
     {
         thread.Abort();
     }
     this.connInfo.Hide();
 }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            IPGW.saveUserInfo(userName.Text, passWord.Text);
            var isSuc = IPGW.IPGW_connect(IPGW.FREE, this.userName.Text, this.passWord.Text);

            if (isSuc)
            {
                this.WindowState = FormWindowState.Minimized;
                this.notifyIcon1.ShowBalloonTip(1000, "提示", "连接免费网络成功", ToolTipIcon.Info);
            }
            else
            {
                MessageBox.Show(IPGW.parseCode[IPGW.lastResultCode]);
            }
            if (thread.IsAlive)
            {
                thread.Abort();
            }
            this.connInfo.Hide();
        }
예제 #5
0
        private void button2_Click(object sender, EventArgs e)
        {
            IPGW.saveUserInfo(userName.Text, passWord.Text);
            bool isSuc = IPGW.IPGW_connect(IPGW.GLOBAL, this.userName.Text, this.passWord.Text);

            if (isSuc)
            {
                this.WindowState = FormWindowState.Minimized;
                this.notifyIcon1.ShowBalloonTip(1000, "提示", IPGW.parseCode[IPGW.lastResultCode], ToolTipIcon.Info);
            }
            else
            {
                MessageBox.Show(IPGW.parseCode[IPGW.lastResultCode]);
            }
            if (!isSuc)
            {
                return;
            }
            this.connInfo.Hide();
            if (this.checkBox1.Checked)
            {
                if (thread.IsAlive)
                {
                    thread.Abort();
                }
                thread = new Thread(Func);
                thread.Start();
            }
            else
            {
                if (thread.IsAlive)
                {
                    thread.Abort();
                }
                this.connInfo.Hide();
            }
        }