コード例 #1
0
        /// <summary>
        /// 发送邮件
        /// </summary>
        /// <param name="SchedulerItem"></param>
        /// <param name="Attachment"></param>
        /// <returns></returns>
        public void SendEmail(DNNGo_PowerForms_Scheduler SchedulerItem, String Attachment, Int32 index, ModuleInfo mItem)
        {
            EmailInfo eInfo = new EmailInfo();

            eInfo.Settings = new ModuleController().GetModule(mItem.ModuleID).ModuleSettings;
            //eInfo.SMTPEnableSSL = SMTPEnableSSL(mItem.PortalID);
            eInfo.PushSettings();
            eInfo.Attachments = Attachment;
            eInfo.MailTo      = SchedulerItem.SenderEmail;
            eInfo.Content     = eInfo.Subject = String.Format("PowerForms Excel. Module Title:{0} , time:{1}", mItem.ModuleTitle, DateTime.Now.ToString());


            try
            {
                String status = NetHelper.SendMail(eInfo);


                //this.ScheduleHistoryItem.AddLogNote(String.Format("SMTPServer:{0}; SMTPUsername:{1}; EnableSMTPSSL:{2}; status:{3};<br />", Host.SMTPServer, Host.SMTPUsername, Host.EnableSMTPSSL, status));

                this.ScheduleHistoryItem.AddLogNote(String.Format("task {0},Send mail to completed. time:{1}<br />", index, DateTime.Now.ToString()));
            }
            catch (Exception exc)
            {
                this.ScheduleHistoryItem.AddLogNote(exc.Source);
            }

            //MailScheduler.AssignMessage(eInfo);
        }
コード例 #2
0
        /// <summary>
        /// 执行单个任务
        /// </summary>
        public void ExecutionTask(DNNGo_PowerForms_Scheduler SchedulerItem, Int32 index, ModuleInfo mItem)
        {
            String Attachment = ExportExcel(SchedulerItem, index);

            if (!String.IsNullOrEmpty(Attachment) && File.Exists(Attachment))
            {
                SendEmail(SchedulerItem, Attachment, index, mItem);
            }
        }
コード例 #3
0
        /// <summary>
        /// 导出表格
        /// </summary>
        /// <param name="SchedulerItem"></param>
        /// <returns></returns>
        public String ExportExcel(DNNGo_PowerForms_Scheduler SchedulerItem, Int32 index)
        {
            String Attachment = String.Empty;
            List <DNNGo_PowerForms_Content> DataList  = DNNGo_PowerForms_Content.FindAllByModuleId(SchedulerItem.ModuleId);
            List <DNNGo_PowerForms_Field>   FieldList = DNNGo_PowerForms_Field.FindAllByModuleId(SchedulerItem.ModuleId);

            if (DataList != null && DataList.Count > 0)
            {
                if (FieldList != null && FieldList.Count > 0)
                {
                    String FileName = SchedulerItem.ExcelName;
                    FileName = Common.ReplaceNoCase(FileName, "{yyyy}", DateTime.Now.ToString("yyyy"));
                    FileName = Common.ReplaceNoCase(FileName, "{mm}", DateTime.Now.ToString("MM"));
                    FileName = Common.ReplaceNoCase(FileName, "{dd}", DateTime.Now.ToString("dd"));
                    FileName = Common.ReplaceNoCase(FileName, "{time}", DateTime.Now.ToString("HHmmss"));
                    FileName = Common.ReplaceNoCase(FileName, "{ModuleID}", SchedulerItem.ModuleId.ToString());

                    Attachment = String.Format("{0}temp\\PowerForms\\{1}.xls", HttpRuntime.AppDomainAppPath, FileName);

                    try
                    {
                        CsvHelper.SaveAsToFile(FieldList, DataList, Attachment, false);
                    }
                    catch (Exception exc)
                    {
                        this.ScheduleHistoryItem.AddLogNote(exc.Source);
                    }
                }
                else
                {
                    this.ScheduleHistoryItem.AddLogNote(String.Format("task {0},field list is empty,Has ignored. time:{1}<br />", index, DateTime.Now.ToString()));
                }
            }
            else
            {
                this.ScheduleHistoryItem.AddLogNote(String.Format("task {0},History records is empty,Has ignored. time:{1}<br />", index, DateTime.Now.ToString()));
            }
            return(Attachment);
        }
コード例 #4
0
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindDataToPage()
        {
            //发件人邮箱
            txtSenderEmail.Text = Settings["PowerForms_SenderEmail"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SenderEmail"].ToString()) ? Convert.ToString(Settings["PowerForms_SenderEmail"]) : Host.HostEmail;

            #region "邮件设置"
            txtAdminEmail.Text         = Settings["PowerForms_AdminEmail"] != null && !string.IsNullOrEmpty(Settings["PowerForms_AdminEmail"].ToString()) ? Convert.ToString(Settings["PowerForms_AdminEmail"]) : Host.HostEmail;
            cbSendToAdmin.Checked      = Settings["PowerForms_SendToAdmin"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SendToAdmin"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_SendToAdmin"]) : true;
            cbSendToSubmitUser.Checked = Settings["PowerForms_SendToSubmitUser"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SendToSubmitUser"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_SendToSubmitUser"]) : true;
            //cbReplaceSender.Checked = Settings["PowerForms_ReplaceSender"] != null && !string.IsNullOrEmpty(Settings["PowerForms_ReplaceSender"].ToString()) ? Convert.ToBoolean(Settings["PowerForms_ReplaceSender"]) : false;
            cbReplyTo.Checked = Settings["PowerForms_ReplyTo"] != null?Convert.ToBoolean(Settings["PowerForms_ReplyTo"]) : true;

            WebHelper.BindList <DNNGo_PowerForms_Field>(ddlSubmitUserEmail, DNNGo_PowerForms_Field.FindAllByView(ModuleId, EnumVerification.email), DNNGo_PowerForms_Field._.Alias, DNNGo_PowerForms_Field._.Name);
            WebHelper.SelectedListByValue(ddlSubmitUserEmail, Settings["PowerForms_SubmitUserEmail"] != null && !string.IsNullOrEmpty(Settings["PowerForms_SubmitUserEmail"].ToString()) ? Convert.ToString(Settings["PowerForms_SubmitUserEmail"]) : "Email");


            DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
            WebHelper.BindList(cblAdminEmailRoles, rc.GetPortalRoles(PortalId), "RoleName", "RoleName");
            WebHelper.SelectedListMultiByValue(cblAdminEmailRoles, Settings["PowerForms_AdminEmailRoles"] != null ? Convert.ToString(Settings["PowerForms_AdminEmailRoles"]) : "");


            //需要读取模版的设置
            DNNGo_PowerForms_Template Template = DNNGo_PowerForms_Template.FindByModuleId(ModuleId);

            txtSendAdminTitle.Text        = !String.IsNullOrEmpty(Template.ReceiversSubject) ? Template.ReceiversSubject : Localization.GetString("PowerForms_ReceiversSubject", this.LocalResourceFile);
            txtSendAdminContent.Text      = !String.IsNullOrEmpty(Template.ReceiversTemplate) ? Server.HtmlDecode(Template.ReceiversTemplate) : Localization.GetString("PowerForms_ReceiversTemplate", this.LocalResourceFile);
            txtSendSubmitUserTitle.Text   = !String.IsNullOrEmpty(Template.ReplySubject) ? Template.ReplySubject : Localization.GetString("PowerForms_ReplySubject", this.LocalResourceFile);
            txtSendSubmitUserContent.Text = !String.IsNullOrEmpty(Template.ReplyTemplate) ? Server.HtmlDecode(Template.ReplyTemplate) : Localization.GetString("PowerForms_ReplyTemplate", this.LocalResourceFile);
            #endregion

            #region "定时邮件设置"
            DNNGo_PowerForms_Scheduler SchedulerItem = DNNGo_PowerForms_Scheduler.FindSettings(this);
            txtScheduleSenderEmail.Text = !String.IsNullOrEmpty(SchedulerItem.SenderEmail) ? SchedulerItem.SenderEmail: Host.HostEmail;
            txtExcelName.Text           = !String.IsNullOrEmpty(SchedulerItem.ExcelName) ? SchedulerItem.ExcelName : "Bulk_{yyyy}_{mm}_{dd}_{time}_{ModuleID}";
            cbScheduleEnable.Checked    = SchedulerItem.Enable != 0;

            #endregion
        }
コード例 #5
0
        /// <summary>
        /// 执行多个任务
        /// </summary>
        public void ExecutionTasks()
        {
            //找出所有需要执行的模块
            List <DNNGo_PowerForms_Scheduler> SchedulerList = DNNGo_PowerForms_Scheduler.FindAllSettings().Distinct <DNNGo_PowerForms_Scheduler>().ToList <DNNGo_PowerForms_Scheduler>();

            for (int i = 0; i < SchedulerList.Count; i++)
            {
                DNNGo_PowerForms_Scheduler SchedulerItem = SchedulerList[i];
                int index = i + 1;

                ModuleInfo mItem = objModules.GetModule(SchedulerItem.ModuleId);//验证当前模块是否存在
                if (mItem != null && mItem.ModuleID > 0 && !mItem.IsDeleted)
                {
                    //this.ScheduleHistoryItem.AddLogNote(String.Format("正在执行导出第{0}个任务,请稍后. time:{1}<br />", index, DateTime.Now.ToString()));
                    ExecutionTask(SchedulerItem, index, mItem);
                    //this.ScheduleHistoryItem.AddLogNote(String.Format("成功完成第{0}个任务,请稍后. time:{1}<br />", index, DateTime.Now.ToString()));
                }
                else
                {
                    this.ScheduleHistoryItem.AddLogNote(String.Format("task {0} error,Has ignored. time:{1}<br />", index, DateTime.Now.ToString()));
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// 设置数据项
        /// </summary>
        private void SetDataItem()
        {
            #region "邮件设置"
            UpdateModuleSetting("PowerForms_AdminEmail", txtAdminEmail.Text.Trim());
            UpdateModuleSetting("PowerForms_SendToAdmin", cbSendToAdmin.Checked.ToString());
            UpdateModuleSetting("PowerForms_SendToSubmitUser", cbSendToSubmitUser.Checked.ToString());
            //UpdateModuleSetting("PowerForms_ReplaceSender", cbReplaceSender.Checked.ToString());
            UpdateModuleSetting("PowerForms_ReplyTo", cbReplyTo.Checked.ToString());

            if (ddlSubmitUserEmail.SelectedIndex >= 0)
            {
                UpdateModuleSetting("PowerForms_SubmitUserEmail", ddlSubmitUserEmail.Items[ddlSubmitUserEmail.SelectedIndex].Value);
            }


            String textStr, idStr = String.Empty;
            WebHelper.GetSelected(cblAdminEmailRoles, out textStr, out idStr);
            UpdateModuleSetting("PowerForms_AdminEmailRoles", idStr);



            //发件人邮箱
            UpdateModuleSetting("PowerForms_SenderEmail", txtSenderEmail.Text.Trim());

            DNNGo_PowerForms_Template Template = DNNGo_PowerForms_Template.FindByModuleId(ModuleId);
            Template.ReceiversSubject  = txtSendAdminTitle.Text.Trim();
            Template.ReceiversTemplate = txtSendAdminContent.Text.Trim();
            Template.ReplySubject      = txtSendSubmitUserTitle.Text.Trim();
            Template.ReplyTemplate     = txtSendSubmitUserContent.Text.Trim();

            Template.LastIP   = WebHelper.UserHost;
            Template.LastTime = xUserTime.UtcTime();
            Template.LastUser = UserId;

            if (Template != null && Template.ID > 0)
            {
                Template.Update();
            }
            else
            {
                Template.ModuleId = ModuleId;
                Template.Insert();
            }

            #endregion


            #region "定时邮件设置"
            DNNGo_PowerForms_Scheduler SchedulerItem = DNNGo_PowerForms_Scheduler.FindSettings(this);
            SchedulerItem.Enable      = cbScheduleEnable.Checked ? 1 : 0;
            SchedulerItem.ExcelName   = txtExcelName.Text.Trim();
            SchedulerItem.SenderEmail = txtScheduleSenderEmail.Text.Trim();
            DNNGo_PowerForms_Scheduler.UpdateSettings(SchedulerItem, this);


            //UpdateModuleSetting("PowerForms_Schedule_SenderEmail", txtScheduleSenderEmail.Text.Trim());
            //UpdateModuleSetting("PowerForms_Schedule_ExcelName", txtExcelName.Text.Trim());
            //UpdateModuleSetting("PowerForms_Schedule_Enable", cbScheduleEnable.Checked.ToString());


            if (cbScheduleEnable.Checked)//开启或创建调度器
            {
                SchedulerHelper sh = new SchedulerHelper();
                sh.UpdateScheduler(this);
            }


            #endregion
        }