private void Export(bool optionCustomersWithOrders, bool optionNewsletterSubscribers) { List <object> exportList = new List <object>(); if (optionNewsletterSubscribers) { List <NewsLetter> newsletterMailingList = NewsLetter.NewsLetterMailingList(optionCustomersWithOrders); exportList = newsletterMailingList.ConvertAll <object>(delegate(NewsLetter g) { return((object)g); }); } else { List <GridCustomer> customerList = new List <GridCustomer>(); if (optionCustomersWithOrders) // filter to customers only with orders { var allCustomers = GridCustomer.GetCustomers(); foreach (var c in allCustomers) { Customer customer = new Customer(c.CustomerID); if (customer.HasOrders()) { customerList.Add(c); } } } else // return all customers { customerList = GridCustomer.GetCustomers(); } exportList = customerList.ConvertAll <object>(delegate(GridCustomer g) { return((object)g); }); } StringBuilder strMailingList = new StringBuilder(); Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=MailingList.csv"); Response.ContentType = "text/csv"; Response.AddHeader("Pragma", "public"); strMailingList.Append(CSVExporter.ExportListToCSV(exportList)); Response.Write(strMailingList.ToString()); Response.End(); }
/// <summary> /// Handles the send button OnClick event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSend_Click(object sender, EventArgs e) { bool testOnly = (rbTestOnly.SelectedValue == "1"); bool withOrdersOnly = (rbCustomersWithOrder.SelectedValue == "1"); bool listOnly = (rbListCustomers.SelectedValue == "1"); bool newsLetter = (rbNewsletter.SelectedValue == "1"); string mailSubject = txtSubject.Text; string mailBody = radDescription.Content; string mailFooter = new Topic("mailfooter").Contents; StringBuilder emailListText = new StringBuilder(); List <EMail> mailingList = new List <EMail>(); if (newsLetter) { mailingList = EMail.NewsLetterMailingList(); } else { mailingList = EMail.MailingList(BulkMailTypeEnum.EmailBlast, withOrdersOnly, mailSubject); } if (listOnly) { List <GridCustomer> l = GridCustomer.GetCustomers(); //List<GridProductVariant> l = GridProductVariant.GetAllVariants(false, AppLogic.EntityType.Unknown, 0); List <object> newList = l.ConvertAll <object>(delegate(GridCustomer g) { return((object)g); }); Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=MailingList.csv"); Response.ContentType = "text/csv"; Response.AddHeader("Pragma", "public"); Response.Write(CSVExporter.ExportListToCSV(newList)); Response.End(); } else { //Send a single message to the currently logged in user if (testOnly) { EMail objEmail = new EMail(); objEmail.RecipientID = ThisCustomer.CustomerID; objEmail.RecipientGuid = ThisCustomer.CustomerGUID; objEmail.EmailAddress = ThisCustomer.EMail; objEmail.MailSubject = mailSubject; objEmail.MailContents = mailBody; objEmail.MailFooter = (new Topic("mailfooter").Contents); objEmail.IncludeFooter = true; objEmail.LogMessage = true; objEmail.Send(); } //Sending Emails else { BulkMailing bm = new BulkMailing(mailingList, mailBody, mailSubject, mailFooter, true, Session.SessionID); if (bm.MailingList.Count > 0) { BulkMailing.ExecuteAsyncBulkSend executeAsyncSend = new BulkMailing.ExecuteAsyncBulkSend(bm.ExecuteBulkSend); //We will check status in case the operation finishes and we need to re-enable buttons, etc. AsyncCallback cb = new AsyncCallback(MailingComplete); IAsyncResult result = executeAsyncSend.BeginInvoke(cb, null); ifrStatus.Attributes["src"] = "asyncstatus.aspx?id=" + Session.SessionID; ifrStatus.Visible = true; ltError.Text = AppLogic.GetString("admin.mailingmgr.BulkMailSending", ThisCustomer.LocaleSetting); btnRemoveEmail.Enabled = false; btnSend.Enabled = false; } else { btnRemoveEmail.Enabled = true; btnSend.Enabled = true; ifrStatus.Visible = false; ltError.Text = AppLogic.GetString("admin.mailingmgr.NoEmails", ThisCustomer.LocaleSetting); } } } }