public IPAreaNode[] GetIPAreaTree() { List <IPAreaNode> tree = new List <IPAreaNode>(); //_iplist.AddRange(IPAreaTableInfo.FindAll()); IPAreaCache.Instance.Items.ForEach(delegate(IPAreaTableInfo info) { IPAreaNode parent = tree.Find(delegate(IPAreaNode node) { return(node.attributes.Country == info.Country); }); if (parent != null) { List <IPAreaNode> provinces = new List <IPAreaNode>(); if (parent.Children != null) { provinces.AddRange(parent.Children); } IPAreaNode provinceparent = provinces.Find(delegate(IPAreaNode node) { return(node.attributes.Province == info.Province); }); if (provinceparent != null && !string.IsNullOrEmpty(info.City)) { IPAreaNode citynode = new IPAreaNode(); citynode.text = info.City; citynode.AreaText = string.Format("{0}/{1}/{2}", info.Country, info.Province, info.City); citynode.attributes = info; provinceparent.AddChildren(citynode); } else { LoadChildren(parent, info); } } else { if (!string.IsNullOrEmpty(info.Country)) { IPAreaNode countrynode = new IPAreaNode(); countrynode.text = info.Country; countrynode.AreaText = info.Country; countrynode.attributes = info; tree.Add(countrynode); LoadChildren(countrynode, info); } } }); return(tree.ToArray()); }
private void LoadChildren(IPAreaNode parent, IPAreaTableInfo info) { if (!string.IsNullOrEmpty(info.Province)) { IPAreaNode newnode = new IPAreaNode(); newnode.text = info.Province; newnode.AreaText = string.Format("{0}/{1}", info.Country, info.Province); newnode.attributes = info; parent.AddChildren(newnode); if (!string.IsNullOrEmpty(info.City)) { IPAreaNode citynode = new IPAreaNode(); citynode.text = info.City; citynode.AreaText = string.Format("{0}/{1}/{2}", info.Country, info.Province, info.City); citynode.attributes = info; newnode.AddChildren(citynode); } } }
private void LoadChildren(IPAreaNode parent,IPAreaTableInfo info) { if (!string.IsNullOrEmpty(info.Province)) { IPAreaNode newnode = new IPAreaNode(); newnode.text = info.Province; newnode.AreaText = string.Format("{0}/{1}", info.Country, info.Province); newnode.attributes = info; parent.AddChildren(newnode); if (!string.IsNullOrEmpty(info.City)) { IPAreaNode citynode = new IPAreaNode(); citynode.text = info.City; citynode.AreaText = string.Format("{0}/{1}/{2}", info.Country, info.Province, info.City); citynode.attributes = info; newnode.AddChildren(citynode); } } }