我有一个自动调用电子邮件的系统。 我想要做的是今天系统陷阱是星期五,我想创建一个 一封电子邮件中的不同表格。
截至目前,我的系统每天都可以调用一封电子邮件。
这是我想要实现的目标。
今天的例子是星期一系统将发送:
“星期二表的到期日产品清单”(与星期二至星期四相同)
星期二 - “星期三到期产品清单”
周三 - “周四到期产品清单”
星期四 - “星期五到期产品清单”
如果这一天是星期五,我想通过电子邮件发送3天到期产品列表,如下所示:
以下是将于周六至周一到期的产品列表。 (每天只在一封电子邮件中附带不同的表格)像这样:
截至目前,我的系统每天都可以发送电子邮件。我不知道我将如何实现 星期五电子邮件爆炸的输出。
以下是我目前的情况:
我创建了两个不同的子类。我的一个子类是周一到周四的电子邮件设置 另一个是星期五的电子邮件设置,由3个不同的表组成。
Sub EmailMondayThursday
Dim ds As New DataSet
Dim cmd As New SqlCommand
Dim dt As New DataTable
Dim adp As New SqlDataAdapter
Dim c As New SqlConnection("myconnectionhere")
Dim emaildate As String
emaildate = DateTime.Today.AddDays(1).Date.ToString("D")
cmd.Connection = c
cmd.CommandText = "sp_progspot_monitor"
cmd.Parameters.AddWithValue("@prdname", "%")
cmd.Parameters.AddWithValue("@prdcde", "%")
cmd.Parameters.AddWithValue("@prdfrdate", Date.Today.AddDays(1))
cmd.Parameters.AddWithValue("@prdtodate", Date.Today.AddDays(1))
cmd.Parameters.AddWithValue("@cost", "%")
cmd.CommandType = CommandType.StoredProcedure
adp.SelectCommand = cmd
adp.Fill(ds)
Dim dv As New DataView(ds.Tables(0))
Dim dvfilter As DataTable = dv.ToTable(True, {"teledte"})
Dim dt2 As New DataTable
For Each dtrow As DataRow In dvfilter.Rows
dv.RowFilter = "Total_Load < Potential_Load"
dt2 = dv.ToTable(False, {"Date", "Prouduct Name", "Product Code", "Total Sales"})
Next
Dim builder As New StringBuilder
builder.Append("<!DOCTYPE html><html>")
builder.Append("<head></head>")
builder.Append("<table>")
builder.Append("<tr>")
builder.Append("<th>Date</th>")
builder.Append("<th>Product Name</th>")
builder.Append("<th>Product Code</th>")
builder.Append("<th>Total Sales</th>")
builder.Append("<tr>")
builder.Append("</table>")
builder.Append("</html>")
For Each row As DataRow In dt2.Rows
builder.Append("<tr>")
Dim i As Integer
i = 1
For Each col As DataColumn In dt2.Columns
builder.Append("<td class=""" & i & """>" & row(col).ToString + " " & "</td>")
i = i + 1
Next
builder.Append("</tr>")
builder.AppendLine()
Next
builder.Append("</tbody>")
builder.Append("</table>")
setemail("myemail@yahoo.com", "pass", builder.ToString)
结束SUb
这是我的FridayEmail的Sub类
Dim ds As New DataSet
Dim cmd As New SqlCommand
Dim dt As New DataTable
Dim adp As New SqlDataAdapter
Dim c As New SqlConnection("myconnectionhere")
Dim emaildtefrm As String
dim emaildteto as String
emaildtefrm = DateTime.Today.AddDays(1).Date.ToString("D")
emaildteto = DateTime.Today.AddDays(3).Date.ToString("D")
cmd.Connection = c
cmd.CommandText = "sp_progspot_monitor"
cmd.Parameters.AddWithValue("@prdname", "%")
cmd.Parameters.AddWithValue("@prdcde", "%")
cmd.Parameters.AddWithValue("@prdfrdate", Date.Today.AddDays(1))
cmd.Parameters.AddWithValue("@prdtodate", Date.Today.AddDays(3))
cmd.Parameters.AddWithValue("@cost", "%")
cmd.CommandType = CommandType.StoredProcedure
adp.SelectCommand = cmd
adp.Fill(ds)
Dim dv As New DataView(ds.Tables(0))
Dim dvfilter As DataTable = dv.ToTable(True, {"teledte"})
Dim dt2 As New DataTable
For Each dtrow As DataRow In dvfilter.Rows
dv.RowFilter = "Total_Load < Potential_Load"
dt2 = dv.ToTable(False, {"Date", "Prouduct Name", "Product Code", "Total Sales"})
Next
Dim builder As New StringBuilder
builder.Append("<!DOCTYPE html><html>")
builder.Append("<head></head>")
builder.Append("<body>")
builder.Append("<p> Below is the list of expiry product from " & emaildtefrm & "to" & emaildteto & "</p>")
builder.Append("<table>")
builder.Append("<tr>")
builder.Append("<th>Date</th>")
builder.Append("<th>Product Name</th>")
builder.Append("<th>Product Code</th>")
builder.Append("<th>Total Sales</th>")
builder.Append("<tr>")
builder.Append("</table>")
builder.Append("</html>")
For Each row As DataRow In dt2.Rows
builder.Append("<tr>")
Dim i As Integer
i = 1
For Each col As DataColumn In dt2.Columns
builder.Append("<td class=""" & i & """>" & row(col).ToString + " " & "</td>")
i = i + 1
Next
builder.Append("</tr>")
builder.AppendLine()
Next
builder.Append("</tbody>")
builder.Append("</table>")
setemail("myemail@yahoo.com", "pass", builder.ToString)
此代码用于捕获当天的日期,以便系统知道当天有条件地根据条件发送电子邮件。
受保护的子ImageButton1_Click(发件人为对象,e为System.Web.UI.ImageClickEventArgs)处理ImageButton1.Click
Dim daytoday As String = DateTime.Today.DayOfWeek
If daytoday.ToString = "1" or Then
EmailMondayThursday()
ElseIf daytoday.ToString = "4" Then
MsgBox("Thursday")
ElseIf daytoday .ToString = "5" Then
ProgSpotEmailFriday()
End If
End Sub
答案 0 :(得分:0)
你星期五的输出包含在一个数据表中,你迭代它,这就是为什么你把它作为一个表。 您需要有3个表,每天一个,或者将它作为单个数据表,但是按日期对产品进行分组以便有3个组,然后代替迭代数据表行并将HTML行附加到HTML ,使这个代码在另一个for循环中迭代组,并在for循环内创建一个HTML表,所以代码应该是这样的,我不知道VB&lt;所以我把它添加为psudo代码
Dim dv As New DataView(ds.Tables(0)) Dim dvfilter As DataTable = dv.ToTable(True,{“teledte”}) 昏暗的dt2作为新的DataTable 对于dvfilter.Rows中的每个dtrow As DataRow dv.RowFilter =“Total_Load&lt; Potential_Load” dt2 = dv.ToTable(False,{“Date”,“Prouduct Name”,“Product Code”,“Total Sales”}) 下一步
Dim builder As New StringBuilder
builder.Append("<!DOCTYPE html><html>")
builder.Append("<head></head>")
builder.Append("<body>")
builder.Append("<p> Below is the list of expiry product from " & emaildtefrm & "to" & emaildteto & "</p>")
For Each from emaildtefrm to emaildteto
builder.Append("<table>")
builder.Append("<tr>")
builder.Append("<th>Date</th>")
builder.Append("<th>Product Name</th>")
builder.Append("<th>Product Code</th>")
builder.Append("<th>Total Sales</th>")
builder.Append("<tr>")
builder.Append("</table>")
builder.Append("</html>")
dim dayProducts as DataTable = dt2.Select(get only products for this day)
For Each row As DataRow In dayProducts .Rows
builder.Append("<tr>")
Dim i As Integer
i = 1
For Each col As DataColumn In dt2.Columns
builder.Append("<td class=""" & i & """>" & row(col).ToString + " " & "</td>")
i = i + 1
Next
builder.Append("</tr>")
builder.AppendLine()
Next
builder.Append("</tbody>")
builder.Append("</table>")
Next
builder.Append("</body>")
setemail("myemail@yahoo.com", "pass", builder.ToString)