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");
        }
Exemple #2
0
        private void InitTree_FromConfig()
        {
            //TreeNode node = new TreeNode("base1");
            //TreeNode node2 = new TreeNode("base2");
            //treeView1.Nodes.Add(node);
            //treeView1.Nodes.Add(node2);
            //node.Nodes.Add("a");
            //node.Nodes.Add("b");
            //node.Nodes.Add("c");
            //node2.Nodes.Add("d");
            //node2.Nodes.Add("e");
            //node2.Nodes.Add("f");
            LogHelper.Debug(this.GetType(), "开始读取配置文件中配置方案信息。。。");
            string sectionsname = "";
            string groupname    = "";

            string[]        sections   = INIOperation.INIGetAllSectionNames(file);
            List <string>   group      = new List <string>();
            List <TreeNode> group_node = new List <TreeNode>();
            TreeNode        node       = null;
            int             count;

            for (int i = 0; i < sections.Length; i++)
            {
                sectionsname = sections[i];
                LogHelper.Debug(this.GetType(), "设置父节点名称为“当前配置”。。。");
                groupname = INIOperation.INIGetStringValue(file, sectionsname, "group", "当前配置");
                if (group.IndexOf(groupname) < 0)
                {
                    group.Add(groupname);
                    node = new TreeNode(groupname);
                    treeView1.Nodes.Add(node);
                    group_node.Add(node);
                }
                count = group.IndexOf(groupname);
                group_node[count].Nodes.Add(sectionsname);
            }
            LogHelper.Debug(this.GetType(), "完成读取配置文件中配置方案信息。。。");
            treeView1.Sort();
        }
Exemple #3
0
        //选择树的节点,触发事件
        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;
                        }
                    }
                }
            }
        }