Example #1
0
        public static List <Dictionary <string, object> > getDSTreeDataALL(string dsID, string keyWord, string filter, string order, Dictionary <string, object> formstate, Database Db)
        {
            FBDataSource model = getDSModel(dsID, Db);

            Database ywDB = getModelDataSource(model.DsCode);

            var type = model.DsType;
            var sql  = model.SqlInfo;



            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            // 获取树形取数的Sql信息
            StringBuilder sb = new StringBuilder();

            sb.Append(sql);

            string sbInit = sb.ToString();

            //过滤条件
            if (!string.IsNullOrEmpty(filter))
            {
                StringBuilder    sbfilter = new StringBuilder();
                List <Condition> filters  = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Condition> >(filter);
                sb.AppendFormat(" {0} ", ConditionParser.Serialize(filters));
            }



            JFBTreeStruct treeInfo = model.treeInfo;

            //排序
            if (!string.IsNullOrEmpty(order))
            {
                List <SortCondition> orders = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SortCondition> >(order);
                if (orders.Count > 0)
                {
                    sb.AppendFormat(" order by {0} ", SortConditionParser.Serialize(orders));
                }
            }
            result = ywDB.Fetch <Dictionary <string, object> >(dealSQL(sb.ToString(), formstate));



            if (!string.IsNullOrEmpty(keyWord))
            {
                string qrySql     = string.Format(" and  {0} like '{1}%'", model.treeInfo.treename, keyWord);
                var    resultList = ywDB.Fetch <Dictionary <string, object> >(dealSQL(sbInit, formstate).Append(new Sql(qrySql)));

                foreach (var item in result)
                {
                    // 获取命中信息
                    var res = resultList.Where(p => p[model.treeInfo.grade].ToString().StartsWith(item[model.treeInfo.grade].ToString()));
                    if (res.ToList().Count > 0)
                    {
                        item["_istarget"] = "1";
                        item["isexpand"]  = true;
                    }
                }
            }


            return(result);
        }
Example #2
0
        public static List <Dictionary <string, object> > getDSTreeData(string dsID, string level, string path, string parentID, string keyWord, string filter, string order, Database Db)
        {
            FBDataSource model = getDSModel(dsID, Db);

            Database ywDB = getModelDataSource(model.DsCode);

            var type = model.DsType;
            var sql  = model.SqlInfo;
            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            // 获取树形取数的Sql信息
            StringBuilder sb = new StringBuilder();

            sb.Append(sql);

            //过滤条件
            if (!string.IsNullOrEmpty(filter))
            {
                StringBuilder    sbfilter = new StringBuilder();
                List <Condition> filters  = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Condition> >(filter);
                sb.AppendFormat(" {0} ", ConditionParser.Serialize(filters));
            }

            JFBTreeStruct treeInfo      = model.treeInfo;
            var           isParentModel = true;

            if (string.IsNullOrEmpty(treeInfo.parentid))
            {
                isParentModel = false;
            }

            #region 获取子节点数据
            if (isParentModel)
            {
                if (string.IsNullOrEmpty(parentID) && !string.IsNullOrEmpty(treeInfo.rootvalue))
                {
                    parentID = treeInfo.rootvalue;
                }
                sb.AppendFormat(" and {0}='{1}'", model.treeInfo.parentid, parentID);
            }
            else
            {
                if (string.IsNullOrEmpty(level))
                {
                    level = model.treeInfo.rootlevel;
                }
                else
                {
                    level = (Convert.ToInt32(level) + 1).ToString();
                }
                if (string.IsNullOrEmpty(path))
                {
                    sb.AppendFormat(" and {0}='{1}' ", model.treeInfo.level, level);
                }
                else
                {
                    sb.AppendFormat(" and  {0}='{1}' and {2} like '{3}%'", model.treeInfo.level, level, model.treeInfo.grade, path);
                }
            }
            #endregion



            //排序
            if (!string.IsNullOrEmpty(order))
            {
                List <SortCondition> orders = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SortCondition> >(order);
                if (orders.Count > 0)
                {
                    sb.AppendFormat(" order by {0} ", SortConditionParser.Serialize(orders));
                }
            }
            result = ywDB.Fetch <Dictionary <string, object> >(sb.ToString());



            if (!string.IsNullOrEmpty(keyWord))
            {
                string qrySql     = string.Format(" and {0} like '{1}%'", model.treeInfo.treename, keyWord);
                var    resultList = ywDB.Fetch <Dictionary <string, object> >(new Sql(sql).Append(new Sql(qrySql)));

                foreach (var item in result)
                {
                    // 获取命中信息
                    var res = resultList.Where(p => p[model.treeInfo.grade].ToString().StartsWith(item[model.treeInfo.grade].ToString()));
                    if (res.ToList().Count > 0)
                    {
                        item["_istarget"] = "1";
                    }
                }
            }


            return(result);
        }