string nowDSN=ConfigurationSettings.AppSettings["data"];
SqlConnection myConnection=new SqlConnection(nowDSN);
SqlDataAdapter myCommand1=new SqlDataAdapter("select * from vendor order by vendor desc",myConnection);
DataSet ds1=new DataSet();
myCommand1.Fill(ds1, "vendor");
dr1 = ds1.Tables["vendor"].Rows[0];
int dscount=ds1.Tables["vendor"].Rows.Count;
//亞旭塑膠厂"楊莉"新采購單-----------------------------------------------------
for(int i1=0;i1<dscount;i1++)
{
SqlDataAdapter myCommand11=new SqlDataAdapter("select * from pur where (purchaser='楊莉' or purchaser='王慶媚') and status='0' and email_caption='0' and status3='1' and vendor='"+ds1.Tables["vendor"].Rows[i1]["vendor"].ToString()+"'",myConnection);
DataSet ds11=new DataSet();
myCommand11.Fill(ds11, "pur");
if(ds11.Tables["pur"].Rows.Count > 0)
{
dr11 = ds11.Tables["pur"].Rows[0];
int dscount11=ds11.Tables["pur"].Rows.Count;
for(int i11=0;i11<dscount11;i11++)
{
body1=body1+"<table border=1 bgcolor=e2f9ff><tr><td width=100>"+ds11.Tables["pur"].Rows[i11]["pono"].ToString()+"</td><td width=120>"+ds11.Tables["pur"].Rows[i11]["part"].ToString()+"</td><td width=350>"+ds11.Tables["pur"].Rows[i11]["specification"].ToString()+"</td><td width=100>"+ds11.Tables["pur"].Rows[i11]["precdate"].ToString()+"</td><td width=100>"+ds11.Tables["pur"].Rows[i11]["qty"].ToString()+"</td><td width=100>"+ds11.Tables["pur"].Rows[i11]["vendor"].ToString()+"</td></tr></table>"+"\r\n";
sum1=sum1+1;
sum11=sum11+1;
subject1=ds11.Tables["pur"].Rows[i11]["vendor"].ToString();
//-------------------------------------------------------------------
string CommandText;
SqlCommand myCommand111 = new SqlCommand();
myCommand111.Connection=myConnection;
myCommand111.Connection.Open();
myCommand111.CommandText = "update pur set email_caption='1' where p_id='"+ds11.Tables["pur"].Rows[i11]["p_id"].ToString()+"'";
myCommand111.ExecuteNonQuery();
myCommand111.Connection.Close(); //如果发送了一次,那么让字段email_caption变为1后就不会重复发送邮件
//-------------------------------------------------------------------
}
SmtpMail.SmtpServer="mail.lw-org.com";
MailMessage oMessage = new MailMessage();
oMessage.BodyFormat = MailFormat.Html;
oMessage.Priority = MailPriority.High;
oMessage.From = "
[email protected]";
oMessage.To = ds1.Tables["vendor"].Rows[i1]["email"].ToString();
oMessage.Bcc = "
[email protected];[email protected]";
//oMessage.Bcc = "
[email protected]"+ds1.Tables["vendor"].Rows[i1]["email2"].ToString();
oMessage.BodyEncoding = Encoding.UTF8;
oMessage.Subject = "亞旭塑膠厂新采購單"+subject1;
oMessage.Body = "亞旭網路採購管理系統"+DateTime.Now.Date.ToShortDateString()+"傳送訊息如下:"+"\r\n"+sum1 +"條新單記錄"+"\r\n"+"<br/><table border=1 bgcolor=718BD6><tr><td width=100>"+"采購單號"+"</td><td width=120>"+"料號"+"</td><td width=350>"+"料品名稱"+"</td><td width=100>"+"交貨日期"+"</td><td width=100>"+"數量"+"</td><td width=100>"+"供應商"+"</td></tr></table>"+body1;
SmtpMail.Send(oMessage);
Response.Write("OK!");
Response.Write("<font color='blue'>");
Response.Write(ds1.Tables["vendor"].Rows[i1]["vendor"].ToString());
Response.Write(ds1.Tables["vendor"].Rows[i1]["email"].ToString());
Response.Write(ds1.Tables["vendor"].Rows[i1]["ven_name"].ToString());
Response.Write("</font>");
Response.Write(sum1+"條記錄"+body1);
Response.Write("<br/>");
}
body1="";
sum1=0;
}
Response.Write("<font color='red'>");
Response.Write("楊莉"+sum11);
Response.Write("條新單記錄");
Response.Write("</font>");
Response.Write("<br/>");