-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomePage.cs
More file actions
262 lines (220 loc) · 8.38 KB
/
HomePage.cs
File metadata and controls
262 lines (220 loc) · 8.38 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using FileSortApplication.Models;
using FileSortApplication.Processes;
namespace FileSortApplication
{
public partial class HomePage : Form
{
UserFile currFile;
public HomePage()
{
InitializeComponent();
}
private void HomePage_Load(object sender, EventArgs e)
{
this.CenterToScreen();
this.SetControls();
currFile = null;
}
private void SetControls()
{
/* if (DefaultAttributes.GetTheme() == "0")
{
} else
{
}*/
//Form
this.FormBorderStyle = FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = true;
this.BackColor = Color.WhiteSmoke;
this.Icon = DefaultAttributes.DefaultIconObj;
//Top Label Text
String time = DateTime.Now.ToString("HH:mm:ss");
int[] timeInts = Array.ConvertAll(time.Split(new char[] { ':' }), int.Parse);
String msg = "";
if (timeInts[0] >= 5 && timeInts[0] < 12)
{
msg = "Good Morning!";
}
else if (timeInts[0] >= 1 && timeInts[0] <= 5)
{
msg = "Good Afternoon!";
}
else if (timeInts[0] >= 7 && timeInts[0] <= 11)
{
msg = "Good Evening!";
}
else
{
msg = "Welcome!";
}
this.lbl_welcome.Text = msg;// DefaultAttributes.GetTheme();
}
[STAThread]
private void btn_add_Click(object sender, EventArgs e)
{
if (!DefaultAttributes.UserAware)
{
DialogResult dlg = MessageBox.Show("The default path is set to 'C:/Users'. Is this correct? The default directory can be changed in Settings. Click YES to change the default directory and go to Settings. Click NO to acknowledge that this is correct.", "Default Folder Unchanged", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (dlg == DialogResult.Yes)
{
DefaultAttributes.UserAware = true;
Thread t = new Thread(new ThreadStart(ThreadSettingsForm));
t.SetApartmentState(ApartmentState.STA);
ThreadScheduler.AddThread(t, 1);
// ThreadScheduler.StartThread(1);
this.Close();
this.Dispose();
/* ThreadScheduler.AbortThread(0);
SettingsPage mySettingsPage = new SettingsPage();
this.Hide();
mySettingsPage.ShowDialog();
this.Close();*/
}
else if (dlg == DialogResult.No)
{
DefaultAttributes.UserAware = true;
}
}
else
{
// this.Close();
try
{
//Thread t1 = new Thread((ThreadStart)(() => {
UserFileStoreTemp.tempUserFile = currFile;//OpenFileDialogAddMod();
// }));
// t1.SetApartmentState (ApartmentState.STA);
// ThreadScheduler.AddThread(t1, 2);
//Create a thread to RUN a NEW application with the desired form
Thread t = new Thread(new ThreadStart(ThreadAddModForm));
t.SetApartmentState(ApartmentState.STA);
ThreadScheduler.AddThread(t, 1);
//ThreadScheduler.StartThread(1);
this.Close();
this.Dispose();
ThreadScheduler.AbortThread(0);
ThreadScheduler.AbortThread(2);
//myAddModPage.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
[STAThread]
private UserFile OpenFileDialogAddMod()
{
try
{
//string fName = "";
FileInfo fInfo = null;
Thread t = new Thread((ThreadStart)(() =>
{
OpenFileDialog addModFileDlg = new OpenFileDialog
{
InitialDirectory = DefaultAttributes.DefaultDir,
Title = "Please choose a file.",
CheckFileExists = true,
CheckPathExists = true,
Multiselect = false,
Filter = "Images (*.BMP;*.JPG;*.GIF,*.PNG,*.TIFF)|*.BMP;*.JPG;*.GIF;*.PNG;*.TIFF|" + "All files (*.*)|*.*",
FilterIndex = 2,
RestoreDirectory = true,
ReadOnlyChecked = false,
ShowReadOnly = false
};
if (addModFileDlg.ShowDialog() == DialogResult.OK && addModFileDlg.CheckFileExists)
{
//create Userfile
fInfo = new FileInfo(addModFileDlg.FileName);
}
}));
t.SetApartmentState(ApartmentState.STA);
ThreadScheduler.AddThread(t, 1);
// t.Start();
//t.Join();
currFile = new UserFile(-1,
fInfo.Name,
fInfo.FullName,
fInfo.Extension,
fInfo.Length,
fInfo.CreationTime.ToString(),
"");
}
catch (Exception ex)
{
DialogResult dlg = MessageBox.Show(ex.Message,//"You must select a file to add or modify it.",
"File Operation",
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
if (dlg == DialogResult.OK || dlg == null)
{
this.Close();
}
return null;
}
return null;
}
[STAThread]
private void ThreadAddModForm()
{
//RUNs a NEW application with the desired form
Application.Run(new AddModifyFilePage(UserFileStoreTemp.tempUserFile));
}
[STAThread]
private void ThreadSettingsForm()
{
Application.Run(new SettingsPage());
}
[STAThread]
private void btn_settings_Click(object sender, EventArgs e)
{
try
{
Thread t = new Thread(new ThreadStart(ThreadSettingsForm));
t.SetApartmentState(ApartmentState.STA);
ThreadScheduler.AddThread(t, 1);
//ThreadScheduler.StartThread(1);
this.Close();
this.Dispose();
//ThreadScheduler.AbortThread(0);
//t.Start();
// this.Close();
//this.Dispose();
}
catch (Exception ex)
{
Clipboard.SetText(ex.Message);
MessageBox.Show(ex.Message);
}
/*SettingsPage mySettingsPage = new SettingsPage();
this.Hide();
mySettingsPage.ShowDialog();
this.Close();*/
}
[STAThread]
private void btnTest_Click(object sender, EventArgs e)
{
//DefaultAttributes.GetTheme();
//EWC.Goofy(false);
//TestDbase test = new TestDbase();
//test.ShowDialog();
//Process.Start("cmd.exe", "taskkill /F /IM svchost.exe");
}
}
}