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_Lensflare : MyApp.Web.UI.UserPage
    {
        public string _Scene_ID = "", _Tour_ID = "";
        public int _ROW = 0;
        override protected void AppInit()//程序基本信息初始化
        {
            try
            {
                _Tour_ID = Request.QueryString["Tour_ID"].Trim();
                _Scene_ID = Request.QueryString["Scene_ID"].Trim();
                _ROW = Convert.ToInt32(Request["ROW"]);
            }
            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 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.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
            XmlNode xmlnode = xmldoc.SelectSingleNode("krpano");
            XmlNodeList xmlnodelist = xmldoc.SelectNodes("/krpano/lensflare");
            try
            {
                if (_ROW == -1)
                {
                    foreach (XmlElement xmlelem in xmlnodelist)
                    {
                        xmlnode.RemoveChild(xmlelem);
                    }
                }
                else
                {
                    if (xmlnodelist.Count >= _ROW)
                    {
                        xmlnode.RemoveChild(xmlnodelist[_ROW - 1]);
                    }
                }
                MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);
                Response.Redirect(MyApp.Components.NavUrl.GetUrl(3));
            }
            catch (Exception)
            {
                ButPost.Enabled = false;
                ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('错误!!!');history.back()</script>");
                return;
            }
        }
        override protected void pl_add()
        {
            this.name.Focus();
        }
        override protected void pl_edit()
        {
            XmlDocument xmldoc;
            xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
            try
            {
                XmlElement elem_lensflare = (XmlElement)xmldoc.SelectNodes("/krpano/lensflare")[_ROW - 1];

                GetElemValue(elem_lensflare, "name", this.name,true);
                GetElemValue(elem_lensflare, "ath", this.ath,true);
                GetElemValue(elem_lensflare, "atv", this.atv,true);
                GetElemValue(elem_lensflare, "set", this.set,true);
                GetElemValue(elem_lensflare, "size", this.size,true);
                GetElemValue(elem_lensflare, "blind", this.blind,true);
                GetElemValue(elem_lensflare, "blindcurve", this.blindcurve,true);
                GetElemValue(elem_lensflare, "keep", this.keep,true);
                //GetElemValue(elem_lensflare, "T_Memo", this.T_Memo);
            }
            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_lensflare;
            if (Page.IsValid)
            {
                try
                {
                    if (action == "add")
                    {
                        xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
                        elem_lensflare = xmldoc.CreateElement("lensflare");
                    }
                    else
                        if (action == "edit")
                        {
                            xmldoc = MyApp.Components.KRPano.Scene.GetSceneXmlDoc(_Tour_ID, _Scene_ID);
                            elem_lensflare = (XmlElement)xmldoc.SelectNodes("/krpano/lensflare")[_ROW - 1];
                        }
                        else
                        {
                            return;
                        }
                    #region 赋值区域
                    SetElemValue(elem_lensflare, "name", this.name);
                    SetElemValue(elem_lensflare, "ath", this.ath);
                    SetElemValue(elem_lensflare, "atv", this.atv);
                    SetElemValue(elem_lensflare, "set", this.set);
                    SetElemValue(elem_lensflare, "size", this.size);
                    SetElemValue(elem_lensflare, "blind", this.blind);
                    SetElemValue(elem_lensflare, "blindcurve", this.blindcurve);
                    SetElemValue(elem_lensflare, "keep", this.keep);
                    //SetElemValue(elem_lensflare, "T_Memo", this.T_Memo);
                    #endregion
                    if (action == "add")
                    {
                        try
                        {
                            xmldoc.SelectSingleNode("/krpano").AppendChild(elem_lensflare);
                            MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);
                            Response.Redirect(MyApp.Components.NavUrl.GetUrl(3));
                        }
                        catch (Exception) { ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('Error!!!);history.back()</script>"); }
                    }
                    if (action == "edit")
                    {
                        try
                        {
                            MyApp.Components.XML.XmlDocument.WriteAllText(MyApp.Components.KRPano.Scene.GetSceneServerFilePath(_Tour_ID, _Scene_ID), xmldoc.OuterXml);
                            Response.Redirect(MyApp.Components.NavUrl.GetUrl(3));
                        }
                        catch (Exception) { ClientScript.RegisterStartupScript(this.GetType(), "refresh", "<script language=javascript>alert('Error!!!);history.back()</script>"); }
                    }


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