using System;
using System.IO;
using System.Diagnostics;
using System.Xml;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace MYAPP.Manage.Project.Design.GigaMap
{
    [AjaxPro.AjaxNamespace("AjaxDemo")]
    public partial class List_GigaMap : MyApp.Web.UI.UserPage
    {
        public int PageRecord = 10000, NowPage, RecordCount, hRecordCount, MaxPage;
        public DataTable list_dt;
        public string _Tour_ID = "", _TypeID = "";
        protected override void AppInit()
        {
            try
            {
                _TypeID = Request.QueryString["TypeID"].Trim();
            }
            catch (Exception) { _TypeID = "-1"; }
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();

            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
            base.AppInit();
        }

        protected override void pl_register_script()
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(List_GigaMap));
            base.pl_register_script();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            MyApp.Components.NavUrl.SetUrl(2);
            try
            {
                Page.DataBind();
            }
            catch (Exception) { }

        }

        protected override void DataInit()
        {

            if (_TypeID == "-1")
            {
                list_dt = MyApp.Components.KRPano.Project.GetDirectorys(String.Format("{0}/GigaMap", _Tour_ID), "", PageRecord, ref NowPage, ref RecordCount, ref hRecordCount, ref MaxPage);
            }
            else
            {
                list_dt = MyApp.Components.KRPano.Project.GetDirectorys(String.Format("{0}/GigaMap", _Tour_ID), String.Format("Type='{0}'", _TypeID), PageRecord, ref NowPage, ref RecordCount, ref hRecordCount, ref MaxPage);
            }

            base.DataInit();
        }
      
        public string GetElemValueByPath(object _Map_ID, string attribute)
        {
            return MyApp.Components.KRPano.GigaMap.GetValue(MyApp.Components.KRPano.GigaMap.GetSceneXmlDoc(_Tour_ID, _Map_ID), "/krpano", attribute);
        }

        public string GetElemValueByPath(object _Map_ID, string path, string attribute)
        {
            return MyApp.Components.KRPano.GigaMap.GetValue(MyApp.Components.KRPano.GigaMap.GetSceneXmlDoc(_Tour_ID, _Map_ID), path, attribute);
        }

        [AjaxPro.AjaxMethod]
        public string ChangeValue(object _Tour_ID, string _Map_ID, string _Path, string _Field, object _Value)
        {
            if ((_Path == "krpano") && (_Field == "Name"))//针对场景名称处理
            {
                _ChangeValue(_Tour_ID, _Map_ID, "/krpano/SSet", "Scene_Name", _Value);
                return _ChangeValue(_Tour_ID, _Map_ID, _Path, _Field, _Value);
            }
            else
            {
                return _ChangeValue(_Tour_ID, _Map_ID, _Path, _Field, _Value);
            }
        }
        public string _ChangeValue(object _Tour_ID, string _Map_ID, string _Path, string _Field, object _Value)
        {
            try
            {
                XmlDocument xmldoc = new XmlDocument();
                xmldoc = MyApp.Components.KRPano.GigaMap.GetSceneXmlDoc(_Tour_ID, _Map_ID);

                #region KRPano
                XmlElement elem = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, _Path);
                SetElemValue(elem, _Field, _Value.ToString());
                #endregion

                MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.GigaMap.GetSceneServerFilePath(_Tour_ID, _Map_ID), xmldoc.OuterXml);
            }
            catch (Exception ex) { return ex.ToString(); }
            return "true";
        }

    }
}