using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BookDemo.QA
{
    public partial class Master : System.Web.UI.MasterPage
    {
        /// <summary>
        /// 关键字访问器
        /// </summary>
        public string Keyword
        {
            set
            {
                this.txtKeyword.Text = value;
                this.txtKeyword2.Text = value;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //查看Session中是否有用户名信息
            //TODO:这里也可以用Cookie做
            if (HttpContext.Current.Session["UserName"] != null)
            {
                lblUserName.Text = HttpContext.Current.Session["UserName"].ToString();//显示当前登陆用户名
            }
            else
            {
                lblUserName.Text = "无";//未登陆，不显示用户名
            }
            //获得Url编码后的当前Url地址，用于在Login页面登陆后返回本页面
            string returnUrl = Server.UrlEncode(Request.Url.PathAndQuery);
            //登陆入口的链接提供当前页面地址的参数
            hlLogin.NavigateUrl = "~/Login.aspx?ReturnUrl=" + returnUrl;
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string keyword = Server.UrlEncode(txtKeyword.Text.Trim());//将关键字进行URL编码
            Response.Redirect("~/SearchResult.aspx?kw=" + keyword, true);//调转到“搜索结果”页面
        }

protected void btnSearch2_Click(object sender, EventArgs e)
{
    string keyword = Server.UrlEncode(txtKeyword2.Text.Trim());//将关键字进行URL编码
    Response.Redirect("~/SearchResult2.aspx?kw=" + keyword, true);//调转到“搜索结果”页面
}

protected void btnClearCache_Click(object sender, EventArgs e)
{
    //实例化QuestionAndAnswersCache类
    QuestionAndAnswersCache qaCache = new QuestionAndAnswersCache();
    qaCache.Remove();//清空缓存
}
    }
}
