using System;
using System.Collections;
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.Common;
using TopWinCMS.BLL;
namespace TopWinCMS.WebUI.Admin.ContentRelease
{
    public partial class Progress : System.Web.UI.Page
    {
        string ModelID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RightsCheck.CheckWorkPower("R_1");
                switch (Request.QueryString["Action"])
                {
                    case "ContentPage":
                        this.Title = "内容页进度";
                        break;
                    case "ClassPage":
                        this.Title = "栏目页进度";
                        break;
                    case "SpecialPage":
                        this.Title = "专题页进度";
                        break;
                    case "MakeAll":
                        this.Title = "全部生成进度";
                        break;
                }
                ShowMessage();
                ShowProgress();
            }
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            ShowMessage();
            ShowProgress();
        }

        private void ShowProgress()
        {
            ModelID = Request["ModelID"];
            string js = null;
            string TatolID = Request["Action"] + "_" + ModelID + "_Tatol";
            string ProgressID = Request["Action"] + "_" + ModelID + "_Progress";
            switch (Request["Action"])
            {
                case "ContentPage":

                    if (MyCache.ReadCache(TatolID) != null)
                    {
                        js = string.Format("PercentChange({0},{1},'Bar1');", MyCache.ReadCache(ProgressID), MyCache.ReadCache(TatolID));
                    }
                    break;
                case "ClassPage":
                    if (MyCache.ReadCache(TatolID) != null)
                    {
                        js = string.Format("PercentChange({0},{1},'Bar1');", MyCache.ReadCache(ProgressID), MyCache.ReadCache(TatolID));
                    }
                    break;
                case "SpecialPage":
                    if (MyCache.ReadCache(TatolID) != null)
                    {
                        js = string.Format("PercentChange({0},{1},'Bar1');", MyCache.ReadCache(ProgressID), MyCache.ReadCache(TatolID));
                    }
                    break;
                case "MakeAll":
                    if (MyCache.ReadCache(TatolID) != null)
                    {
                        js = string.Format("PercentChange({0},{1},'Bar1');", MyCache.ReadCache(ProgressID), MyCache.ReadCache(TatolID));
                    }
                    break;
            }
            if (string.IsNullOrEmpty(js) == false)
            {
                System.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel1, typeof(UpdatePanel), "ProgressJS", js, true);
                //MyJavascript.RegJS(UpdatePanel1, js);
            }
        }

        private void ShowMessage()
        {
            string js = null;
            ModelID = Request["ModelID"];
            switch (Request.QueryString["Action"])
            {
                case "ContentPage":

                    if (MyCache.ReadCache("ContentPage_" + ModelID + "_Message") != null)
                    {
                        js = string.Format("Message('{0}');", MyCache.ReadCache("ContentPage_" + ModelID + "_Message"));
                    }
                    else
                    {
                        js = string.Format("Message('无任务启动');");
                    }
                    break;
                case "ClassPage":
                    if (MyCache.ReadCache("ClassPage_" + ModelID + "_Message") != null)
                    {
                        js = string.Format("Message('{0}');", MyCache.ReadCache("ClassPage_" + ModelID + "_Message"));
                    }
                    else
                    {
                        js = string.Format("Message('无任务启动');");
                    }
                    break;
                case "SpecialPage":
                    if (MyCache.ReadCache("SpecialPage_" + ModelID + "_Message") != null)
                    {
                        js = string.Format("Message('{0}');", MyCache.ReadCache("SpecialPage_" + ModelID + "_Message"));
                    }
                    else
                    {
                        js = string.Format("Message('无任务启动');");
                    }
                    break;
                case "MakeAll":
                    if (MyCache.ReadCache("MakeAll_" + ModelID + "_Message") != null)
                    {
                        js = string.Format("Message('{0}');", MyCache.ReadCache("MakeAll_" + ModelID + "_Message"));
                    }
                    else
                    {
                        js = string.Format("Message('无任务启动');");
                    }
                    break;
            }
            if (string.IsNullOrEmpty(js) == false)
                MyJavascript.RegJS(UpdatePanel1, js);
        }
    }
}