using System;
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;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace JuSNS.Web.system.ads
{
    public partial class index :JuSNS.UI.Page.ManagePage
    {
        protected string sort = "ads";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.menu.Text = showFileContet(Server.MapPath("~/js/ads/menu.js"));
                this.menu_top.Text = showFileContet(Server.MapPath("~/js/ads/menu_top.js"));
                this.body_top.Text = showFileContet(Server.MapPath("~/js/ads/body_top.js"));
                this.body.Text = showFileContet(Server.MapPath("~/js/ads/body.js"));
                this.top.Text = showFileContet(Server.MapPath("~/js/ads/top.js"));
                this.bottom.Text = showFileContet(Server.MapPath("~/js/ads/bottom.js"));
            }
        }

        public string showFileContet(string path)
        {
            string str_content = string.Empty;
            if (File.Exists(path))
            {
                try
                {
                    StreamReader Fso = new StreamReader(path);
                    str_content = Fso.ReadToEnd();
                    Fso.Close();
                    Fso.Dispose();
                }
                catch (IOException e)
                {
                    throw new IOException(e.ToString());
                }
            }
            else
            {
                
            }
            return str_content;
        }
      

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                saveFile(Server.MapPath("~/js/ads/menu.js"), this.menu.Text);
                saveFile(Server.MapPath("~/js/ads/menu_top.js"), this.menu_top.Text);
                saveFile(Server.MapPath("~/js/ads/body_top.js"), this.body_top.Text);
                saveFile(Server.MapPath("~/js/ads/body.js"), this.body.Text);
                saveFile(Server.MapPath("~/js/ads/top.js"), this.top.Text);
                saveFile(Server.MapPath("~/js/ads/bottom.js"), this.bottom.Text);
                Response.Redirect("index.aspx");
            }
        }

        public int saveFile(string path, string fileContent)
        {
            int result = 0;
            if (File.Exists(path))
            {
                try
                {
                    StreamWriter Fso = new StreamWriter(path);
                    Fso.WriteLine(fileContent);
                    Fso.Close();
                    Fso.Dispose();
                }
                catch (IOException e)
                {
                    throw new IOException(e.ToString());
                }
                result = 1;
            }
            else
            {
               
            }
            return result;
        }
    }
}
