Beispiel #1
0
        /// <summary>
        /// 获取section列表
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <param name="loadCount"></param>
        /// <returns></returns>
        public PagerData <SectionModel> GetSectionList(
            string q = null, string sectionType = null,
            int page = 1, int pagesize          = 10)
        {
            string key = GetCacheKey($"{nameof(PageService)}.{nameof(GetSectionList)}", q, sectionType, page.ToString(), pagesize.ToString());

            return(Cache(key, () =>
            {
                var data = new PagerData <SectionModel>();
                //列表
                _SectionDal.PrepareIQueryable((query) =>
                {
                    if (ValidateHelper.IsPlumpString(q))
                    {
                        query = query.Where(x => x.SectionTitle.Contains(q) || x.SectionDescription.Contains(q));
                    }
                    if (ValidateHelper.IsPlumpString(sectionType))
                    {
                        query = query.Where(x => x.SectionType == sectionType);
                    }
                    data.ItemCount = query.Count();
                    var range = PagerHelper.GetQueryRange(page, pagesize);
                    data.DataList = query.OrderByDescending(x => x.UpdateTime).Skip(range[0]).Take(range[1]).ToList();
                    return true;
                });
                return data;
            }));
        }
        public async Task <PagerData <LoginUserInfo> > SearchUser(string q = null, int page = 1, int pagesize = 10)
        {
            var data = new PagerData <LoginUserInfo>();

            using (var db = new QipeilongDbContext())
            {
                var query = db.UserInfo.AsNoTrackingQueryable();

                if (ValidateHelper.IsPlumpString(q))
                {
                    query = query.Where(x =>
                                        x.CompanyName.Contains(q) ||
                                        x.ShopName.Contains(q) ||
                                        x.UserName.Contains(q) ||
                                        x.Contact.Contains(q) ||
                                        x.Mobile.Contains(q) ||
                                        x.Notes.Contains(q) ||
                                        x.Phone.Contains(q) ||
                                        x.ShopNo.Contains(q) ||
                                        x.UID == q);
                }

                data.ItemCount = await query.CountAsync();

                var list = await query.OrderByDescending(x => x.CreatedDate).QueryPage(page, pagesize).ToListAsync();

                data.DataList = list.Select(x => this.Parse(x)).ToList();
            }
            return(data);
        }
Beispiel #3
0
        public async Task <PagerData <FinanceFlowEntity> > QueryFlowByConditions(DateTime?start_time_utc, DateTime?end_time_utc,
                                                                                 int?pay_method,
                                                                                 int page, int pagesize)
        {
            page.Should().BeGreaterOrEqualTo(1);
            pagesize.Should().BeInRange(1, 5000);

            var repo = this._repo;

            var query = repo.Table.AsNoTracking();

            query = query.WhereIf(pay_method != null, x => x.PayMethod == pay_method.Value);
            query = query.WhereIf(start_time_utc != null, x => x.CreateTimeUtc >= start_time_utc);
            query = query.WhereIf(end_time_utc != null, x => x.CreateTimeUtc < end_time_utc);

            var data = new PagerData <FinanceFlowEntity>()
            {
                Page     = page,
                PageSize = pagesize
            };

            data.ItemCount = await query.CountAsync();

            data.DataList = await query
                            .OrderByDescending(x => x.OrderCreateTimeUtc).ThenByDescending(x => x.Id)
                            .QueryPage(page, pagesize).ToListAsync();

            return(data);
        }
Beispiel #4
0
        public void CanMoveTo3rdRange_3Ranges()
        {
            PagerData pager = new PagerData(1, 13, new PagerSettings()
            {
                NumberPagesToDisplay = 5
            });

            CheckPages(pager, 1, 1, 1, 5, 2);
            CheckNavigation(pager, false, false, true, true);

            // Move to last page 5 in first range ( 1 - 5 )
            pager.MoveToPage(5);
            CheckPages(pager, 5, 4, 1, 5, 6);
            CheckNavigation(pager, false, false, true, true);

            // Move to first page 6 in next range ( 6 - 10 )
            pager.MoveNext();
            CheckPages(pager, 6, 5, 6, 10, 7);
            CheckNavigation(pager, true, true, true, true);

            // Move to last page 10 in 2nd range ( 6 - 10 )
            pager.MoveToPage(10);
            CheckPages(pager, 10, 9, 6, 10, 11);
            CheckNavigation(pager, true, true, true, true);

            // Move to first page 11 in last range ( 9 - 13 )
            pager.MoveNext();
            CheckPages(pager, 11, 10, 9, 13, 12);
            CheckNavigation(pager, true, true, false, false);

            // Move to previous page 10 in 2nd range ( 6 - 10 )
            pager.MovePrevious();
            CheckPages(pager, 10, 9, 6, 10, 11);
            CheckNavigation(pager, true, true, true, true);
        }
        public PartialViewResult UsersData(UsersFilterModel model)
        {
            PagerData pager = new PagerData()
            {
                ItemsPerPage = MvcApplication.ItemsPerPage,
                CurrentPage  = model.Page ?? 1
            };

            IEnumerable <UserViewModel> users;

            if (model.UserName != null)
            {
                string userName = model.UserName.ToLower();
                users = _accountManager.GetUsers(HttpContext.GetOwinContext(), u => u.UserName.ToLower().Contains(userName), pager);
            }
            else
            {
                users = _accountManager.GetUsers(HttpContext.GetOwinContext(), pager);
            }

            UsersListViewModel usersModel = new UsersListViewModel()
            {
                Pager = pager,
                Users = users
            };

            Session["UsersPage"] = pager.CurrentPage;
            return(PartialView(usersModel));
        }
Beispiel #6
0
 private void CheckNavigation(PagerData pager, bool showFirst, bool showPrevious, bool showNext, bool showLast)
 {
     Assert.AreEqual(pager.CanShowFirst, showFirst);
     Assert.AreEqual(pager.CanShowPrevious, showPrevious);
     Assert.AreEqual(pager.CanShowNext, showNext);
     Assert.AreEqual(pager.CanShowLast, showLast);
 }
Beispiel #7
0
        public static MvcHtmlString Pager(this HtmlHelper html, PagerData data, Func <int, string> PageURLFunc)
        {
            if (data.TotalPages < 2)
            {
                return(MvcHtmlString.Create(""));
            }

            TagBuilder p = new TagBuilder("ul");

            p.AddCssClass("pagination");
            for (int i = 1; i <= data.TotalPages; i++)
            {
                TagBuilder li = new TagBuilder("li");
                if (i == data.CurrentPage)
                {
                    li.AddCssClass("active");
                }
                TagBuilder a = new TagBuilder("a");
                a.MergeAttribute("href", PageURLFunc(i));
                a.InnerHtml   = i.ToString();
                li.InnerHtml += a.ToString();
                p.InnerHtml  += li.ToString();
            }

            return(MvcHtmlString.Create(p.ToString()));
        }
Beispiel #8
0
        public ActionResult Statistics(SaleFilterModel model)
        {
            if (Session["ItemsPerPage"] != null)
            {
                model.ItemsPerPage = (int)Session["ItemsPerPage"];
            }
            PagerData pager = new PagerData()
            {
                ItemsPerPage = model.ItemsPerPage, CurrentPage = model.page
            };
            var result = _salesManager.GetSales(model, null, pager);

            if (Request.IsAjaxRequest())
            {
                return(Json(new { CurrentPage = pager.CurrentPage, TotalPages = pager.TotalPages, Result = result }, JsonRequestBehavior.AllowGet));
            }
            SalesListModel listModel = new SalesListModel()
            {
                Sales  = result,
                Pager  = pager,
                Filter = model
            };

            return(View("Statistics", listModel));
        }
Beispiel #9
0
        public static MvcHtmlString Pager(this AjaxHelper ajax, PagerData data, string UpdateTargetID, Func <int, string> PageURLFunc, Func <int, string> AjaxURLFunc)
        {
            if (data.TotalPages < 2)
            {
                return(MvcHtmlString.Create(""));
            }

            TagBuilder p = new TagBuilder("ul");

            p.AddCssClass("pagination");
            for (int i = 1; i <= data.TotalPages; i++)
            {
                TagBuilder li = new TagBuilder("li");
                if (i == data.CurrentPage)
                {
                    li.AddCssClass("active");
                }
                TagBuilder a = new TagBuilder("a");
                a.MergeAttribute("data-ajax", "true");
                a.MergeAttribute("data-ajax- mode", "replace");
                a.MergeAttribute("data-ajax-update", "#" + UpdateTargetID);
                a.MergeAttribute("href", PageURLFunc(i));
                a.MergeAttribute("data-ajax-url", AjaxURLFunc(i));
                a.InnerHtml = i.ToString();

                li.InnerHtml += a.ToString();
                p.InnerHtml  += li.ToString();
            }

            return(MvcHtmlString.Create(p.ToString()));
        }
Beispiel #10
0
        public async Task <PagerData <LoginUserInfo> > SearchUser(string q = null, int page = 1, int pagesize = 10)
        {
            var data = new PagerData <LoginUserInfo>();

            using (var db = new QPLEntityDB())
            {
                var query = db.UserInfo.AsNoTrackingQueryable();

                if (ValidateHelper.IsPlumpString(q))
                {
                    var qs = q.Split(new char[] { ' ', ',', ',' })
                             .Select(x => x.Trim())
                             .Where(x => ValidateHelper.IsPlumpString(x));
                    foreach (var kwd in qs)
                    {
                        query = query.Where(x =>
                                            x.CompanyName.Contains(kwd) ||
                                            x.ShopName.Contains(kwd) ||
                                            x.UserName.Contains(kwd) ||
                                            x.Mobile == kwd ||
                                            x.Phone == kwd ||
                                            x.ShopNo == kwd ||
                                            x.UID == kwd);
                    }
                }

                data.ItemCount = await query.CountAsync();

                var list = await query.OrderByDescending(x => x.CreatedDate).QueryPage(page, pagesize).ToListAsync();

                data.DataList = list.Select(x => this.Parse(x)).ToList();
            }
            return(data);
        }
Beispiel #11
0
        /// <summary>
        /// 直接获取client
        /// </summary>
        /// <param name="user_id"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public async Task <PagerData <AuthClient> > GetMyAuthorizedClientsAsync(string user_id, string q, int page, int pagesize)
        {
            var data = new PagerData <AuthClient>();

            await this._AuthClientRepository.PrepareSessionAsync(async db =>
            {
                var now = DateTime.Now;

                var client_query = db.Set <AuthClient>().AsNoTrackingQueryable();
                var token_query  = db.Set <AuthToken>().AsNoTrackingQueryable();

                var client_uids = token_query.Where(x => x.UserUID == user_id && x.ExpiryTime > now && x.IsRemove <= 0).Select(x => x.ClientUID);

                client_query = client_query.Where(x => client_uids.Contains(x.UID) && x.IsRemove <= 0);
                if (ValidateHelper.IsPlumpString(q))
                {
                    client_query = client_query.Where(x => x.ClientName.Contains(q) || x.Description.Contains(q));
                }

                data.ItemCount = await client_query.CountAsync();
                client_query   = client_query.OrderByDescending(x => x.IsOfficial).OrderBy(x => x.ClientName).QueryPage(page, pagesize);
                data.DataList  = await client_query.ToListAsync();

                if (ValidateHelper.IsPlumpList(data.DataList))
                {
                    //
                }

                return(true);
            });

            return(data);
        }
Beispiel #12
0
 private void CheckPages(PagerData pager, int current, int previous, int starting, int ending, int next)
 {
     Assert.AreEqual(pager.CurrentPage, current);
     Assert.AreEqual(pager.PreviousPage, previous);
     Assert.AreEqual(pager.StartingPage, starting);
     Assert.AreEqual(pager.EndingPage, ending);
     Assert.AreEqual(pager.NextPage, next);
 }
Beispiel #13
0
        public void IsMultiplePages()
        {
            PagerData pager = new PagerData(1, 4);

            Assert.IsTrue(pager.IsMultiplePages);
            CheckNavigation(pager, false, false, false, false);
            CheckPages(pager, 1, 1, 1, 4, 2);
        }
Beispiel #14
0
        public IActionResult GetPager(int pageNo, int pages, string category)
        {
            PagerData pagerData = new PagerData()
            {
                Current = pageNo, Pages = pages, Category = category
            };

            return(PartialView("_PagerPartial", pagerData));
        }
        public void Subscribe(RootBuilder describe) {
            describe.Scope("ContentList", mix => {
                mix.Factory<RootShape,dynamic>((context) => Shape.ContentList(ListItems:((ContentListViewModel)context.Get<Model,object>()).Rendered));
                mix.Factory<ContentList,ShapeMetadata>((context) => new ShapeMetadata() {
                    DisplayType = "Summary",
                });
                mix.Factory<ContentList,ParadigmsContext>((context) => new ParadigmsContext());
                mix.Factory<ContentList,ContentListQuery>((context) => new ContentListQuery() { Query = _contentManager.Query() });
                mix.Factory<ContentList,IEnumerable<IContent>>((context) => {
                    var query = context.Get<ContentList, ContentListQuery>();
                    var pager = context.Get<ContentList,PagerData>();
                    if (pager!=null) 
                        return query.Query.Slice(pager.PageSize*(pager.Page-1),pager.PageSize);
                    return query.Query.List();
                });
                mix.Factory<ContentModelBuilder, Func<IContent, ModelShapeBuilder>>((context) => (c) => Builder(c, context));
                // TODO: Could support prefix here
                mix.Factory<ContentShapeBuilder, Func<IContent, object>>((context) => (s) => _origami.ContentShape(s, context.Get<ContentList, ShapeMetadata>().DisplayType));
                mix.Factory<Model,object>((context) => {
                    var source = context.Get<ContentList,IEnumerable<IContent>>();
                    var builder = context.Get<ContentModelBuilder, Func<IContent,ModelShapeBuilder>>();
                    return new ContentListViewModel() {
                        Rendered = source.Select(s => {
                            var root = context.Get<ContentShapeBuilder, Func<IContent, object>>()(s);
                            _origami.Build(builder(s), root);
                            return root;
                        }).ToList()
                    };
                });
                // TODO: Get page size from settings
                mix.Factory<ContentList,PagerData>((context) => {
                    var pager = new PagerData() {
                        Page = 1,
                        PageSize = 10
                    };
                    return pager;
                });
                mix.Parameter<int>("PageSize", (pageSize) => {
                    pageSize.Mutate<ContentList, PagerData>((pager, context) => { pager.PageSize = pageSize.Get(context); });
                });
                mix.Parameter<int>("Page", (page) => {
                    page.Mutate<ContentList, PagerData>((pager, context) => { pager.Page = page.Get(context); });
                });
                mix.Parameter<string>("ContentType", (ct) => {
                    ct.Mutate<ContentList, ContentListQuery>((q,context) => q.Query = q.Query.ForType(ct.Get(context)));
                });
                mix.Parameter<string>("ContentTypes", (ct) => {
                    ct.Mutate<ContentList, ContentListQuery>((q, context) => q.Query = q.Query.ForType(ct.Get(context).Split(new[]{','},StringSplitOptions.RemoveEmptyEntries)));
                });
                // Calculate total pages at end
                mix.Mutate<ContentList, PagerData>((pager, context) => {
                    var query = context.Get<ContentList, ContentListQuery>();
                    pager.TotalPages = query.Query.Count() / pager.PageSize; // TODO: Check calculation
                });

            });
        }
Beispiel #16
0
        public void CanMoveToNextPage_SingleRange()
        {
            PagerData pager = new PagerData(1, 4);

            CheckPages(pager, 1, 1, 1, 4, 2);
            CheckNavigation(pager, false, false, false, false);

            pager.MoveNext();
            CheckPages(pager, 2, 1, 1, 4, 3);
            CheckNavigation(pager, false, false, false, false);
        }
Beispiel #17
0
        /// <summary>
        /// 获取评论分页
        /// </summary>
        /// <param name="threadID"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public PagerData <CommentModel> GetComments(string threadID, int page, int pagesize)
        {
            if (!ValidateHelper.IsPlumpString(threadID))
            {
                return(null);
            }

            string key = Com.GetCacheKey("commentbll.getcomments", threadID, page.ToString(), pagesize.ToString());

            return(Cache(key, () =>
            {
                var data = new PagerData <CommentModel>();
                int[] range = PagerHelper.GetQueryRange(page, pagesize);
                var _commentDal = new CommentDal();
                _commentDal.PrepareIQueryable((query) =>
                {
                    query = query.Where(x => x.ThreadID == threadID);
                    data.ItemCount = query.Count();
                    data.DataList = query.OrderByDescending(x => x.CommentID)
                                    .Skip(range[0]).Take(range[1]).ToList();
                    return true;
                });
                if (ValidateHelper.IsPlumpList(data.DataList))
                {
                    var useridlist = data.DataList.Select(x => x.UserID).Distinct().Where(x => x > 0).ToArray();
                    if (ValidateHelper.IsPlumpList(useridlist))
                    {
                        var userbll = AppContext.GetObject <IUserService>();
                        var userlist = userbll.GetUserByIDS(useridlist);
                        if (ValidateHelper.IsPlumpList(userlist))
                        {
                            data.DataList.ForEach(x =>
                            {
                                x.UserModel = userlist.Where(m => m.UserID == x.UserID).FirstOrDefault();
                            });
                        }
                    }

                    var parentidlist = data.DataList.Select(x => x.ParentCommentID).Distinct().Where(x => x > 0).ToArray();
                    if (ValidateHelper.IsPlumpList(parentidlist))
                    {
                        var commentslist = GetCommentsByIDS(parentidlist);
                        if (ValidateHelper.IsPlumpList(commentslist))
                        {
                            data.DataList.ForEach(x =>
                            {
                                x.ParentComment = commentslist.Where(m => m.CommentID == x.ParentCommentID).FirstOrDefault();
                            });
                        }
                    }
                }
                return data;
            }));
        }
Beispiel #18
0
    public virtual void DataSource(PagerData PagerData)
    {
        var Data = PagerData;

        this.RecordCount         = Data.PagerArgs.RecordCount;
        this.CurrentPage         = Data.PagerArgs.PageIndex;
        this.Repeater.DataSource = Data.Data;
        this.Repeater.DataBind();
        this.PagerElements.Visible = this.RecordCount > this.PageSize;
        TotalPageLabel.Text        = "/ " + Math.Ceiling(RecordCount / PageSize);
    }
Beispiel #19
0
        public IEnumerable <UserViewModel> GetUsers(IOwinContext owinContext,
                                                    PagerData pager = null, Expression <Func <IQueryable <UserViewModel>, IOrderedQueryable <UserViewModel> > > orderBy = null)
        {
            var query = orderBy == null?GetUsers(owinContext, u => true).OrderBy(u => u.UserName) : orderBy.Compile()(GetUsers(owinContext, u => true));

            if (pager == null)
            {
                return(query.ToArray());
            }

            return(GetUsersPage(query, pager));
        }
Beispiel #20
0
        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="keywords"></param>
        /// <param name="page"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public PagerData <UserModel> GetPagerList(
            string name = null, int?sex = null, string email = null, string keywords = null,
            bool LoadRoleAndPrivilege = false,
            int page = 1, int pageSize = 20)
        {
            var data = new PagerData <UserModel>();

            #region 查询
            _UserDal.PrepareIQueryable((query) =>
            {
                if (ValidateHelper.IsPlumpString(name))
                {
                    query = query.Where(x => x.NickName == name);
                    data.UrlParams["name"] = name;
                }

                if (sex != null)
                {
                    query = query.Where(x => x.Sex == sex);
                    data.UrlParams["sex"] = name;
                }

                if (ValidateHelper.IsPlumpString(email))
                {
                    query = query.Where(x => x.Email == email);
                    data.UrlParams["email"] = name;
                }

                if (ValidateHelper.IsPlumpString(keywords))
                {
                    query = query.Where(x =>
                                        x.NickName.Contains(keywords) ||
                                        x.Phone.Contains(keywords) ||
                                        x.Email.Contains(keywords) ||
                                        x.Introduction.Contains(keywords) ||
                                        x.QQ.Contains(keywords));
                    data.UrlParams["q"] = keywords;
                }

                data.ItemCount = query.Count();
                data.DataList  = query.OrderByDescending(x => x.IID).QueryPage(page, pageSize).ToList();
                return(true);
            });
            #endregion

            if (ValidateHelper.IsPlumpList(data?.DataList) && LoadRoleAndPrivilege)
            {
                data.DataList = GetRolesForUserList(data.DataList);
            }

            return(data);
        }
Beispiel #21
0
        public IEnumerable <UserViewModel> GetUsers(IOwinContext owinContext, Expression <Func <UserViewModel, bool> > condition,
                                                    PagerData pager = null, Expression <Func <IQueryable <UserViewModel>, IOrderedQueryable <UserViewModel> > > orderBy = null)
        {
            var query        = GetUsers(owinContext, condition);
            var orderedQuery = orderBy == null?query.OrderBy(u => u.UserName)
                                   : orderBy.Compile()(query);

            if (pager == null)
            {
                return(orderedQuery.ToArray());
            }
            return(GetUsersPage(orderedQuery, pager));
        }
Beispiel #22
0
        public void CanMoveToNextPage_ManyRanges()
        {
            PagerData pager = new PagerData(1, 18, new PagerSettings()
            {
                NumberPagesToDisplay = 5
            });

            CheckPages(pager, 1, 1, 1, 5, 2);
            CheckNavigation(pager, false, false, true, true);

            pager.MoveNext();
            CheckPages(pager, 2, 1, 1, 5, 3);
            CheckNavigation(pager, false, false, true, true);
        }
Beispiel #23
0
	void OnButtonClick() {
		var btn = UIButton.current;
		if (btn == toFirst) {
			PagerData = PagerData.ChangePage(PagerData.FirstPage);
		} else if (btn == toPrev) {
			PagerData = PagerData.ChangePage(PagerData.PrevPage);
		} else if (btn == toNext) {
			PagerData = PagerData.ChangePage(PagerData.NextPage);
		} else if (btn == toLast) {
			PagerData = PagerData.ChangePage(PagerData.LastPage);
		} else throw new System.InvalidOperationException("impossible");

		OnInteraction ();
	}
Beispiel #24
0
        public void SearchProducts(SearchParamModel model)
        {
            var data = new PagerData <object>();

            var response = SearchEsProducts(model);

            data.ItemCount = (int)(response?.Total ?? 0);
            var datalist = response?.Hits?.Select(x => x as Hit <ProductListV2>).Where(x => x != null).Select(x => x.Source).Where(x => x != null).ToList();

            //聚合的数据
            var aggs = GetAggs(response);

            data.DataList = ConvertHelper.NotNullList(data.DataList);
        }
Beispiel #25
0
        public async Task <PagerData <AuthClient> > QueryListAsync(
            string user_uid = null, string q  = null, bool?is_active = null, bool?is_remove = null,
            int page        = 1, int pagesize = 10)
        {
            var data = new PagerData <AuthClient>();

            await this._AuthClientRepository.PrepareSessionAsync(async db =>
            {
                var query = db.Set <AuthClient>().AsNoTrackingQueryable();
                if (is_remove != null)
                {
                    if (is_remove.Value)
                    {
                        query = query.Where(x => x.IsRemove > 0);
                    }
                    else
                    {
                        query = query.Where(x => x.IsRemove <= 0);
                    }
                }
                if (ValidateHelper.IsPlumpString(user_uid))
                {
                    query = query.Where(x => x.UserUID == user_uid);
                }
                if (is_active != null)
                {
                    if (is_active.Value)
                    {
                        query = query.Where(x => x.IsActive > 0);
                    }
                    else
                    {
                        query = query.Where(x => x.IsActive <= 0);
                    }
                }
                if (ValidateHelper.IsPlumpString(q))
                {
                    query = query.Where(x => x.ClientName.Contains(q));
                }

                data.ItemCount = await query.CountAsync();
                data.DataList  = await query
                                 .OrderByDescending(x => x.IsOfficial).OrderByDescending(x => x.CreateTime)
                                 .QueryPage(page, pagesize).ToListAsync();
                return(true);
            });

            return(data);
        }
Beispiel #26
0
        public static object PagerDataMapper_ <T, Result>(this PagerData <T> data, Func <T, Result> selector)
        {
            data.DataList.Should().NotBeNull();

            var res = new
            {
                data.Page,
                data.PageCount,
                data.PageSize,
                data.ItemCount,
                DataList = data.DataList.Select(selector).ToArray()
            };

            return(res);
        }
Beispiel #27
0
        /// <summary>
        /// 自动分页
        /// </summary>
        public static async Task <PagerData <T> > ToPagedListAsync <T, SortColumn>(this IQueryable <T> query,
                                                                                   int page, int pagesize,
                                                                                   Expression <Func <T, SortColumn> > orderby, bool desc = true)
        {
            var data = new PagerData <T>()
            {
                Page     = page,
                PageSize = pagesize
            };

            data.ItemCount = await query.CountAsync();

            data.DataList = await query.OrderBy_(orderby, desc).QueryPage(page, pagesize).ToListAsync();

            return(data);
        }
Beispiel #28
0
        public virtual async Task <PagerData <MenuGroupBase> > QueryMenuGroupList(string q, int page = 1, int pagesize = 20)
        {
            var data = new PagerData <MenuGroupBase>();

            await this._menuGroupRepo.PrepareIQueryableAsync(async query =>
            {
                if (ValidateHelper.IsPlumpString(q))
                {
                    query = query.Where(x => x.GroupName.Contains(q) || x.Description.Contains(q));
                }

                data.ItemCount = await query.CountAsync();
                data.DataList  = await query.OrderByDescending(x => x.UpdateTime).QueryPage(page, pagesize).ToListAsync();
            });

            return(data);
        }
Beispiel #29
0
        public static string GetPagerHtml <T, EXT>(this PagerData <T, EXT> pager, Controller controller, string pageKey, int currentPage, int pageSize)
        {
            var p        = new Dictionary <string, string>();
            var _context = controller.HttpContext;

            var kv = _context.Request.Query.ToDict().Where(x => ValidateHelper.IsNotEmpty(x.Key) && x.Key.ToLower() != pageKey.ToLower()).ToDictionary(x => x.Key, x => ConvertHelper.GetString(x.Value));

            p.AddDict(kv);

            return(PagerHelper.GetPagerHtmlByData(
                       url: _context.Request.PathBase,
                       pageKey: pageKey,
                       urlParams: p,
                       itemCount: pager.ItemCount,
                       page: currentPage,
                       pageSize: pageSize));
        }
Beispiel #30
0
    public static PagerData ApplyArgs <T>(this PagerArgs Args, IQueryable <T> candidates)
    {
        Args.RecordCount = candidates.Count();
        candidates       = candidates.Skip(Args.PageIndex * Args.PageSize).Take(Args.PageSize);
        PagerData data = new PagerData();

        data.PagerArgs = Args;
        try
        {
            data.Data = candidates.ToList();
        }
        catch (Exception e)
        {
            throw new Exception(e.Message);
        }
        return(data);
    }
Beispiel #31
0
        /// <summary>
        /// 获取评论分页
        /// </summary>
        /// <param name="threadID"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public PagerData <CommentModel> GetComments(string threadID, int page, int pagesize)
        {
            if (!ValidateHelper.IsPlumpString(threadID))
            {
                return(null);
            }

            var data        = new PagerData <CommentModel>();
            var _commentDal = new CommentDal();

            _commentDal.PrepareIQueryable((query) =>
            {
                query          = query.Where(x => x.ThreadID == threadID);
                data.ItemCount = query.Count();
                data.DataList  = query.OrderByDescending(x => x.CreateTime).QueryPage(page, pagesize).ToList();
                return(true);
            });
            return(data);
        }
        public async Task <PagerData <LoginUserInfo> > SearchUser(string q = null, int page = 1, int pagesize = 10)
        {
            var data = new PagerData <LoginUserInfo>();

            using (var db = new QPLEntityDB())
            {
                var query = db.T_SalesInfo.AsNoTrackingQueryable();

                if (ValidateHelper.IsPlumpString(q))
                {
                    query = query.Where(x => x.NickName.Contains(q) || x.UserName.Contains(q) || x.UserID == q || x.UID == q);
                }

                data.ItemCount = await query.CountAsync();

                data.DataList = (await query.OrderByDescending(x => x.UpdatedDate).QueryPage(page, pagesize).ToListAsync()).Select(x => this.Parse(x)).ToList();
            }
            return(data);
        }
Beispiel #33
0
    public static PagerData BuildPagerData(int currentPage, int recordsCount, string elementHtmlId, string pageQueryStringKey = "page", int recordsPerPage = 100, bool showGoTo = false)
    {
        PagerData data = new PagerData();
        dynamic request = HttpContext.Current.Request;

        StringBuilder myQueryString = new StringBuilder();
        int validKeys = 0;
        for (int i = 0; i <= request.QueryString.Keys.Count - 1; i++)
        {
          string key = request.QueryString.Keys[i];

          if (!string.IsNullOrEmpty(key))
          {
        if (validKeys > 0)
          myQueryString.Append("&");

        myQueryString.Append(HttpUtility.UrlEncodeUnicode(key));
        myQueryString.Append("=");

        if (key == pageQueryStringKey)
        {
          myQueryString.Append("{0}");
        }
        else
        {
          myQueryString.Append(HttpUtility.UrlEncodeUnicode(request.QueryString[key]));
        }
        validKeys += 1;
          }
        }
        if (request.QueryString[pageQueryStringKey] == null)
          myQueryString.Append("&" + pageQueryStringKey + "={0}");

        data.ActionURL = request.Url.AbsolutePath + "?" + myQueryString.ToString();
        data.RecordsPerPage = recordsPerPage;
        data.ElementHtmlID = elementHtmlId;
        data.RecordsCount = recordsCount;
        data.CurrentPage = currentPage;
        data.ShowGoTo = showGoTo;

        return data;
    }
Beispiel #34
0
        public static MvcHtmlString Pager(PagerData data)
        {
            int currentPage = data.CurrentPage - 1;
              int visiblePageLinksCount = 1;
              int currentBulk = (int)Math.Ceiling((decimal)(currentPage + 1) / visiblePageLinksCount);
              int lastBulkIndex = (int)Math.Ceiling((decimal)(data.RecordsCount / data.RecordsPerPage) / visiblePageLinksCount);
              int lastPageIndex = (int)Math.Ceiling((decimal)data.RecordsCount / data.RecordsPerPage);
              if (data.ActionURL != null)
              {
            data.ActionURL = data.ActionURL.Replace("?&", "?");
              }
              if (!(lastPageIndex == 0))
              {
            // create the main container
            TagBuilder divPager = new TagBuilder("div");
            divPager.MergeAttribute("class", "pager");
            TagBuilder spanNav = new TagBuilder("span");
            spanNav.MergeAttribute("class", "spanNav");
            spanNav.InnerHtml += "";
            for (int i = 0; i <= lastPageIndex - 1; i++)
            {
              if (i == 0)
              {
            // set the first and previous links
            TagBuilder aFirst = new TagBuilder("a");
            TagBuilder aPrevious = new TagBuilder("a");

            // set the classes, texts and href's
            aFirst.MergeAttribute("class", currentBulk == 1 && currentPage == 0 ? "nav-disabled" : "nav pager-first");

            // Remove "Page=1" from the pager url params so that the pages don't have the same content but with different urls
            aFirst.MergeAttribute("href", currentBulk == 1 && currentPage == 0 ? "#First" : data.ActionURL.Replace("?Page={0}", string.Empty).Replace("&Page={0}", string.Empty));
            aFirst.InnerHtml = "&#160;";

            aPrevious.MergeAttribute("class", currentBulk == 1 && currentPage == 0 ? "nav-disabled" : "nav pager-previous");

            // Remove "Page=1" from the pager url params so that the pages don't have the same content but with different urls
            aPrevious.MergeAttribute("href", currentBulk == 1 && currentPage == 0 ? "#Previous" : currentPage == 1 ? data.ActionURL.Replace("?Page={0}", string.Empty).Replace("&Page={0}", string.Empty) : string.Format(data.ActionURL, currentPage));
            aPrevious.InnerHtml = "&#160;";
            //divPager.InnerHtml += aFirst.ToString + aPrevious.ToString
            spanNav.InnerHtml += aFirst.ToString() + aPrevious.ToString();
              }

              // set the pages links
              if (i == currentPage)
              {
            // set the current page container
            TagBuilder spanCurrentPage = new TagBuilder("span");
            spanCurrentPage.MergeAttribute("class", "current");
            spanCurrentPage.SetInnerText((i + 1).ToString());
            //divPager.InnerHtml += spanCurrentPage.ToString
            spanNav.InnerHtml += spanCurrentPage.ToString();
              }
              else
              {
            TagBuilder aPageLink = new TagBuilder("a");
            if (!((int)Math.Ceiling((decimal)(i + 1) / visiblePageLinksCount) != currentBulk))
            {
              aPageLink.MergeAttribute("href", string.Format(data.ActionURL, i + 1));
              aPageLink.SetInnerText((i + 1).ToString());
              divPager.InnerHtml += aPageLink.ToString();
            }
              }

              //' set the next bulk link
              if (i == lastPageIndex - 1)
              {
            // set the next and last links
            TagBuilder aNext = new TagBuilder("a");
            TagBuilder aLast = new TagBuilder("a");

            // set the classes, texts and href's
            aNext.MergeAttribute("class", currentBulk == lastBulkIndex && currentPage == lastPageIndex - 1 ? "nav-disabled" : "nav pager-next");
            aNext.MergeAttribute("href", currentBulk == lastBulkIndex && currentPage == lastPageIndex - 1 ? "#Next" : string.Format(data.ActionURL, currentPage + 2));
            aNext.InnerHtml = "&#160;";
            aLast.MergeAttribute("class", currentBulk == lastBulkIndex && currentPage == lastPageIndex - 1 ? "nav-disabled" : "nav pager-last");
            aLast.MergeAttribute("href", currentBulk == lastBulkIndex && currentPage == lastPageIndex - 1 ? "#Last" : string.Format(data.ActionURL, lastPageIndex));
            aLast.InnerHtml = "&#160;";
            //divPager.InnerHtml += aNext.ToString + aLast.ToString
            spanNav.InnerHtml += aNext.ToString() + aLast.ToString();
              }
            }
            divPager.InnerHtml += spanNav.ToString();
            if (data.ShowGoTo)
            {
              TagBuilder inputGoToPage = new TagBuilder("input");
              inputGoToPage.MergeAttribute("id", "bottom-pager-goto");
              inputGoToPage.MergeAttribute("maxlength", "5");
              inputGoToPage.MergeAttribute("class", "pager-goto field-numeric");
              divPager.InnerHtml += inputGoToPage.ToString(TagRenderMode.SelfClosing);
            }

            // create the inner html elements
            TagBuilder spanPages = new TagBuilder("span");
            spanPages.MergeAttribute("class", "pages");
            divPager.InnerHtml += " ";
            spanPages.SetInnerText("Page");

            TagBuilder curentPageSpan = new TagBuilder("span");
            curentPageSpan.MergeAttribute("class", "curent-page");
            curentPageSpan.InnerHtml += " ";
            curentPageSpan.InnerHtml += data.CurrentPage.ToString();
            spanPages.InnerHtml += curentPageSpan.ToString();
            spanPages.InnerHtml += " ";
            spanPages.InnerHtml += HttpContext.GetGlobalResourceObject("SearchForm", "PageOf");
            spanPages.InnerHtml += " ";
            spanPages.InnerHtml += lastPageIndex.ToString();
            spanPages.InnerHtml += " ";
            spanPages.InnerHtml += HttpContext.GetGlobalResourceObject("SearchForm", "Pages");

            //spanPages.SetInnerText(lastPageIndex.ToString)
            divPager.InnerHtml += " ";

            divPager.InnerHtml += spanPages.ToString();
            if (data.ShowGoTo)
            {
              TagBuilder aGoToPage = new TagBuilder("a");
              aGoToPage.MergeAttribute("class", "goto");
              aGoToPage.MergeAttribute("href", "javascript:void(0)");
              aGoToPage.MergeAttribute("onclick", "goToPage('" + string.Format(data.ActionURL, "").Replace("&Page=", "").Replace("&page=", "").Replace("?Page=", "") + (data.ActionURL.IndexOf("?") > 0 && data.ActionURL.IndexOf("?Page=") < 0 ? "&Page=" : "?Page=") + "','" + "bottom-pager-goto" + "');");
              aGoToPage.InnerHtml = "&#160;";
              divPager.InnerHtml += aGoToPage.ToString();
            }

            return MvcHtmlString.Create(divPager.ToString());
              }
              else
              {
            return null;
              }
        }