Exemplo n.º 1
0
        protected void btnForceNext_Click(object sender, EventArgs e)
        {
            TrackerDotNet.classes.TrackerTools _TTools = new TrackerDotNet.classes.TrackerTools();
            DateTime       _dt          = _TTools.GetClosestNextRoastDate(DateTime.Now.AddDays(14).Date); // add a fortnight;
            ClientUsageTbl _ClientUsage = new ClientUsageTbl();

            _ClientUsage.ForceNextCoffeeDate(_dt.AddDays(3), StringToInt64(CompanyIDLabel.Text));

            CustomersTbl _CustomerTbl = new CustomersTbl();

            _CustomerTbl.IncrementReminderCount(StringToInt64(CompanyIDLabel.Text));

            dgCustomerUsage.DataBind();

            string _ScriptToRun = "showMessage('" + String.Format("{0} force to skip a week of prediction", CompanyNameTextBox.Text) + "');";

            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "CustomerInserted", _ScriptToRun, true);
        }
Exemplo n.º 2
0
        /// <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();
        }