完成上级任务写的代码,还没整理优化,仅仅做个备份,hoho,冗余度很高,效率也低,见谅见谅……
简化后的页面及demo,见页面 http://www.cnblogs.com/suntears/archive/2007/04/24/724833.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 DataProviderCs.DataCommon;
using System.Text;
using System.Web.Mail;
using System.Threading;
namespace WebLkm.MANAGE.vipclub
{
/**//// <summary>
/// sub_confirm 的摘要说明。
/// </summary>
public class sub_confirm : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl frm;
protected System.Web.UI.WebControls.DropDownList searchtype;
protected System.Web.UI.WebControls.TextBox txtSj;
protected System.Web.UI.HtmlControls.HtmlForm frmPage;
protected System.Web.UI.HtmlControls.HtmlInputHidden subcx;
protected System.Web.UI.WebControls.ImageButton quicksubmit;
protected System.Web.UI.HtmlControls.HtmlGenericControl inprocess;
protected System.Web.UI.WebControls.ImageButton release;
变量初始化#region 变量初始化
public string mloginname = System.Configuration.ConfigurationSettings.AppSettings["mailloginname"];
public string mloginpwd = System.Configuration.ConfigurationSettings.AppSettings["mailloginpwd"];
public string mserver = System.Configuration.ConfigurationSettings.AppSettings["mailserver"];
public string vtype = System.Configuration.ConfigurationSettings.AppSettings["validatetype"];
public string from = System.Configuration.ConfigurationSettings.AppSettings["from"];
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>");
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
intipagetop();
if(subcx.Value=="2")
intipagebottom();
}
上部消息列表#region 上部消息列表
private void intipagetop()
{
StringBuilder html=new StringBuilder();
if(Request.QueryString["web_sub_id"]!=null)
{
string[] strweb_sub_id;
string temp=Request.QueryString["web_sub_id"].ToString();
strweb_sub_id=temp.Split(';');
html.Append(@"<table class='tab_bg' width='922' border='0' align='center' cellpadding='1' cellspacing='1'>
<tr class='tab_head'>
<td width=50%>标题</td>
<td width=15%>发布时间</td>
<td width=15%>类别</td>
<td width=20%>作者</td>
</tr>
");
OracleDb conn=new OracleDb();
for(int i=0;i<strweb_sub_id.Length;i++)
{
html.Append(gettr(conn,strweb_sub_id[i]));
}
html.Append("</table>");
frm.InnerHtml=html.ToString();
}
else
{
html.Append("<table class='tab_bg' width='922' border='0' align='center' cellpadding='1' cellspacing='1'><tr align=center><td width=100%>您没有选择要发布的消息</td></tr></table>");
}
}
private string gettr(OracleDb conn,string web_sub_id)
{
if(web_sub_id!="")
{
string strSql="select to_char(ws.PROMULGATE_DATE,'yyyy-mm-dd') PROMULGATE_DATE,ws.WEB_SUB_CN,decode(ws.WEB_SUB_TYPE,'1','促销信息','2','栏目订阅','3','网站消息通知',0) WEB_SUB_TYPE,ws.WRITER from web_sub ws where ws.status='0' and ws.web_sub_id='"+web_sub_id+"'";
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(strSql);
string temp=String.Format(@"<tr class='tab_td' onMouseOver='invertmenu()' onMouseOut='resumemenu()'><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",dt.Rows[0]["web_sub_cn"].ToString(),dt.Rows[0]["PROMULGATE_DATE"].ToString(),dt.Rows[0]["WEB_SUB_TYPE"].ToString(),dt.Rows[0]["WRITER"].ToString());
return temp;
}
else
{
return "";
}
}
#endregion
下部会员列表#region 下部会员列表
private void intipagebottom()
{
StringBuilder html=new StringBuilder();
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(getcrmsql());
conn.CloseDb();
html.Append(@"<table class='tab_bg' width='922' border='0' align='center' cellpadding='1' cellspacing='1'>
<tr class='tab_head'>
<td width=15% align=center onclick='selectall()'><font color=#FF0000><div id=hea style='cursor:hand;'>点击选择全部</div></font><input type=hidden id=cxs name=cxs value=1></td>
<td>会员帐号</td>
<td>会员卡号</td>
<td>姓名</td>
<td>订阅电子报</td>
<td>订阅促销信息</td>
<td>订阅栏目订阅</td>
<td>订阅网站消息通知</td>
</tr>
");
if(dt.Rows.Count>0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
html.AppendFormat(@"
<span onclick='changecheck("+"\"obj{0}\""+@")'><tr class='tab_td' onMouseOver='invertmenu()' onMouseOut='resumemenu()'>
<td align=center onclick='window.event.cancelBubble=true;'><input type=checkbox name=cks id=obj{0} value={0}></td>
<td align='center'>{1}</td>
<td align='center'>{2}</td>
<td align='center'>{3}</td>
<td align='center'>{4}</td>
<td align='center'>{5}</td>
<td align='center'>{6}</td>
<td align='center'>{7}</td>
</tr>
</span>
",dt.Rows[i]["crm_id"].ToString(),dt.Rows[i]["login_name"].ToString(),dt.Rows[i]["card_no"].ToString(),dt.Rows[i]["crm_cn"].ToString(),dt.Rows[i]["flag1"].ToString(),dt.Rows[i]["web_crmsub_type1"].ToString(),dt.Rows[i]["web_crmsub_type2"].ToString(),dt.Rows[i]["web_crmsub_type3"].ToString());
}
}
else
{
html.Append("暂无数据");
}
html.Append(@"</table>");
inprocess.InnerHtml=html.ToString();
}
private string getcrmsql()
{
string strSql="select temp.crm_id,temp.crm_cn,temp.login_name,temp.card_no,temp.flag1,temp.web_crmsub_type1,temp.web_crmsub_type2,temp.web_crmsub_type3 from (Select c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'0','是','1','否','会员未选择(默认:是)') flag1,decode(wc.web_crmsub_type1,'1','是','0','否','会员未选择(默认:是)') web_crmsub_type1,decode(wc.web_crmsub_type2,'1','是','0','否','会员未选择(默认:是)') web_crmsub_type2,decode(wc.web_crmsub_type3,'1','是','0','否','会员未选择(默认:是)') web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0') temp";
if(searchtype.SelectedValue!="0")
{
strSql+=" where temp."+searchtype.SelectedValue+" like '%"+txtSj.Text+"%'";
}
return strSql;
}
#endregion
快速发布按钮#region 快速发布按钮
private void quicksubmit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Request.QueryString["web_sub_id"]!=null)
{
进度条初始化#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);
初始化邮件#region 初始化邮件
string[] strweb_sub_id;
string temp=Request.QueryString["web_sub_id"].ToString();
strweb_sub_id=temp.Split(';');
objMailclass maill=new objMailclass();
maill.mail1=new objMail[strweb_sub_id.Length];
maill.mail2=new objMail[strweb_sub_id.Length];
maill.mail3=new objMail[strweb_sub_id.Length];
for(int i=0;i<strweb_sub_id.Length;i++)
{
objMail objtemp=new objMail();
objtemp=getmail(strweb_sub_id[i]);
if(objtemp.strMailType=="1")
{
maill.mail1[maill.mail1cx]=objtemp;
maill.mail1cx++;
}
else if(objtemp.strMailType=="2")
{
maill.mail2[maill.mail2cx]=objtemp;
maill.mail2cx++;
}
else if(objtemp.strMailType=="3")
{
maill.mail3[maill.mail3cx]=objtemp;
maill.mail3cx++;
}
}
#endregion
process("-110","-156","");
Thread.Sleep(200);
//初始化用户列表DataTable
DataTable dt=new DataTable();
dt=getuser();
if(dt.Rows.Count>0)
{
初始化用户列表#region 初始化用户列表
string sentto1="";
string sentto2="";
string sentto3="";
for(int i=0;i<dt.Rows.Count;i++)
{
if(dt.Rows[i]["flag1"].ToString()=="0")
{
if(dt.Rows[i]["web_crmsub_type1"].ToString()=="1")
{
sentto1=sentto1+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type2"].ToString()=="1")
{
sentto2=sentto2+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type3"].ToString()=="1")
{
sentto3=sentto3+dt.Rows[i]["email"].ToString()+";";
}
}
}
#endregion
发送邮件#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++)
{
sendmail(maill.mail1[i],sentto1);
process("-"+Convert.ToString(156+bx1*i),"-"+Convert.ToString(156+bx1*(i+1)),maill.mail1[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail2cx;i++)
{
sendmail(maill.mail2[i],sentto2);
process("-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*(i+1)),maill.mail2[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail3cx;i++)
{
sendmail(maill.mail3[i],sentto3);
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.mail2[i].strSubject);
Thread.Sleep(2);
}
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;' onclick='javascript:location=location.href.toString();' src=../images/returnbutton.gif width=71 height=25 /> <img src=../images/closebutton.gif style='cursor:hand;' onclick='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
}
else
{
Response.Write("<script language=javascript>alert('没有可以发送邮件的用户');location=location.href.toString();</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('您还没有选择要发送的消息');location=location.href.toString();</script>");
}
}
发送objMail类#region 发送objMail类
private void sendmail(objMail objTemp,string sentto)
{
MailMessage objMail=new MailMessage();
objMail.Bcc=sentto;
objMail.To=from;
objMail.From=from;
objMail.BodyFormat=MailFormat.Html;
objMail.Subject=objTemp.strSubject;
objMail.Body=objTemp.strMail;
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", vtype);
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mloginname);
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mloginpwd);
SmtpMail.SmtpServer=mserver;
if(objMail.To != null && objMail.From!= null && SmtpMail.SmtpServer != null)
{
SmtpMail.Send(objMail);
}
else
{
Response.Write("<script language=javascript>alert('邮件服务器正在维护,无法发送邮件');</script>");
}
}
#endregion
获取订阅信息的用户列表#region 获取订阅信息的用户列表
private DataTable getuser()
{
string strSql=@"Select c.email,c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'','1',null,'1',c.flag1) flag1,decode(wc.web_crmsub_type1,'','1',null,'1',wc.web_crmsub_type1) web_crmsub_type1,decode(wc.web_crmsub_type2,'','1',null,'1',wc.web_crmsub_type2) web_crmsub_type2,decode(wc.web_crmsub_type3,'','1',null,'1',wc.web_crmsub_type3) web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0'";
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(strSql);
conn.CloseDb();
return dt;
}
#endregion
根据web_sub_id获取邮件class#region 根据web_sub_id获取邮件class
private objMail getmail(string web_sub_id)
{
objMail mail=new objMail();
string strSql="select ws.* from web_sub ws where ws.status='0' and ws.web_sub_id='"+web_sub_id+"'";
OracleDb conn=new OracleDb();
conn.DataReader=conn.ExecuteReader(strSql);
if(conn.DataReader.Read())
{
mail.strMailType=conn.DataReader["web_sub_type"].ToString();
string strtemp=conn.DataReader["CONTENT"].ToString();
strtemp=strtemp.Replace("src=\"/","src=\"http://www.liquormart.cn/");
strtemp=strtemp.Replace("HREF=\"/","HREF=\"http://www.liquormart.cn/");
mail.strMail=strtemp;
if(conn.DataReader["WEB_SUB_TYPE"].ToString()=="1")
{
mail.strSubject="利客满促销信息:"+conn.DataReader["WEB_SUB_CN"].ToString();
}
else if(conn.DataReader["WEB_SUB_TYPE"].ToString()=="2")
{
mail.strSubject="利客满栏目订阅:"+conn.DataReader["WEB_SUB_CN"].ToString();
}
else if(conn.DataReader["WEB_SUB_TYPE"].ToString()=="3")
{
mail.strSubject="利客满消息通知:"+conn.DataReader["WEB_SUB_CN"].ToString();
}
else
{
conn.DataReader.Dispose();
conn.CloseDb();
Response.Write("<script language=javascript>alert('数据库数据出错!请记录错误信息:"+web_sub_id+"');location='../../login.aspx';</script>");
}
}
conn.DataReader.Dispose();
conn.CloseDb();
return mail;
}
#endregion
#endregion
输出进度条显示#region 输出进度条显示
private void process(string intSProcess,string intEProcess,string text)
{
备份#region 备份
// Response.Write("<script language=javascript>function move(){for(i="+intSProcess+";i<"+intEProcess+";i++){mydiv2.style.top=100-i*2;mydiv2.style.left=0-i;setTimeout(StartShowWait,1000);}}");
#endregion
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(8);
string temp2=text.Substring(0,8);
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
指定会员发布按钮#region 指定会员发布按钮
private void release_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Request.QueryString["web_sub_id"]!=null)
{
进度条初始化#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);
初始化邮件#region 初始化邮件
string[] strweb_sub_id;
string temp=Request.QueryString["web_sub_id"].ToString();
strweb_sub_id=temp.Split(';');
objMailclass maill=new objMailclass();
maill.mail1=new objMail[strweb_sub_id.Length];
maill.mail2=new objMail[strweb_sub_id.Length];
maill.mail3=new objMail[strweb_sub_id.Length];
for(int i=0;i<strweb_sub_id.Length;i++)
{
objMail objtemp=new objMail();
objtemp=getmail(strweb_sub_id[i]);
if(objtemp.strMailType=="1")
{
maill.mail1[maill.mail1cx]=objtemp;
maill.mail1cx++;
}
else if(objtemp.strMailType=="2")
{
maill.mail2[maill.mail2cx]=objtemp;
maill.mail2cx++;
}
else if(objtemp.strMailType=="3")
{
maill.mail3[maill.mail3cx]=objtemp;
maill.mail3cx++;
}
}
#endregion
process("-110","-156","");
Thread.Sleep(200);
//获得用户DataTable
DataTable dt=new DataTable();
dt=getappointuser();
if(dt.Rows.Count>0)
{
初始化用户列表#region 初始化用户列表
string sentto1="";
string sentto2="";
string sentto3="";
for(int i=0;i<dt.Rows.Count;i++)
{
if(dt.Rows[i]["flag1"].ToString()=="0")
{
if(dt.Rows[i]["web_crmsub_type1"].ToString()=="1")
{
sentto1=sentto1+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type2"].ToString()=="1")
{
sentto2=sentto2+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type3"].ToString()=="1")
{
sentto3=sentto3+dt.Rows[i]["email"].ToString()+";";
}
}
}
#endregion
发送邮件#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++)
{
sendmail(maill.mail1[i],sentto1);
process("-"+Convert.ToString(156+bx1*i),"-"+Convert.ToString(156+bx1*(i+1)),maill.mail1[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail2cx;i++)
{
sendmail(maill.mail2[i],sentto2);
process("-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*(i+1)),maill.mail2[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail3cx;i++)
{
sendmail(maill.mail3[i],sentto3);
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);
Thread.Sleep(2);
}
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;' onclick='javascript:location=location.href.toString();' src=../images/returnbutton.gif width=71 height=25 /> <img src=../images/closebutton.gif style='cursor:hand;' onclick='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
}
else
{
Response.Write("<script language=javascript>alert('没有可以发送邮件的用户');location=location.href.toString();</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('您还没有选择要发送的消息');location=location.href.toString();</script>");
}
}
#endregion
获取指定用户的用户列表#region 获取指定用户的用户列表
private DataTable getappointuser()
{
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt.Columns.Add("email");
dt.Columns.Add("crm_id");
dt.Columns.Add("crm_cn");
dt.Columns.Add("login_name");
dt.Columns.Add("card_no");
dt.Columns.Add("flag1");
dt.Columns.Add("web_crmsub_type1");
dt.Columns.Add("web_crmsub_type2");
dt.Columns.Add("web_crmsub_type3");
string[] temp=Request.Form["cks"].ToString().Split(',');
for(int i=0;i<temp.Length;i++)
{
DataRow dr=dt.NewRow();
string strSql=@"Select c.email,c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'','1',null,'1',c.flag1) flag1,decode(wc.web_crmsub_type1,'','1',null,'1',wc.web_crmsub_type1) web_crmsub_type1,decode(wc.web_crmsub_type2,'','1',null,'1',wc.web_crmsub_type2) web_crmsub_type2,decode(wc.web_crmsub_type3,'','1',null,'1',wc.web_crmsub_type3) web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0' and c.crm_id='"+temp[i]+"'";
conn.DataReader=conn.ExecuteReader(strSql);
if(conn.DataReader.Read())
{
dr["email"]=conn.DataReader["email"].ToString();
dr["crm_id"]=conn.DataReader["crm_id"].ToString();
dr["crm_cn"]=conn.DataReader["crm_cn"].ToString();
dr["login_name"]=conn.DataReader["login_name"].ToString();
dr["card_no"]=conn.DataReader["card_no"].ToString();
dr["flag1"]=conn.DataReader["flag1"].ToString();
dr["web_crmsub_type1"]=conn.DataReader["web_crmsub_type1"].ToString();
dr["web_crmsub_type2"]=conn.DataReader["web_crmsub_type2"].ToString();
dr["web_crmsub_type3"]=conn.DataReader["web_crmsub_type3"].ToString();
dt.Rows.Add(dr);
}
conn.DataReader.Dispose();
}
// string strSql=@"Select c.email,c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'8','是','1') flag1,decode(wc.web_crmsub_type1,'8','是','1') web_crmsub_type1,decode(wc.web_crmsub_type2,'8','是','1') web_crmsub_type2,decode(wc.web_crmsub_type3,'8','是','1') web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0'";
// dt=conn.GetDtRecorder(strSql);
conn.CloseDb();
return dt;
}
#endregion
邮件结构类#region 邮件结构类
public class objMail
{
// public void add(objMail mail)
// {
// strMail+=mail.strMail;
// strSubject+=mail.strSubject;
// }
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;
}
#endregion
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.release.Click += new System.Web.UI.ImageClickEventHandler(this.release_Click);
this.quicksubmit.Click += new System.Web.UI.ImageClickEventHandler(this.quicksubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
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 DataProviderCs.DataCommon;
using System.Text;
using System.Web.Mail;
using System.Threading;
namespace WebLkm.MANAGE.vipclub
{
/**//// <summary>
/// sub_confirm 的摘要说明。
/// </summary>
public class sub_confirm : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlGenericControl frm;
protected System.Web.UI.WebControls.DropDownList searchtype;
protected System.Web.UI.WebControls.TextBox txtSj;
protected System.Web.UI.HtmlControls.HtmlForm frmPage;
protected System.Web.UI.HtmlControls.HtmlInputHidden subcx;
protected System.Web.UI.WebControls.ImageButton quicksubmit;
protected System.Web.UI.HtmlControls.HtmlGenericControl inprocess;
protected System.Web.UI.WebControls.ImageButton release;
变量初始化#region 变量初始化
public string mloginname = System.Configuration.ConfigurationSettings.AppSettings["mailloginname"];
public string mloginpwd = System.Configuration.ConfigurationSettings.AppSettings["mailloginpwd"];
public string mserver = System.Configuration.ConfigurationSettings.AppSettings["mailserver"];
public string vtype = System.Configuration.ConfigurationSettings.AppSettings["validatetype"];
public string from = System.Configuration.ConfigurationSettings.AppSettings["from"];
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>");
#endregion
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
intipagetop();
if(subcx.Value=="2")
intipagebottom();
}
上部消息列表#region 上部消息列表
private void intipagetop()
{
StringBuilder html=new StringBuilder();
if(Request.QueryString["web_sub_id"]!=null)
{
string[] strweb_sub_id;
string temp=Request.QueryString["web_sub_id"].ToString();
strweb_sub_id=temp.Split(';');
html.Append(@"<table class='tab_bg' width='922' border='0' align='center' cellpadding='1' cellspacing='1'>
<tr class='tab_head'>
<td width=50%>标题</td>
<td width=15%>发布时间</td>
<td width=15%>类别</td>
<td width=20%>作者</td>
</tr>
");
OracleDb conn=new OracleDb();
for(int i=0;i<strweb_sub_id.Length;i++)
{
html.Append(gettr(conn,strweb_sub_id[i]));
}
html.Append("</table>");
frm.InnerHtml=html.ToString();
}
else
{
html.Append("<table class='tab_bg' width='922' border='0' align='center' cellpadding='1' cellspacing='1'><tr align=center><td width=100%>您没有选择要发布的消息</td></tr></table>");
}
}
private string gettr(OracleDb conn,string web_sub_id)
{
if(web_sub_id!="")
{
string strSql="select to_char(ws.PROMULGATE_DATE,'yyyy-mm-dd') PROMULGATE_DATE,ws.WEB_SUB_CN,decode(ws.WEB_SUB_TYPE,'1','促销信息','2','栏目订阅','3','网站消息通知',0) WEB_SUB_TYPE,ws.WRITER from web_sub ws where ws.status='0' and ws.web_sub_id='"+web_sub_id+"'";
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(strSql);
string temp=String.Format(@"<tr class='tab_td' onMouseOver='invertmenu()' onMouseOut='resumemenu()'><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td></tr>",dt.Rows[0]["web_sub_cn"].ToString(),dt.Rows[0]["PROMULGATE_DATE"].ToString(),dt.Rows[0]["WEB_SUB_TYPE"].ToString(),dt.Rows[0]["WRITER"].ToString());
return temp;
}
else
{
return "";
}
}
#endregion
下部会员列表#region 下部会员列表
private void intipagebottom()
{
StringBuilder html=new StringBuilder();
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(getcrmsql());
conn.CloseDb();
html.Append(@"<table class='tab_bg' width='922' border='0' align='center' cellpadding='1' cellspacing='1'>
<tr class='tab_head'>
<td width=15% align=center onclick='selectall()'><font color=#FF0000><div id=hea style='cursor:hand;'>点击选择全部</div></font><input type=hidden id=cxs name=cxs value=1></td>
<td>会员帐号</td>
<td>会员卡号</td>
<td>姓名</td>
<td>订阅电子报</td>
<td>订阅促销信息</td>
<td>订阅栏目订阅</td>
<td>订阅网站消息通知</td>
</tr>
");
if(dt.Rows.Count>0)
{
for(int i=0;i<dt.Rows.Count;i++)
{
html.AppendFormat(@"
<span onclick='changecheck("+"\"obj{0}\""+@")'><tr class='tab_td' onMouseOver='invertmenu()' onMouseOut='resumemenu()'>
<td align=center onclick='window.event.cancelBubble=true;'><input type=checkbox name=cks id=obj{0} value={0}></td>
<td align='center'>{1}</td>
<td align='center'>{2}</td>
<td align='center'>{3}</td>
<td align='center'>{4}</td>
<td align='center'>{5}</td>
<td align='center'>{6}</td>
<td align='center'>{7}</td>
</tr>
</span>
",dt.Rows[i]["crm_id"].ToString(),dt.Rows[i]["login_name"].ToString(),dt.Rows[i]["card_no"].ToString(),dt.Rows[i]["crm_cn"].ToString(),dt.Rows[i]["flag1"].ToString(),dt.Rows[i]["web_crmsub_type1"].ToString(),dt.Rows[i]["web_crmsub_type2"].ToString(),dt.Rows[i]["web_crmsub_type3"].ToString());
}
}
else
{
html.Append("暂无数据");
}
html.Append(@"</table>");
inprocess.InnerHtml=html.ToString();
}
private string getcrmsql()
{
string strSql="select temp.crm_id,temp.crm_cn,temp.login_name,temp.card_no,temp.flag1,temp.web_crmsub_type1,temp.web_crmsub_type2,temp.web_crmsub_type3 from (Select c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'0','是','1','否','会员未选择(默认:是)') flag1,decode(wc.web_crmsub_type1,'1','是','0','否','会员未选择(默认:是)') web_crmsub_type1,decode(wc.web_crmsub_type2,'1','是','0','否','会员未选择(默认:是)') web_crmsub_type2,decode(wc.web_crmsub_type3,'1','是','0','否','会员未选择(默认:是)') web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0') temp";
if(searchtype.SelectedValue!="0")
{
strSql+=" where temp."+searchtype.SelectedValue+" like '%"+txtSj.Text+"%'";
}
return strSql;
}
#endregion
快速发布按钮#region 快速发布按钮
private void quicksubmit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Request.QueryString["web_sub_id"]!=null)
{
进度条初始化#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);
初始化邮件#region 初始化邮件
string[] strweb_sub_id;
string temp=Request.QueryString["web_sub_id"].ToString();
strweb_sub_id=temp.Split(';');
objMailclass maill=new objMailclass();
maill.mail1=new objMail[strweb_sub_id.Length];
maill.mail2=new objMail[strweb_sub_id.Length];
maill.mail3=new objMail[strweb_sub_id.Length];
for(int i=0;i<strweb_sub_id.Length;i++)
{
objMail objtemp=new objMail();
objtemp=getmail(strweb_sub_id[i]);
if(objtemp.strMailType=="1")
{
maill.mail1[maill.mail1cx]=objtemp;
maill.mail1cx++;
}
else if(objtemp.strMailType=="2")
{
maill.mail2[maill.mail2cx]=objtemp;
maill.mail2cx++;
}
else if(objtemp.strMailType=="3")
{
maill.mail3[maill.mail3cx]=objtemp;
maill.mail3cx++;
}
}
#endregion
process("-110","-156","");
Thread.Sleep(200);
//初始化用户列表DataTable
DataTable dt=new DataTable();
dt=getuser();
if(dt.Rows.Count>0)
{
初始化用户列表#region 初始化用户列表
string sentto1="";
string sentto2="";
string sentto3="";
for(int i=0;i<dt.Rows.Count;i++)
{
if(dt.Rows[i]["flag1"].ToString()=="0")
{
if(dt.Rows[i]["web_crmsub_type1"].ToString()=="1")
{
sentto1=sentto1+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type2"].ToString()=="1")
{
sentto2=sentto2+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type3"].ToString()=="1")
{
sentto3=sentto3+dt.Rows[i]["email"].ToString()+";";
}
}
}
#endregion
发送邮件#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++)
{
sendmail(maill.mail1[i],sentto1);
process("-"+Convert.ToString(156+bx1*i),"-"+Convert.ToString(156+bx1*(i+1)),maill.mail1[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail2cx;i++)
{
sendmail(maill.mail2[i],sentto2);
process("-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*(i+1)),maill.mail2[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail3cx;i++)
{
sendmail(maill.mail3[i],sentto3);
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.mail2[i].strSubject);
Thread.Sleep(2);
}
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;' onclick='javascript:location=location.href.toString();' src=../images/returnbutton.gif width=71 height=25 /> <img src=../images/closebutton.gif style='cursor:hand;' onclick='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
}
else
{
Response.Write("<script language=javascript>alert('没有可以发送邮件的用户');location=location.href.toString();</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('您还没有选择要发送的消息');location=location.href.toString();</script>");
}
}
发送objMail类#region 发送objMail类
private void sendmail(objMail objTemp,string sentto)
{
MailMessage objMail=new MailMessage();
objMail.Bcc=sentto;
objMail.To=from;
objMail.From=from;
objMail.BodyFormat=MailFormat.Html;
objMail.Subject=objTemp.strSubject;
objMail.Body=objTemp.strMail;
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", vtype);
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", mloginname);
objMail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", mloginpwd);
SmtpMail.SmtpServer=mserver;
if(objMail.To != null && objMail.From!= null && SmtpMail.SmtpServer != null)
{
SmtpMail.Send(objMail);
}
else
{
Response.Write("<script language=javascript>alert('邮件服务器正在维护,无法发送邮件');</script>");
}
}
#endregion
获取订阅信息的用户列表#region 获取订阅信息的用户列表
private DataTable getuser()
{
string strSql=@"Select c.email,c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'','1',null,'1',c.flag1) flag1,decode(wc.web_crmsub_type1,'','1',null,'1',wc.web_crmsub_type1) web_crmsub_type1,decode(wc.web_crmsub_type2,'','1',null,'1',wc.web_crmsub_type2) web_crmsub_type2,decode(wc.web_crmsub_type3,'','1',null,'1',wc.web_crmsub_type3) web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0'";
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt=conn.GetDtRecorder(strSql);
conn.CloseDb();
return dt;
}
#endregion
根据web_sub_id获取邮件class#region 根据web_sub_id获取邮件class
private objMail getmail(string web_sub_id)
{
objMail mail=new objMail();
string strSql="select ws.* from web_sub ws where ws.status='0' and ws.web_sub_id='"+web_sub_id+"'";
OracleDb conn=new OracleDb();
conn.DataReader=conn.ExecuteReader(strSql);
if(conn.DataReader.Read())
{
mail.strMailType=conn.DataReader["web_sub_type"].ToString();
string strtemp=conn.DataReader["CONTENT"].ToString();
strtemp=strtemp.Replace("src=\"/","src=\"http://www.liquormart.cn/");
strtemp=strtemp.Replace("HREF=\"/","HREF=\"http://www.liquormart.cn/");
mail.strMail=strtemp;
if(conn.DataReader["WEB_SUB_TYPE"].ToString()=="1")
{
mail.strSubject="利客满促销信息:"+conn.DataReader["WEB_SUB_CN"].ToString();
}
else if(conn.DataReader["WEB_SUB_TYPE"].ToString()=="2")
{
mail.strSubject="利客满栏目订阅:"+conn.DataReader["WEB_SUB_CN"].ToString();
}
else if(conn.DataReader["WEB_SUB_TYPE"].ToString()=="3")
{
mail.strSubject="利客满消息通知:"+conn.DataReader["WEB_SUB_CN"].ToString();
}
else
{
conn.DataReader.Dispose();
conn.CloseDb();
Response.Write("<script language=javascript>alert('数据库数据出错!请记录错误信息:"+web_sub_id+"');location='../../login.aspx';</script>");
}
}
conn.DataReader.Dispose();
conn.CloseDb();
return mail;
}
#endregion
#endregion
输出进度条显示#region 输出进度条显示
private void process(string intSProcess,string intEProcess,string text)
{
备份#region 备份
// Response.Write("<script language=javascript>function move(){for(i="+intSProcess+";i<"+intEProcess+";i++){mydiv2.style.top=100-i*2;mydiv2.style.left=0-i;setTimeout(StartShowWait,1000);}}");
#endregion
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(8);
string temp2=text.Substring(0,8);
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
指定会员发布按钮#region 指定会员发布按钮
private void release_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
if(Request.QueryString["web_sub_id"]!=null)
{
进度条初始化#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);
初始化邮件#region 初始化邮件
string[] strweb_sub_id;
string temp=Request.QueryString["web_sub_id"].ToString();
strweb_sub_id=temp.Split(';');
objMailclass maill=new objMailclass();
maill.mail1=new objMail[strweb_sub_id.Length];
maill.mail2=new objMail[strweb_sub_id.Length];
maill.mail3=new objMail[strweb_sub_id.Length];
for(int i=0;i<strweb_sub_id.Length;i++)
{
objMail objtemp=new objMail();
objtemp=getmail(strweb_sub_id[i]);
if(objtemp.strMailType=="1")
{
maill.mail1[maill.mail1cx]=objtemp;
maill.mail1cx++;
}
else if(objtemp.strMailType=="2")
{
maill.mail2[maill.mail2cx]=objtemp;
maill.mail2cx++;
}
else if(objtemp.strMailType=="3")
{
maill.mail3[maill.mail3cx]=objtemp;
maill.mail3cx++;
}
}
#endregion
process("-110","-156","");
Thread.Sleep(200);
//获得用户DataTable
DataTable dt=new DataTable();
dt=getappointuser();
if(dt.Rows.Count>0)
{
初始化用户列表#region 初始化用户列表
string sentto1="";
string sentto2="";
string sentto3="";
for(int i=0;i<dt.Rows.Count;i++)
{
if(dt.Rows[i]["flag1"].ToString()=="0")
{
if(dt.Rows[i]["web_crmsub_type1"].ToString()=="1")
{
sentto1=sentto1+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type2"].ToString()=="1")
{
sentto2=sentto2+dt.Rows[i]["email"].ToString()+";";
}
if(dt.Rows[i]["web_crmsub_type3"].ToString()=="1")
{
sentto3=sentto3+dt.Rows[i]["email"].ToString()+";";
}
}
}
#endregion
发送邮件#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++)
{
sendmail(maill.mail1[i],sentto1);
process("-"+Convert.ToString(156+bx1*i),"-"+Convert.ToString(156+bx1*(i+1)),maill.mail1[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail2cx;i++)
{
sendmail(maill.mail2[i],sentto2);
process("-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*i),"-"+Convert.ToString(156+bx1*maill.mail1cx+bx2*(i+1)),maill.mail2[i].strSubject);
Thread.Sleep(2);
}
for(int i=0;i<maill.mail3cx;i++)
{
sendmail(maill.mail3[i],sentto3);
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);
Thread.Sleep(2);
}
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;' onclick='javascript:location=location.href.toString();' src=../images/returnbutton.gif width=71 height=25 /> <img src=../images/closebutton.gif style='cursor:hand;' onclick='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
}
else
{
Response.Write("<script language=javascript>alert('没有可以发送邮件的用户');location=location.href.toString();</script>");
}
}
else
{
Response.Write("<script language=javascript>alert('您还没有选择要发送的消息');location=location.href.toString();</script>");
}
}
#endregion
获取指定用户的用户列表#region 获取指定用户的用户列表
private DataTable getappointuser()
{
OracleDb conn=new OracleDb();
DataTable dt=new DataTable();
dt.Columns.Add("email");
dt.Columns.Add("crm_id");
dt.Columns.Add("crm_cn");
dt.Columns.Add("login_name");
dt.Columns.Add("card_no");
dt.Columns.Add("flag1");
dt.Columns.Add("web_crmsub_type1");
dt.Columns.Add("web_crmsub_type2");
dt.Columns.Add("web_crmsub_type3");
string[] temp=Request.Form["cks"].ToString().Split(',');
for(int i=0;i<temp.Length;i++)
{
DataRow dr=dt.NewRow();
string strSql=@"Select c.email,c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'','1',null,'1',c.flag1) flag1,decode(wc.web_crmsub_type1,'','1',null,'1',wc.web_crmsub_type1) web_crmsub_type1,decode(wc.web_crmsub_type2,'','1',null,'1',wc.web_crmsub_type2) web_crmsub_type2,decode(wc.web_crmsub_type3,'','1',null,'1',wc.web_crmsub_type3) web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0' and c.crm_id='"+temp[i]+"'";
conn.DataReader=conn.ExecuteReader(strSql);
if(conn.DataReader.Read())
{
dr["email"]=conn.DataReader["email"].ToString();
dr["crm_id"]=conn.DataReader["crm_id"].ToString();
dr["crm_cn"]=conn.DataReader["crm_cn"].ToString();
dr["login_name"]=conn.DataReader["login_name"].ToString();
dr["card_no"]=conn.DataReader["card_no"].ToString();
dr["flag1"]=conn.DataReader["flag1"].ToString();
dr["web_crmsub_type1"]=conn.DataReader["web_crmsub_type1"].ToString();
dr["web_crmsub_type2"]=conn.DataReader["web_crmsub_type2"].ToString();
dr["web_crmsub_type3"]=conn.DataReader["web_crmsub_type3"].ToString();
dt.Rows.Add(dr);
}
conn.DataReader.Dispose();
}
// string strSql=@"Select c.email,c.crm_id,c.crm_cn,c.login_name,ca.card_no,decode(c.flag1,'8','是','1') flag1,decode(wc.web_crmsub_type1,'8','是','1') web_crmsub_type1,decode(wc.web_crmsub_type2,'8','是','1') web_crmsub_type2,decode(wc.web_crmsub_type3,'8','是','1') web_crmsub_type3 From crm c,web_crmsub wc,card ca Where c.flag1='0' And c.crm_flag='1' And c.status='0' And wc.crm_id(+)=c.crm_id And wc.status(+)='0' And c.crm_id=ca.crm_id(+) and ca.status(+)='0'";
// dt=conn.GetDtRecorder(strSql);
conn.CloseDb();
return dt;
}
#endregion
邮件结构类#region 邮件结构类
public class objMail
{
// public void add(objMail mail)
// {
// strMail+=mail.strMail;
// strSubject+=mail.strSubject;
// }
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;
}
#endregion
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/**//// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.release.Click += new System.Web.UI.ImageClickEventHandler(this.release_Click);
this.quicksubmit.Click += new System.Web.UI.ImageClickEventHandler(this.quicksubmit_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
简化后的页面及demo,见页面 http://www.cnblogs.com/suntears/archive/2007/04/24/724833.html