-
Notifications
You must be signed in to change notification settings - Fork 5
/
ResultForm.cs
58 lines (49 loc) · 1.54 KB
/
ResultForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.IO;
using System.Windows.Forms;
namespace ZenStatesDebugTool
{
public partial class ResultForm : Form
{
public ResultForm()
{
InitializeComponent();
}
private void SaveToFile(string filename="")
{
string fileName = filename;
if (filename.Trim().Length == 0)
{
string unixTimestamp = Convert.ToString((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMinutes);
fileName = $@"{String.Join("_", this.Text.Split())}_{unixTimestamp}.txt";
}
if (File.Exists(fileName))
{
File.Delete(fileName);
}
using (var sw = new StreamWriter(fileName, true))
{
sw.WriteLine(textBoxFormResult.Text);
}
MessageBox.Show($"File saved as {fileName}");
}
private void buttonSaveResult_Click(object sender, EventArgs e)
{
SaveToFile();
}
private void buttonSaveAs_Click(object sender, EventArgs e)
{
SaveFileDialog saveFileDialog1 = new SaveFileDialog
{
Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*",
FilterIndex = 1,
DefaultExt = "txt",
RestoreDirectory = true
};
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
SaveToFile(saveFileDialog1.FileName);
}
}
}
}