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

namespace JuSNS.Web.system.gift
{
    public partial class index : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "sys";
        JuSNS.Home.Gift gt = new JuSNS.Home.Gift();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string type = Request.QueryString["Type"];
                int n = 0;
                if (type == "Lock")
                {
                    n = gt.LockGift(int.Parse(Request.QueryString["id"]), int.Parse(Request.QueryString["value"]),0);
                    if (n == 1)
                    {
                        Response.Redirect("index.aspx");
                    }
                    else
                    {
                        PageError("操作失败!", "index.aspx");
                    }
                }
                else if (type == "del")
                {
                    n = gt.LockGift(int.Parse(Request.QueryString["id"]), 0, 1);
                    if (n == 1)
                    {
                        Response.Redirect("index.aspx");
                    }
                       else
                    {
                        PageError("删除失败!", "index.aspx");
                    }
                }
                else
                {
                    if (!IsPostBack)
                    {
                        LoadList();
                        this.giftClass.InnerHtml = GetGiftClass();
                    }
                }
            }
            catch { }
        }

        protected string GetGiftClass()
        {
            string listSTR = string.Empty;
            JuSNS.Home.Gift gt = new JuSNS.Home.Gift();
            IDataReader dr = gt.GetGiftClass();
            string unCount = "0";
            while (dr.Read())
            {
                listSTR += "<a href=\"index.aspx?c=" + dr["ID"].ToString() + "\">" + dr["CName"].ToString() + "(" + dr["Count"] + ")</a> &nbsp; ";
                unCount = dr["Count1"].ToString();
            }
            dr.Close();
            return listSTR + " <a href=\"index.aspx?c=0\">未分类(" + unCount + ")</a> &nbsp; <a href=\"index.aspx?\">所有礼物</a>";
        }


        /// <summary>
        /// 加载分页
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        protected void LoadList()
        {
            int r, p, PageIndex = 0;
            PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            DataTable dt = null;

            if (!string.IsNullOrEmpty(Request.QueryString["c"]))
            {
                SqlConditionInfo st = new SqlConditionInfo("@C", Convert.ToInt32(Request.QueryString["c"]), TypeCode.Int32);
                dt = JuSNS.Home.UtilPage.GetPage("Gift_mc_aspx", PageIndex, 20, out r, out p, st);
            }
            else
            {
                dt = JuSNS.Home.UtilPage.GetPage("Gift_m_aspx", PageIndex, 20, out r, out p, null);
            }
            if (dt != null)
            {
                Rpt_UserList.DataSource = dt;
                Rpt_UserList.DataBind();
            }
            //判断是否调用分页
            if (r > 20)
            {
                DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, p, "index.aspx?c="+Request.QueryString["c"]+"");
            }
        }
    }
}
