예제 #1
0
        private void Test()
        {
            string file = "ip_settings.ini";

            //写入/更新键值
            INIOperation.INIWriteValue(file, "Desktop", "Color", "Red");
            INIOperation.INIWriteValue(file, "Desktop", "Width", "3270");

            INIOperation.INIWriteValue(file, "Toolbar", "Items", "Save,Delete,Open");
            INIOperation.INIWriteValue(file, "Toolbar", "Dock", "True");

            //写入一批键值
            INIOperation.INIWriteItems(file, "Menu", "File=文件\0View=视图\0Edit=编辑");

            //获取文件中所有的节点
            string[] sections = INIOperation.INIGetAllSectionNames(file);

            //获取指定节点中的所有项
            string[] items = INIOperation.INIGetAllItems(file, "Menu");

            //获取指定节点中所有的键
            string[] keys = INIOperation.INIGetAllItemKeys(file, "Menu");

            //获取指定KEY的值
            string value = INIOperation.INIGetStringValue(file, "Desktop", "color", "");

            //删除指定的KEY
            INIOperation.INIDeleteKey(file, "desktop", "color");

            //删除指定的节点
            INIOperation.INIDeleteSection(file, "desktop");

            //清空指定的节点
            INIOperation.INIEmptySection(file, "toolbar");
        }
예제 #2
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 + "】保存成功!");
        }