-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
176 lines (155 loc) · 5.41 KB
/
MainForm.cs
File metadata and controls
176 lines (155 loc) · 5.41 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using NeoFlyExport.Properties;
using System;
using System.IO;
using System.Windows.Forms;
namespace NeoFlyExport
{
public partial class MainForm : Form
{
private NeoFlyData neoFlyData = new NeoFlyData();
public MainForm()
{
InitializeComponent();
}
private void MainForm_Shown(object sender, EventArgs e)
{
LoadData();
BindSettings();
}
// Loads data from the database and binds it to the datagrid
private void LoadData()
{
try
{
Cursor = Cursors.WaitCursor;
tspbLoad.Visible = true;
Enabled = false;
neoFlyData.LoadStarted += NeoFlyData_LoadStarted;
neoFlyData.LoadProgress += NeoFlyData_LoadProgress;
neoFlyData.Load();
dgvLog.DataSource = neoFlyData.TableLog;
dgvLog.Columns["Id"].Visible = false;
foreach (DataGridViewColumn col in dgvLog.Columns)
{
col.ReadOnly = col.Name != "Export";
}
dgvLog.AutoResizeColumns();
Enabled = true;
}
finally
{
tspbLoad.Visible = false;
Cursor = Cursors.Default;
}
}
private void NeoFlyData_LoadStarted(object sender, NeoFlyDataLoadEventArgs e)
{
tspbLoad.Maximum = e.RowCount;
}
private void NeoFlyData_LoadProgress(object sender, NeoFlyDataLoadEventArgs e)
{
tspbLoad.Value = e.CurrentRow;
tspbLoad.Value = e.CurrentRow - 1; // Dirty trick to make the progress bar reach 100% https://stackoverflow.com/a/5332770
Application.DoEvents();
}
private void tsbExportGPX_Click(object sender, EventArgs e)
{
if (sfdGPX.ShowDialog() == DialogResult.OK)
{
Cursor = Cursors.WaitCursor;
try
{
neoFlyData.ExportToGPXFile(sfdGPX.FileName);
}
finally
{
Cursor = Cursors.Default;
}
}
}
private void tsbSelectAll_Click(object sender, EventArgs e)
{
neoFlyData.SelectAllFlights(true);
}
private void tsbSelectNone_Click(object sender, EventArgs e)
{
neoFlyData.SelectAllFlights(false);
}
private void dgvLog_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
// Allows checking a range of checkboxes with a shift-click
if (e.ColumnIndex == dgvLog.Columns["Export"].Index)
{
object value = dgvLog.Rows[e.RowIndex].Cells[e.ColumnIndex].EditedFormattedValue;
foreach (DataGridViewCell cell in dgvLog.SelectedCells)
{
if (cell.ColumnIndex == e.ColumnIndex)
cell.Value = value;
}
}
}
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
Properties.Settings.Default.Save();
}
private void tsddbExportExternalViewer_ButtonClick(object sender, EventArgs e)
{
try
{
// Exports the current selection to a temporary file and opens it in an external viewer
Cursor = Cursors.WaitCursor;
neoFlyData.ExportToExternalViewer();
}
finally
{
Cursor = Cursors.Default;
}
}
private void dgvLog_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
// Exports the current flight to a temporary file and opens it in an external viewer
Cursor = Cursors.WaitCursor;
int logId = (int)dgvLog.Rows[e.RowIndex].Cells["Id"].Value;
neoFlyData.ExportToExternalViewer(logId);
}
finally
{
Cursor = Cursors.Default;
}
}
private void tsbSettings_Click(object sender, EventArgs e)
{
new SettingsForm().ShowDialog();
BindSettings();
}
private void BindSettings()
{
tsddbExportExternalViewer.Visible = Settings.Default.ExternalViewers.Count > 0;
tsddbExportExternalViewer.DropDownItems.Clear();
foreach (var viewer in Settings.Default.ExternalViewers)
{
tsddbExportExternalViewer.DropDownItems.Add(new ToolStripButton()
{
Text = Path.GetFileNameWithoutExtension(viewer),
DisplayStyle = ToolStripItemDisplayStyle.Text,
ToolTipText = viewer
});
}
}
private void tsddbExportExternalViewer_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
try
{
// Exports the current selection to a temporary file and opens it in an external viewer
Cursor = Cursors.WaitCursor;
neoFlyData.ExportToExternalViewer(0, e.ClickedItem.ToolTipText);
}
finally
{
Cursor = Cursors.Default;
}
}
}
}