using System;
using System.IO;
using System.Collections.Generic;
using System.Xml;
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 MYAPP.Manage.Project.Design.Tour
{
    public partial class AD_Tour : MyApp.Web.UI.UserPage
    {
        public string _Tour_ID = "";
        string _Skin_Dir = "";

        override protected void AppInit()//程序基本信息初始化
        {
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();
            }
            catch (Exception)
            {
                ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
            _Skin_Dir = String.Format("/project/{0}/Skin", _Tour_ID);
            base.AppInit();
        }

        override protected void DataInit()//数据初始化
        {
            #region //填充场景列表
            DataRow[] list_dr = MyApp.Components.KRPano.Project.GetDirectorys(String.Format("{0}/Scene", _Tour_ID), "");
            List<ListItem> li = new List<ListItem>();
            this.ddl_Scene_ID.Items.Add(new ListItem("", ""));
            foreach (DataRow dr in list_dr)
            {
                li.Add(new ListItem(dr["Name"].ToString() + ":" + GetElemValueByPath(_Tour_ID, dr["Name"], "Name"), dr["Name"].ToString()));
            }
            this.ddl_Scene_ID.Items.AddRange(li.ToArray());
            #endregion

            #region //填充矩阵地图列表
            DataRow[] listmap_dr = MyApp.Components.KRPano.Project.GetDirectorys(String.Format("{0}/GigaMap", _Tour_ID), "");
            List<ListItem> map_li = new List<ListItem>();

            this.ddl_Map_ID.Items.Add(new ListItem("", ""));
            foreach (DataRow dr in listmap_dr)
            {
                map_li.Add(new ListItem(dr["Name"].ToString() + ":" + MyApp.Components.KRPano.GigaMap.GetValue(MyApp.Components.KRPano.GigaMap.GetSceneXmlDoc(_Tour_ID, dr["Name"]), "/krpano", "Name"), dr["Name"].ToString()));
            }
            this.ddl_Map_ID.Items.AddRange(map_li.ToArray());
            #endregion

            #region //填充皮肤列表
            MyApp.Components.Accessories acc = new MyApp.Components.Accessories();
            DataTable dt = acc.GetFiles(Server.MapPath(_Skin_Dir), "*.skin");
            foreach (DataRow dr in dt.Rows)
            {
                this.ddl_Skin.Items.Add(new ListItem(dr["File_Path"].ToString(), dr["File_Path"].ToString()));
            }
            #endregion

            #region
            DataSet myds = new DataSet();
            DataTable dt_type = MyApp.Components.Area.Get_TypeTreeTable();
            myds.Tables.Add(dt_type);
            DataRow drx = dt_type.NewRow(); drx["id"] = "0"; dt_type.Rows.Add(drx);
            myds.Relations.Add("NodeRelation", dt_type.Columns["id"], dt_type.Columns["upid"]);
            PopulateSubTree(drx, 1, 0, "", true);
            #endregion
            base.DataInit();

        }

        private void PopulateSubTree(DataRow dbRow, int level, int _UpID, string ne, bool _enable_tf)
        {
            int len = dbRow.GetChildRows("NodeRelation").Length;
            int i = 0;
            string dr_head = "";
            foreach (DataRow dr in dbRow.GetChildRows("NodeRelation"))
            {
                if (level > -1)
                {
                    if (i == (len - 1))
                    {
                        dr_head = ne + "└";
                    }
                    else
                    {
                        dr_head = ne + "├";
                    }
                }

                if (_enable_tf)
                {
                    this.Area_ID.Items.Add(new ListItem(dr_head + dr["name"].ToString(), dr["id"].ToString()));
                }
                else
                {
                    this.Area_ID.Items.Add(new ListItem(dr_head + dr["name"].ToString(), "-" + dr["id"].ToString()));
                }
                if (i == len - 1)
                {
                    PopulateSubTree(dr, level + 1, Convert.ToInt32(dr["id"]), ne + "　", _enable_tf);
                }
                else
                {
                    PopulateSubTree(dr, level + 1, Convert.ToInt32(dr["id"]), ne + "│", _enable_tf);
                }
                i++;
            }
        }

        public string GetElemValueByPath(object _Tour_ID, object scene_id, string attribute)
        {
            string _File_Dir = Server.MapPath(String.Format("/Project/{0}/Scene/{1}/scene.xml", _Tour_ID, scene_id.ToString()));
            StreamReader sr = System.IO.File.OpenText(_File_Dir);
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.LoadXml(sr.ReadToEnd());
            sr.Close();
            XmlNode xmlnode = xmldoc.ChildNodes[0];
            XmlElement xmlelem = (XmlElement)xmlnode;
            if (xmlelem.GetAttribute(attribute).Trim() != "")
            {
                return xmlelem.GetAttribute(attribute).Trim();
            }
            else
            {
                return "　";
            }
        }

        protected override void pl_register_script()
        {
            this.ddl_Scene_ID.Attributes.Add("onchange", "javascrpt:{$('DefScene_ID').value=this.value}");
            this.ddl_Map_ID.Attributes.Add("onchange", "javascrpt:{$('DefMap_ID').value=this.value}");
            this.ddl_Skin.Attributes.Add("onchange", "javascrpt:{$('Skin').value=this.value}");
            base.pl_register_script();
        }

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

        protected void Page_Load(object sender, EventArgs e)
        {

        }
        override protected void pl_del()
        {
            pl_edit();

            try
            {
                if (this.LockTF.Checked)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert(\"当前项目被锁定不能删除! 请先在项目设置里面去掉锁定选项!!!\");history.back()</script>");
                }
                else
                {
                    Directory.Delete(Server.MapPath(String.Format("/Project/{0}", _Tour_ID)), true);
                    Response.Redirect(MyApp.Components.NavUrl.GetUrl(1));
                }
            }
            catch (Exception)
            {
                ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
        }
        override protected void pl_edit()
        {
            XmlDocument xmldoc;
            XmlElement elem_krpano, elem_Project, elem_Google, elem_events, ele_display, ele_control, ele_autorotate, ele_progress;
            xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));

            try
            {
                //this.ID.Attributes("Text","Value");
                this.ID.Text = _Tour_ID;
                #region KRPano
                elem_krpano = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/krpano");
                GetElemValue(elem_krpano, "onstart", this.onstart, true);
                GetElemValue(elem_krpano, "basedir", this.basedir, true);
                GetElemValue(elem_krpano, "bgcolor", this.bgcolor, true);
                GetElemValue(elem_krpano, "actionintervalbase", this.actionintervalbase, true);
                GetElemValue(elem_krpano, "tweenintervalbase", this.tweenintervalbase, true);
                GetElemValue(elem_krpano, "idletime", this.idletime, true);
                GetElemValue(elem_krpano, "colorcorrection", this.colorcorrection, true);
                GetElemValue(elem_krpano, "logkey", this.logkey, true);
                GetElemValue(elem_krpano, "showerrors", this.showerrors, true);
                GetElemValue(elem_krpano, "debugmode", this.debugmode, true);

                #endregion

                #region General
                elem_Project = (XmlElement)xmldoc.GetElementsByTagName("Project", "")[0];
                GetElemValue(elem_Project, "Name", this.Name, true);
                GetElemValue(elem_Project, "Skin", this.Skin, true); GetElemValue(elem_Project, "Skin", this.ddl_Skin, true);
                GetElemValue(elem_Project, "Width", this.Width, true);
                GetElemValue(elem_Project, "Height", this.Height, true);
                GetElemValue(elem_Project, "LockTF", this.LockTF, true);

                //this.Date.Text = GetDateYMD(GetElemValue(elem_Project, "Date"));

                GetElemValue(elem_Project, "Date", this.Date, true);
                GetElemValue(elem_Project, "Key", this.Key, true);
                GetElemValue(elem_Project, "Intro", this.Intro, true);
                GetElemValue(elem_Project, "GoogleMapTF", this.GoogleMapTF, true);
                GetElemValue(elem_Project, "CustomMapTF", this.CustomMapTF, true);
                GetElemValue(elem_Project, "AutoTourTF", this.AutoTourTF, true);
                GetElemValue(elem_Project, "MapProject_ID", this.MapProject_ID, true);
                GetElemValue(elem_Project, "MapProject_URL", this.MapProject_URL, true);

                GetElemValue(elem_Project, "Order", this.Order, true);
                GetElemValue(elem_Project, "Area_ID", this.Area_ID, true);
                #endregion

                #region DefScene
                GetElemValue(elem_Project, "DefScene_ID", this.DefScene_ID, true);
                GetElemValue(elem_Project, "DefMap_ID", this.DefMap_ID, true);
                this.ddl_Scene_ID.SelectedValue = this.DefScene_ID.Text.Trim();
                this.ddl_Map_ID.SelectedValue = this.DefMap_ID.Text.Trim();
                #endregion

                #region Area
                XmlElement elem_Area = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/area");
                GetElemValue(elem_Area, "mode", this.area_mode, true);

                GetElemValue(elem_Area, "align", this.area_align, true);
                GetElemValue(elem_Area, "x", this.area_x, true);
                GetElemValue(elem_Area, "y", this.area_y, true);
                GetElemValue(elem_Area, "width", this.area_width, true);
                GetElemValue(elem_Area, "height", this.area_height, true);

                GetElemValue(elem_Area, "left", this.area_left, true);
                GetElemValue(elem_Area, "top", this.area_top, true);
                GetElemValue(elem_Area, "right", this.area_right, true);
                GetElemValue(elem_Area, "bottom", this.area_bottom, true);
                #endregion

                #region BKSound
                XmlElement elem_bksound = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/BKSound");
                GetElemValue(elem_bksound, "SceneSoundID", this.SceneSoundID, true);
                GetElemValue(elem_bksound, "TourSoundID", this.TourSoundID, true);
                GetElemValue(elem_bksound, "mp3file", this.mp3file, true);
                GetElemValue(elem_bksound, "volume", this.volume, true);
                GetElemValue(elem_bksound, "pan", this.pan, true);
                GetElemValue(elem_bksound, "loops", this.loops, true);
                GetElemValue(elem_bksound, "oncomplete", this.oncomplete, true);
                #endregion

                #region Google
                elem_Google = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/Google");
                GetElemValue(elem_Google, "lng", this.google_lng, true);
                GetElemValue(elem_Google, "lat", this.google_lat, true);
                GetElemValue(elem_Google, "zoom", this.google_zoom, true);
                GetElemValue(elem_Google, "height", this.google_height, true);
                #endregion

                #region Events
                elem_events = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/events");
                GetElemValue(elem_events, "keep", this.keep, true);
                GetElemValue(elem_events, "onenterfullscreen", this.onenterfullscreen, true);
                GetElemValue(elem_events, "onexitfullscreen", this.onexitfullscreen, true);
                GetElemValue(elem_events, "onloaderror", this.onloaderror, true);
                GetElemValue(elem_events, "onkeydown", this.onkeydown, true);
                GetElemValue(elem_events, "onkeyup", this.onkeyup, true);
                GetElemValue(elem_events, "onclick", this.onclick, true);
                GetElemValue(elem_events, "onmousedown", this.onmousedown, true);
                GetElemValue(elem_events, "onmouseup", this.onmouseup, true);
                GetElemValue(elem_events, "onmousewheel", this.onmousewheel, true);
                GetElemValue(elem_events, "onidle", this.onidle, true);
                GetElemValue(elem_events, "onviewchange", this.onviewchange, true);
                GetElemValue(elem_events, "onviewchanged", this.onviewchanged, true);
                GetElemValue(elem_events, "onresize", this.onresize, true);
                #endregion

                #region Display
                ele_display = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/display");
                GetElemValue(ele_display, "flash10", this.flash10, true);
                GetElemValue(ele_display, "fps", this.fps, true);
                GetElemValue(ele_display, "details", this.details, true);
                GetElemValue(ele_display, "tessmode", this.tessmode, true);
                GetElemValue(ele_display, "movequality", this.movequality, true);
                GetElemValue(ele_display, "stillquality", this.stillquality, true);
                GetElemValue(ele_display, "movequality10", this.movequality10, true);
                GetElemValue(ele_display, "stillquality10", this.stillquality10, true);
                GetElemValue(ele_display, "stilltime", this.stilltime, true);
                GetElemValue(ele_display, "sharpen", this.sharpen, true);
                GetElemValue(ele_display, "showpolys", this.showpolys, true);

                GetElemValue(ele_display, "html5rendermode", this.html5rendermode, true);
                GetElemValue(ele_display, "hardwarelimit", this.hardwarelimit, true);
                #endregion

                #region Control
                ele_control = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/control");
                GetElemValue(ele_control, "usercontrol", this.usercontrol, true);
                GetElemValue(ele_control, "mousetype", this.mousetype, true);
                GetElemValue(ele_control, "touchtype", this.touchtype, true);
                GetElemValue(ele_control, "movetocursor", this.movetocursor, true);
                GetElemValue(ele_control, "cursorsize", this.cursorsize, true);
                GetElemValue(ele_control, "mouseaccelerate", this.mouseaccelerate, true);
                GetElemValue(ele_control, "mousespeed", this.mousespeed, true);
                GetElemValue(ele_control, "mousefriction", this.mousefriction, true);
                GetElemValue(ele_control, "keybaccelerate", this.keybaccelerate, true);
                GetElemValue(ele_control, "keybspeed", this.keybspeed, true);
                GetElemValue(ele_control, "keybfriction", this.keybfriction, true);
                GetElemValue(ele_control, "keybinvert", this.keybinvert, true);
                GetElemValue(ele_control, "mousefovchange", this.mousefovchange, true);
                GetElemValue(ele_control, "keybfovchange", this.keybfovchange, true);
                GetElemValue(ele_control, "fovspeed", this.fovspeed, true);
                GetElemValue(ele_control, "fovfriction", this.fovfriction, true);
                GetElemValue(ele_control, "keycodesleft", this.keycodesleft, true);
                GetElemValue(ele_control, "keycodesright", this.keycodesright, true);
                GetElemValue(ele_control, "keycodesup", this.keycodesup, true);
                GetElemValue(ele_control, "keycodesdown", this.keycodesdown, true);
                GetElemValue(ele_control, "keycodesin", this.keycodesin, true);
                GetElemValue(ele_control, "keycodesout", this.keycodesout, true);
                GetElemValue(ele_control, "headswing", this.headswing, true);

                GetElemValue(ele_control, "zoomtocursor", this.zoomtocursor, true);
                GetElemValue(ele_control, "zoomoutcursor", this.zoomoutcursor, true);
                GetElemValue(ele_control, "touchfriction", this.touchfriction, true);
                GetElemValue(ele_control, "trackpadzoom", this.trackpadzoom, true);
                #endregion

                #region cursors
                XmlElement ele_cursors = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/cursors");
                GetElemValue(ele_cursors, "url", this.cursors_url, true);
                GetElemValue(ele_cursors, "type", this.cursors_type, true);
                GetElemValue(ele_cursors, "move", this.cursors_move, true);
                GetElemValue(ele_cursors, "drag", this.cursors_drag, true);
                GetElemValue(ele_cursors, "arrow_l", this.cursors_arrow_l, true);
                GetElemValue(ele_cursors, "arrow_lu", this.cursors_arrow_lu, true);
                GetElemValue(ele_cursors, "arrow_ld", this.cursors_arrow_ld, true);
                GetElemValue(ele_cursors, "arrow_r", this.cursors_arrow_r, true);
                GetElemValue(ele_cursors, "arrow_ru", this.cursors_arrow_ru, true);
                GetElemValue(ele_cursors, "arrow_rd", this.cursors_arrow_rd, true);
                GetElemValue(ele_cursors, "arrow_u", this.cursors_arrow_u, true);
                GetElemValue(ele_cursors, "arrow_d", this.cursors_arrow_d, true);
                #endregion

                #region ContextMenu
                var ele_contextmenu = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/contextmenu");
                GetElemValue(ele_contextmenu, "fullscreen", this.fullscreen, true);
                GetElemValue(ele_contextmenu, "enterfs", this.enterfs, true);
                GetElemValue(ele_contextmenu, "exitfs", this.exitfs, true);
                #endregion

                #region Autorotate
                ele_autorotate = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/autorotate");
                GetElemValue(ele_autorotate, "enabled", this.enabled, true);
                GetElemValue(ele_autorotate, "waittime", this.waittime, true);
                GetElemValue(ele_autorotate, "accel", this.accel, true);
                GetElemValue(ele_autorotate, "speed", this.speed, true);
                GetElemValue(ele_autorotate, "horizon", this.horizon, true);
                GetElemValue(ele_autorotate, "tofov", this.tofov, true);
                #endregion

                #region Progress
                ele_progress = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/progress");
                GetElemValue(ele_progress, "showreloads", this.showreloads, true);
                GetElemValue(ele_progress, "showload", this.showload, true);
                GetElemValue(ele_progress, "showwait", this.showwait, true);
                GetElemValue(ele_progress, "parent", this.parent, true);
                #endregion

                #region View
                XmlElement elem_View = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/view");
                GetElemValue(elem_View, "fovtype", this.view_fovtype, true);
                GetElemValue(elem_View, "maxpixelzoom", this.view_maxpixelzoom, true);
                GetElemValue(elem_View, "hlookat", this.view_hlookat, true);
                GetElemValue(elem_View, "vlookat", this.view_vlookat, true);
                GetElemValue(elem_View, "fov", this.view_fov, true);
                GetElemValue(elem_View, "fovmin", this.view_fovmin, true);
                GetElemValue(elem_View, "fovmax", this.view_fovmax, true);
                GetElemValue(elem_View, "limitview", this.view_limitview, true);
                GetElemValue(elem_View, "hlookatmin", this.view_hlookatmin, true);
                GetElemValue(elem_View, "hlookatmax", this.view_hlookatmax, true);
                GetElemValue(elem_View, "vlookatmin", this.view_vlookatmin, true);
                GetElemValue(elem_View, "vlookatmax", this.view_vlookatmax, true);

                this.view.Text = elem_View.OuterXml;
                #endregion

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


        public string GetDateYMD(string _time)
        {
            string _stime = "";

            string[] strs = _time.Split('/');
            if (strs.Length > 1)
            {
                try
                {
                    for (int i = strs.Length - 1; i >= 0; i--)
                    {
                        //_stime +=strs[i] + "-";
                        _stime += Convert.ToInt32(strs[i]).ToString("00") + "-";
                    }
                    _stime = _stime.TrimEnd('-');
                }
                catch
                {
                    _stime = DateTime.Now.ToString("yyyy-MM-dd");
                }
            }
            else if (_time.Split('-').Length > 1)
            {
                _stime = _time;
            }
            else
            {
                _stime = DateTime.Now.ToString("yyyy-MM-dd");
            }

            return _stime;
        }


        protected void ButPost_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            XmlElement elem_krpano, elem_Project, elem_Google, elem_events, ele_display, ele_control, ele_autorotate, ele_progress;

            if (Page.IsValid)
            {
                _Tour_ID = Convert.ToInt64(this.ID.Text.Trim()).ToString();
                try
                {
                    if (action == "edit")
                    {
                        xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
                    }
                    #region 赋值区域

                    #region KRPano
                    elem_krpano = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/krpano");
                    SetElemValue(elem_krpano, "onstart", this.onstart, true);
                    SetElemValue(elem_krpano, "basedir", this.basedir, true);
                    SetElemValue(elem_krpano, "bgcolor", this.bgcolor, true);
                    SetElemValue(elem_krpano, "actionintervalbase", this.actionintervalbase, true);
                    SetElemValue(elem_krpano, "tweenintervalbase", this.tweenintervalbase, true);
                    SetElemValue(elem_krpano, "idletime", this.idletime, true);
                    SetElemValue(elem_krpano, "colorcorrection", this.colorcorrection, true);
                    SetElemValue(elem_krpano, "logkey", this.logkey, true);
                    SetElemValue(elem_krpano, "showerrors", this.showerrors, true);
                    SetElemValue(elem_krpano, "debugmode", this.debugmode, true);
                    #endregion

                    #region General
                    elem_Project = (XmlElement)xmldoc.GetElementsByTagName("Project", "")[0];
                    SetElemValue(elem_Project, "Name", this.Name);
                    SetElemValue(elem_Project, "Skin", this.Skin);
                    SetElemValue(elem_Project, "Width", this.Width);
                    SetElemValue(elem_Project, "Height", this.Height);
                    SetElemValue(elem_Project, "LockTF", this.LockTF);
                    SetElemValue(elem_Project, "Date", this.Date);
                    SetElemValue(elem_Project, "Key", this.Key);
                    SetElemValue(elem_Project, "Intro", this.Intro);
                    SetElemValue(elem_Project, "GoogleMapTF", this.GoogleMapTF);
                    SetElemValue(elem_Project, "CustomMapTF", this.CustomMapTF);
                    SetElemValue(elem_Project, "AutoTourTF", this.AutoTourTF);
                    SetElemValue(elem_Project, "MapProject_ID", this.MapProject_ID);
                    SetElemValue(elem_Project, "MapProject_URL", this.MapProject_URL);
                    SetElemValue(elem_Project, "Order", this.Order);
                    SetElemValue(elem_Project, "Area_ID", this.Area_ID);
                    #endregion

                    #region DefScene
                    SetElemValue(elem_Project, "DefScene_ID", this.DefScene_ID);
                    SetElemValue(elem_Project, "DefMap_ID", this.DefMap_ID, true);
                    #endregion

                    #region Area
                    XmlElement elem_Area = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/area");
                    SetElemValue(elem_Area, "mode", this.area_mode);

                    SetElemValue(elem_Area, "align", this.area_align, true);
                    SetElemValue(elem_Area, "x", this.area_x);
                    SetElemValue(elem_Area, "y", this.area_y);
                    SetElemValue(elem_Area, "width", this.area_width);
                    SetElemValue(elem_Area, "height", this.area_height);

                    SetElemValue(elem_Area, "left", this.area_left);
                    SetElemValue(elem_Area, "top", this.area_top);
                    SetElemValue(elem_Area, "right", this.area_right);
                    SetElemValue(elem_Area, "bottom", this.area_bottom);
                    #endregion

                    #region BKSound
                    XmlElement elem_bksound = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/BKSound");
                    SetElemValue(elem_bksound, "SceneSoundID", this.SceneSoundID);
                    SetElemValue(elem_bksound, "TourSoundID", this.TourSoundID);
                    SetElemValue(elem_bksound, "mp3file", this.mp3file);
                    SetElemValue(elem_bksound, "volume", this.volume);
                    SetElemValue(elem_bksound, "pan", this.pan);
                    SetElemValue(elem_bksound, "loops", this.loops);
                    SetElemValue(elem_bksound, "oncomplete", this.oncomplete);
                    #endregion

                    #region Google
                    elem_Google = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/Google");
                    SetElemValue(elem_Google, "lng", this.google_lng);
                    SetElemValue(elem_Google, "lat", this.google_lat);
                    SetElemValue(elem_Google, "zoom", this.google_zoom);
                    SetElemValue(elem_Google, "height", this.google_height);
                    #endregion

                    #region Events
                    elem_events = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/events");
                    SetElemValue(elem_events, "keep", this.keep, true);
                    SetElemValue(elem_events, "onenterfullscreen", this.onenterfullscreen, true);
                    SetElemValue(elem_events, "onexitfullscreen", this.onexitfullscreen, true);
                    SetElemValue(elem_events, "onloaderror", this.onloaderror, true);
                    SetElemValue(elem_events, "onkeydown", this.onkeydown, true);
                    SetElemValue(elem_events, "onkeyup", this.onkeyup, true);
                    SetElemValue(elem_events, "onclick", this.onclick, true);
                    SetElemValue(elem_events, "onmousedown", this.onmousedown, true);
                    SetElemValue(elem_events, "onmouseup", this.onmouseup, true);
                    SetElemValue(elem_events, "onmousewheel", this.onmousewheel, true);
                    SetElemValue(elem_events, "onidle", this.onidle, true);
                    SetElemValue(elem_events, "onviewchange", this.onviewchange, true);
                    SetElemValue(elem_events, "onviewchanged", this.onviewchanged, true);
                    SetElemValue(elem_events, "onresize", this.onresize, true);
                    #endregion

                    #region Display
                    ele_display = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/display");
                    SetElemValue(ele_display, "flash10", this.flash10);
                    SetElemValue(ele_display, "fps", this.fps);
                    SetElemValue(ele_display, "details", this.details);
                    SetElemValue(ele_display, "tessmode", this.tessmode);
                    SetElemValue(ele_display, "movequality", this.movequality);
                    SetElemValue(ele_display, "stillquality", this.stillquality);
                    SetElemValue(ele_display, "movequality10", this.movequality10);
                    SetElemValue(ele_display, "stillquality10", this.stillquality10);
                    SetElemValue(ele_display, "stilltime", this.stilltime);
                    SetElemValue(ele_display, "showpolys", this.showpolys);

                    SetElemValue(ele_display, "html5rendermode", this.html5rendermode, true);
                    SetElemValue(ele_display, "hardwarelimit", this.hardwarelimit, true);
                    #endregion

                    #region cursors
                    XmlElement ele_cursors = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/cursors");
                    SetElemValue(ele_cursors, "url", this.cursors_url);
                    SetElemValue(ele_cursors, "type", this.cursors_type);
                    SetElemValue(ele_cursors, "move", this.cursors_move);
                    SetElemValue(ele_cursors, "drag", this.cursors_drag);
                    SetElemValue(ele_cursors, "arrow_l", this.cursors_arrow_l);
                    SetElemValue(ele_cursors, "arrow_lu", this.cursors_arrow_lu);
                    SetElemValue(ele_cursors, "arrow_ld", this.cursors_arrow_ld);
                    SetElemValue(ele_cursors, "arrow_r", this.cursors_arrow_r);
                    SetElemValue(ele_cursors, "arrow_ru", this.cursors_arrow_ru);
                    SetElemValue(ele_cursors, "arrow_rd", this.cursors_arrow_rd);
                    SetElemValue(ele_cursors, "arrow_u", this.cursors_arrow_u);
                    SetElemValue(ele_cursors, "arrow_d", this.cursors_arrow_d);
                    #endregion

                    #region Control
                    ele_control = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/control");
                    SetElemValue(ele_control, "usercontrol", this.usercontrol);
                    SetElemValue(ele_control, "mousetype", this.mousetype);
                    SetElemValue(ele_control, "touchtype", this.touchtype, true);
                    SetElemValue(ele_control, "movetocursor", this.movetocursor);
                    SetElemValue(ele_control, "cursorsize", this.cursorsize);
                    SetElemValue(ele_control, "mouseaccelerate", this.mouseaccelerate);
                    SetElemValue(ele_control, "mousespeed", this.mousespeed);
                    SetElemValue(ele_control, "mousefriction", this.mousefriction);
                    SetElemValue(ele_control, "keybaccelerate", this.keybaccelerate);
                    SetElemValue(ele_control, "keybspeed", this.keybspeed);
                    SetElemValue(ele_control, "keybfriction", this.keybfriction);
                    SetElemValue(ele_control, "keybinvert", this.keybinvert);
                    SetElemValue(ele_control, "mousefovchange", this.mousefovchange);
                    SetElemValue(ele_control, "keybfovchange", this.keybfovchange);
                    SetElemValue(ele_control, "fovspeed", this.fovspeed);
                    SetElemValue(ele_control, "fovfriction", this.fovfriction);
                    SetElemValue(ele_control, "keycodesleft", this.keycodesleft);
                    SetElemValue(ele_control, "keycodesright", this.keycodesright);
                    SetElemValue(ele_control, "keycodesup", this.keycodesup);
                    SetElemValue(ele_control, "keycodesdown", this.keycodesdown);
                    SetElemValue(ele_control, "keycodesin", this.keycodesin);
                    SetElemValue(ele_control, "keycodesout", this.keycodesout);
                    SetElemValue(ele_control, "headswing", this.headswing);

                    SetElemValue(ele_control, "zoomtocursor", this.zoomtocursor);
                    SetElemValue(ele_control, "zoomoutcursor", this.zoomoutcursor);
                    SetElemValue(ele_control, "touchfriction", this.touchfriction);
                    SetElemValue(ele_control, "trackpadzoom", this.trackpadzoom);
                    #endregion

                    #region ContextMenu
                    var ele_contextmenu = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/contextmenu");
                    SetElemValue(ele_contextmenu, "fullscreen", this.fullscreen);
                    SetElemValue(ele_contextmenu, "enterfs", this.enterfs);
                    SetElemValue(ele_contextmenu, "exitfs", this.exitfs);
                    #endregion

                    #region Autorotate
                    ele_autorotate = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/autorotate");
                    SetElemValue(ele_autorotate, "enabled", this.enabled);
                    SetElemValue(ele_autorotate, "waittime", this.waittime);
                    SetElemValue(ele_autorotate, "accel", this.accel);
                    SetElemValue(ele_autorotate, "speed", this.speed);
                    SetElemValue(ele_autorotate, "horizon", this.horizon);
                    SetElemValue(ele_autorotate, "tofov", this.tofov);
                    #endregion

                    #region Progress
                    ele_progress = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/progress");
                    SetElemValue(ele_progress, "showreloads", this.showreloads);
                    SetElemValue(ele_progress, "showload", this.showload);
                    SetElemValue(ele_progress, "showwait", this.showwait);
                    SetElemValue(ele_progress, "parent", this.parent, true);
                    #endregion

                    #region View
                    XmlElement elem_View = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/view");
                    SetElemValue(elem_View, "fovtype", this.view_fovtype);
                    SetElemValue(elem_View, "maxpixelzoom", this.view_maxpixelzoom);
                    SetElemValue(elem_View, "hlookat", this.view_hlookat);
                    SetElemValue(elem_View, "vlookat", this.view_vlookat);
                    SetElemValue(elem_View, "fov", this.view_fov);
                    SetElemValue(elem_View, "fovmin", this.view_fovmin);
                    SetElemValue(elem_View, "fovmax", this.view_fovmax);
                    SetElemValue(elem_View, "limitview", this.view_limitview);
                    SetElemValue(elem_View, "hlookatmin", this.view_hlookatmin);
                    SetElemValue(elem_View, "hlookatmax", this.view_hlookatmax);
                    SetElemValue(elem_View, "vlookatmin", this.view_vlookatmin);
                    SetElemValue(elem_View, "vlookatmax", this.view_vlookatmax);
                    #endregion

                    #endregion
                    if (action == "edit")
                    {
                        try
                        {
                            MyApp.Components.XML.XmlDocument.WriteAllText(Server.MapPath(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID)), xmldoc.OuterXml);
                            ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>top.updatetour();</script>");
                        }
                        catch (Exception) { ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>"); }
                    }


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

    }
}
