街道管理项目

来源:互联网 发布:java 计算器编程代码 编辑:程序博客网 时间:2024/04/27 18:51
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace 街道项目{  public   class Bust    {        public string jiedao { get; set; }//街道        public string Juwei { get; set; }//居委会        public string Jianzhu { get; set; }//楼房        public string Room { get; set; } //房间号    }}

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.Xml;namespace 街道项目{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        Bust bb = new Bust();               private void treeView1_MouseClick(object sender, MouseEventArgs e)        {        }            private void Form1_Load(object sender, EventArgs e)        {            XmlDocument xml = new XmlDocument();            //读取XML文件            xml.Load("Address.xml");            //读取XML的根节点            XmlNode root = xml.DocumentElement;            //将值赋给jiedao            bb.jiedao = root.Attributes["name"].Value;            //创建根节点 rootNode            TreeNode rootNode = new TreeNode();            //为根节点rootNode赋值            rootNode.Text = bb.jiedao;            //将根节点rootNode绑定到tvLise控件上            treeView1.Nodes.Add(rootNode);            //遍历街道中所有居委会            foreach (XmlNode item in root.ChildNodes)            {                //创建节点                TreeNode oneNode = new TreeNode();                //赋值                oneNode.Text = item.Attributes["name"].Value;                //遍历居委会中所有住房                foreach (XmlNode child in item.ChildNodes)                {                    //创建节点                    TreeNode twoNode = new TreeNode();                    ///赋值                    twoNode.Text = child.Attributes["name"].Value;                    //遍历住房中所有房间号                    foreach (XmlNode node in child.ChildNodes)                    {                        //创建节点                        TreeNode threeNode = new TreeNode();                        //赋值                        threeNode.Text = node.InnerText;                        //将threeNode子节点归属到twoNode父节点                        twoNode.Nodes.Add(threeNode);                    }                    //将twoNode子节点归属到oneNode父节点                    oneNode.Nodes.Add(twoNode);                }                //将oneNode子节点归属到rootNode根节点                rootNode.Nodes.Add(oneNode);            }                   }    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)        {            //为控件txtjiedao 赋值            jiedao.Text = "石牌街道";            //点击节点获取值            TreeNode node = this.treeView1.SelectedNode;            if (node.Level == 1)            {                //赋值                   juweuhui.Text = node.Text;            }            else if (node.Level == 2)            {                louhao.Text = node.Text;                juweuhui.Text = node.Parent.Text;            }            else if (node.Level == 3)            {                fangjianhao.Text = node.Text;                louhao.Text = node.Parent.Text;                juweuhui.Text = node.Parent.Parent.Text;            }        }    }}




0 0
原创粉丝点击