Beispiel #1
0
        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 + "】保存成功!");
        }
Beispiel #2
0
        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切换成功!");
        }