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[0is 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(
110030-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();
    }

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值