using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using MYAPP.inc;

namespace MYAPP.Manage.Project.Design.MProject
{
    public partial class Manager_MProject : MyApp.Web.UI.UserPage
    {
        #region --初始化部分
        public string _Tour_ID = "";
        public string _LocalName = "";
        public string _XPath = "";
        #endregion 


        override protected void AppInit()//程序基本信息初始化
        {

            #region --初期代码 实现功能
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();
                _LocalName = Request.QueryString["LocalName"].Trim();
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
            if ((Request.QueryString["XPath"] != null) && (Request.QueryString["XPath"].Trim() != ""))
            {
                _XPath = Request.QueryString["XPath"];
            }
            if (_XPath == "")
            {
                _XPath = _LocalName;
            }
            #endregion

            base.AppInit();
        }


        override protected void DataInit()//数据初始化
        {
            XmlDocument xmldoc;
            xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));

            XmlNodeList xmlnodelist = xmldoc.SelectNodes(_XPath);

            string url = "javascript:";
            foreach (XmlNode xnode in xmlnodelist)
            {
                XmlElement xle = (XmlElement)xnode;
                ComponentArt.Web.UI.TreeViewNode node = CreateNode(xle.GetAttribute("Name"), Convert.ToInt32(xle.GetAttribute("ID")), true, "", url);

                this.TV_Tree.Nodes.Add(node);

                TreeBindView(node, xle);
            }


        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void TreeBindView( ComponentArt.Web.UI.TreeViewNode pnode,XmlElement xlle)
        {
            XmlNodeList xmlnodelist = xlle.ChildNodes;
            string url = "javascript:";

            foreach (XmlNode xnode in xmlnodelist)
            {
                XmlElement xle = (XmlElement)xnode;
                ComponentArt.Web.UI.TreeViewNode node = CreateNode(xle.GetAttribute("Name"), Convert.ToInt32(xle.GetAttribute("ID")), true, "", url);

                pnode.Nodes.Add(node);

                TreeBindView(node,xle);
            }
        }


        private ComponentArt.Web.UI.TreeViewNode CreateNode(string name, int id, bool expanded, string imageurl, string navurl)
        {
            ComponentArt.Web.UI.TreeViewNode node = new ComponentArt.Web.UI.TreeViewNode();
            node.Text = name;
            node.NavigateUrl = navurl;
            //node.NavigateUrl = "javascript:alert(\""+node.Text+"\")";
            node.Target = "mainBEFrame";

            node.Value = id.ToString();
            node.ImageUrl = imageurl;
            node.Expanded = expanded;
            return node;
        }
    }
}