using System;
using TopWinCMS.BLL;
using TopWinCMS.Common;

namespace TopWinCMS.WebUI.Admin
{
    public partial class Member_Manage : System.Web.UI.Page
    {
        MemberManage MyClassBLL = new MemberManage();
        public SQLModel s_model = new SQLModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                Check();
                try
                {
                    s_model.PageNo = Convert.ToInt32(Request["PageNo"]);
                }
                catch
                {
                    s_model.PageNo = 1;
                }

                common();
                string Action = Request["Action"];

                GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);

                if (Action == "Search")
                {
                    Search();
                }
                else if (Action == "GuoQi")
                {
                    GuoQi();
                }
                else if (Action == null)
                {
                    BindList();
                }


            }
        }

        private void Check()
        {
            DDL_BatchToDo.Items[1].Enabled = RightsCheck.HasRight("MM_3");
            DDL_BatchToDo.Items[2].Enabled = RightsCheck.HasRight("MM_4");
            DDL_BatchToDo.Items[3].Enabled = RightsCheck.HasRight("MM_4");


            if (RightsCheck.HasRight("MM_3") == RightsCheck.HasRight("MM_4") == false)
            {
                RightsCheck.CheckWorkPower("MM_3");
            }
        }

        protected void BindList()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);

            L_Path.Text = Config.SiteName + " → <a href=\"Member.aspx\">会员中心</a>";


            MyClassBLL.BindList(GV_List, PageNavigation1, s_model);

        }

        private void Search()
        {
            GV_List.EmptyDataTemplate = TopWinCMS.WebFactory.PageBase.GetTemplate(this);
            try
            {
                DDL_Sort.SelectedValue = Request["Sort"];
                TB_KeyWord.Text = Request["Keyword"];
            }
            catch { TB_KeyWord.Text = ""; }

            L_Path.Text = Config.SiteName + " → <a href=\"Member.aspx\">会员中心</a> → 会员搜索";
            s_model.WHERE = " " + Request["Sort"] + " like '%" + MyString.SQL_ESC(Request["Keyword"]) + "%'";

            MyClassBLL.BindList(GV_List, PageNavigation1, s_model);


        }
        private void GuoQi()
        {
            L_Path.Text = Config.SiteName + " → <a href=\"Member.aspx\">会员中心</a> → 会员搜索 → " + NTB_Days.Text + "天没有登录用户";
            NTB_Days.Text = Request["Days"];

            s_model.WHERE = " DateOff >= " + NTB_Days.Text;

            MyClassBLL.BindList(GV_List, PageNavigation1, s_model);


        }
        /// <summary>
        /// 分页共用
        /// </summary>
        private void common()
        {
            s_model.Fields = "*";
            s_model.TableName = "VW_TopWinCMS_Member";
            s_model.OrderField = "ID desc";

            s_model.PageSize = PageNavigation1.PageSize;
        }
        protected string IDState(object IDState)
        {
            switch (IDState.ToString())
            {
                case "0":
                    return "激活";

                case "1":
                    return "封号";

                case "2":
                    return "待验证";

                default:
                    return "参数错误";
            }
        }
        protected void BT_Search_Click(object sender, EventArgs e)
        {
            Response.Redirect("Member.aspx?Action=Search&Sort=" + DDL_Sort.SelectedValue + "&Keyword=" + TB_KeyWord.Text.Trim());
        }
        protected void BT_GuoQi_Click(object sender, EventArgs e)
        {
            Response.Redirect("Member.aspx?Action=GuoQi&Days=" + NTB_Days.Text);
        }

        protected void BT_OK_Click(object sender, EventArgs e)
        {
            MyClassBLL.BatchToDo(GetSelectedRow.IDs(GV_List), DDL_BatchToDo.SelectedValue);
        }


        protected void PageNavigation1_PageChanging(object src, TopWinCMS.WebControls.PageChangingEventArgs e)
        {

        }
    }
}