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;

namespace JuSNS.Web.system.ask
{
    public partial class index : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "ask";
        JuSNS.Home.Ask ask = new JuSNS.Home.Ask();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string Type = Request.QueryString["Type"];
                if (Type == "del")
                {
                    if (ask.DeleteAskClass(Convert.ToInt32(Request.QueryString["id"])) > 0)
                    {
                        Response.Redirect("index.aspx");
                    }
                }
                else
                {
                    DataTable dt = ask.GetAskClass(0, 0);
                    string lStr = string.Empty;
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            lStr += "<li><a href=\"index.aspx?c=" + dt.Rows[i]["ID"].ToString() + "\">" + dt.Rows[i]["className"].ToString() + "</a> <a href=\"javascript:del('" + dt.Rows[i]["ID"].ToString() + "')\">[删除]</a></li>";
                            DataTable dt1 = ask.GetAskClass(Convert.ToInt32(dt.Rows[i]["ID"].ToString()), 1);
                            if (dt1 != null && dt1.Rows.Count > 0)
                            {
                                for (int j = 0; j< dt1.Rows.Count; j++)
                                {
                                    lStr += "<li>&nbsp;---- <a href=\"index.aspx?c=" + dt1.Rows[j]["ID"].ToString() + "\">" + dt1.Rows[j]["className"].ToString() + "</a> <a href=\"javascript:del('" + dt1.Rows[j]["ID"].ToString() + "')\">[删除]</a></li>";
                                }
                            }
                            dt1.Clear(); dt1.Dispose();
                            ListItem li = new ListItem();
                            li.Text = dt.Rows[i]["className"].ToString();
                            li.Value = dt.Rows[i]["ID"].ToString();
                            this.ParentID.Items.Add(li);
                        }
                    }
                    dt.Dispose();
                    this.ClassList.InnerHtml = lStr;
                    string c = Request.QueryString["c"];
                    //if (!string.IsNullOrEmpty(c))
                    //{
                    //    this.TxtclassID.Value = c;
                    //    DataTable dt1 = ns.GetNewsClassID(Convert.ToInt32(c));
                    //    if (dt1 != null && dt1.Rows.Count > 0)
                    //    {
                    //        this.ClassName.Text = dt1.Rows[0]["className"].ToString();
                    //    }
                    //    dt1.Dispose();
                    //}
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                int ParentID = Convert.ToInt32(this.ParentID.SelectedValue);
                string className = this.ClassName.Text;
                if (ask.askClassAdd(ParentID, className) > 0)
                {
                    Response.Redirect("index.aspx");
                }
                else
                {
                    PageError("增加失败。", "");
                }
            }
        }
    }
}
