Beispiel #1
0
        public static bool ToValue(List <FilterComp> items)
        {
            bool rtn = true;

            foreach (FilterComp item in items)
            {
                if (item.IsFirst)
                {
                    if (item.Child != null && item.Child.Count > 0)
                    {
                        rtn = FilterComp.ToValue(item.Child);
                    }
                    else
                    {
                        rtn = item.CurValue;
                    }
                }
                else
                {
                    bool r;
                    if (item.Child != null && item.Child.Count > 0)
                    {
                        r = FilterComp.ToValue(item.Child);
                    }
                    else
                    {
                        r = item.CurValue;
                    }

                    if (item.IsAnd)
                    {
                        rtn = rtn && r;
                    }
                    else
                    {
                        rtn = rtn || r;
                    }
                }
            }
            return(rtn);
        }
Beispiel #2
0
        /// <summary>
        /// 获取当前数据的表达式
        /// </summary>
        /// <returns></returns>
        protected virtual bool GetLinqWhereExp(object o)
        {
            bool currtn = true;                    //当前检索项的值
            FilterCompCollection Comps    = new FilterCompCollection();
            FilterCompCollection curComps = Comps; //当前检索项
            FilterCompCollection child;

            for (int i = 0; i < FilterItems.Count; i++)
            {
                SearchItem item = FilterItems[i];
                if (item.SqlPrefixType == SqlPrefixType.EndByGroup)
                {
                    continue;
                }
                currtn = item.ToLinkFilter(o);

                switch (item.SqlPrefixType)
                {
                case SqlPrefixType.AndSingle:
                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = true, CurValue = currtn
                    });
                    break;

                case SqlPrefixType.OrSingle:
                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = false, CurValue = currtn
                    });
                    break;

                case SqlPrefixType.AfterGroupByAnd:
                    child = new FilterCompCollection()
                    {
                        Owners = curComps
                    };
                    child.Add(new FilterComp()
                    {
                        IsFirst = true, IsAnd = true, CurValue = currtn
                    });

                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = true, CurValue = currtn, Child = child
                    });
                    curComps = child;
                    break;

                case SqlPrefixType.AfterGroupByOr:
                    child = new FilterCompCollection()
                    {
                        Owners = curComps
                    };
                    child.Add(new FilterComp()
                    {
                        IsFirst = true, IsAnd = true, CurValue = currtn
                    });

                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = false, CurValue = currtn, Child = child
                    });
                    curComps = child;
                    break;

                case SqlPrefixType.BeforeGroupByAnd:
                    if (curComps.Owners != null)
                    {
                        curComps = curComps.Owners;
                    }

                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = true, CurValue = currtn
                    });
                    break;

                case SqlPrefixType.BeforeGroupByOr:
                    if (curComps.Owners != null)
                    {
                        curComps = curComps.Owners;
                    }

                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = false, CurValue = currtn
                    });
                    break;

                default:
                    curComps.Add(new FilterComp()
                    {
                        IsFirst = (i == 0), IsAnd = true, CurValue = currtn
                    });
                    break;
                }
            }
            return(FilterComp.ToValue(Comps));
        }