Пример #1
0
        /// <summary>
        /// 获取分类的树型数据
        /// </summary>
        /// <param name="code">主键</param>
        /// <param name="nodeid">节点id</param>
        /// <returns></returns>
        public IList <TreeJSONBase> GetQueryProTree(string code, string nodeid)
        {
            string    filter         = string.Empty;
            bool      treeshow       = false;
            bool      lazyload       = false;
            DataTable propertyInfodt = new DataTable();
            DataTable dt             = richDac.GetQueryProTree(code, ref propertyInfodt);


            DataRow dr = propertyInfodt.Rows[0];

            //是否能构建成树
            treeshow = (dr["treeshow"].ToString() == "1");
            lazyload = (dr["tree_lazyload"].ToString() == "1");

            if (treeshow)
            {
                QueryPropertyTreeBuilder builder = new QueryPropertyTreeBuilder();
                builder.ID            = dr["tree_id"].ToString();
                builder.Text          = dr["tree_text"].ToString();
                builder.TreeSearchKey = dr["tree_searchkey"].ToString();
                builder.TreeRefKey    = dr["list_treerefkey"].ToString();

                if ("root" == nodeid)//首次加载
                {
                    filter = "(" + dr["tree_pid"].ToString() + " is null or " + dr["tree_pid"].ToString() + "='')";
                    if (lazyload)
                    {
                        return(builder.GetExtTreeList(dt, dr["tree_pid"].ToString(), dr["tree_id"].ToString(), filter, TreeDataLevelType.TopLevel, 2));
                    }
                    else
                    {
                        return(builder.GetExtTreeList(dt, dr["tree_pid"].ToString(), dr["tree_id"].ToString(), filter, TreeDataLevelType.TopLevel));
                    }
                }
                else
                {
                    //return builder.GetExtTreeList(dt, dr["tree_pid"].ToString(), dr["tree_id"].ToString(), filter, TreeDataLevelType.LazyLevel);
                    return(builder.LazyLoadTreeList(dt, dr["tree_pid"].ToString(), dr["tree_id"].ToString(), nodeid));
                }
            }
            else
            {
                IList <TreeJSONBase> rootlist = new List <TreeJSONBase>();
                IList <TreeJSONBase> list     = new List <TreeJSONBase>();

                QueryPropertyTreeJSON root = new QueryPropertyTreeJSON();
                root.id       = "root";
                root.cls      = "folder";
                root.text     = "root";
                root.expanded = true;
                // root.@checked = false;
                root.children = list;

                foreach (DataRow row in dt.Rows)
                {
                    QueryPropertyTreeJSON child = new QueryPropertyTreeJSON();
                    child.id   = row[dr["tree_id"].ToString()].ToString();
                    child.text = row[dr["tree_text"].ToString()].ToString();
                    child.cls  = "file";
                    if (!string.IsNullOrWhiteSpace(dr["tree_searchkey"].ToString()))
                    {
                        child.treesearchkey = row[dr["tree_searchkey"].ToString()].ToString();
                    }
                    if (!string.IsNullOrWhiteSpace(dr["list_treerefkey"].ToString()))
                    {
                        child.treerefkey = dr["list_treerefkey"].ToString();//row[dr["list_treerefkey"].ToString()].ToString();
                    }

                    child.leaf = true;
                    root.children.Add(child);
                }

                rootlist.Add(root);
                return(list);//rootlist;
            }
        }