Asp.net中帶進度條的批量靜態頁產生

來源:互聯網
上載者:User
asp.net|靜態

Asp.net中帶進度條的批量靜態頁產生

namespace WDFROG.BLL
...{
    public delegate void CreateHtmlHandler(string fileName,string msg,int percent );
    public class News
    ...{
        private const string C_ERR_MSG = "You have no rights!";
        private const string C_CHK_NAME = "NewsManage";
        private static  string C_DIR = ConfigurationManager.AppSettings["NewsHtml"];
       
        public  event CreateHtmlHandler CompleteAFile;
        public static int Create(string AdminName,NewsInfo news)
        ...{
            IPermissionChecker chk = PermissionCheckerFactory.GetChecker(AdminName, C_CHK_NAME);
            chk.Check(C_ERR_MSG);
            news.HtmlFile =FileOperator.GetRandFileName(".html");
            int ret= NewsDAL.Create(news);
            CreateHtmlFile(news);
            return ret;
        }
        public static int DeleteByIdList(string AdminName,string IdList)
        ...{
            IPermissionChecker chk = PermissionCheckerFactory.GetChecker(AdminName, C_CHK_NAME);
            chk.Check(C_ERR_MSG);
            DataTable dt = SelectHtmlFileByIdList(IdList).Tables[0];
            string fileName = "";
            foreach (DataRow dr in dt.Rows)
            ...{
                if (!(dr[0] is DBNull))
                ...{
                    fileName = dr[0].ToString();
                    if(string.IsNullOrEmpty(fileName))
                    ...{
                      fileName = FileOperator.MapPath(C_DIR + fileName);
                      File.Delete(fileName);
                    }
                }
            }
            return NewsDAL.DeleteByIdList(IdList);

        }
        public static int DeleteByNewsID(string AdminName, int NewsID)
        ...{
            IPermissionChecker chk = PermissionCheckerFactory.GetChecker(AdminName, C_CHK_NAME);
            chk.Check(C_ERR_MSG);
            string fileName = SelectHtmlFile(NewsID);
            if (!string.IsNullOrEmpty(fileName))
                File.Delete(HttpContext.Current.Server.MapPath(C_DIR + fileName));
            return NewsDAL.DeleteByNewsID(NewsID);

        }
        public static DataSet QueryPage(int ClassID, string Title, int PageSize, int PageIndex)
        ...{
            return NewsDAL.QueryPage(ClassID,Title,PageSize,PageIndex);

        }
        public static int QueryPageCount(int ClassID, string Title)
        ...{
            return NewsDAL.QueryPageCount( ClassID, Title);

        }
        public static DataSet QueryTopNews(int ClassID, int Num, bool OrderType)
        ...{
            return NewsDAL.QueryTopNews(ClassID, Num, OrderType);

        }
        public static string SelectHtmlFile(int NewsID)
        ...{
            return NewsDAL.SelectHtmlFile(NewsID);
        }
        public static DataSet SelectHtmlFileByIdList(string IdList)
        ...{
            return NewsDAL.SelectHtmlFileByIdList(IdList);

        }
        public static int Update(string AdminName,NewsInfo news)
        ...{
            IPermissionChecker chk = PermissionCheckerFactory.GetChecker(AdminName, C_CHK_NAME);
            chk.Check(C_ERR_MSG);
            int ret= NewsDAL.Update(news);
            CreateHtmlFile(news);
            return ret;
        }
        public static DataSet QueryPageWithContent(int ClassID, string Title, int PageSize, int PageIndex)
        ...{
            return NewsDAL.QueryPageWithContent( ClassID, Title, PageSize, PageIndex);

        }
      //這裡
        public  void CreateHtmlFile(int startPage, int endPage,int pageSize,int ClassID)
        ...{
            int total = QueryPageCount(ClassID, string.Empty);
            total=(total % pageSize)==0 ? total / pageSize : (total /pageSize) +1;
            if (total < endPage)
                endPage = total;
            string fileName = "";
            string HtmlFile = "";
            int rTotal = (endPage - startPage + 1) * pageSize; //總記錄數
            for (int i = startPage; i <= endPage; i++)
            ...{
                DataTable dt = QueryPageWithContent(ClassID, string.Empty, pageSize, i).Tables[0];
                int curR = (i-startPage) * pageSize;
                foreach (DataRow dr in dt.Rows)
                ...{
                    if (!(dr["HtmlFile"] is DBNull))
                    ...{
                        HtmlFile = dr["HtmlFile"].ToString();
                        if (string.IsNullOrEmpty(HtmlFile))
                        ...{
                            HtmlFile = FileOperator.GetRandFileName(".html");
                        }
                        fileName = XMLData.GetFileNameByID(TemplateNode.News, (int)dr["TemplateID"]);
                        string tempContent = FileOperator.LoadFileWithCache(fileName);
                        tempContent = tempContent.Replace("{$NewsTitle$}", dr["title"].ToString());
                        tempContent = tempContent.Replace("{$NewsContent$}", dr["content"].ToString());
                        tempContent = tempContent.Replace("{$NewsAddTime$}", ((DateTime)dr["AddTime"]).ToString("yyyy-MM-dd"));
                        curR++;
                        FileOperator.SaveFile(FileOperator.MapPath(C_DIR + HtmlFile), tempContent);
                        if (CompleteAFile != null)
                            CompleteAFile(HtmlFile, string.Empty,(curR * 100)/rTotal);
                    }
                }
            }
        }
        private static void CreateHtmlFile(NewsInfo news)
        ...{
            string fileName = XMLData.GetFileNameByID(TemplateNode.News, news.TemplateID);
            string tempContent = FileOperator.LoadFileWithCache(fileName);
            tempContent = tempContent.Replace("{$NewsTitle$}", news.Title);
            tempContent = tempContent.Replace("{$NewsContent$}", news.Content);
            tempContent=tempContent.Replace("{$NewsAddTime$}",news.AddTime.ToString("yyyy-MM-dd"));
            FileOperator.SaveFile(HttpContext.Current.Server.MapPath(C_DIR + news.HtmlFile),tempContent);
        }
    }
} public partial class _Default : System.Web.UI.Page
...{
 
    protected void Page_Load(object sender, EventArgs e)
    ...{

    }
    protected void NavigateButton1_Click(object sender, EventArgs e)
    ...{
        WDFROG.BLL.News.DeleteByIdList(Admin.AdminName, "1,2,3,4,5,6");
    }
    protected void Button1_Click(object sender, EventArgs e)
    ...{
        WDFROG.BLL.News objNews = new News();
        objNews.CompleteAFile += new CreateHtmlHandler(CreateAFile);
        Response.Buffer = false;
        Response.Write("<div style="width: 100px; height: 25px;background-color:yellow;" Id="cp">_</div>" + Environment.NewLine);
        objNews.CreateHtmlFile(1, 100, 30, -1);
        Response.Write("<script>cp.style.visibility='hidden'</script>");
    }
    protected void CreateAFile(string fileName, string msg, int percent)
    ...{
        this.Response.Write(string.Format("<script> cp.innerHTML='Complete {0}%'; </script>", percent ));
        Response.Flush();
    }
}



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.