using System;
using System.IO;
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.GoogleMap
{
    public partial class Edit_Map : MyApp.Web.UI.UserPage
    {
        public string _Tour_ID = "";

        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;
            }
            base.AppInit();
        }

        override protected void DataInit()//数据初始化
        {
        }

        protected override void pl_register_script()
        {

            foreach (Control obj in this.theform.Controls)
            {
                if ((obj.GetType().Name == "TextBox") || (obj.GetType().Name == "DropDownList") || (obj.GetType().Name == "RadioButtonList"))
                {
                    WebControl wc = ((WebControl)obj);
                    if (wc.ID.ToLower() == wc.ID)
                    {
                        wc.Attributes.Add("onchange", "javascrpt:set_plugin('" + wc.ID + "',$('" + wc.ID + "').value);");
                    }
                }
                else
                {
                    WebControl wc = ((WebControl)obj);
                    if (wc.ID.ToLower() == wc.ID)
                    {
                        wc.Attributes.Add("onclick", "javascrpt:set_plugin('" + wc.ID + "',$('" + wc.ID + "').checked);");
                    }
                }
            }
            base.pl_register_script();
        }

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

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

        override protected void pl_edit()
        {
            XmlDocument xmldoc;
            XmlElement elem_plugin;
            xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));

            try
            {
                elem_plugin = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin");

                GetElemValue(elem_plugin, "name", this.name, true);
                GetElemValue(elem_plugin, "url", this.url, true);
                GetElemValue(elem_plugin, "zorder", this.zorder, true);
                GetElemValue(elem_plugin, "alpha", this.alpha, true);
                GetElemValue(elem_plugin, "blendmode", this.blendmode, true);
                GetElemValue(elem_plugin, "align", this.align, true);
                GetElemValue(elem_plugin, "edge", this.edge, true);
                GetElemValue(elem_plugin, "x", this.x, true);
                GetElemValue(elem_plugin, "y", this.y, true);

                GetElemValue(elem_plugin, "ox", this.ox, true);
                GetElemValue(elem_plugin, "oy", this.oy, true);

                GetElemValue(elem_plugin, "width", this.width, true);
                GetElemValue(elem_plugin, "height", this.height, true);
                GetElemValue(elem_plugin, "refreshrate", this.refreshrate, true);
                GetElemValue(elem_plugin, "scale", this.scale, true);
                GetElemValue(elem_plugin, "smoothing", this.smoothing, true);

                GetElemValue(elem_plugin, "mask", this.mask, true);
                GetElemValue(elem_plugin, "rotate", this.rotate, true);

                GetElemValue(elem_plugin, "visible", this.visible, true);
                GetElemValue(elem_plugin, "enabled", this.enabled, true);
                GetElemValue(elem_plugin, "capture", this.capture, true);
                GetElemValue(elem_plugin, "handcursor", this.handcursor, true);
                GetElemValue(elem_plugin, "keep", this.keep, true);
                GetElemValue(elem_plugin, "children", this.children, true);
                GetElemValue(elem_plugin, "preload", this.preload, true);

                GetElemValue(elem_plugin, "Intro", this.Intro, true);

                GetElemValue(elem_plugin, "style", this.style, true);

                #region 效果
                GetElemValue(elem_plugin, "effect", this.effect, true);
                #endregion

                #region 父子控制
                GetElemValue(elem_plugin, "parent", this.parent, true);
                GetElemValue(elem_plugin, "scalechildren", this.scalechildren, true);
                #endregion

                #region 事件
                GetElemValue(elem_plugin, "onover", this.onover, true);
                GetElemValue(elem_plugin, "onhover", this.onhover, true);
                GetElemValue(elem_plugin, "onout", this.onout, true);
                GetElemValue(elem_plugin, "onclick", this.onclick, true);
                GetElemValue(elem_plugin, "ondown", this.ondown, true);
                GetElemValue(elem_plugin, "onup", this.onup, true);
                GetElemValue(elem_plugin, "onloaded", this.onloaded, true);
                #endregion

                #region
                GetElemValue(elem_plugin, "key", this.key, true);
                GetElemValue(elem_plugin, "maptype", this.maptype, true);
                GetElemValue(elem_plugin, "lng", this.lng, true);
                GetElemValue(elem_plugin, "lat", this.lat, true);
                GetElemValue(elem_plugin, "zoom", this.zoom, true);

                if (this.key.Text.Trim() == "")
                {
                    this.key.Text = MyApp.Components.Google.google.GetKey();
                }
                if ((this.zoom.Text.Trim() == "0") || (this.zoom.Text.Trim() == ""))
                {
                    this.lng.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "lng");
                    this.lat.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "lat");
                    this.zoom.Text = MyApp.Components.KRPano.Project.Get_ProjectNodeConfigValue(_Tour_ID, "/Project/Google", "zoom");
                }

                GetElemValue(elem_plugin, "dragging", this.dragging, true);
                GetElemValue(elem_plugin, "scrollwheel", this.scrollwheel, true);
                GetElemValue(elem_plugin, "continuouszoom", this.continuouszoom, true);
                GetElemValue(elem_plugin, "keyboard", this.keyboard, true);
                GetElemValue(elem_plugin, "crosshairs", this.crosshairs, true);
                GetElemValue(elem_plugin, "onmapready", this.onmapready, true);
                GetElemValue(elem_plugin, "onmapmoved", this.onmapmoved, true);
                GetElemValue(elem_plugin, "onmapzoomed", this.onmapzoomed, true);
                #endregion

                #region spot_set
                XmlElement spot_set = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/spot_set");
                GetElemValue(spot_set, "onover", this.spot_onover, true);
                GetElemValue(spot_set, "onhover", this.spot_onhover, true);
                GetElemValue(spot_set, "onout", this.spot_onout, true);
                GetElemValue(spot_set, "onclick", this.spot_onclick, true);
                #endregion

                #region radar
                XmlElement elem_radar = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/radar");
                GetElemValue(elem_radar, "visible", this.radar_visible, true);
                GetElemValue(elem_radar, "dragable", this.radar_dragable, true);
                GetElemValue(elem_radar, "behindspots", this.radar_behindspots, true);
                GetElemValue(elem_radar, "size", this.radar_size, true);
                GetElemValue(elem_radar, "alpha", this.radar_alpha, true);
                GetElemValue(elem_radar, "fillcolor", this.radar_fillcolor, true);
                GetElemValue(elem_radar, "fillalpha", this.radar_fillalpha, true);
                GetElemValue(elem_radar, "linecolor", this.radar_linecolor, true);
                GetElemValue(elem_radar, "linealpha", this.radar_linealpha, true);
                GetElemValue(elem_radar, "linewidth", this.radar_linewidth, true);

                GetElemValue(elem_radar, "glow", this.radar_glow, true);
                GetElemValue(elem_radar, "glowcolor", this.radar_glowcolor, true);
                GetElemValue(elem_radar, "glowwidth", this.radar_glowwidth, true);
                GetElemValue(elem_radar, "glowstrength", this.radar_glowstrength, true);
                #endregion

                #region zoomcontrol
                XmlElement elem_zoomcontrol = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/zoomcontrol");
                GetElemValue(elem_zoomcontrol, "x", this.zoomcontrol_x, true);
                GetElemValue(elem_zoomcontrol, "y", this.zoomcontrol_y, true);
                GetElemValue(elem_zoomcontrol, "anchor", this.zoomcontrol_anchor, true);
                GetElemValue(elem_zoomcontrol, "visible", this.zoomcontrol_visible, true);
                GetElemValue(elem_zoomcontrol, "hasscrolltrack", this.zoomcontrol_hasscrolltrack, true);
                #endregion

                #region positioncontrol
                XmlElement elem_positioncontrol = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/positioncontrol");
                GetElemValue(elem_positioncontrol, "x", this.positioncontrol_x, true);
                GetElemValue(elem_positioncontrol, "y", this.positioncontrol_y, true);
                GetElemValue(elem_positioncontrol, "anchor", this.positioncontrol_anchor, true);
                GetElemValue(elem_positioncontrol, "visible", this.positioncontrol_visible, true);
                #endregion

                #region control action
                GetElemValue(elem_plugin, "ac_show", this.ac_show, true);
                GetElemValue(elem_plugin, "ac_hidden", this.ac_hidden, true);
                #endregion
            }
            catch (Exception)
            {
                ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
        }

        protected void ButPost_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            XmlElement elem_plugin;
            if (Page.IsValid)
            {
                try
                {

                    if (action == "edit")
                    {
                        xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));

                    }

                    elem_plugin = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin");
                    #region 赋值区域



                    SetElemValue(elem_plugin, "name", this.name);
                    SetElemValue(elem_plugin, "url", this.url);
                    SetElemValue(elem_plugin, "zorder", this.zorder);
                    SetElemValue(elem_plugin, "alpha", this.alpha);
                    SetElemValue(elem_plugin, "blendmode", this.blendmode);
                    SetElemValue(elem_plugin, "align", this.align);
                    SetElemValue(elem_plugin, "edge", this.edge);
                    SetElemValue(elem_plugin, "x", this.x);
                    SetElemValue(elem_plugin, "y", this.y);

                    SetElemValue(elem_plugin, "ox", this.ox);
                    SetElemValue(elem_plugin, "oy", this.oy);

                    SetElemValue(elem_plugin, "width", this.width);
                    SetElemValue(elem_plugin, "height", this.height);
                    SetElemValue(elem_plugin, "refreshrate", this.refreshrate);
                    SetElemValue(elem_plugin, "scale", this.scale);
                    SetElemValue(elem_plugin, "smoothing", this.smoothing);

                    SetElemValue(elem_plugin, "mask", this.mask);
                    SetElemValue(elem_plugin, "rotate", this.rotate);

                    SetElemValue(elem_plugin, "visible", this.visible);
                    SetElemValue(elem_plugin, "enabled", this.enabled);
                    SetElemValue(elem_plugin, "capture", this.capture);
                    SetElemValue(elem_plugin, "handcursor", this.handcursor);
                    SetElemValue(elem_plugin, "keep", this.keep);
                    SetElemValue(elem_plugin, "children", this.children);
                    SetElemValue(elem_plugin, "preload", this.preload);
                    SetElemValue(elem_plugin, "Intro", this.Intro);

                    SetElemValue(elem_plugin, "style", this.style);

                    #region 效果
                    SetElemValue(elem_plugin, "effect", this.effect);
                    #endregion

                    #region 父子控制
                    SetElemValue(elem_plugin, "parent", this.parent);
                    SetElemValue(elem_plugin, "scalechildren", this.scalechildren);
                    #endregion


                    #region 事件
                    SetElemValue(elem_plugin, "onover", this.onover);
                    SetElemValue(elem_plugin, "onhover", this.onhover);
                    SetElemValue(elem_plugin, "onout", this.onout);
                    SetElemValue(elem_plugin, "onclick", this.onclick);
                    SetElemValue(elem_plugin, "ondown", this.ondown);
                    SetElemValue(elem_plugin, "onup", this.onup);
                    SetElemValue(elem_plugin, "onloaded", this.onloaded);
                    #endregion

                    #region
                    SetElemValue(elem_plugin, "key", this.key);
                    SetElemValue(elem_plugin, "maptype", this.maptype);
                    SetElemValue(elem_plugin, "lng", this.lng);
                    SetElemValue(elem_plugin, "lat", this.lat);
                    SetElemValue(elem_plugin, "zoom", this.zoom);

                    SetElemValue(elem_plugin, "dragging", this.dragging);
                    SetElemValue(elem_plugin, "scrollwheel", this.scrollwheel);
                    SetElemValue(elem_plugin, "continuouszoom", this.continuouszoom);
                    SetElemValue(elem_plugin, "keyboard", this.keyboard);
                    SetElemValue(elem_plugin, "crosshairs", this.crosshairs);
                    SetElemValue(elem_plugin, "onmapready", this.onmapready);
                    SetElemValue(elem_plugin, "onmapmoved", this.onmapmoved);
                    SetElemValue(elem_plugin, "onmapzoomed", this.onmapzoomed);
                    #endregion   


                    #region spot_set
                    XmlElement spot_set = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/spot_set");
                    SetElemValue(spot_set, "onover", this.spot_onover);
                    SetElemValue(spot_set, "onhover", this.spot_onhover);
                    SetElemValue(spot_set, "onout", this.spot_onout);
                    SetElemValue(spot_set, "onclick", this.spot_onclick);
                    #endregion

                    #region radar
                    XmlElement elem_radar = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/radar");
                    SetElemValue(elem_radar, "visible", this.radar_visible);
                    SetElemValue(elem_radar, "dragable", this.radar_dragable);
                    SetElemValue(elem_radar, "behindspots", this.radar_behindspots);
                    SetElemValue(elem_radar, "size", this.radar_size);
                    SetElemValue(elem_radar, "alpha", this.radar_alpha);
                    SetElemValue(elem_radar, "fillcolor", this.radar_fillcolor);
                    SetElemValue(elem_radar, "fillalpha", this.radar_fillalpha);
                    SetElemValue(elem_radar, "linecolor", this.radar_linecolor);
                    SetElemValue(elem_radar, "linealpha", this.radar_linealpha);
                    SetElemValue(elem_radar, "linewidth", this.radar_linewidth);

                    SetElemValue(elem_radar, "glow", this.radar_glow);
                    SetElemValue(elem_radar, "glowcolor", this.radar_glowcolor);
                    SetElemValue(elem_radar, "glowwidth", this.radar_glowwidth);
                    SetElemValue(elem_radar, "glowstrength", this.radar_glowstrength);
                    #endregion

                    #region zoomcontrol
                    XmlElement elem_zoomcontrol = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/zoomcontrol");
                    SetElemValue(elem_zoomcontrol, "x", this.zoomcontrol_x);
                    SetElemValue(elem_zoomcontrol, "y", this.zoomcontrol_y);
                    SetElemValue(elem_zoomcontrol, "anchor", this.zoomcontrol_anchor);
                    SetElemValue(elem_zoomcontrol, "visible", this.zoomcontrol_visible);
                    SetElemValue(elem_zoomcontrol, "hasscrolltrack", this.zoomcontrol_hasscrolltrack);
                    #endregion

                    #region positioncontrol
                    XmlElement elem_positioncontrol = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/GoogleMap/plugin/positioncontrol");
                    SetElemValue(elem_positioncontrol, "x", this.positioncontrol_x);
                    SetElemValue(elem_positioncontrol, "y", this.positioncontrol_y);
                    SetElemValue(elem_positioncontrol, "anchor", this.positioncontrol_anchor);
                    SetElemValue(elem_positioncontrol, "visible", this.positioncontrol_visible);
                    #endregion


                    #region control action
                    SetElemValue(elem_plugin, "ac_show", this.ac_show);
                    SetElemValue(elem_plugin, "ac_hidden", this.ac_hidden);
                    #endregion

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