进度条3
Pingfen_jindutiao.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pingfen_jindutiao.aspx.cs" Inherits="Pingfen_jindutiao" %>
<!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>
<meta http-equiv="Refresh"content="1;url=Pingfen.aspx"/>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Pingfen_jindutiao.aspx.cs" Inherits="Pingfen_jindutiao" %>
<!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>
<meta http-equiv="Refresh"content="1;url=Pingfen.aspx"/>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Pingfen_jindutiao : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DateTime startTime = System.DateTime.Now;
DateTime endTime = System.DateTime.Now;
// 根据 ProgressBar.htm 显示进度条界面
string templateFileName = Path.Combine(Server.MapPath("."), "Jindutiao.aspx");
StreamReader reader = new StreamReader(@templateFileName, System.Text.Encoding.GetEncoding("gb2312"));
string html = reader.ReadToEnd();
reader.Close();
Response.Write(html);
Response.Flush();
System.Threading.Thread.Sleep(1000);
string jsBlock;
// 处理完成
jsBlock = "<script>BeginTrans('缓冲');</script>";
Response.Write(jsBlock);
Response.Flush();
System.Threading.Thread.Sleep(1000);
// 根据处理任务处理情况更新进度条
for (int i = 1; i <= 100; i++)
{
System.Threading.Thread.Sleep(20);
jsBlock = "<script>SetPorgressBar('"+ i.ToString() + "','" + i.ToString() + "');</script>";
Response.Write(jsBlock);
Response.Flush();
}
// 处理完成
jsBlock = "<script>EndTrans('完成。');</script>";
Response.Write(jsBlock);
Response.Flush();
// 用时
endTime = DateTime.Now;
jsBlock = "<script>SetTimeInfo('用时" + GetTimeSpan(startTime, endTime) + "');</script>";
Response.Write(jsBlock);
Response.Flush();
}
protected string GetTimeSpan(DateTime startTime, DateTime endTime)
{
string timeSpan = string.Empty;
TimeSpan ts = endTime - startTime;
if (ts.Days > 0)
timeSpan += ts.Days.ToString() + "天";
if (ts.Hours > 0)
timeSpan += ts.Hours.ToString() + "小时";
if (ts.Minutes > 0)
timeSpan += ts.Minutes.ToString() + "分钟";
if (ts.Seconds > 0)
timeSpan += ts.Seconds.ToString() + "秒";
return timeSpan;
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class Pingfen_jindutiao : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DateTime startTime = System.DateTime.Now;
DateTime endTime = System.DateTime.Now;
// 根据 ProgressBar.htm 显示进度条界面
string templateFileName = Path.Combine(Server.MapPath("."), "Jindutiao.aspx");
StreamReader reader = new StreamReader(@templateFileName, System.Text.Encoding.GetEncoding("gb2312"));
string html = reader.ReadToEnd();
reader.Close();
Response.Write(html);
Response.Flush();
System.Threading.Thread.Sleep(1000);
string jsBlock;
// 处理完成
jsBlock = "<script>BeginTrans('缓冲');</script>";
Response.Write(jsBlock);
Response.Flush();
System.Threading.Thread.Sleep(1000);
// 根据处理任务处理情况更新进度条
for (int i = 1; i <= 100; i++)
{
System.Threading.Thread.Sleep(20);
jsBlock = "<script>SetPorgressBar('"+ i.ToString() + "','" + i.ToString() + "');</script>";
Response.Write(jsBlock);
Response.Flush();
}
// 处理完成
jsBlock = "<script>EndTrans('完成。');</script>";
Response.Write(jsBlock);
Response.Flush();
// 用时
endTime = DateTime.Now;
jsBlock = "<script>SetTimeInfo('用时" + GetTimeSpan(startTime, endTime) + "');</script>";
Response.Write(jsBlock);
Response.Flush();
}
protected string GetTimeSpan(DateTime startTime, DateTime endTime)
{
string timeSpan = string.Empty;
TimeSpan ts = endTime - startTime;
if (ts.Days > 0)
timeSpan += ts.Days.ToString() + "天";
if (ts.Hours > 0)
timeSpan += ts.Hours.ToString() + "小时";
if (ts.Minutes > 0)
timeSpan += ts.Minutes.ToString() + "分钟";
if (ts.Seconds > 0)
timeSpan += ts.Seconds.ToString() + "秒";
return timeSpan;
}
}
Jindutiao.aspx
Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Jindutiao.aspx.cs" Inherits="Jindutiao" %>
<!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">
//开始处理
function BeginTrans(msg)
{
WriteText("Msg1",msg);
}
//设置进度条进度
function SetPorgressBar(msg, pos)
{
ProgressBar.style.width= pos + "%";
WriteText("Msg1",msg + " 已完成" + pos + "%");
}
//处理结束
function EndTrans(msg)
{
if(msg=="")
WriteText("Msg1","完成。");
else
WriteText("Msg1",msg);
}
//设置时间信息
function SetTimeInfo(msg)
{
WriteText("Msg2",msg);
}
// 更新文本显示信息
function WriteText(id, str)
{
var strTag = '<font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><B>' + str + '</B></font>';
if (document.all) document.all[id].innerHTML = strTag;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table align="center" style="height:100%">
<tr style="height:45%"><td></td></tr>
<tr>
<td>
<div id="Msg1" style="height:16px;"><font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><b>正在加载</b></font></div>
<div id="ProgressBarSide" style="width:300px; color:Silver;border-width:1px; border-style:Solid;">
<div id="ProgressBar" align="center" style="height:20px; width:0%; background-color:#316AC5;"></div>
</div>
<div id="Msg2" style="height:16px;"><font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><b></b></font></div>
</td>
</tr>
<tr style="height:50%"><td></td></tr>
</table>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Jindutiao.aspx.cs" Inherits="Jindutiao" %>
<!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">
//开始处理
function BeginTrans(msg)
{
WriteText("Msg1",msg);
}
//设置进度条进度
function SetPorgressBar(msg, pos)
{
ProgressBar.style.width= pos + "%";
WriteText("Msg1",msg + " 已完成" + pos + "%");
}
//处理结束
function EndTrans(msg)
{
if(msg=="")
WriteText("Msg1","完成。");
else
WriteText("Msg1",msg);
}
//设置时间信息
function SetTimeInfo(msg)
{
WriteText("Msg2",msg);
}
// 更新文本显示信息
function WriteText(id, str)
{
var strTag = '<font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><B>' + str + '</B></font>';
if (document.all) document.all[id].innerHTML = strTag;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table align="center" style="height:100%">
<tr style="height:45%"><td></td></tr>
<tr>
<td>
<div id="Msg1" style="height:16px;"><font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><b>正在加载</b></font></div>
<div id="ProgressBarSide" style="width:300px; color:Silver;border-width:1px; border-style:Solid;">
<div id="ProgressBar" align="center" style="height:20px; width:0%; background-color:#316AC5;"></div>
</div>
<div id="Msg2" style="height:16px;"><font face="Verdana, Arial, Helvetica" size="2" color="#ea9b02"><b></b></font></div>
</td>
</tr>
<tr style="height:50%"><td></td></tr>
</table>
</form>
</body>
</html>