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

namespace JuSNS.Web.help
{
    public partial class index : JuSNS.UI.Page.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string key = Request.QueryString["key"];
            if (!string.IsNullOrEmpty(key))
            {
                LoadList(key);
            }
            else
            {
                string r = Request.QueryString["r"];
                string a = Request.QueryString["a"];
                if (!string.IsNullOrEmpty(a) || !string.IsNullOrEmpty(r))
                {
                    string Hid = string.Empty;
                    if (!string.IsNullOrEmpty(a))
                    {
                        Hid = a;
                    }
                    if (!string.IsNullOrEmpty(r))
                    {
                        Hid = r;
                    }
                    this.showR.Visible = true;
                    this.showC.Visible = false;
                    JuSNS.Home.Help Help = new JuSNS.Home.Help();
                    DataTable dt = Help.getHelpInfo(Hid);
                    this.ptitle.InnerText = "找不到相关帮助";
                    this.HelpTitle.InnerHtml = "找不到相关帮助";
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        this.ptitle.InnerText = "帮助中心：" + dt.Rows[0]["Title"].ToString();
                        this.HelpTitle.InnerHtml = dt.Rows[0]["Title"].ToString();
                        this.HelpContent.InnerHtml = dt.Rows[0]["Content"].ToString();
                    }
                    dt.Clear(); dt.Dispose();
                }
                else
                {
                    this.showR.Visible = false;
                    this.showC.Visible = true;
                    if (!IsPostBack)
                    {
                        LoadList(string.Empty);
                    }
                }
            }
        }

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

            if (!string.IsNullOrEmpty(key))
            {
                SqlConditionInfo st = new SqlConditionInfo("@SN", key, TypeCode.String);
                st.Blur = 3;
                dt = JuSNS.Home.UtilPage.GetPage("Search_HelpList_aspx", PageIndex, 20, out r, out p, st);
            }
            else
            {
                dt = JuSNS.Home.UtilPage.GetPage("HelpList_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");
            }
        }

    }
}
