0

スケジューラを介して Windows で自動起動するプログラムがあります。クエリを実行し、クエリの結果を電子メールで送信します。これはすべて機能します。私がやりたいことは、プログラムを次のレベルに引き上げることです。10か所あります。場所の DM は、このレポートを毎日受信する必要があります (店舗のみを受信します)。したがって、基本的に私がやりたいことは、別の tableadapter の形式でコードを繰り返し、その情報を電子メールで送信することです。私の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' + '%')

繰り返しますが、これはすべて機能します。しかし、2 番目のクエリはまったく同じですが、store_ID を "112" に置き換えます。次に、そのクエリ結果を 1929 の ID とは異なるアドレスに電子メールで送信する必要があります...これを達成するための最善の方法について何か提案はありますか?

4

1 に答える 1

0
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
        'TODO: This line of code loads data into the 'DataSet.Paid_Out_Tb' table. You can move, or remove it, as needed.

        Try
            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            Me.Paid_Out_TbTableAdapter.Fill(Me.DataSet.Paid_Out_Tb)
            Me.DataTable1TableAdapter.Fill(Me.DataSet.DataTable1)
            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>
            Dim Payouts453 = _
            <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.DataTable1.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() & Payouts453.ToString() 'this is to add another chart  You would use a seperate dataset obviously
                SmtpServer.Send(mail)
                'MsgBox("mail send")
            End If

        Catch ex As Exception

            MsgBox(ex.ToString)


        End Try






        Me.Close() 'Closes the program when it's finished.


    End Sub

これを達成する最も簡単な方法は、別のテーブルアダプターを追加して別のクエリを実行することです...おそらく最も効率的ではありませんが、送信されるデータの量については...動作します..

于 2012-07-31T16:31:20.047 に答える