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;

public partial class etw_c_m_menuedit : System.Web.UI.Page
{
    public string menuid = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie GetCookie = Request.Cookies["cook_admin"];
        if (Request.Cookies["cook_admin"] == null)
        {
            Response.Redirect("index.aspx");
        }
        if (Request.QueryString["menuid"] != null)
        {
            menuid = Request.QueryString["menuid"].ToString();
            if (!IsPostBack)
            {
                etw.etw_menu lead = new etw.etw_menu();
                lead.id = Convert.ToInt32(menuid);
                lead.GetModel();
                menuname.Text = Fun.Fancode(lead.menuname);
                url.Text = Fun.Fancode(lead.Url);
                orderby.Text=lead.orderby.ToString();
                sqltext.Text = lead.sqltext;
                BindDrpClass(lead.parentid.ToString());

            }
        }
    }
    private void BindDrpClass(string parentid)//父级分类
    {
        etw.etw_menu aaa = new etw.etw_menu();
        DataTable dt = aaa.GetClassList("").Tables[0];
        ddlClass.Items.Clear();
        DataSet ds = DbHelperSQL.Query("select id,menuname from etw_menu where id=" + parentid + "");
        if (ds.Tables[0].Rows.Count > 0)
        {
            ddlClass.Items.Add(new ListItem(ds.Tables[0].Rows[0]["menuname"].ToString(), ds.Tables[0].Rows[0]["id"].ToString()));
            ddlClass.Items.Add(new ListItem("一级功能菜单", "0"));
        }
        else
        {
            ddlClass.Items.Add(new ListItem("一级功能菜单", "0"));
            ddlClass.Items.Add(new ListItem("一级功能菜单", "0"));
        }

        DataRow[] drs = dt.Select("parentid= " + 0);
        foreach (DataRow dr in drs)
        {
            string classid = dr["id"].ToString();
            string classname = dr["menuname"].ToString();
            classname = "┠－" + classname;
            ddlClass.Items.Add(new ListItem(classname, classid));
            int sonparentid = int.Parse(classid);
            string blank = "　┠－";

            BindNode(sonparentid, dt, blank);
        }
        ddlClass.DataBind();
    }
    private void BindNode(int parentid, DataTable dt, string blank)
    {
        DataRow[] drs = dt.Select("parentid= " + parentid);
        foreach (DataRow dr in drs)
        {
            string classid = dr["id"].ToString();
            string classname = dr["menuname"].ToString();

            classname = blank + classname;
            ddlClass.Items.Add(new ListItem(classname, classid));

            int sonparentid = int.Parse(classid);
            string blank2 = "　" + blank;

            BindNode(sonparentid, dt, blank2);
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        etw.etw_menu lead = new etw.etw_menu();
        lead.id = Convert.ToInt32(menuid);
        lead.menuname = Fun.Encode(menuname.Text.Trim());
        lead.Url = Fun.Encode(url.Text.Trim());
        lead.parentid = Convert.ToInt32(ddlClass.SelectedValue);
        lead.orderby = Convert.ToSingle(orderby.Text.ToString());
        lead.sqltext = Fun.Encode(sqltext.Text.Trim());
        lead.Update();
        Fun.JsAlerT("修改成功", "menulist.aspx"); 
    }
}
