1.街道管理系统效果图
需要一个类 Address :
public class Address { // 街道信息属性
//街道 public string root { get; set; }
//委员会 public string juwei { get; set; }
//建筑 public string jianzhu { get; set; }
//房间号 public string fjname { get; set; } }
2.需要一个集合:
//街道信息存储双列泛型集合
public Dictionary<string, Address> Dic = new Dictionary<string, Address>();
3.以下是绑定TreeView的方法:
public void binDing() { string Name = null; string Name1 = null; TreeNode Node1=null; TreeNode Node2=null;
foreach (Address item in Dic.Values) { if (Name != item.juwei) { Node1 = new TreeNode(item.juwei); Node.Nodes.Add(Node1); } if (Name1 != item.jianzhu) { Node2 = new TreeNode(item.jianzhu); Node1.Nodes.Add(Node2); } TreeNode Node3 = new TreeNode(item.fjname); Node3.Tag = item; Node2.Nodes.Add(Node3); Name = item.juwei; Name1 = item.jianzhu; } }
4.绑定相关信息
public void binBing1() { if (tvLsit.SelectedNode.Level != 3) return;
Address ress = (Address)tvLsit.SelectedNode.Tag;
txtstreet.Text=ress.root; txtcouncil.Text=ress.juwei; txttowerNum.Text=ress.jianzhu; txtRoomNum.Text = ress.fjname; }
5.生成文档:
public void text() { StringBuilder b = new StringBuilder(); foreach (Address item in Dic.Values)
{ b.AppendLine(item.root);
b.AppendLine(item.juwei);
b.AppendLine(item.jianzhu);
b.AppendLine(item.fjname); } FileStream aa = new FileStream("text.bin", FileMode.Create);
StreamWriter w = new StreamWriter(aa);
w.Write(b); w.Close(); aa.Close();
}
6.所需的xml:
XML文件: 复制代码 <?xml version="1.0" encoding="gb2312"?> <root name="石牌街道"> <juwei name="瑞华居委"> <jianzhu smid="6" name="瑞华花园1栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> <jianzhu smid="7" name="瑞华花园2栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> </juwei> <juwei name="金帝居委"> <jianzhu smid="4" name="金帝花园1栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> </juwei> <juwei name="朝阳居委"> <jianzhu smid="5" name="朝阳花园1栋"> <fjname>101室</fjname> <fjname>102室</fjname> </jianzhu> </juwei> </root> 复制代码
此项目有一定的难度,在建类的时候没有思路不知道该建几个类,考虑不到。