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;
using JuSNS.Config;
using JuSNS.Common;
using JuSNS.Model;
using JuSNS.Home;
using JuSNS.UI.Control;

namespace JuSNS.Web.user.friend
{
    public partial class inviterec : JuSNS.UI.Page.UserPage
    {
        private int confirm;
        private int pending;
        private string a;
        /// <summary>
        /// 是否显示再次邀请
        /// </summary>
        protected bool showr = false;
        protected void Page_Load(object sender, EventArgs e)
        {
            a = Request.QueryString["a"];
            if (a == null)
            {
                PageError("参数错误", ""+rooDir+"/home/default.aspx");
            }
            a = a.ToLower();
            if (a != "pending" && a != "confirmed")
            {
                PageError("参数错误", "" + rooDir + "/home/default.aspx");
            }
            JuSNS.Home.Friend frd = new Friend();
            frd.InviteStat(UserID, out confirm, out pending);
            this.LtrPendingCount.Text = pending.ToString();
            this.LtrConfirmCount.Text = confirm.ToString();
            this.LtrCaption.Text = "还有 " + pending + " 个邀请没被接受";
            BindData();
            DataBind();
        }
        /// <summary>
        /// 分页绑定数据
        /// </summary>
        protected void BindData()
        {
            int ReCount, PgCount;
            int PageIndex = 1;
            if (Request.QueryString["Page"] != null)
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            DataTable dt = new DataTable();
            string PageUrl = "inviterec.aspx?a=" + a;
            SqlConditionInfo[] sc = new SqlConditionInfo[2];
            sc[0] = new SqlConditionInfo("@UserID", UserID, TypeCode.Int32);
            if (a == "confirmed")
            {
                this.HlkLink.Text = "待确认邀请记录";
                this.HlkLink.NavigateUrl = "invite-rec.aspx?a=pending";
                this.LtrCaption.Text = "已成功邀请 " + confirm + " 人";
                sc[1] = new SqlConditionInfo("@Reply", 1, TypeCode.Int32);
            }
            else
            {
                this.HlkLink.Text = "成功邀请记录";
                this.HlkLink.NavigateUrl = "invite-rec.aspx?a=confirmed";
                showr = true;
                sc[1] = new SqlConditionInfo("@Reply", 0, TypeCode.Int32);
            }
            dt = UtilPage.GetPage("friend_invite", PageIndex, PAGESZ, out ReCount, out PgCount, sc);
            this.RptData.DataSource = dt;
            this.RptData.DataBind();
            if (ReCount > PAGESZ)
            {
                this.DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, PgCount, PageUrl);
            }
            else
            {
                this.DivPage.Visible = false;
            }
        }
    }
}
