public static object GetTreeData(DbContext db, FilterTree tree) { if (!string.IsNullOrEmpty(tree.sourceModel)) { if (tree.sourceModel2 == tree.sourceModel) { tree.sourceModel2 = null; } ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(tree.sourceModel); string textField = tree.textField; if (string.IsNullOrEmpty(textField)) { textField = serviceConfig.model.textField; } //lyl update at 2018-12-28 DbContext db2find = db; if (!string.IsNullOrEmpty(serviceConfig.model.dbName)) { db2find = SysContext.GetOtherDB(serviceConfig.model.dbName); } List <Dictionary <string, object> > dic = GetAllProperty(db2find, tree.filter, tree.sourceModel, tree.parentField, "ID", textField, tree.fields, tree.orderBy); IList list = FillTreeChild(db2find, dic, "ID", textField, tree.parentField, null, tree.sourceModel, tree); if (!string.IsNullOrEmpty(tree.rootText)) { return(new object[1] { new { text = tree.rootText, rootNode = true, children = list } }); } return(list); } return(null); }
private static IList FillTreeChild(DbContext dbContext_0, IList <Dictionary <string, object> > lstDicValues, string strIDFiled, string strTextFiled, string strParentIDFiled, string string_3, string sourceModel2, FilterTree filter) { bool flag = filter.sourceModel2 == sourceModel2; List <Dictionary <string, object> > list = null; if (string.IsNullOrEmpty(strParentIDFiled)) { list = lstDicValues.ToList(); } else { if (!string.IsNullOrEmpty(string_3)) { list = (from a in lstDicValues where ObEx.ToStr(a[strParentIDFiled]) == string_3 select a).ToList(); } else { list = (from a in lstDicValues where a[strParentIDFiled] == DBNull.Value || a[strParentIDFiled] == null || ObEx.ToStr(a[strParentIDFiled]) == "" || ObEx.ToStr(a[strParentIDFiled]) == "0" select a).ToList(); } } List <object> list2 = new List <object>(); foreach (Dictionary <string, object> item in list) { Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary["id"] = item[strIDFiled]; dictionary["text"] = item[strTextFiled]; dictionary["model"] = sourceModel2; dictionary["iconcss"] = sourceModel2; string text = flag ? filter.fields2 : filter.fields; if (!string.IsNullOrEmpty(text)) { string[] array = text.Split(','); foreach (string key in array) { dictionary[key] = item[key]; } } IList list3 = null; if (!string.IsNullOrEmpty(strParentIDFiled)) { list3 = FillTreeChild(dbContext_0, lstDicValues, strIDFiled, strTextFiled, strParentIDFiled, ObEx.ToStr(item[strIDFiled]), sourceModel2, filter); } if (!flag && !string.IsNullOrEmpty(filter.sourceModel2) && !string.IsNullOrEmpty(filter.refSourceField)) { ServiceConfig serviceConfig = ServiceHelper.GetServiceConfig(filter.sourceModel2); string textField = serviceConfig.model.textField; FilterGroup filterGroup = new FilterGroup(); filterGroup.rules.Add(new FilterRule { op = "equal", value = ObEx.ToStr(item[strIDFiled]), field = filter.refSourceField }); if (filter.filter2 != null) { filterGroup.groups.Add(filter.filter2); } List <Dictionary <string, object> > lstDic = GetAllProperty(dbContext_0, filterGroup, filter.sourceModel2, filter.parentField2, "ID", textField, filter.fields2); IList list4 = FillTreeChild(dbContext_0, lstDic, "ID", textField, filter.parentField2, null, filter.sourceModel2, filter); if (list3 == null) { list3 = list4; } else if (list4 != null) { foreach (object item2 in list4) { list3.Add(item2); } } } if (list3 != null && list3.Count > 0) { dictionary["children"] = list3; } list2.Add(dictionary); } return(list2); }