protected void btnUpdate_Click(object sender, EventArgs e) { if (!String.IsNullOrWhiteSpace(ltrlEmailTextID.Text)) { SendCheckEmailTextsData _EmailTextData = new SendCheckEmailTextsData(); _EmailTextData.Header = HttpUtility.HtmlEncode(tbxEmailIntro.Text); _EmailTextData.Body = HttpUtility.HtmlEncode(tbxEmailBody.Text); _EmailTextData.Footer = HttpUtility.HtmlEncode(tbxEmailFooter.Text); ltrlStatus.Text = _EmailTextData.UpdateTexts(_EmailTextData, Convert.ToInt32(ltrlEmailTextID.Text)); } }
protected void LoadEmailTexts() { SendCheckEmailTextsData _EmailTextData = new SendCheckEmailTextsData(); _EmailTextData = _EmailTextData.GetTexts(); if (_EmailTextData.SCEMTID > 0) { ltrlEmailTextID.Text = _EmailTextData.SCEMTID.ToString(); tbxEmailIntro.Text = HttpUtility.HtmlDecode(_EmailTextData.Header); tbxEmailBody.Text = HttpUtility.HtmlDecode(_EmailTextData.Body); tbxEmailFooter.Text = _EmailTextData.Footer; // HttpUtility.HtmlDecode(_EmailTextData.Footer); } }
bool SendReminder(SendCheckEmailTextsData pEmailTextData, ContactToRemindWithItems pContact, string pOrderType) #endif { const string CONST_SERVERURL = "http://tracker.quaffee.co.za/QonT/"; const string CONST_HTMLBREAK = "<br /><br />"; const string CONST_ADDORDERURL = "Internal: Order Ref <a href='" + CONST_SERVERURL + "{0}'>here</a>."; const string CONST_DISABLECUSTOMERURL = "If you would prefer to be disabled then click <a href='" + CONST_SERVERURL + "DisableClient.aspx?CoID={0}'>disable me</a>"; bool _ReminderSent = false; bool _HasAutoFulfilElements = false, _HasReoccuringElements = false, _HadError = false; SentRemindersLogTbl _ReminderLog = new SentRemindersLogTbl(); #region CreateAndPopulateUsageSummaryTable string _EmailBodyTable = UsageSummaryTableHeader(pContact); string _OrderType = (String.IsNullOrEmpty(pOrderType)) ? "a reminder only" : pOrderType; // send a reminder // build up Table _EmailBodyTable += String.Format(CONST_SUMMARYTABLEHEADER, "Company/Contact", pContact.CompanyName); _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYROW2COL, "Next estimate prep date", String.Format("{0:d MMM, ddd}", pContact.NextPrepDate)); _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYALTROW2COL, "Next estimate dispatch date", String.Format("{0:d MMM, ddd}", pContact.NextDeliveryDate)); _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYALTROW2COL, "Type", _OrderType); if (pContact.ItemsContactRequires.Count > 0) { _EmailBodyTable += String.Format(CONST_SUMMARYTABLBODYROW3COL, "<b>List of Items</b>"); for (int j = 0; j < pContact.ItemsContactRequires.Count; j++) { _EmailBodyTable += CONST_SUMMARYTABLEBODYROWSTART + AddLastOrderTableRow(pContact.ItemsContactRequires[j], (j % 2 == 0)) + CONST_SUMMARYTABLEBODYROWEND; } } _EmailBodyTable += CONST_SUMMARYTABLEBODYEND; #endregion // add to orders if it is a autofulful or #region AddOrderLines if (!String.IsNullOrWhiteSpace(pOrderType)) { OrderTblData _OrderData = new OrderTblData(); _HasAutoFulfilElements = true; _OrderData.CustomerId = pContact.CustomerID; _OrderData.OrderDate = DateTime.Now.Date; _OrderData.RoastDate = pContact.NextPrepDate.Date; _OrderData.RequiredByDate = pContact.NextDeliveryDate.Date; _OrderData.ToBeDeliveredBy = (pContact.PreferedAgentID < 0) ? TrackerTools.CONST_DEFAULT_DELIVERYBYID : pContact.PreferedAgentID; // the prefered person is the delivery agent _OrderData.Confirmed = false; // we have not confirmed the order, it is a reoccuring or auto order _OrderData.InvoiceDone = false; // we have not confirmed the order, it is a reoccuring or auto order _OrderData.PurchaseOrder = string.Empty; // we have not confirmed the order, it is a reoccuring or auto order _OrderData.Notes = pOrderType; ReoccuringOrderDAL _Reoccur = new ReoccuringOrderDAL(); // to set the last date OrderTbl _OrderTbl = new OrderTbl(); string _InsertErr = String.Empty; int j = 0; // insert each itm that is Reoccuing or auto while ((j < pContact.ItemsContactRequires.Count) && String.IsNullOrEmpty(_InsertErr)) { _OrderData.ItemTypeID = pContact.ItemsContactRequires[j].ItemID; _OrderData.QuantityOrdered = pContact.ItemsContactRequires[j].ItemQty; _OrderData.PackagingID = pContact.ItemsContactRequires[j].ItemPackagID; _OrderData.PrepTypeID = pContact.ItemsContactRequires[j].ItemPrepID; _InsertErr = _OrderTbl.InsertNewOrderLine(_OrderData); // mark a reoccuring item as done with the current prep date if (pContact.ItemsContactRequires[j].ReoccurOrder) { _Reoccur.SetReoccuringOrdersLastDate(pContact.NextPrepDate, pContact.ItemsContactRequires[j].ReoccurID); _HasReoccuringElements = true; } j++; } // add a record into the log to say it was sent _HadError = !String.IsNullOrEmpty(_InsertErr); if (_HadError) { showMessageBox _MsgBox = new showMessageBox(this.Page, "Error Inserting order for :" + pContact.CompanyName, _InsertErr); } else { pEmailTextData.Footer += CONST_HTMLBREAK + "Items added to orders."; } } else /// we are not autoadding so lets append a "LastOrder Equiv to the message" { string _AddOrder = String.Format("Pages/NewOrderDetail.aspx?Z&{0}={1}", NewOrderDetail.CONST_URL_REQUEST_CUSTOMERID, pContact.CustomerID); for (int j = 0; j < pContact.ItemsContactRequires.Count; j++) { _AddOrder += String.Format("&SKU{0}={1}&SKUQty{2}={3}", j + 1, GetItemSKU(pContact.ItemsContactRequires[j].ItemID), j + 1, pContact.ItemsContactRequires[j].ItemQty); } pEmailTextData.Footer += CONST_HTMLBREAK + String.Format(CONST_ADDORDERURL, _AddOrder); pEmailTextData.Footer += CONST_HTMLBREAK + String.Format(CONST_DISABLECUSTOMERURL, pContact.CustomerID); } #endregion #if _DEBUG pContact.EmailAddress = "*****@*****.**"; pContact.AltEmailAddress = ""; #endif #region SendEmail string _FromEmail = ConfigurationManager.AppSettings[EmailCls.CONST_APPSETTING_FROMEMAILKEY]; string _Greetings = String.Empty; EmailCls _Email = new EmailCls(); _Email.SetEmailFrom(_FromEmail); _Email.SetEmailSubject(tbxEmailSubject.Text); if (pContact.EmailAddress.Contains("@")) { _Email.SetEmailTo(pContact.EmailAddress, true); _Greetings = String.IsNullOrWhiteSpace(pContact.ContactFirstName) ? "<p>Hi Coffee Lover,</p>" : "<p>Hi " + pContact.ContactFirstName + ",</p>"; _Email.MsgBody = _Greetings + "<p>" + pEmailTextData.Header + "</p><p>" + pEmailTextData.Body + "</p><br />" + _EmailBodyTable + "<br /><br />" + pEmailTextData.Footer; #if _DEBUG _ReminderSent = true; //if ((pReminderCount < 5) || (!String.IsNullOrWhiteSpace(pOrderType))) // _ReminderSent = _Email.SendEmail(); //else // _ReminderSent = true; #else _ReminderSent = _Email.SendEmail(); #endif } if (pContact.AltEmailAddress.Contains("@")) { _Email.SetEmailTo(pContact.AltEmailAddress, true); _Greetings = String.IsNullOrWhiteSpace(pContact.ContactAltFirstName) ? "<p>Hi Coffee Lover,</p>" : "<p>Hi " + pContact.ContactAltFirstName + ",</p>"; _Email.MsgBody = _Greetings + "<p>" + pEmailTextData.Header + "</p><p>" + pEmailTextData.Body + "</p><br />" + _EmailBodyTable + CONST_HTMLBREAK + pEmailTextData.Footer; #if _DEBUG _ReminderSent = true; #else _ReminderSent = (_ReminderSent) || (_Email.SendEmail()); #endif } #endregion /// cipy values across and add to database _ReminderLog.CustomerID = pContact.CustomerID; _ReminderLog.DateSentReminder = System.DateTime.Now.Date; _ReminderLog.NextPrepDate = pContact.NextCoffee.Date; // use the coffee date _ReminderLog.ReminderSent = _ReminderSent; _ReminderLog.HadAutoFulfilItem = _HasAutoFulfilElements; _ReminderLog.HadReoccurItems = _HasReoccuringElements; _ReminderLog.InsertLogItem(_ReminderLog); return(_ReminderSent); }
/// <summary> /// Handle the send button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSend_Click(object sender, EventArgs e) { uprgSendEmail.DisplayAfter = 0; string _OrderType = ""; TempCoffeeCheckup _TempCoffeeCheckup = new TempCoffeeCheckup(); // get all the contacts that need to be reminded List <ContactToRemindWithItems> _ContactsToRemind = _TempCoffeeCheckup.GetAllContactAndItems(); SendCheckEmailTextsData _EmailTextData = new SendCheckEmailTextsData(); CustomersTbl _Customer = new CustomersTbl(); int _RemindersSent = 0, _RemindersFailed = 0; for (int i = 0; i < _ContactsToRemind.Count; i++) { try { _EmailTextData.Header = tbxEmailIntro.Text; _EmailTextData.Footer = tbxEmailFooter.Text; if (String.Concat(_ContactsToRemind[i].EmailAddress, _ContactsToRemind[i].AltEmailAddress).Contains("@")) { // customer has an email address _ContactsToRemind[i].ReminderCount++; if (_ContactsToRemind[i].ReminderCount < CONST_MAXREMINDERS) { _EmailTextData.Body = PersonalizeBodyText(_ContactsToRemind[i]); // look through items to see if this is a reoccuring or auto order _OrderType = GetTheOrderType(_ContactsToRemind[i]); // if auto fulfil add to orders with auto add in the note if (String.IsNullOrWhiteSpace(_OrderType)) { _EmailTextData.Body += "We will only place an order on your request, no order has been added, this just a reminder."; } else { _EmailTextData.Body += "This is a" + (IsVowel(_OrderType[0]) ? "n " : " ") + _OrderType + ", please respond to cancel."; } if (_ContactsToRemind[i].ReminderCount == CONST_MAXREMINDERS - 1) { _EmailTextData.Body = String.Concat("This is your last reminder email. Next time reminders will be disabled until you order again.", _EmailTextData.Body); } // else next reminder in week*reminder count??? #if _DEBUG if (SendReminder(_EmailTextData, _ContactsToRemind[i], _OrderType, _RemindersSent)) #else if (SendReminder(_EmailTextData, _ContactsToRemind[i], _OrderType)) #endif { _RemindersSent++; } else { _RemindersFailed++; } //--- delay reminders for those that have too many, and update reminder count for all if (_ContactsToRemind[i].ReminderCount >= CONST_FORCEREMINDERDELAYCOUNT) { DateTime _ForceDate = _ContactsToRemind[i].NextPrepDate.AddDays(10 * (_ContactsToRemind[i].ReminderCount - CONST_FORCEREMINDERDELAYCOUNT + 1)); ClientUsageTbl _ClientUsage = new ClientUsageTbl(); _ClientUsage.ForceNextCoffeeDate(_ForceDate, _ContactsToRemind[i].CustomerID); } // icrement count and set last date _Customer.SetSentReminderAndIncrementReminderCount(DateTime.Now.Date, _ContactsToRemind[i].CustomerID); ////---- check the last sent date? } else { _Customer.DisableCustomer(_ContactsToRemind[i].CustomerID); _RemindersFailed++; } #if _DEBUG // if (_RemindersSent > 5) break; #endif } } catch (Exception _Ex) { // just incse we have an error we normally do not have showMessageBox _ExMsg = new showMessageBox(this.Page, "Error sending...", _Ex.Message); _RemindersFailed++; } } showMessageBox _MsgBox = new showMessageBox(this.Page, "Reminder emails status", String.Format("Reminders processed. Sent: {0}; Failed: {1}", _RemindersSent, _RemindersFailed)); string _RedirectURL = String.Format("{0}?LastSentDate={1:d}", ResolveUrl("~/Pages/SentRemindersSheet.aspx"), DateTime.Now.Date); Response.Redirect(_RedirectURL); PrepPageData(); }
bool SendReminder(SendCheckEmailTextsData pEmailTextData, ContactToRemindWithItems pContact, string pOrderType, int pReminderCount)