生成静态进度条

1.bar.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>进度条</title>
<script language="javascript" type="text/javascript">
function $(obj){
return document.getElementById(obj);
}
//i为当前执行到的记录,count为总数
//比如总共需要生成的静态数为100,那么现在执行到5%,那么进度条块进到5%的地方
function loadBar(i,count){
//var a = parseFloat(i*100/count);
var a = parseInt(i*100/count);
$("bar").style.width = a + "%";

if($("bar").style.width == "100%"){
$("bar").innerHTML = "完成";
}else{
$("bar").innerHTML = a + "%";


}

}
</script>
<style type="text/css">
body{
text-align:center;
font-size:12px;
}
.graph{
width:450px;
border:1px solid #F8B3D0;
height:25px;
margin:0 auto;
}
#bar{
display:block;
background:#FFE7F4;
float:left;
height:100%;
text-align:center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="graph">
<strong id="bar" style="width:1%;"></strong>
</div>
</div>

</form>

</body>
</html>

2.

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 System.IO;
using System.Threading;
using System.Net;
namespace DtCms.Web
{
    public partial class progressbar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public string ip="";
        protected void btnOk_Click(object sender, EventArgs e)
        {
            ip = lbip.Text;
            string sql = "select id from dt_article ";
            DataSet ds = DtCms.DBUtility.DbHelperOleDb.Query(sql);
            int count = ds.Tables[0].Rows.Count;



            for (int i = 0; i < count; i++)
            {
                if (i == 0)
                {


                    string strFileName = filestr(Server.MapPath("~/bar.html"));
                    Response.Write(strFileName);
                }
                string id=ds.Tables[0].Rows[i]["id"].ToString();
                string path = ip + "show.aspx?id="+id;

                get_html(path,Server.MapPath("~/article/show_"+id+".html"));
                Response.Write(path);

                Response.Write("<script>loadBar(" + (i + 1) + ","+count+");</script>");

                Thread.Sleep(1000);
            }
        }



        public string filestr(string path)
        {
            FileStream fs = new FileStream(path,FileMode.Open);
            StreamReader sr = new StreamReader(fs);
            string s = sr.ReadToEnd();
            sr.Dispose();
            return s;
        
        }




        public void get_html(string url, string path)
        {

            HttpWebRequest hwr = HttpWebRequest.Create(url) as HttpWebRequest;
            HttpWebResponse resp = hwr.GetResponse() as HttpWebResponse;
            Stream strea = resp.GetResponseStream();
            StreamReader sr = new StreamReader(strea);

            string s = sr.ReadToEnd();
            sr.Dispose();

            FileStream fs = new FileStream(path,FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            sw.Flush();
            sw.Write(s);
            sw.Dispose();
            fs.Dispose();


            

        
        }
    }
}

posted @   甜菜波波  阅读(241)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
点击右上角即可分享
微信分享提示