using AllBase; using TemuKJD.BaseForms; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; namespace TemuKJD.KJDForms.ToolForms { public partial class ChangeIPForm : LRBaseForm { public ChangeIPForm() { InitializeComponent(); MaximizeBox = false; } private AdslHelper adsl = null; public static Thread spanTimethread; public AdslHelper GetAdsl() { string adslName = "宽带连接";//txtAdslName.Text.Trim(); string account = txtAccount.Text.Trim();//055192515753 string password = txtPassword.Text.Trim();//382443 adsl = new AdslHelper(adslName, account, password); return adsl; } //拨号 private void ConnectionButtonX_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtAccount.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text.Trim())) { BaseMsgForm.ShowInfo("请输入账号和密码"); return; } try { bool result= GetAdsl().Connect(); if (result) { BaseMsgForm.ShowInfo("ADSL拨号连接成功!"); } else { BaseMsgForm.ShowInfo("ADSL拨号连接失败!"); } } catch { BaseMsgForm.ShowInfo("ADSL拨号连接失败!"); return; } } //断开 private void DisConnectionButtonX_Click(object sender, EventArgs e) { try { bool result= GetAdsl().Disconnect(); if (result) { BaseMsgForm.ShowInfo("ADSL断开连接成功!"); } else { BaseMsgForm.ShowInfo("ADSL断开连接失败!"); } return; } catch { BaseMsgForm.ShowInfo("ADSL拨号断开连接失败!"); return; } } int spanTime = 0; bool startFlag = false; //定时 private void spanTimeButtonX_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtAccount.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text.Trim())) { BaseMsgForm.ShowInfo("请输入账号和密码"); return; } CheckInt(txtMinutes, out spanTime); if (spanTime == 0) return; bool ok = !startFlag; startFlag = ok; spanTimeButtonX.Text = "停止执行"; if(!startFlag) { spanTimeButtonX.Text = "开始执行"; spanTimethread.Abort(); return; } spanTimethread = new Thread(new ThreadStart(workOn));//开始定时 spanTimethread.Start(); } public string FormName = "自动拨号"; public void workOn() { while (true) { if (!startFlag) break; new Thread(OnSetShow).Start(); GetAdsl().Disconnect();//断开 Thread.Sleep(500); GetAdsl().Connect();//重连 Thread.Sleep(spanTime*60*1000); } } public void OnSetShow() { try { int count = spanTime*60; while (true) { count--; if (count < 0|| !startFlag ) { break; } if (this.txtMinutes.InvokeRequired) { this.Invoke(new Action(() => { txtSurplus.Text = count.ToString(); })); } else { txtSurplus.Text = count.ToString(); } Thread.Sleep(1 * 1000); } } catch { } } public bool CheckInt(TextBox box, out int d) { if (int.TryParse(box.Text, out d)) return true; BaseMsgForm.ShowInfo("请输入数字", "提示"); box.Focus(); return false; } private void ChangeIPForm_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; Hide(); } private void ChangeIPForm_Load(object sender, EventArgs e) { if (BaseClass.Ico != null) Icon = BaseClass.Ico; } } }