using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace JuSNS.Web.inc.Ajax.gift
{
    public partial class list : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            JuSNS.Home.Gift gt = new JuSNS.Home.Gift();
            string curPage = Request.QueryString["page"];
            string classID = Request.QueryString["classID"];
            string n = Request.QueryString["n"];
            int page = 0;
            string listStr = "<ul>";
            if (curPage == "" || curPage == null || curPage == string.Empty) { page = 1; }
            else
            {
                try { page = int.Parse(curPage); }
                catch
                {
                    page = 1;
                }
            }
            int i, j;
            DataTable dt = gt.GiftListPage(UserID, classID, n, page, 27, out i, out j);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int k = 0; k < dt.Rows.Count; k++)
                {
                    listStr += "<li><img style=\"cursor:pointer;\" onclick=\"showGInfo('" + dt.Rows[k]["ID"].ToString() + "');\" src=\"" + rooDir + "/template/images/gift/" + dt.Rows[k]["picture"].ToString() + "\" title=\"名称：" + dt.Rows[k]["gName"].ToString() + "，需要积分：" + dt.Rows[k]["point"].ToString() + "，被使用次数：" + dt.Rows[k]["UseNumber"].ToString() + "\" /></li>";
                }
                dt.Clear();
                dt.Dispose();
            }
            else
            {
                listStr += "没有记录";
            }
            listStr += "</ul>";
            listStr += "<div  class=\"pagination\">" + ShowPage(page, i, j, classID, n) + "</div>";
            Response.Write(listStr);
            Response.End();
        }

        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="page">当前页码</param>
        /// <param name="Cnt">总记录数</param>
        /// <param name="pageCount">最大页数</param>
        /// <returns></returns>
        protected string ShowPage(int page, int Cnt, int pageCount,string classid,string n)
        {
            string urlstr = "共" + Cnt.ToString() + "条记录,共" + pageCount.ToString() + "页，当前第" + page.ToString() + "页 ";
            urlstr += "<a  href=\"javascript:void(0)\" onclick=\"ShowGiftList('1','"+classid+"','"+n+"');\" title=\"首页\" >首页</a> ";
            if ((page - 1) < 1)
            {
                urlstr += "<a href=\"javascript:void(0);\"><span class=\"c999\">上一页</span></a>";
            }
            else
            {
                urlstr += " <a href=\"javascript:void(0)\" onclick=\"ShowGiftList('" + (page - 1) + "','" + classid + "','" + n + "');\" title=\"上一页\" >上一页</a> ";
            }
            if (page == pageCount)
            {
                urlstr += "<a href=\"javascript:void(0);\"><span class=\"c999\">下一页</span></a>";
            }
            else
            {
                urlstr += " <a  href=\"javascript:void(0)\" onclick=\"ShowGiftList('" + (page + 1) + "','" + classid + "','" + n + "');\" title=\"下一页\" >下一页</a> ";
            }
            urlstr += " <a  href=\"javascript:void(0)\" onclick=\"ShowGiftList('" + pageCount + "','" + classid + "','" + n + "');\" title=\"尾页\">尾页</a> ";
            return urlstr;
        }
    }
}
