所以,这笔交易 - 我已经为我的公司制作了这个PTO计划大约一个月左右了。我正在做最后的质量检查,并遇到了我在之前的测试中没有看到的问题。
因此,一旦经理登录到应用程序,他们就会进入屏幕以批准PTO。他们可以在datagridview中选择多行并单击批准,这些记录在数据库端更新 - 它记录批准的人以及时间和日期,并更新批准状态的布尔值。所有这些都按预期工作。
问题是当我通过电子邮件向用户发送PTO已获批准的时间。作为SQL更新命令的一部分,应用程序生成数据表,并在批准的每个PTO日为该表添加名称,电子邮件,PTO日期,PTO类型,小时数和用户ID。我将那张桌子推到我的电子邮件子站,这一切都变得混乱。它将电子邮件发送给已批准PTO的每个用户,但每个人都获得相同的PTO详细信息 - 即使我知道我传递的数据表具有每个用户的正确数据。
请参阅下面的代码 - 我在这里缺少什么?感谢您的帮助 - 这是我留下的最大问题,这件事几乎可以部署了!
编辑添加:我认为问题出在我制作PTORows数据流的地方,我认为它始终选择approvalemaillist数据表中的第一行并填充它。
Public Sub sendEmail(approvalEmailList As DataTable)
Dim linecount As Integer = 0
Dim hours As New Integer
Dim sb As New StringBuilder
Dim ptoType As New List(Of String)
Dim itercount As Integer = 0
Dim spottype As Integer = 0
Dim makecount As Integer = 0
Dim email = From row In approvalEmailList.AsEnumerable()
Select row.Field(Of String)("Email") Distinct
'For Each str As String In email
For Each row As DataRow In approvalEmailList.Rows
sb.Clear()
'Reset Linecount for new email
linecount = 0
sb.AppendLine("PTO Request Approved")
sb.AppendLine("")
sb.AppendLine("PTO Request Details:")
sb.AppendLine("")
sb.AppendLine("PTO Request Approval Date: " & DateTime.Today)
Dim PTORows() As DataRow = approvalEmailList.Select("Email = '" & email(linecount).ToString & "'", "PTODate Desc")
Dim PTODate As Date = Nothing
For Each pto As DataRow In PTORows
PTODate = PTORows(linecount).ItemArray(2).ToString
If PTORows(linecount).ItemArray(4).ToString = True Then
hours = 4
Else
hours = 8
End If
sb.AppendLine("PTO Date: " & PTODate.ToShortDateString & " - PTO Type: " & PTORows(linecount).ItemArray(3).ToString & " - Hours: " & hours.ToString)
linecount += 1
Next
'makemath(PTORows(0).ItemArray(5).ToString)
'makecount += 1
sb.AppendLine("")
'sb.AppendLine("PTO Balances after approval:")
'sb.AppendLine("")
'sb.AppendLine("PTO Balance: " & PTOBal.ToString)
'sb.AppendLine("Personal Day Balance: " & Personal.ToString)
'sb.AppendLine("Floating Holiday Balance: " & Float.ToString)
Dim OutApp = CreateObject("Outlook.Application")
Dim OutMail = OutApp.CreateItem(0)
With OutMail
.To = email(linecount).ToString 'str.ToString
.CC = MainForm.GlobalVariables.currentADUser.EmailAddress
.Subject = "PTO Approved"
.body = sb.ToString()
.send
End With
Next
Dim mgsRslt As MsgBoxResult = MessageBox.Show("PTO Request approved - email(s) successfully sent!",
"Success",
MessageBoxButtons.OK,
MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1)
If mgsRslt = MsgBoxResult.Ok Then
Me.Controls.Clear() 'removes all the controls on the form
InitializeComponent() 'load all the controls again
MgrApprove_Load() 'Load everything in your form load event again
End If
End Sub
答案 0 :(得分:1)
您需要进行一些更改:
循环显示您的电子邮件清单(已注释掉):
.to("stream:out)"
然后,选择应该是这个,因为您只希望父表记录与电子邮件地址匹配。
For Each str As String In email
在子循环中,将行引用为行
Dim PTORows() As DataRow = approvalEmailList.Select("Email = '" & str & "'", "PTODate Desc")