예제 #1
0
        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);
        }
예제 #2
0
        private static List <Dictionary <string, object> > GetAllProperty(DbContext dbFind, FilterGroup filter, string modelName, string parentFiled, string valueFiled, string textFiled, string fileds = null, string orderBy = null)
        {
            Type entityType = GetEntityType(modelName, "Report");

            if (entityType == null)
            {
                return(null);
            }
            //lyl 2018-12-28 还没有弄完,感觉需要 修改DbHelper 的DBContext
            IList listData = DbHelper.GetListData(dbFind, entityType, filter, orderBy);
            List <Dictionary <string, object> > list = new List <Dictionary <string, object> >();

            valueFiled = (string.IsNullOrEmpty(valueFiled) ? "ID" : valueFiled);
            foreach (object item in listData)
            {
                Dictionary <string, object> dictionary = new Dictionary <string, object>();
                Type type = item.GetType();
                dictionary[valueFiled] = DataHelper.GetPropertyValue(type, item, valueFiled);
                if (!string.IsNullOrEmpty(parentFiled))
                {
                    dictionary[parentFiled] = DataHelper.GetPropertyValue(type, item, parentFiled);
                }
                dictionary[textFiled] = DataHelper.GetPropertyValue(type, item, textFiled);
                if (!string.IsNullOrEmpty(fileds))
                {
                    string[] array = fileds.Split(',');
                    foreach (string text in array)
                    {
                        try
                        {
                            dictionary[text] = DataHelper.GetPropertyValue(type, item, text);
                        }
                        catch
                        {
                        }
                    }
                }
                list.Add(dictionary);
            }
            return(list);
        }