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.group
{
    public partial class index : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "group";
        protected void Page_Load(object sender, EventArgs e)
        {
            Operate();
            LoadList();
        }

        /// <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.Trim() != "")
            {
                SqlConditionInfo st = new SqlConditionInfo("@Key", Key.Text, TypeCode.String);
                st.Blur = 3;
                dt = JuSNS.Home.UtilPage.GetPage("managegrouplist_Key_aspx", PageIndex, PAGESZ, out r, out p, st);
            }
            else
            {
                dt = JuSNS.Home.UtilPage.GetPage("managegrouplist_aspx", PageIndex, PAGESZ, out r, out p, null);
            }

            if (dt != null)
            {
                Rpt_GroupList.DataSource = dt;
                Rpt_GroupList.DataBind();
            }
            //判断是否调用分页
            if (r > PAGESZ)
            {
                DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, p, "index.aspx");
            }
        }

        /// <summary>
        /// 操作
        /// </summary>
        protected void Operate()
        {
            JuSNS.Home.UserGroup group = new JuSNS.Home.UserGroup();
            string s_Act = Request.QueryString["action"];
            string s_ID = Request.QueryString["id"];
            if (s_Act == "del")
            {
                if (string.IsNullOrEmpty(s_ID))
                {
                    PageError("参数传递错误!", "index.aspx");
                }
                if (group.Del(Convert.ToInt32(s_ID)) == 1)
                    PageRight("删除群组成功!", "index.aspx");
                else
                    PageError("删除群组失败!", "index.aspx");
            }
            else if (s_Act == "isRec")
            {
                group.isRec(Convert.ToInt32(s_ID), Convert.ToInt32(Request.QueryString["st"]));
            }
        }

        protected string GetRec(object isrec,object groupid)
        {
            if (isrec.ToString() == "1")
            {
                return "<a href=\"javascript:void(0);\" onclick=\"IsRec('" + groupid.ToString() + "',0)\"><span style=\"color:Red\">取消推荐</span></a>";
            }
            else
            {
                return "<a href=\"javascript:void(0);\" onclick=\"IsRec('" + groupid.ToString() + "',1)\">推荐</a>";
            }
        }

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