示例#1
0
    private void Bind(string nick, string session, DateTime start, DateTime end)
    {
        int    TotalCount = 0; //总记录数
        int    TotalPage  = 1; //总页数
        string ip         = Request.QueryString["visitip"];
        int    page       = 1;

        try
        {
            page = int.Parse(Request.QueryString["Page"]);
            if (ViewState["page"] != null)
            {
                page = int.Parse(ViewState["page"].ToString());
                ViewState["page"] = null;
            }
        }
        catch { }

        IList <TopVisitInfo> list       = visitDal.GetVisitInfoByIp(DataHelper.Encrypt(HttpUtility.UrlDecode(Request.Cookies["nick"].Value)), ip, start, end);
        List <GoodsInfo>     cachegoods = new List <GoodsInfo>();

        if (Cache["taobaogoodslist"] != null)
        {
            cachegoods = (List <GoodsInfo>)Cache["taobaogoodslist"];
        }
        for (int i = 0; i < list.Count; i++)
        {
            if (!string.IsNullOrEmpty(list[i].GoodsId))
            {
                List <GoodsInfo> mylist = cachegoods.Where(o => o.num_iid == list[i].GoodsId).ToList();
                if (mylist.Count == 0)
                {
                    GoodsInfo rinfo = TaoBaoAPI.GetGoodsInfo(nick, session, list[i].GoodsId);
                    list[i].GoodsName = rinfo.title;
                    cachegoods.Add(rinfo);
                    if (Cache["taobaogoodslist"] == null)
                    {
                        Cache.Insert("taobaogoodslist", cachegoods, null, DateTime.Now.AddHours(12), System.Web.Caching.Cache.NoSlidingExpiration);
                    }
                }
                else
                {
                    list[i].GoodsName = mylist[0].title;
                }
            }

            if (!string.IsNullOrEmpty(list[i].GoodsClassId))
            {
                IList <GoodsClassInfo> cList = GoodsClassList.Where(o => o.cid == list[i].GoodsClassId).ToList();
                if (cList.Count > 0)
                {
                    list[i].GoodsClassName = cList[0].name;
                }
            }
        }

        TotalCount      = list.Count;
        pds.DataSource  = list;
        pds.AllowPaging = true;
        pds.PageSize    = 20;

        if (TotalCount == 0)
        {
            TotalPage = 1;
        }
        else
        {
            if (TotalCount % pds.PageSize == 0)
            {
                TotalPage = TotalCount / pds.PageSize;
            }
            else
            {
                TotalPage = TotalCount / pds.PageSize + 1;
            }
        }

        string startstr = HttpUtility.UrlEncode(start.ToString("yyyy-MM-dd-HH"));
        string endstr   = HttpUtility.UrlEncode(end.ToString("yyyy-MM-dd-HH"));

        pds.CurrentPageIndex = page - 1;
        lblCurrentPage.Text  = "共" + TotalCount.ToString() + "条记录 当前页:" + page + "/" + TotalPage;

        lnkFrist.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1&visitip=" + ip + "&start=" + startstr + "&end=" + endstr;
        if (!pds.IsFirstPage)
        {
            lnkPrev.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (page - 1) + "&visitip=" + ip + "&start=" + startstr + "&end=" + endstr;
        }

        if (!pds.IsLastPage)
        {
            lnkNext.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + (page + 1) + "&visitip=" + ip + "&start=" + startstr + "&end=" + endstr;
        }
        lnkEnd.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + TotalPage + "&visitip=" + ip + "&start=" + startstr + "&end=" + endstr;

        Rpt_PageVisit.DataSource = pds;
        Rpt_PageVisit.DataBind();
        TB_Start.Text = start.ToString("yyyy-MM-dd HH");
        TB_End.Text   = end.ToString("yyyy-MM-dd HH");
    }