0

我有一个 DotNetNuke 模块,其中包含一个名为 CRMCheck 的视图和调度程序类。

我已经设置我的调度程序任务每隔几分钟给我的班级打电话。(MyModule.Modules.CRM.CRMCheck)

我需要检索为 Module 或 TabSettings 保存的设置。我正在保存 Module 和 ModuleTabSettings,默认情况下,DNN 将在使用 Settings[] 时使用 ModuleTabSettings 并同时保存两者。

所以我的主要问题是我想获取我保存在调度程序 DoWork() 方法应该使用的模块的设置部分中的电子邮件地址。

我也遇到了一个问题,即您在使用调度程序时无法获取门户 ID,而 DNN 在这篇文章中指出:https ://dnncommunity.org/forums/aft/191

这是错误:

在此处输入图像描述

这是我的模块视图类下方的调度程序代码:

    public class CRMCheck : SchedulerClient
{
    private readonly DaoCRM m_DaoCRM = new DaoCRM();


public CRMCheck(ScheduleHistoryItem oItem) : base()
    {
        this.ScheduleHistoryItem = oItem;
    }

    public Control LocalResourceFile { get; private set; }

    public override void DoWork()
    {
        try
        {
            //Perform required items for logging
            this.Progressing();

            //Your code goes here
            DateTime? TimeNow = DateTime.Now;
            var CRMItems = ShowCRMListDNN();
            foreach (var item in CRMItems)
            {
                DateTime? RegisteredDateINDatabase = item.DateRegistered;
                var TimeDifference = TimeNow - RegisteredDateINDatabase;
                var DidTheyPurchaseSomething = item.PurchasedSomething;
                if(TimeDifference.Value.TotalHours > 3 && DidTheyPurchaseSomething == false)
                {
                    //email and stuff
                    SendSuccessEmailToAdmin(item.FirstName, item.LastName, item.CompanyName, item.EmailAddress, item.Cellphone, item.ERPUserId, item.DateRegistered, item.PortalID, item.PurchasedSomething);
                }
            }


            //To log note
            this.ScheduleHistoryItem.AddLogNote("Item Executed");

            //Show success
            this.ScheduleHistoryItem.Succeeded = true;
        }
        catch (Exception ex)
        {
            this.ScheduleHistoryItem.Succeeded = false;
            //InsertLogNote("Exception= " + ex.ToString());
            this.Errored(ref ex);
            DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
        }
    }

    public List<CRM> ShowCRMListDNN()
    {
        var result = new List<CRM>();
        try
        {
            return result = m_DaoCRM.ShowCRMListNoPortalID();
        }
        catch (Exception ex)
        {
        EventLogController logController = new EventLogController();
        logController.AddLog("Problem fetching CRM List for Scheduled Job.", ex.ToString(), EventLogController.EventLogType.ADMIN_ALERT);
        return result;
      }
    }

    /// <summary>
    /// Sends an email when the job runs
    /// </summary>
    /// <remarks>ZR - Added - 09/03/2018</remarks>
    private void SendSuccessEmailToAdmin(string FirstName, string LastName, string CompanyName, string Email, string Cellphone, int ERPUserID, DateTime? DateRegistered, int Portal, bool PurchasedSomething)
    {
        if (Settings["CRMEmail"] != null && !string.IsNullOrWhiteSpace(Settings["CRMEmail"].ToString()))
        {
            System.Text.StringBuilder strAdminEmailMsg = new System.Text.StringBuilder();

            strAdminEmailMsg.AppendLine("<br><br>");
            strAdminEmailMsg.AppendLine("<table style=\"border-color:#007799;color:#007799;border-style:double;font-family:arial,verdana;font-size:8pt;\" width=\"70%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\">");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td style=\"text-align:center;background:#007799;color:#ffffff;font-weight:bold;font-family:arial;font-size:11pt;\">New Customer Registration</td>");
            strAdminEmailMsg.AppendLine("    </tr>");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td align=\"center\"><table width=\"80%\" style=\"font-family:verdana;font-size:8pt;\">");
            strAdminEmailMsg.AppendFormat("  <tr><td align=\"left\">Date:</td><td align=\"left\">{0}</td></tr>", DateTime.Now.ToLocalTime()).AppendLine();
            strAdminEmailMsg.AppendLine("</table>");

            strAdminEmailMsg.AppendLine("<table style=\"color:#007799;font-family:arial,verdana;font-size:8pt;\" width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"0\">");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td>&nbsp;</td>");
            strAdminEmailMsg.AppendLine("    </tr>");
            strAdminEmailMsg.AppendLine("    <tr>");
            strAdminEmailMsg.AppendLine("        <td style=\"text-align:center\">&nbsp;");
            //all changes in inner table
            strAdminEmailMsg.AppendLine("            <table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" bordercolor=\"#007799\" border=\"1\" style=\"font-family:verdana;font-size:8pt;border-collapse:collapse;\">");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">FirstName</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", FirstName);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">Last Name</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", LastName);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">Company Name</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", CompanyName);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("                <tr>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">Email</td>");
            strAdminEmailMsg.AppendFormat("                  <td style=\"color:#000000;\" bgcolor=\"#e7e8e9\">{0}</td>", Email);
            strAdminEmailMsg.AppendLine("                </tr>");
            strAdminEmailMsg.AppendLine("            </table>");
            strAdminEmailMsg.AppendLine("        </td>");
            strAdminEmailMsg.AppendLine("    </tr>");
            strAdminEmailMsg.AppendLine("</table>");

            SendEmail("System Job", strAdminEmailMsg.ToString(), Settings["CRMEmail"].ToString());
        }
    }

    /// <summary>
    /// Send an email
    /// </summary>
    /// <param name="MailSubject"></param>
    /// <param name="MailMessage"></param>
    /// <param name="RecipientEmail"></param>
    private void SendEmail(string MailSubject, string MailMessage, string RecipientEmail)
    {
        bool EmailSent = false;

        //EmailSent = webcall
        EmailSent = SessionManager.GSettings.Globalvars.ClHelper.eBusiness.SendEmail(-1, 2, RecipientEmail, MailSubject, MailMessage);

        //Show a message to the user if it was sent or not
        if (!EmailSent)
        {
            EventLogController logController = new EventLogController();
            logController.AddLog("Problem sending Job Email", "", EventLogController.EventLogType.ADMIN_ALERT);
        }

    }

}
4

1 回答 1

0

我通过创建一个转到 Dao 类的方法找到了一种解决方法,通过该方法我可以调用 ModuleSettings 表的数据库查询。

于 2020-06-10T15:20:43.680 回答