Ejemplo n.º 1
0
        //查询到的数据可以进行缓存
        public List <NodeInfoFromDB> GetAllOrgnizationInfo()
        {
            List <int> liCount = new List <int> {
                30, 20, 40, 40
            };                                                   //每个节点的子节点数量
            //根  zhongguo 中国 1
            NodeInfoFromDB root = new NodeInfoFromDB {
                ParentIndex = "0", Index = "1", Name = "中国"
            };

            List <string> liProvinceName = new List <string> {
                "浙江", "杭州", "萧山", "西兴"
            };
            List <string> liNodeIndex = new List <string> {
                "zhejiang", "hangzhou", "xiaoshan", "xixing"
            };
            List <List <NodeInfoFromDB> > matrix = new List <List <NodeInfoFromDB> >();

            matrix.Add(new List <NodeInfoFromDB> {
                root
            });

            //先添加第一层
            List <NodeInfoFromDB> listFirst = new List <NodeInfoFromDB>();//z浙江01到30

            for (int j = 1; j < liCount[0] + 1; ++j)
            {
                var temp = new NodeInfoFromDB {
                    Index = liNodeIndex[0] + j.ToString().PadLeft(2, '0'), Name = liProvinceName[0] + j.ToString().PadLeft(2, '0'), ParentIndex = "1"
                };
                listFirst.Add(temp);
            }
            matrix.Add(listFirst);

            List <NodeInfoFromDB> listRow = new List <NodeInfoFromDB>(listFirst);//当前行

            for (int i = 1; i < liProvinceName.Count; ++i)
            {
                List <NodeInfoFromDB> listTemp = new List <NodeInfoFromDB>();//下一行
                foreach (var item in listRow)
                {
                    for (int jk = 1; jk < liCount[i] + 1; ++jk)
                    {
                        var temp = new NodeInfoFromDB
                        {
                            Index       = item.Index.Replace(liNodeIndex[i - 1], liNodeIndex[i]) + jk.ToString().PadLeft(2, '0'),
                            Name        = item.Name.Replace(liProvinceName[i - 1], liProvinceName[i]) + jk.ToString().PadLeft(2, '0'),
                            ParentIndex = item.Index
                        };
                        listTemp.Add(temp);
                    }
                }
                listRow = new List <NodeInfoFromDB>(listTemp);
                matrix.Add(listTemp);
            }
            var allOrgs = new List <NodeInfoFromDB>();

            matrix.ForEach(c => allOrgs.AddRange(c));
            return(allOrgs);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从缓存中获取树节点,不存在则创建,
        /// </summary>
        /// <param name="org"></param>
        /// <returns></returns>
        private TreeNodeModel GetOrCreateCacheOrgsNode(NodeInfoFromDB org)
        {
            TreeNodeModel model;

            if (!_cacheOrgs.TryGetValue(org.Index, out model))
            {
                model = TransFromNodeInfo(org);
                _cacheOrgs.Add(org.Index, model);
            }
            return(model);
        }
Ejemplo n.º 3
0
 public TreeNodeModel TransFromNodeInfo(NodeInfoFromDB info)
 {
     if (info == null)
     {
         return(null);
     }
     return(new TreeNodeModel
     {
         Index = info.Index,
         Name = info.Name,
         ParentIndex = info.ParentIndex,
         Nodes = new ObservableCollection <TreeNodeModel>()
     });
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 根据信息,创建不同节点(组织还是设备)
 /// </summary>
 /// <param name="info"></param>
 /// <returns></returns>
 public TreeNodeModel TransFromNodeInfo(NodeInfoFromDB info)
 {
     if (info == null)
     {
         return(null);
     }
     return(new TreeNodeModel
     {
         Index = info.Index,
         Name = info.Name,
         ParentIndex = info.ParentIndex,
         Nodes = new ObservableCollection <TreeNodeModel>(),
         //Image= new BitmapImage(new Uri(@"th.jfif")),//bad performance
         Image = TreeUtil.ImageRescource//use static Image will imporve performance
     });
 }