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.Publish
{
    [AjaxPro.AjaxNamespace("AjaxDemo")]
    public partial class index : MyApp.Web.UI.UserPage
    {
        public string _Tour_ID = "";

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

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

        }

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

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

            try
            {
                #region 
                XmlElement elem_Publish = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/Publish");
                GetElemValue(elem_Publish, "SwfXmlTF", this.SwfXmlTF, true);
                GetElemValue(elem_Publish, "SingleSwfTF", this.SingleSwfTF, true);
                GetElemValue(elem_Publish, "ExpiredDateTF", this.ExpiredDateTF, true);
                GetElemValue(elem_Publish, "ExpiredDate", this.ExpiredDate, true);
                GetElemValue(elem_Publish, "ExpiredURL", this.ExpiredURL, true);
                GetElemValue(elem_Publish, "DomainTF", this.DomainTF, true);
                GetElemValue(elem_Publish, "DomainList", this.DomainList, true);
                GetElemValue(elem_Publish, "ExportFolder", this.ExportFolder, true);
                GetElemValue(elem_Publish, "SceneXMLTF", this.SceneXMLTF, true);
                GetElemValue(elem_Publish, "OfflineTF", this.OfflineTF, true);

                #endregion
            }
            catch (Exception)
            {
                //ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
        }
        protected void ButPublish_Click(object sender, EventArgs e)
        {
            ButPost_Click(sender, e);
            Response.Redirect("../Export_TourXml.aspx?action=Publish&Tour_ID=" + _Tour_ID);
        }

        protected void ButPost_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();

            if (Page.IsValid)
            {
                try
                {
                    if (action == "edit")
                    {
                        xmldoc = MyApp.Components.XML.XmlDocument.Load(MyApp.Components.KRPano.Project.Get_Project_Name(_Tour_ID));
                    }
                    #region 赋值区域
                    #region 
                    XmlElement elem_Publish = (XmlElement)MyApp.Components.XML.XmlDocument.SelectSingleNode(ref xmldoc, "/Project/Publish");
                    SetElemValue(elem_Publish, "SwfXmlTF", this.SwfXmlTF);
                    SetElemValue(elem_Publish, "SingleSwfTF", this.SingleSwfTF);
                    SetElemValue(elem_Publish, "ExpiredDateTF", this.ExpiredDateTF);
                    SetElemValue(elem_Publish, "ExpiredDate", this.ExpiredDate);
                    SetElemValue(elem_Publish, "ExpiredURL", this.ExpiredURL);
                    SetElemValue(elem_Publish, "DomainTF", this.DomainTF);
                    SetElemValue(elem_Publish, "DomainList", this.DomainList);
                    SetElemValue(elem_Publish, "ExportFolder", this.ExportFolder);
                    SetElemValue(elem_Publish, "SceneXMLTF", this.SceneXMLTF);
                    SetElemValue(elem_Publish, "OfflineTF", this.OfflineTF);
                    #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>");
                }
            }
        }
    }
}