• 把数据拼接成html发送邮件


    System.DateTime today = DateTime.Now.Date;
    string str = string.Empty;
    foreach (System.Data.DataRow dr in data.Rows)
    {
    string status = dr["Risk"].ToString();
    if (status != "Open")
    {
    continue;
    }
    string dateStr = dr["逾期"].ToString().Substring(0, 10);
    int year = 0;
    int month = 0;
    int day = 0;
    int.TryParse(dateStr.Substring(6, 4), out year);
    int.TryParse(dateStr.Substring(3, 2), out month);
    int.TryParse(dateStr.Substring(0, 2), out day);
    System.DateTime date = new DateTime(year, month, day);
    int days = (date - today).Days;
    int dlDays = 4;
    switch (today.DayOfWeek)
    {
    case DayOfWeek.Monday:
    case DayOfWeek.Tuesday:
    case DayOfWeek.Friday:
    dlDays = 4; break;
    case DayOfWeek.Wednesday:
    case DayOfWeek.Thursday:
    dlDays = 5; break;
    case DayOfWeek.Saturday:
    dlDays = 3; break;
    case DayOfWeek.Sunday:
    dlDays = 2; break;
    }
    if (days <= dlDays)
    {
    str += "<tr>";
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">" + dr["ID"].ToString() + "</td>";
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">" + dr["主题"].ToString() + "</td>";
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">" + dr["Name"].ToString() + "</td>";
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">" + dr["Date"].ToString() + "</td>";
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">" + days.ToString() + "</td>";
    if (days == 0)
    {
    if ((date - today).Hours > 0)
    {
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap;background-color:#d15b47;color:#fff"">" + (date - today).Hours + "</td>";
    }
    else
    {
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap;background-color:#d15b47;color:#fff"">" + (date - today).Minutes + "</td>";
    }
    }
    else if (days == 1)
    {
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap;background-color:#d15b47;color:#fff""></td>";
    }
    else if (date.DayOfWeek == DayOfWeek.Monday)
    {
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap;background-color:#d15b47;color:#fff""></td>";
    }
    else
    {
    str += @"<td style=""border:inset #CCCCCC 1.0pt;border-top:none;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap""></td>";
    }
    str += "</tr>";
    }
    }
    if (!string.IsNullOrWhiteSpace(str))
    {
    content = string.Format(@"
    <h3>请求</h3>
    <table>
    <thead>
    <tr>
    <th style=""border:inset #CCCCCC 1.0pt;background:#CCCCCC;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">ID</th>
    <th style=""border:inset #CCCCCC 1.0pt;background:#CCCCCC;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">主题</th>
    <th style=""border:inset #CCCCCC 1.0pt;background:#CCCCCC;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">Name</th>
    <th style=""border:inset #CCCCCC 1.0pt;background:#CCCCCC;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">Date</th>
    <th style=""border:inset #CCCCCC 1.0pt;background:#CCCCCC;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">Remark</th>
    <th style=""border:inset #CCCCCC 1.0pt;background:#CCCCCC;padding:1.5pt 1.5pt 1.5pt 1.5pt;white-space:nowrap"">risk</th>
    </tr>
    </thead>
    <tbody>
    {0}
    </tbody>
    </table>", str);
    }

  • 相关阅读:
    Docker入门系列4:命令行小结
    Docker入门系列3:使用
    Docker入门系列2 安装
    Docker入门系列1:简介
    在VMware下安装CentOS系列1:配置VMware
    bugzilla 系列1安装
    查看SELinux状态并关闭SELinux
    Qt 编程指南 5 丰富文本编辑控件
    Qt 编程指南 4 单行编辑控件
    Qt 编程指南 4 按钮2 打开网页和文件夹
  • 原文地址:https://www.cnblogs.com/Depingblogs/p/13304735.html
Copyright © 2020-2023  润新知