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 List_MPorject : MyApp.Web.UI.UserPage
    {
        #region --初期代码
        public string _Tour_ID = "";
        public string _LocalName = "";
        public string _XPath = "";

        public DataTable list_dt;
        public int _ROW = 0;
        public int key = 0;
        #endregion 


        #region --分页处理
        public string lwhere = "";
        public string xpath = "";
        public string xml_url = "";

        public bool ispage = false;
        public int pageitem = 0;

        public string _display = "none";
        #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;
            }

           this.xds.XPath =  _XPath;
            #endregion 


           xml_url = MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID);
           xpath =  _XPath;

           lwhere = "lwhere";

           base.AppInit();
        }

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

            //XmlDocument xmlconfig = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Project_Name_config(_Tour_ID));


            XmlNodeList xmllist = xmldoc.SelectNodes(this.xds.XPath);

            //this.rp_list.DataSource = xmllist;
            //this.rp_list.DataBind();

            int max=0;
            for (int i = 0; i < xmllist.Count; i++)
            {
                XmlElement xle = (XmlElement)xmllist[i];
                try
                {
                    if (xle.GetAttribute("ID").Trim() != "")
                    {
                        max = Convert.ToInt32(xle.GetAttribute("ID").Trim());
                    }
                }
                catch
                {

                }
                if (max > key)
                {
                    key = max;
                }
            }


        }

        protected override void pl_register_script()
        {
            base.pl_register_script();
        }

        protected void Page_Init(object sender, EventArgs e)
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
         
            if (!Page.IsPostBack)
            {

                XmlDocument xmldoc;
                xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Project_Name_Config(_Tour_ID));
                XmlElement xle = (XmlElement) xmldoc.SelectSingleNode("/" + _XPath );
                try
                {
                    ispage = Convert.ToBoolean(xle.GetAttribute("ispage"));
                }
                catch
                {
                    ispage = false;
                }

                if (ispage)
                {
                    _display = "";
                }
                else
                {
                    _display = "none";
                }
                try
                {
                    pageitem = Convert.ToInt32( xle.GetAttribute("pageitems"));
                }
                catch
                {
                    pageitem = 18;
                }

                listinfo.PageRecord = pageitem;
                listinfo.PageTF = ispage;
                try
                {
                    string url = "";
                    if (xle.GetAttribute("viewtype").ToString().Trim() == "view")
                    {
                         url = "AD_MProject.aspx?action=edit&Tour_ID=" + @_Tour_ID + "&LocalName=" + @_LocalName + "&ROW=1&XPath=" + @_XPath + "&ViewType=view";
                    }
                    if (xle.GetAttribute("keyrecursion").ToString().Trim() == "true")
                    {
                        url = "Manager_MProject.aspx?Tour_ID=" + @_Tour_ID + "&LocalName=" + @_LocalName ;
                    }
                    if (url.Trim() != "")
                    {
                        Response.Redirect(url);
                    }
                }
                catch
                { }

            }
            MyApp.Components.NavUrl.SetUrl(2);

           
            try
            {
                Page.DataBind();
            }
            catch (Exception) { }
        }

        protected void rp_list_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            //((XmlElement)Container.DataItem).GetAttribute("Name")
        }
    }
}