Exemplo n.º 1
0
        private void LoadConfig()
        {
            if (!File.Exists(Device.fun_normal_configFilePath) || ToolCls.FileIsUsed(Device.fun_normal_configFilePath))
            {
                MessageBox.Show("文件下载中,请稍后再试!");
                return;
            }
            var core_Content = File.ReadAllText(Device.fun_normal_configFilePath);
            var aryContent   = core_Content.Split('\n');

            foreach (var item in aryContent)
            {
                if (item.Contains("="))
                {
                    var ary_item = item.Split('=');
                    dictConfig.Add(ary_item[0], ary_item[1]);
                }
            }
            foreach (Control item in this.Controls)//赋值给控件
            {
                if (item is TextBox)
                {
                    var textBox = item as TextBox;
                    var key     = textBox.Name.Replace("txt_", "");
                    if (dictConfig.ContainsKey(key))
                    {
                        textBox.Text = dictConfig[key];
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void LoadConfig()
        {
            if (!File.Exists(Device.eth_configFilePath) || ToolCls.FileIsUsed(Device.eth_configFilePath))
            {
                MessageBox.Show("文件下载中,请稍后再试!");
                return;
            }
            var         eth_Content = File.ReadAllText(Device.eth_configFilePath);
            XmlDocument doc         = new XmlDocument();

            doc.LoadXml(eth_Content);
            var eth_el  = ToolCls.GetFromXMLEl(doc, "/root/eth");
            var dns_el  = ToolCls.GetFromXMLEl(doc, "/root/eth/dns");
            var ip      = eth_el.GetAttribute("ip");
            var submask = eth_el.GetAttribute("submask");
            var gateway = eth_el.GetAttribute("gateway");
            var dns1    = dns_el.GetAttribute("dns1");
            var dns2    = dns_el.GetAttribute("dns2");

            txtIP.Text      = ip;
            txtsubmask.Text = submask;
            txtgateway.Text = gateway;
            txtdns1.Text    = dns1;
            txtdns2.Text    = dns2;
        }
Exemplo n.º 3
0
        private void SaveConfig()
        {
            if (string.IsNullOrWhiteSpace(txtIP.Text))
            {
                MessageBox.Show("IP不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(txtsubmask.Text))
            {
                MessageBox.Show("子网掩码不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(txtgateway.Text))
            {
                MessageBox.Show("网关不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(txtdns1.Text))
            {
                MessageBox.Show("dns1不能为空");
                return;
            }
            if (string.IsNullOrWhiteSpace(txtdns2.Text))
            {
                MessageBox.Show("dns2不能为空");
                return;
            }
            var         eth_Content = File.ReadAllText(Device.eth_configFilePath);
            XmlDocument doc         = new XmlDocument();

            doc.LoadXml(eth_Content);
            var eth_el = ToolCls.GetFromXMLEl(doc, "/root/eth");
            var dns_el = ToolCls.GetFromXMLEl(doc, "/root/eth/dns");

            eth_el.SetAttribute("ip", txtIP.Text);
            eth_el.SetAttribute("submask", txtsubmask.Text);
            eth_el.SetAttribute("gateway", txtgateway.Text);
            dns_el.SetAttribute("dns1", txtdns1.Text);
            dns_el.SetAttribute("dns2", txtdns2.Text);
            doc.Save(Device.eth_configFilePath);
        }