Asp.net中带进度条的批量静态页生成

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();
    }
}

时间: 2024-08-03 07:21:10

Asp.net中带进度条的批量静态页生成的相关文章

jQuery.Uploadify插件实现带进度条的批量上传功能_jquery

本文实例讲述了jQuery.Uploadify插件实现带进度条的批量上传功能.分享给大家供大家参考,具体如下: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="UpLoad.aspx.cs" Inherits="UploadifyDemo_UpLoad" %> <html xmlns="http://www.w3.org/1999/xh

在ASP.NET中显示进度条

asp.net|显示 对于加载时间比较长的ASP.NET页面,我们可以在客户端浏览器中显示进度条来显示页面正在装载.下面就是具体的实现过程: 新建项目,名字为WebPortal,在项目类型中选择Visual C#项目或者Visual Basic项目都可: 在模板类型中选择ASP.NET Web应用程序: 位置里输入:http://localhost/WebPortal: 添加新项:名字为ShowProgress的Web窗体. 在您的Web窗体ShowProgress.aspx上添加任何其他的We

ASP.NET实现带进度条的文件上传(多种风格)

文件上传 带进度条 多种风格 非常漂亮!

asp.net 中 FileUploadProgress 进度条在本地中可以使用 ,为何部署到服务器上以后运行时报500错误

问题描述 报错原因:是因为下面的代码去掉如上代码后程序可以正常使用,但是进度条就会出错,该如何解决呀???? 解决方案 解决方案二:对应的dll有没有部署上去?解决方案三:你用fidler或者浏览器的开发者工具查看一下response的信息,服务器500,应该只是响应头的信息,响应体还有详细信息.或许是你的上传的dll没部署好或者dll本身问题.解决方案四:这出错信息,太少,不好分析啊解决方案五:我的dll部署上去了呀解决方案六:各位高手提出的解决方案我会一个一个的去试不管如何都谢谢各位的指导解

Asp无组件上传带进度条(续)

上传|无组件 几个月前,写过一篇关于Asp无组件上传带进度条的Blog,当时主要分析了一下通过Web文件上传并在后台获取分析数据的实现原理.其中实现进度条的根本就是要实现分块获取数据,根据分块大小和块数记录已上传大小.还有一些具体的细节问题当时并没有说清楚: Q: 进度信息如何访问?A: 进度信息保存在Application中,每次上传时生成一个进度ID,根据这个进度ID可以检索Application中的当前上传进度信息. Q: 进度信息以什么形式保存在Application中?A: Asp太弱

带进度条的ASP无组件断点续传下载

无组件|下载 <%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> <%Option Explicit%> <% '================================== ''带进度条的ASP无组件断点续传下载 ''================================== '简介: '1)利用xmlhttp方式 '2)无组件 '3)异步方式获取,节省服务器资源 '4)服务器到服务器的文

asp.net单文件带进度条上传的解决方案_实用技巧

最近做项目中遇到很多问题,比如带进度条的文件上传,看了网上很多资料还没找到真正意义上的ASP.NET实现进度条上传(可能是我没找到),下面我来跟大家分享一下我实现的这个程序. 首先看下界面效果,当然你可以完全修改界面为你自己所用. 先解释一下这个程序,该程序采用了jquery框架,实现了小文件上传,不超过80Mb,可以在web.config文件中进行相应的配置,但是有个最大值,具体需要查看msdn.开发环境采用visual studio 2013 .net framework 4.5,运行的时候

asp.net文件上传带进度条实现案例(多种风格)_实用技巧

先饱饱眼福: 在之前的文章中也有类似带进度条文件传送的案例,大家可以翻阅之前的文章对知识点进行扩充. 部分代码: <%@ Page Language="C#" %> <%@ Register Assembly="MattBerseth.WebControls.AJAX" Namespace="MattBerseth.WebControls.AJAX.Progress" TagPrefix="mb" %>

ASP实现带进度条测试网速的代码程序

ASP实现带进度条的测试网速. 把下列代码存为xxx.ASP的文件,放在你的服务器上就可以直接运行了. <% Response.Expires = 0 Response.Expiresabsolute = Now() - 1 Response.AddHeader "pragma","no-cache" Response.AddHeader "cache-control","private" Response.CacheC