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
{
    public partial class showPoint : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            JuSNS.Home.User us = new JuSNS.Home.User();
            IDataReader dr = us.GetUserPoint(UserID);
            string listStr = string.Empty;
            string sTime = Request.QueryString["sTime"];
            string eTime = Request.QueryString["eTime"];
            if (!string.IsNullOrEmpty(Request.QueryString["type"]))
            {
                string curPage = Request.QueryString["page"];
                int page = 0;

                if (curPage == "" || curPage == null || curPage == string.Empty) { page = 1; }
                else
                {
                    try { page = int.Parse(curPage); }
                    catch
                    {
                        page = 1;
                    }
                }
                int i, j;
                DataTable dt = us.SearchPointHistoryPage(UserID, sTime, eTime, page, 20, out i, out j);
                if (dt != null && dt.Rows.Count > 0)
                {
                    listStr += "<ul>";
                    for (int k = 0; k < dt.Rows.Count; k++)
                    {
                        string utf = string.Empty;
                        if (dt.Rows[k]["UTF"].ToString() == "0")
                        {
                            utf = "<span class=\"green\">增加</span>";
                        }
                        else
                        {
                            utf = "<span class=\"reshow\">减少</span>";
                        }
                        string ContentStr = string.Empty;
                        if (dt.Rows[k]["content"] != null && dt.Rows[k]["content"].ToString() != string.Empty)
                        {
                            ContentStr = "【" + dt.Rows[k]["Content"].ToString() + "】";
                        }
                        listStr += "<li> &nbsp; &bull; " + utf + " " + ContentStr + "积分:" + dt.Rows[k]["Point"].ToString() + " | " + JuSNS.Config.UiConfig.gName + ":" + dt.Rows[k]["GPoint"].ToString() + " <span class=\"time\">(" + dt.Rows[k]["CreatTime"].ToString() + ")</span></li>";
                    }
                    dt.Clear();
                    dt.Dispose();
                }
                else
                {
                    listStr += "没有记录";
                }
                listStr += "</ul>";
                listStr += "<div class=\"pagination\">" + ShowPage(page, i, j, sTime, eTime) + "</div>";
            }
            else
            {
                listStr = "<div class=\"content\">";
                if (dr.Read())
                {
                    listStr += "<div class=\"cpstr\"> &nbsp; &bull; 积分：<span>" + dr["integral"].ToString() + "</span>  <br /> &nbsp; &bull; " + JuSNS.Config.UiConfig.gName + "：<span>" + dr["inteyb"].ToString() + "</span></div>";
                    listStr += "<div class=\"cpstr\"> &nbsp; <a href=\"javascript:void(0);\" onclick=\"javascript:showPointHistory('1','" + sTime + "','" + eTime + "');\">查看记录</a> &nbsp;&nbsp;  <a href=\"" + rooDir + "/help/?a=point\" style=\"cursor:help;\" target=\"_blank\"><span style=\"color:Red;\">如何获得积分和" + JuSNS.Config.UiConfig.gName + "</span></a></div>";
                }
                dr.Close();
                listStr += "</div>";
                listStr += "<div class=\"content\" id=\"div_pointhisty\" style=\"display:none\">loading...</div>";
            }
            string listStr1 = string.Empty;
            if (Request.QueryString["type"] != "s")
            {
                listStr1 += "<div class=\"boxtitle chengse\"><div class=\"nl bold\">我的" + JuSNS.Config.UiConfig.SiteName + "账户:</div>";
                listStr1 += "<div class=\"nr\"><a href=\"javascript:closediv($('point_idwindow'));\">关闭窗口</a></div></div>";
                Response.Write("<div class=\"f_box1\">" + listStr1 + "<div class=\"content padding10\">" + listStr + "</div></div>");
            }
            else
            {
                Response.Write(listStr1 + "<div class=\"content padding10\">" + listStr + "</div>");
            }
            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 sTime,string eTime)
        {
            string urlstr = " &nbsp; 共" + Cnt.ToString() + "条记录,共" + pageCount.ToString() + "页,当前第" + page.ToString() + "页  ";
            urlstr += "<a href=\"javascript:showPointHistory('1','" + sTime + "','" + eTime + "');\" title=\"首页\" >首页</a> ";
            if ((page - 1) < 1)
            {
                urlstr += " 上一页 ";
            }
            else
            {
                urlstr += " <a href=\"javascript:showPointHistory('" + (page - 1) + "','" + sTime + "','" + eTime + "');\" title=\"上一页\" >上一页</a> ";
            }
            //for (int i = page; i < (page + 10); i++)
            //{
            //    if (i > pageCount)
            //    {
            //        break;
            //    }
            //    else
            //    {
            //        urlstr += "&nbsp;&nbsp;<a href=\"javascript:showPointHistory('" + i + "','" + sTime + "','" + eTime + "');\" title=\"上一页\" >" + i + "</a>&nbsp;";
            //    }
            //}
            if (page == pageCount)
            {
                urlstr += " 下一页 ";
            }
            else
            {
                urlstr += " <a href=\"javascript:showPointHistory('" + (page + 1) + "','" + sTime + "','" + eTime + "');\" title=\"下一页\" >下一页</a> ";
            }
            urlstr += " <a href=\"javascript:showPointHistory('" + pageCount + "','" + sTime + "','" + eTime + "');\" title=\"尾页\">尾页</a> ";
            return urlstr;
        }
    }
}
