Esempio n. 1
0
        public IList <TreeJSONBase> GetTreeList(string helpid, string clientQuery, string outJsonQuery, string leftLikeJsonQuery, string clientSqlFilter, string nodeid, bool ormMode)
        {
            string           filter = string.Empty;
            CommonHelpEntity item   = richDac.GetCommonHelpItem(helpid);

            TreeListBuilder builder = new TreeListBuilder();

            string treePid     = item.TreePid;
            string treeChildId = item.TreeChildId;

            if (ormMode)
            {
                string   tableName = item.TableName;
                string[] s         = item.TableName.Split(' ');//有别名
                if (s.Length > 0)
                {
                    tableName = s[s.Length - 1].Trim();
                }
                builder.ID       = DataConverterHelper.FieldToProperty(tableName, item.CodeField); //item.CodeField;
                builder.Text     = DataConverterHelper.FieldToProperty(tableName, item.NameField); //item.NameField;
                treePid          = DataConverterHelper.FieldToProperty(tableName, item.TreePid);
                item.TreeChildId = DataConverterHelper.FieldToProperty(tableName, item.TreeChildId);
            }
            else
            {
                builder.ID   = item.CodeField;
                builder.Text = item.NameField;
            }

            DataTable dt = richDac.GetTreeList(helpid, clientQuery, outJsonQuery, leftLikeJsonQuery, clientSqlFilter, nodeid, ormMode);

            string sort = string.Empty;

            if (!string.IsNullOrWhiteSpace(item.SortProperty))
            {
                sort = item.SortProperty + " asc ";
            }

            if (string.IsNullOrEmpty(treePid))
            {
                throw new Exception("树节点pid未设置,请在通用帮助注册设置[父节点id]和[子节点id]!");
            }

            Type type = dt.Columns[treePid].DataType;

            if ("root" == nodeid)//首次加载
            {
                if (type == typeof(Int64) || type == typeof(Int32))
                {
                    filter = "(" + treePid + "=0 or " + treePid + " is null)";
                }
                else
                {
                    filter = "(" + treePid + "='' or " + treePid + "is null)";
                }
                return(builder.GetExtTreeList(dt, treePid, treeChildId, filter, sort, TreeDataLevelType.TopLevel, 2));
            }
            else//懒加载
            {
                //return builder.GetExtTreeList(dt, item.TreePid, item.TreeChildId, filter, TreeDataLevelType.LazyLevel);
                return(builder.LazyLoadTreeList(dt, treePid, treeChildId, nodeid));
            }
        }