private TreeCodeTableModel GetDisplayTreeNodeByNode(TreeCodeTableModel node, IEnumerable <TreeCodeTableModel> list)
        {
            if (node != null)
            {
                if (isFirst)
                {
                    isFirst = true;
                }
                node.Children = list;
                node.open     = true;
                string pid = node.ParentId;

                var _list = GetChildrenNode(pid);

                var __list = _list.Children.ToList();
                for (int i = 0; i < __list.Count; i++)//必须这么写
                {
                    if (__list[i].CODE_VALUE == node.CODE_VALUE)
                    {
                        __list[i] = node;
                    }
                }
                _list.Children = __list;
                if (pid != this.Root)
                {
                    var _pnode = GetDisplayTreeNodeByNode(getTreeNode(pid), _list.Children);
                    return(_pnode == null ? _list : _pnode);
                }
                else
                {
                    return(_list);
                }
            }
            return(null);
        }
        private TreeCodeTableModel MergeOutHouse(TreeCodeTableModel person, TreeCodeTableModel house, bool isSrc)
        {
            string             pid   = person.ParentId;
            TreeCodeTableModel pNode = getTreeNode(pid);
            var _list = GetChildrenNode(pid);

            pNode.open = true;
            var __list = _list.Children.ToList();

            for (int i = 0; i < __list.Count; i++)//必须这么写
            {
                if (__list[i].CODE_VALUE == person.CODE_VALUE)
                {
                    __list[i] = person;
                    //person.IsSelect = true;
                }
            }
            pNode.Children = __list;

            TreeCodeTableModel result = MergeInHouse(pNode, house, house);

            if (result == null)
            {
                return(MergeOutHouse(pNode, house, false));
            }

            return(result);
        }
 private TreeCodeTableModel MergeInHouse(TreeCodeTableModel person, TreeCodeTableModel house, TreeCodeTableModel bighouse)
 {
     if (house.CODE_VALUE == person.CODE_VALUE)
     {
         house.open = person.Children != null;
         if (!house.IsSelect)
         {
             house.IsSelect = person.IsSelect;
         }
         house.Children = person.Children;
         return(bighouse);
     }
     else
     {
         if (house.Children != null)
         {
             var _list = house.Children;
             //for (int i = 0; i < _list.Count(); i++)
             //{
             foreach (TreeCodeTableModel bean in house.Children)
             {
                 // TreeCodeTableModel _o = bean;
                 var _res = MergeInHouse(person, bean, bighouse);
                 if (_res != null)
                 {
                     return(_res);
                 }
                 // return _bean;
             }
             //}
         }
         return(null);
     }
 }
Exemplo n.º 4
0
        public override TreeCodeTableModel GetChildrenNode(string key)
        {
            TreeCodeTableModel   result = new TreeCodeTableModel();
            List <CodeDataModel> list   = new List <CodeDataModel>();

            if (key == "0")
            {
                list = DbContext.TreeCodeTable.Where(a => a.CODE_VALUE.EndsWith("000"))
                       //.Where(a => a.CODE_VALUE.StartsWith(key))
                       .Select(a => new CodeDataModel()
                {
                    CODE_VALUE = a.CODE_VALUE,
                    CODE_TEXT  = a.CODE_NAME
                }).ToList();
            }
            else
            {
                string keySub = key.Substring(0, 3);
                list = DbContext.TreeCodeTable
                       .Where(a => a.CODE_VALUE.StartsWith(keySub))
                       .Select(a => new CodeDataModel()
                {
                    CODE_VALUE = a.CODE_VALUE,
                    CODE_TEXT  = a.CODE_NAME
                }).ToList();
            }
            var root = list.Where(a => a.CODE_VALUE == key).FirstOrDefault();

            if (root != null)
            {
                result.CODE_TEXT  = root.CODE_TEXT;
                result.CODE_VALUE = root.CODE_VALUE;
                if (list.Count > 1)
                {
                    result.isParent = true;
                    result.IsLeaf   = false;
                    result.nocheck  = OnlyLeafCheckbox ? true.Value <bool?>() : null;
                    //result.IsSelect = false;
                    result.Children = new List <TreeCodeTableModel>();
                }
                list.ForEach(a =>
                {
                    if (a != root)
                    {
                        ((List <TreeCodeTableModel>)result.Children).Add(
                            new TreeCodeTableModel()
                        {
                            CODE_VALUE = a.CODE_VALUE,
                            CODE_TEXT  = a.CODE_TEXT
                        }
                            );
                    }
                });
            }

            return(result);
        }
        public override TreeCodeTableModel GetChildrenNode(string key)
        {
            TreeCodeTableModel root = new TreeCodeTableModel()
            {
                CODE_TEXT  = "",
                CODE_VALUE = key,
                IsLeaf     = false,
                isParent   = true,
                nocheck    = OnlyLeafCheckbox ? true.Value <bool?>() : null
                             //IsSelect = true
            };

            root.Children = GetChildrenNodes(key);
            return(root);
        }
Exemplo n.º 6
0
        private void SetFileDataList(string root, List <TreeCodeTableModel> fileDataList, string name, bool isRoot)
        {
            string[] fStrs = Directory.GetFileSystemEntries(root, "*", SearchOption.TopDirectoryOnly);
            foreach (string fstr in fStrs)
            {
                if (Directory.Exists(fstr))
                {
                    string             fstr2 = Path.GetFileName(fstr);
                    TreeCodeTableModel ctm   = new TreeCodeTableModel();
                    ctm.CODE_VALUE = name + "\\" + fstr2;
                    ctm.CODE_TEXT  = fstr2;
                    if (isRoot)
                    {
                        ctm.ParentId = "0";
                    }
                    else
                    {
                        ctm.ParentId = name;
                    }
                    ctm.isParent = true;
                    ctm.IsLeaf   = false;
                    fileDataList.Add(ctm);
                    //sParent = true;
                    SetFileDataList(root + "\\" + fstr2, fileDataList, name + "\\" + fstr2, false);
                }
                else
                {
                    string             fstr2 = Path.GetFileName(fstr);
                    TreeCodeTableModel ctm   = new TreeCodeTableModel();
                    ctm.CODE_VALUE = name + "\\" + Path.GetFileName(fstr2);
                    ctm.CODE_TEXT  = this.setFileText(ctm.CODE_VALUE);

                    if (isRoot)
                    {
                        ctm.ParentId = "0";
                    }
                    else
                    {
                        ctm.ParentId = name;
                    }

                    ctm.isParent = false;
                    ctm.IsLeaf   = true;
                    fileDataList.Add(ctm);
                }
            }
        }
        private void BindChild(TreeCodeTableModel node, ArrangeBuilder ab)
        {
            if (this.KeyValues != null && this.KeyValues.Count() > 0)
            {
                var _kvs = this.KeyValues.ToList();

                foreach (var k in _kvs)
                {
                    if (node.CODE_VALUE == k)
                    {
                        node.IsSelect = true;
                        break;
                    }
                }
            }

            node.Arrange    = ab.GetText();
            node.LayerLevel = ab.LayerLevel;
            this.OnTreeNodeSetting(node);
            var _nodes = GetChildrenNodes(node.CODE_VALUE).ToList();

            if (_nodes != null && _nodes.Count > 0)
            {
                node.Children = _nodes;
                node.isParent = true;

                ArrangeBuilder abb = ab.Copy();
                abb.AddLevelNode();
                for (int i = 0; i < node.Children.Count(); i++)
                {
                    abb.AddNode();
                    BindChild((node.Children as IList <TreeCodeTableModel>)[i], abb);
                }
            }
            else
            {
                node.isParent = false;
                node.Children = new List <TreeCodeTableModel>();
            }
        }
 public override TreeCodeTableModel GetDisplayTreeNode(string key)
 {
     if (KeyValues == null)
     {
         TreeCodeTableModel bean = getTreeNode(key);
         if (bean != null)
         {
             bean.IsSelect = true;
             return(GetDisplayTreeNodeByNode(bean, null));
         }
         return(bean);
     }
     else
     {
         TreeCodeTableModel bean = null;
         foreach (string _key in KeyValues)
         {
             TreeCodeTableModel _bean = getTreeNode(_key);
             if (_bean != null)
             {
                 _bean.IsSelect = true;
                 if (bean != null)
                 {
                     TreeCodeTableModel beanM = MergeInHouse(_bean, bean, bean);
                     if (beanM == null)
                     {
                         beanM = MergeOutHouse(_bean, bean, true);
                     }
                     bean = beanM;
                 }
                 else
                 {
                     bean = GetDisplayTreeNodeByNode(_bean, null);
                 }
             }
         }
         return(bean);
     }
 }
        public override TreeCodeTableModel GetAllTree()
        {
            TreeCodeTableModel root = new TreeCodeTableModel();

            root.CODE_VALUE = Root;
            ArrangeBuilder ab = new ArrangeBuilder();


            if (Root == "0")
            {
                root.CODE_TEXT = "";
                root.IsLeaf    = false;
                root.isParent  = true;
                root.nocheck   = OnlyLeafCheckbox ? root.isParent.Value <bool?>() : null;
            }
            else
            {
                root = getTreeNode(Root);
            }
            // root.Arrange = ab.GetText();
            BindChild(root, ab);
            return(root);
        }
 protected virtual void OnTreeNodeSetting(TreeCodeTableModel nodeModel)
 {
 }