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.Scene
{
    public partial class AD_Scene : MyApp.Web.UI.UserPage
    {
        public string _Scene_ID = "", _Tour_ID = "", _TypeID = "";
        override protected void AppInit()//程序基本信息初始化
        {
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();
                _Scene_ID = Request.QueryString["Scene_ID"].Trim();
            }
            catch (Exception)
            {
                ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
            base.AppInit();
        }

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

        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_Prev_Scene_ID.Attributes.Add("onchange", "javascrpt:{$('Prev_Scene_ID').value=this.value}");
            this.ddl_Next_Scene_ID.Attributes.Add("onchange", "javascrpt:{$('Next_Scene_ID').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()
        {
            try
            {
                _TypeID = MyApp.Components.KRPano.Scene.GetValue(MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID), "/krpano", "TypeID");
                Directory.Delete(Server.MapPath(String.Format("/Project/{0}/scene/{1}", _Tour_ID, _Scene_ID)), true);
                //ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>oWindow.updatescenetree();window.location='List_TreeScene.aspx?Tour_ID=" + _Tour_ID + "&TypeID=" + _TypeID + "';</script>");
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>oWindow.delscene(" + _Scene_ID + ");window.location='List_TreeScene.aspx?Tour_ID=" + _Tour_ID + "&TypeID=" + _TypeID + "';</script>");
            }
            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;
            xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
            _TypeID = MyApp.Components.KRPano.Scene.GetValue(MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID), "/krpano", "TypeID");
            try
            {
                this.ID.Text = _Scene_ID;
                #region KRPano
                XmlElement elem_krpano = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];
                GetElemValue(elem_krpano, "onstart", this.onstart, true);
                GetElemValue(elem_krpano, "basedir", this.basedir, true);
                GetElemValue(elem_krpano, "logkey", this.logkey, true);
                GetElemValue(elem_krpano, "actionintervalbase", this.actionintervalbase, true);
                #endregion

                #region General
                XmlElement elem_Project = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];
                GetElemValue(elem_Project, "Name", this.Name, true);

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

                GetElemValue(elem_Project, "Date", this.Date, true);
                GetElemValue(elem_Project, "LockTF", this.LockTF, true);
                GetElemValue(elem_Project, "GoogleMapTF", this.GoogleMapTF, true);
                GetElemValue(elem_Project, "HotspotAutoTF", this.HotspotAutoTF, true);
                GetElemValue(elem_Project, "HotspotAutoByTF", this.HotspotAutoByTF, true);
                GetElemValue(elem_Project, "Intro", this.Intro, true);
                #endregion

                #region Set
                XmlElement elem_set = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/SSet");
                GetElemValue(elem_set, "Prev_Scene_ID", this.Prev_Scene_ID);
                GetElemValue(elem_set, "Next_Scene_ID", this.Next_Scene_ID);
                GetElemValue(elem_set, "Prev_Scene_ID", this.ddl_Prev_Scene_ID);
                GetElemValue(elem_set, "Next_Scene_ID", this.ddl_Next_Scene_ID);
                GetElemValue(elem_set, "Order", this.Order);
                GetElemValue(elem_set, "Key", this.Key);
                GetElemValue(elem_set, "SearchTF", this.SearchTF);

                try
                {
                    if (this.Prev_Scene_ID.Text.Trim() == "")
                    {
                        this.Prev_Scene_ID.Text = (Convert.ToInt64(_Scene_ID) - 1).ToString();
                    }
                    if (this.Next_Scene_ID.Text.Trim() == "")
                    {
                        this.Next_Scene_ID.Text = (Convert.ToInt64(_Scene_ID) + 1).ToString();
                    }
                }
                catch (Exception) { }
                #endregion

                #region BKSound
                XmlElement elem_bksound = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/BKSound");
                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 Preview
                //XmlElement elem_Preview = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/preview");
                //GetElemValue(elem_Preview, "type", this.preview_type, true);
                //#endregion

                #region Image
                XmlElement elem_Image = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/image");
                GetElemValue(elem_Image, "type", this.image_type, true);
                GetElemValue(elem_Image, "multires", this.image_multires, true);
                if (this.image_multires.SelectedValue == "true")
                {
                    this.image_multires.Enabled = true;
                }
                else
                {
                    this.image_multires.Enabled = false;
                }
                #endregion

                #region View
                XmlElement elem_View = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/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);

                GetElemValue(elem_View, "camroll", this.camroll, true);
                GetElemValue(elem_View, "fisheyefovlink", this.fisheyefovlink, true);
                GetElemValue(elem_View, "fisheye", this.fisheye, true);
                GetElemValue(elem_View, "stereographic", this.stereographic, true);
                GetElemValue(elem_View, "pannini", this.pannini, true);
                GetElemValue(elem_View, "architectural", this.architectural, true);
                GetElemValue(elem_View, "architecturalonlymiddle", this.architecturalonlymiddle, true);
                #endregion

                #region 自定义地图
                XmlElement elem_CustomMap = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/CustomMap");
                GetElemValue(elem_CustomMap, "enable", this.map_enable, true);
                GetElemValue(elem_CustomMap, "lng", this.map_lng, true);
                GetElemValue(elem_CustomMap, "lat", this.map_lat, true);
                GetElemValue(elem_CustomMap, "zoom", this.map_zoom, true);
                #endregion

                #region Google
                XmlElement elem_Google = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/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, "heading", this.google_heading, true);
                GetElemValue(elem_Google, "height", this.google_height, true);
                GetElemValue(elem_Google, "GoogleMapTF", this.GoogleMapTF, true);

                if ((this.google_zoom.Text.Trim() == "0") || (this.google_zoom.Text.Trim() == "") || (this.google_zoom.Text.Trim() == "1"))
                {
                    this.google_lng.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "lng");
                    this.google_lat.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "lat");
                    this.google_zoom.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "zoom");
                    this.google_height.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "height");
                }
                #endregion

                #region Events
                XmlElement elem_events = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/events");
                GetElemValue(elem_events, "onxmlcomplete", this.onxmlcomplete, true);
                GetElemValue(elem_events, "onpreviewcomplete", this.onpreviewcomplete, true);
                GetElemValue(elem_events, "onloadcomplete", this.onloadcomplete, true);
                GetElemValue(elem_events, "onnewpano", this.onnewpano, true);
                GetElemValue(elem_events, "onremovepano", this.onremovepano, true);
                GetElemValue(elem_events, "onclick", this.sceneonclick,true);
                GetElemValue(elem_events, "onmousedown", this.onmousedown, true);
                GetElemValue(elem_events, "onmouseup", this.onmouseup, true);
                GetElemValue(elem_events, "onkeydown", this.onkeydown, true);
                GetElemValue(elem_events, "onkeyup", this.onkeyup, true);

                #endregion

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

        protected void ButPost_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            Button bn = (Button)sender;
            if (Page.IsValid)
            {
                _Scene_ID = this.ID.Text.Trim();
                try
                {
                    if (action == "edit")
                    {
                        xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
                    }
                    #region 赋值区域

                    #region KRPano
                    XmlElement elem_krpano = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];
                    SetElemValue(elem_krpano, "onstart", this.onstart);
                    SetElemValue(elem_krpano, "basedir", this.basedir);
                    SetElemValue(elem_krpano, "logkey", this.logkey);
                    SetElemValue(elem_krpano, "actionintervalbase", this.actionintervalbase);
                    #endregion

                    #region General
                    XmlElement elem_Project = (XmlElement)xmldoc.GetElementsByTagName("krpano", "")[0];
                    SetElemValue(elem_Project, "Name", this.Name);
                    SetElemValue(elem_Project, "Date", this.Date);
                    SetElemValue(elem_Project, "LockTF", this.LockTF);
                    SetElemValue(elem_Project, "GoogleMapTF", this.GoogleMapTF);
                    SetElemValue(elem_Project, "HotspotAutoTF", this.HotspotAutoTF);
                    SetElemValue(elem_Project, "HotspotAutoByTF", this.HotspotAutoByTF);
                    SetElemValue(elem_Project, "Intro", this.Intro);
                    #endregion


                    #region SSet
                    XmlElement elem_sset = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/SSet");
                    SetElemValue(elem_sset, "Scene_ID", _Scene_ID);
                    SetElemValue(elem_sset, "Scene_Name", this.Name);
                    SetElemValue(elem_sset, "GoogleMapTF", this.GoogleMapTF);
                    SetElemValue(elem_sset, "Prev_Scene_ID", this.Prev_Scene_ID);
                    SetElemValue(elem_sset, "Next_Scene_ID", this.Next_Scene_ID);
                    SetElemValue(elem_sset, "Order", this.Order);
                    SetElemValue(elem_sset, "Key", this.Key);
                    SetElemValue(elem_sset, "SearchTF", this.SearchTF);
                    SetElemValue(elem_sset, "Intro", this.Intro);
                    SetElemValue(elem_sset, "GoogleMapTF", this.GoogleMapTF);
                    #endregion

                    #region BKSound
                    XmlElement elem_bksound = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/BKSound");
                    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 Preview
                    //XmlElement elem_Preview = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/preview");
                    //SetElemValue(elem_Preview, "type", this.preview_type);
                    //SetElemValue(elem_Preview, "details", "32");
                    //if (this.preview_type.Text.Trim() == "SPHERE")
                    //{
                    //    //if (this.image_multires.SelectedValue.Trim() == "false")
                    //    //{
                    //    //    SetElemValue(elem_Preview, "url", "s.jpg");
                    //    //}
                    //    //else
                    //    //{
                    //    //    SetElemValue(elem_Preview, "url", "b/preview.jpg");
                    //    //}
                    //}
                    //else
                    //{
                    //}
                    //#endregion

                    #region Image
                    XmlElement elem_Image = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/image");
                    SetElemValue(elem_Image, "type", this.image_type);
                    SetElemValue(elem_Image, "multires", this.image_multires);


                    if (this.image_multires.SelectedValue.Trim() == "false")
                    {
                        if (System.IO.Directory.Exists(MyApp.Components.File.FileManage.GetRootDir(String.Format("/Project/{0}/scene/{1}/cube", _Tour_ID, _Scene_ID))))
                        {
                            SetElemValue(elem_Image, "type", "CUBE");

                            XmlDocument xml_b=MyApp.Components.XML.XmlDocument.Load("/Data/Templates/Scene/scene.xml");
                            XmlElement elem_b = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xml_b, "/krpano/image");
                            elem_Image.InnerXml = elem_b.InnerXml;
                        }
                        //else
                        //{
                        //    XmlElement elem_Sphere = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/image/sphere");
                        //    SetElemValue(elem_Image, "type", "SPHERE");
                        //    SetElemValue(elem_Sphere, "url", "b.jpg");
                        //}
                    }

                    #endregion

                    #region View
                    XmlElement elem_View = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/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);

                    SetElemValue(elem_View, "camroll", this.camroll, true);
                    SetElemValue(elem_View, "fisheyefovlink", this.fisheyefovlink, true);
                    SetElemValue(elem_View, "fisheye", this.fisheye, true);
                    SetElemValue(elem_View, "stereographic", this.stereographic, true);
                    SetElemValue(elem_View, "pannini", this.pannini, true);
                    SetElemValue(elem_View, "architectural", this.architectural, true);
                    SetElemValue(elem_View, "architecturalonlymiddle", this.architecturalonlymiddle, true);
                    #endregion

                    #region 自定义地图
                    XmlElement elem_CustomMap = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/CustomMap");
                    SetElemValue(elem_CustomMap, "enable", this.map_enable);
                    SetElemValue(elem_CustomMap, "lng", this.map_lng);
                    SetElemValue(elem_CustomMap, "lat", this.map_lat);
                    SetElemValue(elem_CustomMap, "zoom", this.map_zoom);
                    #endregion

                    #region Google
                    try
                    {
                        //this.google_heading.Text = (Convert.ToDouble(this.google_heading.Text) - 90).ToString();
                    }
                    catch (Exception) { }

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

                    #region Events
                    XmlElement elem_events = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/krpano/events");
                    SetElemValue(elem_events, "onxmlcomplete", this.onxmlcomplete, true);
                    SetElemValue(elem_events, "onpreviewcomplete", this.onpreviewcomplete, true);
                    SetElemValue(elem_events, "onloadcomplete", this.onloadcomplete, true);
                    SetElemValue(elem_events, "onnewpano", this.onnewpano, true);
                    SetElemValue(elem_events, "onremovepano", this.onremovepano, true);
                    SetElemValue(elem_events, "onclick", this.sceneonclick, true);
                    SetElemValue(elem_events, "onmouseup", this.onmouseup, true);
                    SetElemValue(elem_events, "onmousedown", this.onmousedown, true);
                    SetElemValue(elem_events, "onkeydown", this.onkeydown, true);
                    SetElemValue(elem_events, "onkeyup", this.onkeyup, true);
                    #endregion


                    #region   背景音乐设置动作
                    bool sound_tf = false;
                    string str_sound = "";
                    XmlElement ac_elem_bksound;
                    ac_elem_bksound = (XmlElement)xmldoc.SelectSingleNode("/krpano/action[@name='_playscenesound']");
                    if ((ac_elem_bksound != null) && (ac_elem_bksound.OuterXml != ""))
                    {
                    }
                    else
                    {
                        ac_elem_bksound = xmldoc.CreateElement("action");
                        ac_elem_bksound.SetAttribute("name", "_playscenesound");
                        sound_tf = true;
                    }
                    if (this.mp3file.Text.Trim() != "")
                    {
                        str_sound = string.Format("playsound2D({0}, {1}, {2}, {3}, {4}, {5});", "scenebksound", this.mp3file.Text.Trim(), this.volume.Text.Trim(), this.pan.Text.Trim(), this.loops.Text.Trim(), this.oncomplete.Text.Trim());
                    }

                    ac_elem_bksound.InnerText = str_sound.Trim();

                    if (sound_tf)
                    {
                        xmldoc.SelectSingleNode("/krpano").AppendChild(ac_elem_bksound);
                    }
                    #endregion


                    xmldoc.LoadXml(xmldoc.OuterXml.Replace("{Scene_ID}", this.ID.Text.Trim()));

                    #endregion

                    if (action == "edit")
                    {
                        try
                        {
                            MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);

                            //MyApp.Components.XML.XmlDocument.WriteAllText(Server.MapPath(String.Format("/Project/{0}/scene/{1}/include_scene.xml", _Tour_ID, _Scene_ID)), xmldoc.ChildNodes[0].InnerXml);
                            MyApp.Components.KRPano.Scene.UploadScenePic("b", _Tour_ID, _Scene_ID);

                            if (bn.CommandName == "ret")
                            {
                                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>top.updatescenebyid('" + _Scene_ID + "');window.location='List_TreeScene.aspx?Tour_ID=" + _Tour_ID + "&TypeID=" + MyApp.Components.KRPano.Scene.GetValue(MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID), "/krpano", "TypeID") + "';</script>");
                            }
                            else
                            {
                                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>top.updatescenebyid('" + _Scene_ID + "');</script>");
                            }
                        }
                        catch (Exception) { ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('Error!!!);</script>"); }
                    }
                }
                catch (Exception)
                {
                    ButPost.Enabled = false;
                    ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                    return;
                }
            }
        }


        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;
        }
    }
}
