diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index 19645ee..fe132ee 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -42,6 +42,7 @@ this.administrationToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.helpToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.exportResultToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.resultStatusStrip.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -127,6 +128,8 @@ // // fileToolStripMenuItem // + this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.exportResultToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(48, 20); this.fileToolStripMenuItem.Text = "Файл"; @@ -176,6 +179,13 @@ this.helpToolStripMenuItem.Size = new System.Drawing.Size(65, 20); this.helpToolStripMenuItem.Text = "Справка"; // + // exportResultToolStripMenuItem + // + this.exportResultToolStripMenuItem.Name = "exportResultToolStripMenuItem"; + this.exportResultToolStripMenuItem.Size = new System.Drawing.Size(219, 22); + this.exportResultToolStripMenuItem.Text = "Экспортировать результат"; + this.exportResultToolStripMenuItem.Click += new System.EventHandler(this.exportResultToolStripMenuItem_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -216,6 +226,7 @@ private System.Windows.Forms.ToolStripMenuItem administrationToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem journalToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem exportResultToolStripMenuItem; } } diff --git a/MainForm.cs b/MainForm.cs index acb76cb..84fbdc6 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -12,6 +12,9 @@ namespace AwesomeEmailExtractor { public partial class MainForm : Form { + public int count; + public List uniqueEmails; + public MainForm() { InitializeComponent(); @@ -36,10 +39,10 @@ namespace AwesomeEmailExtractor uniqueListBox.DataSource = null; // Объявляем список уникальных e-mail-ов - List uniqueEmails = new List(); + uniqueEmails = new List(); // Вызываем метод для извлечения e-mail-ов - int count = ExtactEmailsAlgorithm.Extract(sourceText, out uniqueEmails); + count = ExtactEmailsAlgorithm.Extract(sourceText, out uniqueEmails); // Выводим результат toolStripStatusLabel.Text = "Успех!"; @@ -80,5 +83,27 @@ namespace AwesomeEmailExtractor AdministrationForm administrationForm = FormManager.Current.CreateForm(); administrationForm.ShowDialog(this); } + + private void exportResultToolStripMenuItem_Click(object sender, EventArgs e) + { + // Показать окно с выбором файла + SaveFileDialog saveFileDialog = new SaveFileDialog(); + saveFileDialog.Filter = "Текстовый файл (*.txt)|*.txt"; + saveFileDialog.FileName = "Результат.txt"; + + var res = saveFileDialog.ShowDialog(); + + + // Сохранить результат в файл + if (res == DialogResult.OK) + { + string fileName = saveFileDialog.FileName; + string resultText = $"Количество e-mail-ов в тексте: {count}\nСписок уникальных e-mail-ов:\n{string.Join("\n", uniqueEmails)}"; + + System.IO.File.WriteAllText(fileName, resultText); + + MessageBox.Show("E-mail-ы успешно сохранены в файл", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } } }