コード例 #1
0
        /// <summary>
        /// 新增
        /// </summary>
        public bool Insert(EmailSendBccAccountEntity model)
        {
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic["EmailID"]                  = model.EmailID;
            dic["EmailBccAccountID"]        = model.EmailBccAccountID;
            dic["EmailSendBccAccountState"] = model.EmailSendBccAccountState;

            return(SQLHelperFactory.Instance.ExecuteNonQuery("Insert_emailsendbccaccount", dic) > 0);
        }
コード例 #2
0
        /// <summary>
        /// 發送郵件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSend_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(htmlEditor.ContentHtml))
            {
                "郵件内容不能爲空".ShowDialog();
                return;
            }
            DateTime?startDatetime = null;

            if ((!dpSendDate.SelectedDate.HasValue && tpSendTime.SelectedTime.HasValue) || (dpSendDate.SelectedDate.HasValue && !tpSendTime.SelectedTime.HasValue))
            {
                "請選擇發送日期/時間".ShowDialog();
                return;
            }
            if (dpSendDate.SelectedDate.HasValue && tpSendTime.SelectedTime.HasValue)
            {
                startDatetime = dpSendDate.SelectedDate.Value;
                startDatetime = startDatetime.Value.AddHours(tpSendTime.SelectedTime.Value.Hour);
                startDatetime = startDatetime.Value.AddMinutes(tpSendTime.SelectedTime.Value.Minute);
            }


            #region 判斷有沒填寫發件人抄送人
            if (_SendMailList.Count == 0)
            {
                "你還沒填寫發件人!".ShowDialog();
                return;
            }
            if (_BccMailList.Count == 0)
            {
                "你還沒填寫抄送人!".ShowDialog();
                return;
            }
            #endregion

            EmailInfoEntity email = new EmailInfoEntity();
            email.EmailTitle    = tbTheme.Text;
            email.EmailFilePath = htmlEditor.ContentHtml;
            email.EmailState    = 2;//新增的時候,是草稿狀態;等新增完成會修改狀態為0
            email.TotalQty      = _BccMailList.Count;
            if (startDatetime.HasValue)
            {
                email.EmailStartSendTime = startDatetime.Value;
            }

            Thread thread = new Thread(s =>
            {
                Stopwatch st = new Stopwatch();
                st.Start();
                int bccTotal = _BccMailList.Count;
                this.Dispatcher.BeginInvoke(MainWindow.ShowMessage, string.Format("正在新增邮件,进度:{0}/{1},耗時:{2}秒", 0, bccTotal, 0));

                //新增郵件
                int EmailID = ER_Repository.Insert(email);
                if (EmailID <= 0)
                {
                    return;
                }
                foreach (var send in _SendMailList)
                {
                    EmailSendAccountEntity entity = new EmailSendAccountEntity();
                    entity.EmailID        = EmailID;
                    entity.EmailAccountID = send.EmailAccountID;
                    ESR_Repository.Insert(entity);
                }


                //LogHelper.Info("插入發送信息時間:" + DateTime.Now + ",插入密送人數量:" + _BccMailList.Count);
                int bccCount = 0;
                List <EmailSendBccAccountEntity> sendBcc = new List <EmailSendBccAccountEntity>();
                foreach (var bcc in _BccMailList)
                {
                    bccCount++;
                    EmailSendBccAccountEntity entity = new EmailSendBccAccountEntity();
                    entity.EmailID                  = EmailID;
                    entity.EmailBccAccountID        = bcc.EmailBccAccountID;
                    entity.EmailSendBccAccountState = 0;
                    sendBcc.Add(entity);
                    if (bccCount > 100)
                    {
                        ESBR_Repository.InsertBatch(sendBcc);
                        this.Dispatcher.BeginInvoke(MainWindow.ShowMessage, string.Format("新增郵件中,進度:{0}/{1},耗時:{2}秒", bccCount, bccTotal, st.ElapsedMilliseconds / 1000));
                        sendBcc.Clear();
                    }
                }
                if (sendBcc.Count > 0)
                {
                    ESBR_Repository.InsertBatch(sendBcc);
                }

                email.EmailID    = EmailID;
                email.EmailState = 0;
                ER_Repository.Update(email);
                st.Stop();
                this.Dispatcher.BeginInvoke(MainWindow.ShowMessage, string.Format("新增邮件完成,进度:{0}/{1},耗時:{2}秒", bccCount, bccTotal, st.ElapsedMilliseconds / 1000));
                _SendMailList.Clear();
                _BccMailList.Clear();
            });
            thread.Start();
            "正在後臺進行郵件新建,將會關閉當前窗口,草稿狀態==正在創建郵件中".ShowDialog();

            this.Dispatcher.BeginInvoke(MainWindow.GotoPage, "郵件管理");

            ClearControl();
        }