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.Map
{
    public partial class AD_Map : MyApp.Web.UI.UserPage
    {
        public string _Tour_ID = "";
        public int _ROW = 0;

        override protected void AppInit()//程序基本信息初始化
        {
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();
                _ROW = Convert.ToInt32(Request.QueryString["ROW"].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()//数据初始化
        {
            XmlDocument xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
            XmlNodeList xmlnodelist_plugin = xmldoc.SelectNodes("/Project/Plugins/plugin");
            foreach (XmlElement xmlele_plugin in xmlnodelist_plugin)
            {
                this.parent.Items.Add(new ListItem("插件: " + xmlele_plugin.GetAttribute("name"), xmlele_plugin.GetAttribute("name")));
                this.mask.Items.Add(new ListItem("地图: " + xmlele_plugin.GetAttribute("name"), xmlele_plugin.GetAttribute("name")));
            }

            XmlNodeList xmlnodelist_map = xmldoc.SelectNodes("/Project/Maps/Map");
            foreach (XmlElement xmlele_plugin in xmlnodelist_map)
            {
                this.parent.Items.Add(new ListItem("地图: " + xmlele_plugin.GetAttribute("name"), xmlele_plugin.GetAttribute("name")));
                this.mask.Items.Add(new ListItem("地图: " + xmlele_plugin.GetAttribute("name"), xmlele_plugin.GetAttribute("name")));
            }
        }

        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)
        {

        }
        override protected void pl_del()
        {
            XmlDocument xmldoc;
            xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
            XmlNode xmlnode = xmldoc.SelectSingleNode("/Project/Maps");
            XmlNodeList xmlnodelist = xmldoc.SelectNodes("/Project/Maps/Map");
            try
            {
                if (_ROW == -1)
                {
                    foreach (XmlElement elem_plugin in xmlnodelist)
                    {
                        xmlnode.RemoveChild(elem_plugin);
                    }
                }
                else
                {
                    if (xmlnodelist.Count >= _ROW)
                    {
                        xmlnode.RemoveChild(xmlnodelist[_ROW - 1]);
                    }
                }
                MyApp.Components.XML.XmlDocument.WriteAllText(Server.MapPath(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID)), xmldoc.OuterXml);
                //Response.Redirect(MyApp.Components.NavUrl.GetUrl(2));
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>top.updatecustommap();window.location='List_Map.aspx?Tour_ID=" + _Tour_ID + "';</script>");
            }
            catch (Exception)
            {
                ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
        }
        override protected void pl_add()
        {
            if (_ROW > 0)
            {
                pl_edit();
                this.id.Text = "";
                this.name.Text = "";
                this.url.Text = "";
            }
            this.name.Focus();
        }
        override protected void pl_edit()
        {
            XmlDocument xmldoc;
            xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));

            try
            {
                XmlElement elem_plugin = (XmlElement)xmldoc.SelectNodes("/Project/Maps/Map")[_ROW - 1];

                GetElemValue(elem_plugin, "id", this.id, true);
                GetElemValue(elem_plugin, "name", this.name, true);
                GetElemValue(elem_plugin, "title", this.title, 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, "dragmap", this.dragmap, 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 mapset
                GetElemValue(elem_plugin, "x_offset", this.x_offset, true);
                GetElemValue(elem_plugin, "y_offset", this.y_offset, true);
                GetElemValue(elem_plugin, "pix_m", this.pix_m, true);
                GetElemValue(elem_plugin, "default", this.defaulttf, true);
                GetElemValue(elem_plugin, "heading", this.heading, true);
                GetElemValue(elem_plugin, "hint", this.hint, true);
                #endregion

                #region RaderSet
                GetElemValue(elem_plugin, "radar_width", this.radar_width, true);
                GetElemValue(elem_plugin, "radar_height", this.radar_height, true);
                GetElemValue(elem_plugin, "radar_linecolor", this.radar_linecolor, true);
                GetElemValue(elem_plugin, "radar_fillcolor", this.radar_fillcolor, true);
                GetElemValue(elem_plugin, "radar_scale", this.radar_scale, true);
                GetElemValue(elem_plugin, "radar_smoothing", this.radar_smoothing, true);
                #endregion

                #region ICON
                GetElemValue(elem_plugin, "icon_init", this.icon_init, true);
                GetElemValue(elem_plugin, "icon_visit", this.icon_visit, true);
                GetElemValue(elem_plugin, "icon_onhover", this.icon_onhover, true);
                GetElemValue(elem_plugin, "icon_active", this.icon_active, 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 == "add")
                    {
                        xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
                        elem_plugin = xmldoc.CreateElement("Map");
                    }
                    else
                        if (action == "edit")
                        {
                            xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
                            elem_plugin = (XmlElement)xmldoc.SelectNodes("/Project/Maps/Map")[_ROW - 1];
                        }
                        else
                        {
                            return;
                        }
                    #region 赋值区域

                    SetElemValue(elem_plugin, "id", this.id);
                    SetElemValue(elem_plugin, "name", this.name);
                    SetElemValue(elem_plugin, "title", this.title);
                    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, "dragmap", this.dragmap);

                    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 mapset
                    SetElemValue(elem_plugin, "x_offset", this.x_offset);
                    SetElemValue(elem_plugin, "y_offset", this.y_offset);
                    SetElemValue(elem_plugin, "pix_m", this.pix_m);
                    SetElemValue(elem_plugin, "default", this.defaulttf);
                    SetElemValue(elem_plugin, "heading", this.heading);
                    SetElemValue(elem_plugin, "hint", this.hint);
                    #endregion

                    #region RaderSet
                    SetElemValue(elem_plugin, "radar_width", this.radar_width);
                    SetElemValue(elem_plugin, "radar_height", this.radar_height);
                    SetElemValue(elem_plugin, "radar_linecolor", this.radar_linecolor);
                    SetElemValue(elem_plugin, "radar_fillcolor", this.radar_fillcolor);
                    SetElemValue(elem_plugin, "radar_scale", this.radar_scale);
                    SetElemValue(elem_plugin, "radar_smoothing", this.radar_smoothing);
                    #endregion

                    #region ICON
                    SetElemValue(elem_plugin, "icon_init", this.icon_init);
                    SetElemValue(elem_plugin, "icon_visit", this.icon_visit);
                    SetElemValue(elem_plugin, "icon_onhover", this.icon_onhover);
                    SetElemValue(elem_plugin, "icon_active", this.icon_active);
                    #endregion

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

                    #endregion
                    if (action == "add")
                    {
                        try
                        {
                            MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/Maps");
                            xmldoc.SelectSingleNode("/Project/Maps").AppendChild(elem_plugin);
                            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.updatecustommap();window.location='List_Map.aspx?Tour_ID=" + _Tour_ID + "';</script>");
                            //Response.Redirect(MyApp.Components.NavUrl.GetUrl(2));
                        }
                        catch (Exception)
                        {
                            ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                        }
                    }
                    if (action == "edit")
                    {
                        try
                        {
                            MyApp.Components.XML.XmlDocument.WriteAllText(Server.MapPath(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID)), xmldoc.OuterXml);
                            //Response.Redirect(MyApp.Components.NavUrl.GetUrl(2));
                            ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>top.updatecustommapbyid(" + _ROW + ");window.location='List_Map.aspx?Tour_ID=" + _Tour_ID + "';</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>");
                }
            }
        }
    }
}
