добавляет экспорт результата в файл

This commit is contained in:
Maxim Slipenko 2022-05-24 13:19:07 +03:00
parent c25a92b271
commit 7d71bfeb46
Signed by: Maks1mS
GPG Key ID: 7461AF39A8705FB8
2 changed files with 38 additions and 2 deletions

11
MainForm.Designer.cs generated
View File

@ -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;
}
}

View File

@ -12,6 +12,9 @@ namespace AwesomeEmailExtractor
{
public partial class MainForm : Form
{
public int count;
public List<string> uniqueEmails;
public MainForm()
{
InitializeComponent();
@ -36,10 +39,10 @@ namespace AwesomeEmailExtractor
uniqueListBox.DataSource = null;
// Объявляем список уникальных e-mail-ов
List<string> uniqueEmails = new List<string>();
uniqueEmails = new List<string>();
// Вызываем метод для извлечения 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>();
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);
}
}
}
}