//快速查找
        private void button7_Click(object sender, RoutedEventArgs e)
        {
            if ("" == comboBox5.Text && "" == comboBox6.Text)
            {
                return;
            }

            for (int i = 0; i < lvwconfiguration.Items.Count; i++)
            {
                ConfigurationMember tmp = new ConfigurationMember();
                tmp = (ConfigurationMember)lvwconfiguration.Items[i];

                //按品牌查找
                if (tmp.Brand == comboBox5.Text && comboBox6.Text == "")
                {
                    lvwconfiguration.ScrollIntoView(lvwconfiguration.Items[i]);
                    lvwconfiguration.SelectedIndex = i;
                    lvwconfiguration.Focus();
                    break;
                }

                //按品牌和型号查找
                if (tmp.Brand == comboBox5.Text && tmp.Model == comboBox6.Text)
                {
                    lvwconfiguration.ScrollIntoView(lvwconfiguration.Items[i]);
                    lvwconfiguration.SelectedIndex = i;
                    lvwconfiguration.Focus();
                    break;
                }
            }
        }
        private void lvwconfiguration_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ConfigurationMember member = (ConfigurationMember)lvwconfiguration.SelectedItem;

            if (null != member)
            {
                textBox1.Text          = member.Brand;
                textBox2.Text          = member.Model;
                checkBox1.IsChecked    = (member.Hexadecimal == "Yes" ? true : false);
                comboBox1.SelectedItem = member.Baudrate;
                comboBox2.SelectedItem = member.Parity;
                comboBox3.SelectedItem = member.Databits;
                comboBox4.SelectedItem = member.Stopbits;
                textBox3.Text          = member.BootCode;
                textBox4.Text          = member.ShutdownCode;
                textBox5.Text          = member.RGB1;
                textBox6.Text          = member.RGB2;
                textBox7.Text          = member.VIDEO;
                textBox8.Text          = member.SVIDEO;
            }
        }
        //加载配置
        public void ShowListViewConfig()
        {
            LoadProjectorConfig();
            xnl = xmlDoc.SelectSingleNode("ConfigList").ChildNodes;

            //遍历xml文件中的配置
            foreach (XmlNode xn in xnl)
            {
                ConfigurationMember member = new ConfigurationMember();
                XmlElement          xe     = (XmlElement)xn;
                member.Brand = xe.GetAttribute("Brand");

                //对比combobox中已有的品牌,防止重复添加
                if (cmbBrand.Items.Cast <object>().All(x => x.ToString() != member.Brand))
                {
                    cmbBrand.Items.Add(member.Brand);
                }
                member.Model = xe.GetAttribute("Model");

                XmlNodeList xnlSub = xe.ChildNodes;
                foreach (XmlNode xnSub in xnlSub)
                {
                    if (xnSub.Name == "Baudrate")
                    {
                        member.Baudrate = xnSub.InnerText;
                    }

                    if (xnSub.Name == "Parity")
                    {
                        member.Parity = xnSub.InnerText;
                    }

                    if (xnSub.Name == "Databits")
                    {
                        member.Databits = xnSub.InnerText;
                    }

                    if (xnSub.Name == "Stopbits")
                    {
                        member.Stopbits = xnSub.InnerText;
                    }

                    if (xnSub.Name == "Hexadecimal")
                    {
                        member.Hexadecimal = xnSub.InnerText;
                    }

                    if (xnSub.Name == "BootCode")
                    {
                        member.BootCode = xnSub.InnerText;
                    }

                    if (xnSub.Name == "Shutdown")
                    {
                        member.ShutdownCode = xnSub.InnerText;
                    }

                    if (xnSub.Name == "RGB1")
                    {
                        member.RGB1 = xnSub.InnerText;
                    }

                    if (xnSub.Name == "RGB2")
                    {
                        member.RGB2 = xnSub.InnerText;
                    }

                    if (xnSub.Name == "VIDEO")
                    {
                        member.VIDEO = xnSub.InnerText;
                    }

                    if (xnSub.Name == "SVIDEO")
                    {
                        member.SVIDEO = xnSub.InnerText;
                    }
                }

                listView.Items.Add(member);
            }

            //排序
            SortListViewItems();
        }
Example #4
0
        public void AddXmlNode(ConfigurationMember member)
        {
            LoadXmlFile();

            //创建PresentConfig节点
            XmlElement xePresentConfig = xmlDoc.CreateElement("PresentConfig");

            //添加PresentConfig节点的品牌属性
            xePresentConfig.SetAttribute("Brand", member.Brand);

            //添加PresentConfig节点的型号属性
            xePresentConfig.SetAttribute("Model", member.Model);

            //添加PresentConfig节点的十六进制码子节点
            XmlElement xnHexadecimal = xmlDoc.CreateElement("Hexadecimal");

            xnHexadecimal.InnerText = member.Hexadecimal;
            xePresentConfig.AppendChild(xnHexadecimal);

            //添加PresentConfig节点的波特率子节点
            XmlElement xnBaudrate = xmlDoc.CreateElement("Baudrate");

            xnBaudrate.InnerText = member.Baudrate;
            xePresentConfig.AppendChild(xnBaudrate);

            //添加PresentConfig节点的校验位子节点
            XmlElement xnParity = xmlDoc.CreateElement("Paritybit");

            xnParity.InnerText = member.Parity;
            xePresentConfig.AppendChild(xnParity);

            //添加PresentConfig节点的数据位子节点
            XmlElement xnDatabits = xmlDoc.CreateElement("Databits");

            xnDatabits.InnerText = member.Databits;
            xePresentConfig.AppendChild(xnDatabits);

            //添加PresentConfig节点的停止位子节点
            XmlElement xnStopbits = xmlDoc.CreateElement("Stopbit");

            xnStopbits.InnerText = member.Stopbits;
            xePresentConfig.AppendChild(xnStopbits);

            //添加PresentConfig节点的开机码子节点
            XmlElement xnStartingUp = xmlDoc.CreateElement("Boot");

            xnStartingUp.InnerText = member.BootCode;
            xePresentConfig.AppendChild(xnStartingUp);

            //添加PresentConfig节点的关机码子节点
            XmlElement xnShutdown = xmlDoc.CreateElement("Shutdown");

            xnShutdown.InnerText = member.ShutdownCode;
            xePresentConfig.AppendChild(xnShutdown);

            //添加PresentConfig节点的RGB1子节点
            XmlElement xnRGB1 = xmlDoc.CreateElement("RGB1");

            xnRGB1.InnerText = member.RGB1;
            xePresentConfig.AppendChild(xnRGB1);

            //添加PresentConfig节点的RGB2子节点
            XmlElement xnRGB2 = xmlDoc.CreateElement("RGB2");

            xnRGB2.InnerText = member.RGB2;
            xePresentConfig.AppendChild(xnRGB2);

            //添加PresentConfig节点的VIDEO子节点
            XmlElement xnVIDEO = xmlDoc.CreateElement("VIDEO");

            xnVIDEO.InnerText = member.VIDEO;
            xePresentConfig.AppendChild(xnVIDEO);

            //添加PresentConfig节点的SVIDEO子节点
            XmlElement xnSVIDEO = xmlDoc.CreateElement("SVIDEO");

            xnSVIDEO.InnerText = member.SVIDEO;
            xePresentConfig.AppendChild(xnSVIDEO);

            xmlDoc.Save(file);
        }