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 System.Collections.Generic;
using JuSNS.Model;
using JuSNS.Home;
using JuSNS.UI.Control;

namespace JuSNS.Web.app
{
    public partial class applist : JuSNS.UI.Page.UserPage
    {
        /// <summary>
        /// 类别
        /// </summary>
        protected int type = 0;
        protected string hot = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            int.TryParse(Request.QueryString["t"], out type);
            if (type == 0)
                this.allapp.Attributes.Add("class", "current");

            hot = Request.QueryString["hot"];
            if (!string.IsNullOrEmpty(hot))
            {
                this.hotapp.Attributes.Add("class", "current");
                this.allapp.Attributes.Remove("class");
            }

            bindAppType();
            bindAppList();
        }

        /// <summary>
        /// 绑定应用类别
        /// </summary>
        protected void bindAppType()
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("type", typeof(int));
            dt.Columns.Add("typestr", typeof(string));
            dt.Columns.Add("typeclass", typeof(string));
            foreach (KeyValuePair<int, string> kv in JuSNS.Config.UserApiConfig.AppType)
            {
                DataRow dr = dt.NewRow();
                dr["typeclass"] = "";
                if (type == kv.Key)
                {
                    dr["typeclass"] = "current";
                }
                dr["type"] = kv.Key;
                dr["typestr"] = kv.Value;
                dt.Rows.Add(dr);
            }
            this.apptypelist.DataSource = dt;
            this.apptypelist.DataBind();
        }
        /// <summary>
        /// 绑定应用列表
        /// </summary>
        protected void bindAppList()
        {
            string pagecode = "AppList_aspx";
            SqlConditionInfo sci = null;
            if (hot != null && hot.ToLower() == "hot")
            {
                pagecode = "Apphot_aspx";
            }

            if (type != 0)
            {
                pagecode = "apptype_aspx";
                sci = new SqlConditionInfo("type", type, TypeCode.Int32);
            }
            int ReCount, PgCount;
            int PageIndex = 1;
            if (Request.QueryString["Page"] != null)
            {
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            }
            DataTable dt = UtilPage.GetPage(pagecode, PageIndex, PAGESZ, out ReCount, out PgCount, sci);
            this.myapplist.DataSource = dt;
            this.myapplist.DataBind();
            string PageUrl = "applist.aspx";
            if (PgCount > 1)
            {
                this.DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, PgCount, PageUrl);
            }
        }
    }
}
