-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
102 lines (92 loc) · 2.68 KB
/
MainForm.cs
File metadata and controls
102 lines (92 loc) · 2.68 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
namespace TextSearch
{
using System;
using System.IO;
using System.Windows.Forms;
using TextSearch.TextFiles;
/// <summary>
///
/// </summary>
public partial class MainForm : Form
{
private OpenFileDialog openFileDialog;
private IFile file;
public MainForm()
{
InitializeComponent();
CreateFileLoading();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void LoadFile_Click(object sender, EventArgs e)
{
CreateFileLoading();
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
pathTextBox.Text = openFileDialog.FileName;
FileLoading(SelectedType(openFileDialog.FilterIndex), pathTextBox.Text);
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SearchButton_Click(object sender, EventArgs e)
{
resultListView.DataSource = (file as IFile).Find(searchTextBox.Text);
}
/// <summary>
///
/// </summary>
private void CreateFileLoading()
{
if (openFileDialog != null)
{
return;
}
openFileDialog = new OpenFileDialog();
openFileDialog.Multiselect = false;
openFileDialog.Filter = SupportedFileTypes();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private string SupportedFileTypes()
{
string files = string.Empty;
foreach (string type in Enum.GetNames(typeof(FileTypes)))
{
files += type + "|*." + type.ToLower() + "|";
}
return files.Substring(0, files.Length - 1);
}
private FileTypes SelectedType(int index)
{
return (FileTypes) index;
}
/// <summary>
///
/// </summary>
/// <param name="type"></param>
/// <param name="path"></param>
private void FileLoading(FileTypes type, string path)
{
switch (type)
{
case FileTypes.RTF:
file = new Rtf(path);
break;
default:
file = new Txt(path);
break;
}
textBodyTextBox.Text = file.Body;
documentNameLabel.Text = "Nazwa dokumentu: " + Path.GetFileName(path);
}
}
}