示例#1
0
    protected override void OnPreRender(EventArgs e)
    {
        if (Session["SearchData"] is ContentList)
        {
            ContentList searchContentList = Session["SearchData"] as ContentList;
            this.Controls.Clear();
            this.Controls.Add(searchContentList);
            Session["SearchData"] = null;
            return;
        }

        int             pageId       = 1;
        List <DateTime> linkDateList = new List <DateTime>();

        //Try Parse PageId
        if (!string.IsNullOrEmpty(Request.QueryString["pageId"]))
        {
            int.TryParse(Request.QueryString["pageId"], out pageId);
            if (pageId < 1)
            {
                pageId = 1;
            }
        }


        using (CLinq.DataContext db = CLinq.DataContext.Create())
        {
            var dateQuery =
                from l in db.Links
                group l by l.LinkDate.Date into lg
                orderby lg.Key descending
                select lg.Key;

            int maxPage = Math.Max(dateQuery.Count() / 3, 1) + 1;

            if (pageId == 1)
            {
                linkDateList = dateQuery.Take(3).ToList();
            }
            else if (pageId > maxPage)
            {
                Response.Redirect(cms.Current.GetRootPath);
            }
            else
            {
                linkDateList = dateQuery.Take(3 * pageId).Skip((3 * pageId) - 3).ToList();
            }
        }

        this.Controls.Clear();
        foreach (DateTime linkDate in linkDateList)
        {
            ContentList contentList = new ContentList();
            contentList.LoadData(linkDate);
            this.Controls.Add(contentList);
        }

        if (this.ShowPageLinks)
        {
            if (pageId > 1)
            {
                this.Controls.Add(GetNavigationLink(false, pageId));
            }
            this.Controls.Add(GetNavigationLink(true, pageId));
        }
    }