我在 VS2010 中使用 C#.NET。在下面的代码中,我检查数据网格中的每条记录是否已被选中进行报告。如果选中,然后我会检查 3 个可用联系人字段中的每一个,以查看是否需要通过将生成的报告通过电子邮件发送给他们来联系该实体。
文件名保存为“IN_MUL_*BusinessID_Date_Time_ContactPoint*”,例如。“IN_MUL_25_05202013_09.11.14_BUS”。如果我从同一个 Sample# 中选择 2 个测试结果来报告,这意味着它们在其帐户上具有相同的 ContactResults 结构,2 个电子邮件对话向同一个人打开,并附有相同的报告。在这种情况下,代码正在正确处理,但从逻辑上讲,我只需要一个对话,因为它是给同一个人的同一份报告。
有谁知道一种相当简单的方法,我可以检查是否已经创建了与某人的对话并具有特定的附件,如果是,请忽略该处理?
我的代码如下:
private void emailReports()
{
foreach (DataGridViewRow recRow in dgvTests.Rows)
{
if (((recRow.Cells["Select"].Value != null) && Boolean.Parse(recRow.Cells["Select"].Value.ToString())))
{
// If Business should be contacted with Sample Test Results
if ((recRow.Cells["BusinessContactResults"].Value != null) && (Boolean.Parse(recRow.Cells["BusinessContactResults"].Value.ToString()) == true) && (recRow.Cells["BusinessEmail"].Value != null))
{
Microsoft.Office.Interop.Outlook.Application objApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mail = null;
mail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mail.To = recRow.Cells["BusinessEmail"].Value.ToString();
mail.Subject = "Inspection Notification";
mail.Body = "";
mail.Attachments.Add((object)string.Format("{0}IN_{1}_{2}_{3}_BUS.pdf", reptLoc, strLSN, recRow.Cells["BusinessID"].Value, dtString), Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, 1, (object)"Attachment");
mail.Display();
}
if ((recRow.Cells["SupplierContactResults"].Value != null) && (Boolean.Parse(recRow.Cells["SupplierContactResults"].Value.ToString()) == true) && (recRow.Cells["SupplierEmail"].Value != null))
{
Microsoft.Office.Interop.Outlook.Application objApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mail = null;
mail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mail.To = recRow.Cells["SupplierEmail"].Value.ToString();
mail.Subject = "Inspection Notification";
mail.Body = "";
mail.Attachments.Add((object)string.Format("{0}IN_{1}_{2}_{3}_SUP.pdf", reptLoc, strLSN, recRow.Cells["BusinessID"].Value, dtString), Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, 1, (object)"Attachment");
mail.Display();
}
if ((recRow.Cells["CorporateContactResults"].Value != null) && (Boolean.Parse(recRow.Cells["CorporateContactResults"].Value.ToString()) == true) && (recRow.Cells["CorporateEmail"].Value != null))
{
Microsoft.Office.Interop.Outlook.Application objApp = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.MailItem mail = null;
mail = (Microsoft.Office.Interop.Outlook.MailItem)objApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
mail.To = recRow.Cells["CorporateEmail"].Value.ToString();
mail.Subject = "Inspection Notification";
mail.Body = "";
mail.Attachments.Add((object)string.Format("{0}IN_{1}_{2}_{3}_CRP.pdf", reptLoc, strLSN, recRow.Cells["BusinessID"].Value, dtString), Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, 1, (object)"Attachment");
mail.Display();
}
}
}
}
任何帮助将不胜感激。