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 index : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "sys";
        JuSNS.Home.Space sp = new JuSNS.Home.Space();
        protected void Page_Load(object sender, EventArgs e)
        {
            string r = Request.QueryString["r"];
            if (r != string.Empty && r != null)
            {
                int id = Convert.ToInt32(Request.QueryString["id"]);
                string P = "1";
                if (Request.QueryString["page"] != string.Empty && Request.QueryString["page"] != null)
                {
                    P = Request.QueryString["page"];
                }
                if (r == "islock")
                {
                    sp.UpdateSpaceTemplateLockStatc(id, 1);
                    Response.Redirect("index.aspx?page=" + P + "");
                }
                if (r == "unlock")
                {
                    sp.UpdateSpaceTemplateLockStatc(id, 0);
                    Response.Redirect("index.aspx?page=" + P + "");
                }
                if (r == "del")
                {
                    sp.UpdateSpaceTemplateLockStatc(id, 2);
                    Response.Redirect("index.aspx?page=" + P + "");
                }
            }
            else
            {
                tlist();
            }
        }

        protected void tlist()
        {
            int r = 0, p = 0, PageIndex = 0, pagsize = 20;
            PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            DataTable dt = null;

            dt = sp.GetSpaceTemplateList1(PageIndex, pagsize, out r, out p, null);
            if (dt != null && dt.Rows.Count > 0)
            {
                RptData.DataSource = dt;
                RptData.DataBind();
            }

            //判断是否调用分页
            if (pagsize > 20)
            {
                DivPage.InnerHtml = JuSNS.UI.Control.PageNavigator.Pagination(PageIndex, p, "space.aspx");
            }
        }

        protected string GetLockStatic(object sid)
        {
            string listStr = string.Empty;
            IDataReader dr = sp.GetSpaceTemplate(Convert.ToInt32(sid.ToString()));
            if (dr.Read())
            {
                if (dr["isLock"].ToString() != "1")
                {
                    listStr += "<a href=\"index.aspx?r=islock&id=" + sid.ToString() + "\" title=\"点击锁定\">正常</a>";
                }
                else
                {
                    listStr += "<a href=\"index.aspx?r=unlock&id=" + sid.ToString() + "\" title=\"点击解锁\"><q style=\"color:red;\">锁定</q></a>";
                }
                listStr += "<span>" + dr["UserNumber"].ToString() + "人使用</span>";
            }
            dr.Close();
            return listStr;
        }
    }
}
