demo模拟的是发送多封邮件过程中进度条的显示。其中图片设计的不太规范,所以js控制进度条移动的代码有点乱,这个大家可以替换成自己的,这里只是演示作用。
进度条动态增长的原理是:一个中间扣空的酒瓶子图片,这个图片下面放另外一张图片,移动下层图片以实现进度条增长效果。
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
System.Text;
using
System.Threading;
namespace
guagedemo

{

/**//// <summary>
/// guagedemo 的摘要说明。
/// </summary>
public class guagedemo : System.Web.UI.Page

{
public StringBuilder textpile=new StringBuilder(@"<table><tr><td background=images/titlebg.gif height=32 class=t2 width=100%> 发送邮件</td></tr><tr><td><table width=100% border=0 cellspacing=0 cellpadding=0><tr><td width=1 bgcolor=#ADDB52></td><td width=561 valign=top><table width=100% border=0 cellspacing=0 cellpadding=0 background=images/tablebg.gif><tr><td height=6 colspan=2></td></tr>");
private void Page_Load(object sender, System.EventArgs e)

{
// 在此处放置用户代码以初始化页面
objMailclass mail=new objMailclass();
mail.mail1=new objMail[3];
mail.mail1cx=3;
mail.mail2=new objMail[3];
mail.mail2cx=3;
mail.mail3=new objMail[3];
mail.mail3cx=3;
mail.mail1[0]=new objMail();
mail.mail1[0].strSubject="类别1邮件:邮件1";
mail.mail1[1]=new objMail();
mail.mail1[1].strSubject="类别1邮件:邮件2";
mail.mail1[2]=new objMail();
mail.mail1[2].strSubject="类别1邮件:邮件3";
mail.mail2[0]=new objMail();
mail.mail2[0].strSubject="类别2邮件:邮件1";
mail.mail2[1]=new objMail();
mail.mail2[1].strSubject="类别2邮件:邮件2";
mail.mail2[2]=new objMail();
mail.mail2[2].strSubject="类别2邮件:邮件3";
mail.mail3[0]=new objMail();
mail.mail3[0].strSubject="类别3邮件:邮件1";
mail.mail3[1]=new objMail();
mail.mail3[1].strSubject="类别3邮件:邮件2";
mail.mail3[2]=new objMail();
mail.mail3[2].strSubject="类别3邮件:邮件3";
intipagetop(mail);
}

输出进度条显示#region 输出进度条显示
private void process(string intSProcess,string intEProcess,string text)

{
Response.Write("<script language=javascript>itop="+intSProcess+";ileft=mydiv2.offsetLeft;function move(){if(mydiv2.style.top!='"+intEProcess+"px'){ileft=ileft-1;itop=itop-2;mydiv2.style.top=itop-2;mydiv2.style.left=ileft-1;if(haha.value=='0'){mydiv3.innertText='100%';}else{ttt=(0-itop-70)/4.14;if(ttt>100)ttt=100;aaa=ttt.toString();if(ttt==100){mydiv3.innertText='100%';}else{mydiv3.innerText=aaa.slice(0,aaa.lastIndexOf('.'))+'%';}}setTimeout(move,10)}}");
if(text!="")

{
string temp=text.Substring(5);
string temp2=text.Substring(0,5);
textpile.AppendFormat(@"<tr><td width=6% height=30 align=center><img src=images/titlelog.gif width=10 height=10 /></td><td width=94%><span class=t1>{1} </span> <span class=t2>{0}</span></td></tr>",temp,temp2);
Response.Write("mydiv4.innerHTML='<table width=563 border=0 cellspacing=0 cellpading=0>"+textpile.ToString()+"</table></td><td width=1 bgcolor=#ADDB52></td></tr></table></td></tr><tr><td height=5 background=images/bottomline.gif></td></tr></table></table>';");
}
Response.Write("move();</script>");
Response.Flush();
}
#endregion
private void intipagetop(objMailclass maill)

{

进度条初始化#region 进度条初始化
Response.Write(@"<html><head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
<title>无标题文档</title>
<style type=text/css>
<!--
.t1 {
font-family: "+"/"宋体/""+@";
font-size: 14px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-transform: none;
color: #639500;
text-decoration: none;
}
.t2 {
font-family: "+"/"宋体/""+@";
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-transform: none;
color: #000000;
text-decoration: none;
}
-->
</style>
</head><body style='overflow:-Scroll;overflow-y:hidden;overflow-x:hidden;'><input id=haha value=1 type=hidden>");
Response.Write("<div id='mydiv' style='position:absolute;width:500;height:600;top:-100px;left:-300px;z-index:100;'><img src=images/process_02.gif>");
Response.Write("</div>");
Response.Write("<div id='mydiv2' style='position:absolute;top:100px;left:50px;z-index:99;'><img src=images/process_03.gif>");
Response.Write("</div>");
Response.Write("<div id='mydiv4' style='position:absolute;top:72px;left:360px;z-index:101;'>");
Response.Write("</div>");
Response.Write("<div style='background:url(images/process_01.gif) no-repeat;position:absolute;width=96px;height=103px;top:72px;left:240px;z-index:101;'><table width=100% height=100% border=0 cellspacing=0 cellpading=0><tr><td height=100% width=100% valign=middle align='center'><div id='mydiv3' >12%</div></td></tr></table>");
Response.Write("</div>");
Response.Write("<script language=javascript>");
Response.Write(@"function StartShowWait(){mydiv.style.visible='visible';mydiv2.style.visible='visible';mydiv4.style.visible='visible';} ");
Response.Write("StartShowWait();</script>");
Response.Write(@"</body></html>");
Response.Flush();
#endregion
process("-70","-110","");
Thread.Sleep(200);
process("-110","-156","");
Thread.Sleep(200);

发送邮件#region 发送邮件

根据邮件数量,进行百分比动态分配#region 根据邮件数量,进行百分比动态分配
int cx=maill.mail1cx+maill.mail2cx+maill.mail3cx;
int temp1;
if(((330*maill.mail1cx)/cx)%2>0)
temp1=(330*maill.mail1cx)/cx+1;
else
temp1=(330*maill.mail1cx)/cx;
int temp2;
if(((330*(maill.mail1cx+maill.mail2cx))/cx)%2>0)
temp2=(330*(maill.mail1cx+maill.mail2cx))/cx+1;
else
temp2=(330*(maill.mail1cx+maill.mail2cx))/cx;
int bx1;
if(maill.mail1cx!=0)

{
if((temp1/maill.mail1cx)%2>0)

{
bx1=temp1/maill.mail1cx+1;
}
else

{
bx1=temp1/maill.mail1cx;
}
}
else

{
bx1=0;
}
int bx2;
if(maill.mail2cx!=0)

{
if(((temp2-temp1)/maill.mail2cx)%2>0)

{
bx2=(temp2-temp1)/maill.mail2cx+1;
}
else

{
bx2=(temp2-temp1)/maill.mail2cx;
}
}
else

{
bx2=0;
}
int bx3;
if(maill.mail3cx!=0)

{
if(((330-temp2)/maill.mail3cx)%2>0)

{
bx3=(330-temp2)/maill.mail3cx+1;
}
else

{
bx3=(330-temp2)/maill.mail3cx;
}
}
else

{
bx3=0;
}
#endregion
for(int i=0;i<maill.mail1cx;i++)

{
//此处延时半秒模拟发送邮件
Thread.Sleep(500);
process("-"+Convert.ToString(156+bx1*i),"-"+Convert.ToString(156+bx1*(i+1)),maill.mail1[i].strSubject);
}
for(int i=0;i<maill.mail2cx;i++)

{
//此处延时半秒模拟发送邮件
Thread.Sleep(500);
process("-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*(i+1)),maill.mail2[i].strSubject);
}
for(int i=0;i<maill.mail3cx;i++)

{
//此处延时半秒模拟发送邮件
Thread.Sleep(500);
process("-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*maill.mail2cx+bx3*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*maill.mail2cx+bx3*(i+1)),maill.mail3[i].strSubject);
}
textpile.Append("<tr><td height=30 colspan=2 align=center class=t1>发送成功!</td></tr><tr><td height=10 colspan=2 align=center class=t1></td></tr><tr><td height=40 colspan=2 align=center class=t1><img style='cursor:hand;' οnclick='javascript:location=location.href.toString();' src=images/returnbutton.gif width=71 height=25 /> <img src=images/closebutton.gif style='cursor:hand;' οnclick='javascript:window.close();' width=71 height=25 /></td></tr>");
Response.Write("<script language='javascript'>haha.value='0';mydiv3.innerText='100%';mydiv4.innerHTML=/""+textpile.ToString()+@"</table></td><td width=1 bgcolor=#ADDB52></td></tr></table></td></tr><tr><td height=5 background=images/bottomline.gif></td></tr></table>"+"/";setTimeout(finish,1200); function finish(){mydiv3.innerText='100%';}</script></body></html>");
Response.Flush();
Response.Close();
#endregion
}
public class objMail

{
public string strMail;
public string strSubject;
public string strMailType;
}
public class objMailclass

{
public objMail[] mail1;
public int mail1cx=0;
public objMail[] mail2;
public int mail2cx=0;
public objMail[] mail3;
public int mail3cx=0;
}

Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)

{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}
已经对前台如何控制图片进行了演示,这次就仅仅做功能模拟。别忘了打开页面的时候加上start参数,这样才可以启动查数程序。
前台代码:
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
html
>
<
head
>
<
title
>
ajaxguagedemo
</
title
>
<
meta
name
="GENERATOR"
Content
="Microsoft Visual Studio .NET 7.1"
>
<
meta
name
="CODE_LANGUAGE"
Content
="C#"
>
<
meta
name
=vs_defaultClientScript
content
="JavaScript"
>
<
meta
name
=vs_targetSchema
content
="http://schemas.microsoft.com/intellisense/ie5"
>

<
script
language
=javascript
>
function returnresponse()


{
urls="ajaxguagedemo.aspx?guage=1";
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlHttp.open("GET",urls,true);

xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)

{
temp=xmlHttp.responseText;
document.getElementById("ddf").innerText=temp;
if(temp!="100%")

{
returnresponse();
}
}
}
xmlHttp.send(urls);
}
</
script
>
</
head
>
<
body
MS_POSITIONING
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
input
type
=button
onclick
="returnresponse()"
value
=1111111
>
<
div
id
=ddf
></
div
>
</
form
>
</
body
>
</
html
>
后台代码如下:
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
System.Threading;
namespace
guagedemo

{

/**//// <summary>
/// ajaxguagedemo 的摘要说明。
/// </summary>
public class ajaxguagedemo : System.Web.UI.Page

{
static public int percent=0;//静态变量,记录百分比
private void Page_Load(object sender, System.EventArgs e)

{
// 在此处放置用户代码以初始化页面
if(Request.QueryString["start"]!=null)

{
startThread();//开始新进程处理查数程序
}
if(Request.QueryString["guage"]!=null)

{
ajaxResponse();//响应ajax,返回百分比
}
}
private void guage()

{
for(int i=0;i<100;i++)

{
percent++;
Thread.Sleep(500);
}
}
public void startThread()

{
System.Threading.Thread thread=new System.Threading.Thread(new System.Threading.ThreadStart(guage));
thread.Start();
}
private void ajaxResponse()

{
Response.Write(percent.ToString()+"%");
Response.Flush();
Response.Close();
}


Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)

{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()

{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}