private void Init() { LogHelper.Debug(this.GetType(), "开始读取网络适配器信息。。。"); List <string> NetWork_Name = new List <string>(); NetWorkOperation NetWork = new NetWorkOperation(); NetWork_Name = NetWork.Query_NetWork_Name(); for (int i = 0; i < NetWork_Name.Count; i++) { comboBox1.Items.Insert(0, NetWork_Name[i]); if (NetWork_Name[i].IndexOf("连接") > 0) { comboBox1.SelectedIndex = comboBox1.Items.IndexOf(NetWork_Name[i]); } } LogHelper.Debug(this.GetType(), "完成读取网络适配器信息。。。"); }
private void Button4_Click(object sender, EventArgs e) { string sectionname = null; if (treeView1.SelectedNode != null) { sectionname = treeView1.SelectedNode.Text; } string str = null; string txtIP = textBox1.Text; string txtSubMark = textBox2.Text; string txtGateWay = textBox3.Text; string txtDNS1 = textBox4.Text; string txtDNS2 = textBox5.Text; //string NetworkDescription = comboBox1.Text; string NetWork_Name = comboBox1.SelectedItem.ToString(); string[] arr = NetWork_Name.Split('|'); Boolean Str_return = true; string txtIpRadio, txtDnsRadio; NetWorkOperation NetWork = new NetWorkOperation(); if (sectionname != null && sectionname != "当前配置") { str = sectionname; } else if (sectionname == null || sectionname == "当前配置") { str = Interaction.InputBox("请输入方案名称!\n\n如方案名称已存在,则会覆盖以前的方案!", "新方案", "", -1, -1); } if (str == null || str == "") { MessageBox.Show("方案名称不能为空!"); return; } if (radioButton2.Checked) { txtIpRadio = "1"; Str_return = NetWork.IP_Check(txtIP, txtSubMark, txtGateWay); if (!Str_return) { return; } INIOperation.INIWriteValue(file, str, "networkdescription", arr[2]); INIOperation.INIWriteValue(file, str, "ipradio", txtIpRadio); INIOperation.INIWriteValue(file, str, "iplist", txtIP); INIOperation.INIWriteValue(file, str, "masklist", txtSubMark); INIOperation.INIWriteValue(file, str, "gatewaylist", txtGateWay); } else { txtIpRadio = "0"; INIOperation.INIWriteValue(file, str, "networkdescription", arr[2]); INIOperation.INIWriteValue(file, str, "ipradio", txtIpRadio); } if (radioButton4.Checked) { txtDnsRadio = "1"; Str_return = NetWork.Dns_Check(txtDNS1, txtDNS2); if (!Str_return) { return; } INIOperation.INIWriteValue(file, str, "dnsradio", txtDnsRadio); INIOperation.INIWriteValue(file, str, "preferreddnslist", txtDNS1); INIOperation.INIWriteValue(file, str, "optionaldnslist", txtDNS2); } else { txtDnsRadio = "0"; INIOperation.INIWriteValue(file, str, "dnsradio", txtDnsRadio); } treeView1.Nodes.Clear(); InitTree_FromConfig(); this.treeView1.ExpandAll(); MessageBox.Show("方案【" + str + "】保存成功!"); }
private void Button2_Click(object sender, EventArgs e) { string txtIP = textBox1.Text; string txtSubMark = textBox2.Text; string txtGateWay = textBox3.Text; string txtDNS1 = textBox4.Text; string txtDNS2 = textBox5.Text; string NetWork_Name = ""; NetWorkOperation NetWork = new NetWorkOperation(); string[] ip = new string[] { txtIP.Trim() }; string[] SubMark = new string[] { txtSubMark.Trim() }; string[] GateWay = new string[] { txtGateWay.Trim() }; string[] DNS = new string[] { txtDNS1.Trim(), txtDNS2.Trim() }; NetWork_Name = comboBox1.SelectedItem.ToString(); string[] arr = NetWork_Name.Split('|'); LogHelper.Debug(this.GetType(), "开始进行IP切换。。。"); Boolean Str_return = true; if (radioButton2.Checked) { Str_return = NetWork.IP_Check(txtIP, txtSubMark, txtGateWay); if (!Str_return) { return; } LogHelper.Debug(this.GetType(), "IP地址格式检测 Str_return = " + Str_return); Str_return = NetWork.SetIpInfo(ip, SubMark, GateWay, arr[2]); if (!Str_return) { return; } LogHelper.Debug(this.GetType(), "设置IP Str_return = " + Str_return); } else { Str_return = NetWork.EnableIpDHCP(arr[2]); if (!Str_return) { return; } LogHelper.Debug(this.GetType(), "设置IPDHCP Str_return = " + Str_return); } if (radioButton4.Checked) { Str_return = NetWork.Dns_Check(txtDNS1, txtDNS2); if (!Str_return) { return; } LogHelper.Debug(this.GetType(), "DNS地址格式检测 Str_return = " + Str_return); Str_return = NetWork.SetDnsInfo(DNS, arr[2]); if (!Str_return) { return; } LogHelper.Debug(this.GetType(), "设置DNS Str_return = " + Str_return); } else { Str_return = NetWork.EnableDnsDHCP(arr[2]); if (!Str_return) { return; } LogHelper.Debug(this.GetType(), "设置IPDHCP Str_return = " + Str_return); } MessageBox.Show("IP切换成功!"); }
//选择树的节点,触发事件 private void TreeView1_MouseDown(object sender, MouseEventArgs e) { //选择树的节点并点击右键,触发事件 if (e.Button == MouseButtons.Right)//判断你点的是不是右键 { Point ClickPoint = new Point(e.X, e.Y); TreeNode CurrentNode = treeView1.GetNodeAt(ClickPoint); if (CurrentNode != null && true == CurrentNode.Checked) //判断你点的是不是一个节点 { switch (CurrentNode.Name) //根据不同节点显示不同的右键菜单,当然你可以让它显示一样的菜单 { case "": //右键菜单 CurrentNode.ContextMenuStrip = contextMenuStrip1; break; default: break; } } treeView1.SelectedNode = CurrentNode;//选中这个节点 } //选择树的节点并点击左键,触发事件 if (e.Button == MouseButtons.Left) { if ((sender as TreeView) != null) { treeView1.SelectedNode = treeView1.GetNodeAt(e.X, e.Y); if (treeView1.SelectedNode != null) { string sectionname = treeView1.SelectedNode.Text; //设置点击当前配置时自动读取当前使用的IP设置信息 if (sectionname == "当前配置") { LogHelper.Debug(this.GetType(), "“当前配置”获取IP配置信息。。。"); NetWorkOperation NetWork = new NetWorkOperation(); string NetWork_Name = comboBox1.SelectedItem.ToString(); string[] arr = NetWork_Name.Split('|'); int DhcpCount = NetWork.Query_NetWork_Dhcp_Status(arr[2]); if (DhcpCount > 0) { radioButton1.Checked = true; radioButton2.Checked = false; radioButton3.Checked = true; radioButton4.Checked = false; textBox1.Enabled = false; textBox2.Enabled = false; textBox3.Enabled = false; textBox4.Enabled = false; textBox5.Enabled = false; } else { List <string> list = NetWork.GetNetWork(arr[2]); radioButton1.Checked = false; radioButton2.Checked = true; radioButton3.Checked = false; radioButton4.Checked = true; textBox1.Enabled = true; textBox2.Enabled = true; textBox3.Enabled = true; textBox4.Enabled = true; textBox5.Enabled = true; textBox1.Text = list[0]; textBox2.Text = list[1]; textBox3.Text = list[2]; textBox4.Text = list[1]; textBox5.Text = list[2]; } return; } LogHelper.Debug(this.GetType(), "读取配置文件信息到IP栏并展示。。。"); string ipradio = INIOperation.INIGetStringValue(file, sectionname, "ipradio", ""); string dnsradio = INIOperation.INIGetStringValue(file, sectionname, "dnsradio", ""); string iplist = INIOperation.INIGetStringValue(file, sectionname, "iplist", ""); string masklist = INIOperation.INIGetStringValue(file, sectionname, "masklist", ""); string gatewaylist = INIOperation.INIGetStringValue(file, sectionname, "gatewaylist", ""); string preferreddnslist = INIOperation.INIGetStringValue(file, sectionname, "preferreddnslist", ""); string optionaldnslist = INIOperation.INIGetStringValue(file, sectionname, "optionaldnslist", ""); string networkdescription = INIOperation.INIGetStringValue(file, sectionname, "networkdescription", ""); string NetWorkName = ""; for (int i = 0; i < comboBox1.Items.Count; i++) { NetWorkName = comboBox1.Items[i].ToString(); string[] arr = NetWorkName.Split('|'); if (arr[2] == networkdescription) { comboBox1.SelectedIndex = comboBox1.Items.IndexOf(NetWorkName); break; } } if (ipradio != "") { if (ipradio == "1") { radioButton1.Checked = false; radioButton2.Checked = true; textBox1.Enabled = true; textBox2.Enabled = true; textBox3.Enabled = true; } else { radioButton1.Checked = true; radioButton2.Checked = false; textBox1.Enabled = false; textBox2.Enabled = false; textBox3.Enabled = false; } if (dnsradio == "1") { radioButton3.Checked = false; radioButton4.Checked = true; textBox4.Enabled = true; textBox5.Enabled = true; } else { radioButton3.Checked = true; radioButton4.Checked = false; textBox4.Enabled = false; textBox5.Enabled = false; } textBox1.Text = iplist; textBox2.Text = masklist; textBox3.Text = gatewaylist; textBox4.Text = preferreddnslist; textBox5.Text = optionaldnslist; } } } } }