Beispiel #1
0
        private Symbol Lookup(string symName, TableTreeNode node)
        {
            var tmp = node.Table.Lookup(symName);

            if (tmp != null)
            {
                return(tmp);
            }
            else
            {
                if (_CurrentNode.Parent == null)
                {
                    return(null);
                }
                return(Lookup(symName, _CurrentNode.Parent));
            }
        }
Beispiel #2
0
 public T LookupExactOrAddNew(ContentName name, int part, Func <T> f)
 {
     if (part == name.ComponentCount)
     {
         if (contents.Count > 0)
         {
             return(contents.First.Value);
         }
         else
         {
             return(contents.AddLast(f()).Value);
         }
     }
     else
     {
         string        s = name [part];
         TableTreeNode child;
         if (!children.TryGetValue(s, out child))
         {
             children.Add(s, child = new TableTreeNode());
         }
         return(child.LookupExactOrAddNew(name, part + 1, f));
     }
 }
Beispiel #3
0
 public void AddValue(ContentName name, int part, T value, out bool valueAdded, out bool nameAdded, bool exclude)
 {
     if (part == name.ComponentCount)
     {
         if (exclude && contents.Contains(value))
         {
             nameAdded  = false;
             valueAdded = false;
         }
         contents.AddLast(value);
         nameAdded  = contents.Count == 1;
         valueAdded = true;
     }
     else
     {
         string        s = name [part];
         TableTreeNode child;
         if (!children.TryGetValue(s, out child))
         {
             children.Add(s, child = new TableTreeNode());
         }
         child.AddValue(name, part + 1, value, out valueAdded, out nameAdded, exclude);
     }
 }
Beispiel #4
0
 public TableTreeNode(TableTreeNode parent, SymbolTable table)
 {
     this.Parent = parent;
     this.Table  = table;
     Children    = new Dictionary <string, TableTreeNode>();
 }
Beispiel #5
0
 public TableTree()
 {
     _RootNode    = new TableTreeNode(null, new SymbolTable("GLOBAL"));
     _CurrentNode = _RootNode;
 }
Beispiel #6
0
 public InterestTable()
 {
     Root = new TableTreeNode();
 }
Beispiel #7
0
    /// <summary>
    /// 调用 OnQuery 回调方法获得数据源
    /// </summary>
    protected async Task QueryData()
    {
        // 目前设计使用 Items 参数后不回调 OnQueryAsync 方法
        if (Items == null)
        {
            if (OnQueryAsync == null && DynamicContext != null && typeof(TItem).IsAssignableTo(typeof(IDynamicObject)))
            {
                // 动态数据
                SelectedRows.Clear();
                QueryItems = DynamicContext.GetItems().Cast <TItem>();
                if (DynamicContext.OnGetSelectedRows != null)
                {
                    SelectedRows.AddRange(DynamicContext.OnGetSelectedRows().Cast <TItem>());
                }
                TotalCount = QueryItems.Count();
            }
            else
            {
                // 数据集合
                await OnQuery();
            }
        }
        else
        {
            RowsCache = null;
        }

        async Task OnQuery()
        {
            QueryData <TItem>?queryData = null;
            var queryOption             = new QueryPageOptions()
            {
                IsPage          = IsPagination,
                PageIndex       = PageIndex,
                PageItems       = PageItems,
                SearchText      = SearchText,
                SortOrder       = SortOrder,
                SortName        = SortName,
                SortList        = string.IsNullOrEmpty(SortString) ? null : new List <string>(SortString.Split(",", StringSplitOptions.RemoveEmptyEntries)),
                Filters         = Filters.Values,
                Searchs         = GetSearchs(),
                AdvanceSearchs  = GetAdvanceSearchs(),
                CustomerSearchs = GetCustomerSearchs(),
                SearchModel     = SearchModel,
                StartIndex      = StartIndex
            };

            if (CustomerSearchModel != null)
            {
                queryOption.SearchModel = CustomerSearchModel;
            }

            queryData = await InternalOnQueryAsync(queryOption);

            RowsCache       = null;
            Items           = null;
            QueryItems      = queryData.Items;
            TotalCount      = queryData.TotalCount;
            IsAdvanceSearch = queryData.IsAdvanceSearch;

            // 处理选中行逻辑
            ProcessSelectedRows();

            // 分页情况下内部不做处理防止页码错乱
            if (!queryOption.IsPage)
            {
                ProcessPageData(queryData, queryOption);
            }

            if (IsTree)
            {
                await ProcessTreeData();
            }

            void ProcessSelectedRows()
            {
                // 判断模型是否有 [Key] Id 等可识别字段尝试重构
                var rows = new List <TItem>();

                if (HasKeyAttribute)
                {
                    // 更新选中行逻辑
                    foreach (var item in SelectedRows)
                    {
                        var key = Utility.GetKeyValue <TItem, object>(item);
                        if (key != null)
                        {
                            var row = QueryItems.FirstOrDefault(i => Utility.GetKeyValue <TItem, object>(i).ToString() == key.ToString());
                            if (row != null)
                            {
                                rows.Add(row);
                            }
                        }
                    }
                }
                else
                {
                    foreach (var row in SelectedRows)
                    {
                        if (QueryItems.Any(i => i == row))
                        {
                            rows.Add(row);
                        }
                    }
                }
                SelectedRows = rows;
            }

            void ProcessPageData(QueryData <TItem> queryData, QueryPageOptions queryOption)
            {
                var filtered = queryData.IsFiltered;
                var sorted   = queryData.IsSorted;
                var searched = queryData.IsSearch;

                // 外部未处理 SearchText 模糊查询
                if (!searched && queryOption.Searchs.Any())
                {
                    QueryItems = QueryItems.Where(queryOption.Searchs.GetFilterFunc <TItem>(FilterLogic.Or));
                    TotalCount = QueryItems.Count();
                }

                // 外部未处理自定义高级搜索 内部进行高级自定义搜索过滤
                if (!IsAdvanceSearch && queryOption.CustomerSearchs.Any())
                {
                    QueryItems      = QueryItems.Where(queryOption.CustomerSearchs.GetFilterFunc <TItem>());
                    TotalCount      = QueryItems.Count();
                    IsAdvanceSearch = true;
                }

                // 外部未过滤,内部自行过滤
                if (!filtered && queryOption.Filters.Any())
                {
                    QueryItems = QueryItems.Where(queryOption.Filters.GetFilterFunc <TItem>());
                    TotalCount = QueryItems.Count();
                }

                // 外部未处理排序,内部自行排序
                // 先处理列头排序 再处理默认多列排序
                if (!sorted)
                {
                    if (queryOption.SortOrder != SortOrder.Unset && !string.IsNullOrEmpty(queryOption.SortName))
                    {
                        var invoker = Utility.GetSortFunc <TItem>();
                        QueryItems = invoker(QueryItems, queryOption.SortName, queryOption.SortOrder);
                    }
                    else if (queryOption.SortList != null && queryOption.SortList.Any())
                    {
                        var invoker = Utility.GetSortListFunc <TItem>();
                        QueryItems = invoker(QueryItems, queryOption.SortList);
                    }
                }
            }

            async Task ProcessTreeData()
            {
                KeySet.Clear();
                if (HasKeyAttribute)
                {
                    CheckExpandKeys(TreeRows);
                }
                if (KeySet.Count > 0)
                {
                    TreeRows = new List <TableTreeNode <TItem> >();
                    foreach (var item in QueryItems)
                    {
                        var node = new TableTreeNode <TItem>(item)
                        {
                            HasChildren = CheckTreeChildren(item),
                        };
                        node.IsExpand = IsExpandRow(node);
                        if (node.IsExpand)
                        {
                            await RestoreIsExpand(node);
                        }
                        TreeRows.Add(node);
                    }
                }
                else
                {
                    TreeRows = QueryItems.Select(item => new TableTreeNode <TItem>(item)
                    {
                        HasChildren = CheckTreeChildren(item)
                    }).ToList();
                }
            }
        }
    }