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.sys
{
    public partial class Vo : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "sys";
        JuSNS.Home.Space sp = new JuSNS.Home.Space();
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string type = Request.QueryString["Type"];
                int n = 0;

                if (type == "Lock")
                {
                    n = sp.LockDelVocation(int.Parse(Request.QueryString["id"]), int.Parse(Request.QueryString["value"]), 1);
                    if (n == 1)
                    {
                        Response.Redirect("vo.aspx");
                    }
                    else
                    {
                        PageError("操作行业失败!", "vo.aspx");
                    }
                }
                else if (type == "del")
                {
                    n = sp.LockDelVocation(int.Parse(Request.QueryString["id"]), 0, 0);
                    if (n == 1)
                    {
                        Response.Redirect("vo.aspx");
                    }
                    else if (n == 2)
                    {
                        PageError("该行业已经在前台被会员被使用，不能删除!", "vo.aspx");
                    }
                    else
                    {
                        PageError("删除行业失败!", "vo.aspx");
                    }
                }
                else
                {
                    if (!IsPostBack)
                    {
                        LoadList();
                    }
                }
            }
            catch { }
        }

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

            if (Key.Text != "")
            {
                SqlConditionInfo st = new SqlConditionInfo("@Name", Key.Text, TypeCode.String);
                st.Blur = 3;
                dt = JuSNS.Home.UtilPage.GetPage("Search_VocationList_aspx", PageIndex, 20, out r, out p, st);
            }
            else
            {
                dt = JuSNS.Home.UtilPage.GetPage("VocationList_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, "vo.aspx");
            }
        }

        /// <summary>
        /// 执行搜索过程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
                LoadList();
        }
    }
}
