using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TopWinCMS.BLL;
using TopWinCMS.BLL.PageFactory;
using TopWinCMS.BLL.PageFactory.Pages;
using TopWinCMS.Common;
using TopWinCMS.Model;
using TopWinCMS.Model.Enum;
namespace TopWinCMS.WebUI.Admin.ContentRelease
{
    public partial class MakeJs : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RightsCheck.CheckWorkPower("R_3");
                if (Request["Action"] == "Static")
                {
                    this.Title = "生成静态脚本";

                    LB_Path.Text = "内容发布 → JS发布 → <a href='MakeJs.aspx?Action=Static'>生成静态脚本</a>";
                }
                else
                {
                    this.Title = "生成动态调用脚本";
                    LB_Path.Text = "内容发布 → JS发布 → <a href='MakeJs.aspx'>生成动态调用脚本</a>";
                }
            }
        }

        protected void BT_ALL_Click(object sender, EventArgs e)
        {

            if (Request["Action"] == "Static")
            {
                List<UDTInfo> list = new UDTManage().GetTag(3);
                FileIO fileio = new FileIO();
                foreach (UDTInfo model in list)
                {
                    if (model.JsPath.Length > 0)
                    {
                        fileio.WriterFile(HttpContext.Current.Server.MapPath(model.JsPath), model.Tag);
                    }
                }
            }
            else
            {
                List<UDTInfo> list = new UDTManage().GetTag(2);

                foreach (UDTInfo model in list)
                {
                    SaveJs(model.JsPath, model.Tag);
                }
            }
            MsgBox.Alert("生成完毕！", UpdatePanel1);
        }

        #region
        /// <summary>
        /// 保存Js文件
        /// </summary>
        /// <param name="Path"></param>
        /// <param name="Tag"></param>
        public void SaveJs(string Path, string Tag)
        {
            string strHTML = TopWinCMS.BLL.PageFactory.Pages.UDT.Transact(Tag);


            new FileIO().WriterFile(HttpContext.Current.Server.MapPath(Path), MyJavascript.HTML2JS(strHTML));

        }
        #endregion
    }
}