【问题标题】:Send Daily Emails via single nested loops function通过单个嵌套循环功能发送每日电子邮件
【发布时间】:2014-04-15 13:16:48
【问题描述】:

我正在创建一个每天运行一次的网页,用于向主管发送电子邮件通知。我希望每位主管都能收到一封电子邮件,其中包含有关其所有员工的数据,其中可能包含多个事件。

我有一些这样的数据:

supervisorEmail |   employeeID  |   eventDate   |   eventDetails
===================================================================================================
george@blah.org |   jones       |   2014-03-18  |   Watch a movie
george@blah.org |   jones       |   2014-03-20  |   Convention registration
george@blah.org |   smith       |   2014-03-20  |   Convention registration
george@blah.org |   smith       |   2014-03-20  |   Convention registration
gayle@blah.org  |   nloya       |   2014-03-13  |   some other stuff
gayle@blah.org  |   nloya       |   2014-03-25  |   this and that

我首先检索所有上述数据并将其放入 DataTable。
接下来,我需要按主管分组,以便每个人都能收到一封电子邮件。 在每封电子邮件中,我需要为该主管过滤的行。我看到了如何将 LINQ 用于其中的一些。我现在迷失了这一切。我至少可以朝正确的方向推进吗?

【问题讨论】:

  • “一个每天运行一次的网页”为什么不把它作为一个计划好的控制台应用程序呢?
  • 所以看看所有 LINQ 方法的列表。 (真的没有那么多。)其中一个应该作为按某些属性对项目进行分组的可能有用的工具脱颖而出。
  • 网页与控制台应用程序不是这里的问题!我还没有那么远,那么坚持这个问题的主题怎么样?除非我是超级专家,否则这里不是问问题的好地方吗?

标签: c# sql .net linq datatable


【解决方案1】:

您可以通过supervisorEmail对数据进行分组:

var groups = data.GroupBy(d => d.supervisorEmail);
foreach(var g in groups)
{
    SendEmail(g.Key, g);   // g is an IEnumerable<some type> with the data for that supervisor
}

public void SendEmail(string supervisorEmail, IEnumerable<some type> data)
{
    // send data to supervisor
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-15
    • 1970-01-01
    • 2018-12-19
    • 2012-02-04
    • 1970-01-01
    • 2022-08-14
    • 2012-01-13
    相关资源
    最近更新 更多