Exemplo n.º 1
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            appStopWatch.Start();
            try
            {
                //这种读取方式,这个xml需要保存时Unicode格式,不是utf-8
                //utf-8编码为utf-8,如果是utf-16,编码为unicode
                XmlDocument xmlDoc   = new XmlDocument();
                string      path     = AppDomain.CurrentDomain.BaseDirectory;
                string      dataFile = path + "EqukCommonData1.xml";
                xmlDoc.Load(dataFile);
                XmlNode rootNode = xmlDoc.SelectSingleNode("//peoples");

                XmlReader      xmlReader      = XmlReader.Create("EqukCommonData1.xml");
                XmlSerializer  xmlSearializer = new XmlSerializer(typeof(EqukCommonData));
                EqukCommonData equkCommonData = (EqukCommonData)xmlSearializer.Deserialize(xmlReader);

                XmlReader     xmlPeoplesReader     = XmlReader.Create("PeoplesData.xml");
                XmlSerializer xmlPeoplesSerializer = new XmlSerializer(typeof(peoples));
                peoples       peopleSet            = (peoples)xmlPeoplesSerializer.Deserialize(xmlReader);

                //如果是民族
                //tvProperties.ItemsSource = getPeoples(equkCommonData);

                //加载发证机关
                tvProperties.ItemsSource = getIDPublishers(equkCommonData);
                appStopWatch.Stop();
                label2.Content = "加载耗时:" + appStopWatch.ElapsedMilliseconds.ToString() + "   ms";
            }
            catch
            {
            }
        }
Exemplo n.º 2
0
        private List <NodeItem> getPeoples(peoples equkCommonData)
        {
            List <NodeItem> treeViewItemSource = new List <NodeItem>();
            NodeItem        peopleRootNode     = new NodeItem {
                parentId = -1, DisplayName = "证件类型", id = 0
            };

            treeViewItemSource.Add(peopleRootNode);


            List <people>   peopleTypes   = equkCommonData.PeopleList;
            List <NodeItem> peopleDicData = new List <NodeItem>();
            int             nodeCount     = peopleRootNode.parentId + 1;

            foreach (people aPeopleType in peopleTypes)
            {
                NodeItem peopleNode = new NodeItem
                {
                    //parentId = peopleRootNode.id,
                    DisplayName = aPeopleType.name,
                    id          = Int32.Parse(aPeopleType.code),
                };
                peopleDicData.Add(peopleNode);
            }
            peopleRootNode.Children = peopleDicData;

            return(treeViewItemSource);
        }