我有一个通过调度程序自动启动 Windows 的程序。它所做的是运行查询,然后通过电子邮件发送查询结果。这一切都有效。我想做的是将程序提升到一个新的水平。我们有 10 个地点。位置 DM 应每天收到此报告(仅收到他们的商店)。所以基本上我想做的是以不同的表格适配器的形式重复代码并通过电子邮件发送该信息。我的 C# 代码是:
Imports System.Net.Mail
Imports System.Linq
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()
Me.Paid_Out_TbTableAdapter.Fill(Me.DataSet.Paid_Out_Tb)
Dim payouts = _
<html>
<body>
<table border="1">
<tr><th>Store #</th><th>Date</th><th>Amount</th><th>User</th><th>Comment</th></tr>
<%= From paidOut In Me.DataSet.Paid_Out_Tb.AsEnumerable _
Select <tr><td><%= paidOut.Store_Id %></td>
<td><%= Convert.ToDateTime(paidOut.Paid_Out_Datetime).ToString("M/d/yy") %>
</td><td><%= "$" & paidOut.Paid_Out_Amount.ToString("0.00") %></td>
<td><%= paidOut.Update_UserName %></td>
<td><%= paidOut.Paid_Out_Comment %></td></tr> %>
</table>
</body>
</html>
If (Me.DataSet.Paid_Out_Tb.Count = 0) Then 'This cheks to see if the dataset is Null. We do not want to email if the set is Null
Me.Close()
Else
SmtpServer.Credentials = New _
Net.NetworkCredential("*****", "****") 'Assign the network credentials
SmtpServer.Port = 25 'Assign the SMTP Port
SmtpServer.Host = "10.0.*.*" 'Assign the Server IP
mail = New MailMessage() 'Starts a mail message
mail.From = New MailAddress("***@***.com") 'Sets the "FROM" address
mail.To.Add("****@****.com") 'Sets the "To" address
'mail.CC.Add("****@****.com") 'set this if you would like to CC
mail.Subject = "Paid Out Report for 1929"
mail.IsBodyHtml = True
mail.Body = payouts.ToString()
SmtpServer.Send(mail)
'MsgBox("mail send")
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
我的查询是:
SELECT Store_Id, Paid_Out_Amount, Paid_Out_Comment, Paid_Out_Datetime, Update_UserName, Till_Number
FROM Paid_Out_Tb
WHERE (Store_Id = 1929) AND (Paid_Out_Datetime >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0)) AND (Paid_Out_Datetime < DATEADD(day, DATEDIFF(day, 0,
GETDATE()), 0)) AND (Paid_Out_Amount > 20) OR
(Store_Id = 1929) AND (Paid_Out_Datetime >= DATEADD(day, DATEDIFF(day, 0, GETDATE()) - 1, 0)) AND (Paid_Out_Datetime < DATEADD(day, DATEDIFF(day, 0,
GETDATE()), 0)) AND (Paid_Out_Comment LIKE N'%' + 'Filter' + '%')
同样,这一切都有效。但我的第二个查询将完全相同,只是我将用“112”替换 store_ID。然后,我需要将该查询结果通过电子邮件发送到与 1929 id 不同的地址......关于如何最好地完成此任务的任何建议?