private void btn_changeDevNet_Click(object sender, EventArgs e) { //参数验证 IPAddress ip; if (!IPAddress.TryParse(txt_devIPV4.Text, out ip)) { MessageBox.Show(txt_devIPV4.Text + " IP 地址不正确!"); txt_devIPV4.Focus(); return; } if (!IPAddress.TryParse(txt_devMask.Text, out ip)) { MessageBox.Show(txt_devMask.Text + " 子网掩码不正确!"); txt_devMask.Focus(); return; } if (!IPAddress.TryParse(txt_devGatway.Text, out ip)) { MessageBox.Show(txt_devGatway.Text + " 网关地址不正确!"); txt_devGatway.Focus(); return; } if (!IPAddress.TryParse(txt_devDNS.Text, out ip)) { MessageBox.Show(txt_devDNS.Text + " IP 地址不正确!"); txt_devDNS.Focus(); return; } //生成参数 ChangeDevIPData parameters = new ChangeDevIPData(); CurrentDev = parameters; if (BindDeviceList.Count < 1) { MessageBox.Show("请先搜索并选择需要修改网络配置的设备!"); return; } parameters.SN = BindDeviceList[selectDevIndex].SN; //获取选择设备的SN parameters.Switch = chk_isDevDHCP.Checked; // parameters.newIP = txt_devIPV4.Text; parameters.newmask = txt_devMask.Text; parameters.newgateway = txt_devGatway.Text; parameters.newdnsweb = txt_devDNS.Text; parameters.aliasName = txt_devAliasName.Text; parameters.userName = txt_userName.Text; parameters.password = txt_password.Text; try { string cmdStr = JsonConvert.SerializeObject(parameters); groupSendData(cmdStr); } catch (Exception ex) { MessageBox.Show("修改网络参数发生错误:" + ex.Message); } }
/// <summary> /// 开始搜索设备 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_SearchDev_Click(object sender, EventArgs e) { BindDeviceList.Clear(); //清除既有设备数据 CurrentDev = null; //清除设置设备ip命令标志 lab_devCount.Text = "0"; var localIP = GetLocalIP(); //获取电脑当前本地IP SearchCmd cmd = new SearchCmd("SearchDev", localIP); var searchCMD = JsonConvert.SerializeObject(cmd); startReceiveData(); //启动接收消息 groupSendData(searchCMD); //发送查询信息到设备组 }
private void displayReceiveedMsg() { if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(this.displayReceiveedMsg));//检查是否需要委托执行 } else { BindDeviceList[selectDevIndex].AliasName = CurrentDev.aliasName; BindDeviceList[selectDevIndex].IPV4 = CurrentDev.newIP; BindDeviceList[selectDevIndex].SubnetMask = CurrentDev.newmask; BindDeviceList[selectDevIndex].Gateway = CurrentDev.newgateway; BindDeviceList[selectDevIndex].DNS = CurrentDev.newdnsweb; BindDeviceList[selectDevIndex].IsDHCP = CurrentDev.Switch; this.dGrid_devList.Refresh(); //实际的执行程序体 MessageBox.Show(msgShow); CurrentDev = null; } }