private bool SaveWithNames(bool savingWithDate, bool saveWithDate, DateTime dateFrom, DateTime dateTo, List <string> allEmails) //savingWithDate - in main window checked to save with date, saveWithDate - save with date in file name { string excelFileName = "some"; if (saveWithDate) { excelFileName = DateTime.Now.Date.ToString("MM/dd/yyyy") + "-AdresųEksportas"; if (savingWithDate) { excelFileName = excelFileName + "-" + dateFrom.Date.ToString("MM/dd/yyyy") + "-" + dateTo.Date.ToString("MM/dd/yyyy"); } } else { excelFileName = TextBox_FileName.Text; } bool saved = ExcelFuncions.AddEmailsToFile(excelFileName, this.savingFolderName, allEmails); return(saved); }
private void Button_Send_Click(object sender, EventArgs e) { if (currentUser != null) { bool fromExcel = false; Regex rgx = new Regex(@"^\s+$"); List <string> allEmailsList = new List <string>(); List <string> goodEmailList = new List <string>(); this.Enabled = false; badEmailList = new List <string>(); OpenFileDialog_ExportAddressList.Disposed += MainWindowEnableHandler; if (rgx.IsMatch(TextBox_Emails.Text) || TextBox_Emails.Text == "") { OpenFileDialog_ExportAddressList.Filter = "Excel Files|*.xlsx;*.xlsm;*.xlsb;*.xltx;*.xltm;*.xls;*.xlt;*.xls;*.xml;*.xml;*.xlam;*.xla;*.xlw;*.xlr;"; DialogResult result = OpenFileDialog_ExportAddressList.ShowDialog(this); if (result == DialogResult.OK) { allEmailsList = ExcelFuncions.GetEmailsFromFile(OpenFileDialog_ExportAddressList.FileName); } if (result == DialogResult.Cancel || result == DialogResult.Abort) { OpenFileDialog_ExportAddressList.Dispose(); } fromExcel = true; } else { string allEmailsString = TextBox_Emails.Text; allEmailsList = allEmailsString.Split('\n').ToList(); } for (int i = 0; i < allEmailsList.Count; i++) { string newEmail = allEmailsList[i]; if (allEmailsList.Count - 1 != i && !fromExcel) { newEmail = newEmail.Remove(newEmail.Count() - 1); } try { if (newEmail != null && newEmail != "" && !newEmail.Contains(Environment.NewLine)) { MailAddress m = new MailAddress(newEmail); goodEmailList.Add(newEmail); } } catch (FormatException) { this.badEmailList.Add(newEmail); } } SendEmail sendEmail = new SendEmail(currentUser.GetEmail(), currentUser.GetPassword()); List <string> emails = goodEmailList; sendEmail.SendEmails(emails, mail.GetSubject(), mail.GetBody()); Success successWindow; if (goodEmailList.Count > 0) { successWindow = new Success("Laiškai išsiųsti sėkmingai!"); successWindow.Show(); if (badEmailList.Count > 0) { successWindow.Disposed += SuccessClosedBadEmailsHandler; } else { successWindow.Disposed += MainWindowEnableHandler; } } else if (badEmailList.Count > 0) { BadEmailsWindow badEmailsWindow = new BadEmailsWindow(this, badEmailList); badEmailsWindow.Show(); } } else { Warning warningWindow = new Warning(this, "Jūs nepasirinkote vartotojo"); warningWindow.Show(); } }