-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm3.cs
516 lines (455 loc) · 14.1 KB
/
Form3.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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
/*
* Created by SharpDevelop.
* User: JT
* Date: 17.2.2010
* Time: 12:59
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Threading;
using System.IO;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using System.Data.OleDb;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Data.SqlTypes;
namespace PDFv2
{
/// <summary>
/// Description of Form3.
/// </summary>
public partial class Form3 : Form
{
private connect connect = new connect();
public Form3()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
int rdr=0;
void Form3Load(object sender, EventArgs e)
{
// this.compare.Enabled = false;
this.ShowDBClick(sender, e);
// ShDB();
}
/* void showDBaseClick(object sender, EventArgs e)
{
//richSolutionX.Text = "";
this.dbCondList.Items.Clear();
this.dbFileList.Items.Clear();
MySqlDataReader Reader;
Reader = connect.executeGetFile();
while (Reader.Read())
{
ListViewItem rowFile = new ListViewItem(Reader.GetValue(0).ToString());
rowFile.SubItems.Add(Reader.GetValue(1).ToString());
rowFile.SubItems.Add(Reader.GetValue(2).ToString());
dbFileList.Items.Add(rowFile);
}
Reader.Close();
}
*/
public void disableBtn()
{
SetbuttonEnable(showDB, false);
// SetbuttonEnable(compare, false);
// SetbuttonEnable(createdb, false);
SetbuttonEnable(download, false);
SetbuttonEnable(DropDB, false);
/*
this.showDB.Enabled = false;
this.compare.Enabled = false;
this.createdb.Enabled = false;
this.download.Enabled = false;
this.DropDB.Enabled = false;
*/
}
private Thread noveVlakno;
public void enableBtn()
{
SetbuttonEnable(showDB, true);
// SetbuttonEnable(compare, true);
// SetbuttonEnable(createdb, true);
SetbuttonEnable(download, true);
SetbuttonEnable(DropDB, true);
/*
this.showDB.Enabled = true;
// this.compare.Enabled = true;
this.createdb.Enabled = true;
this.download.Enabled = true;
this.DropDB.Enabled = true;
*/
}
void ShowDBClick(object sender, EventArgs e)
{
rdr = 1;
disableBtn();
SetStatusLabelText(StatusLabel, "Loading");
this.CondTextBox.Clear();
this.richTextBox1.Clear();
this.listCompare.Items.Clear();
this.listviewdb.Items.Clear();
this.listresult.Items.Clear();
noveVlakno = new Thread(ShDB);
noveVlakno.Start();
// ShDB();
}
public void ShDB()
{
SetStatusLabelText(StatusLabel, "Loading");
MySqlDataReader Reader;
Reader = connect.executeGetFile();
while (Reader.Read())
{
ListViewItem rowFile = new ListViewItem(Reader.GetValue(0).ToString());
rowFile.SubItems.Add(Reader.GetValue(1).ToString());
rowFile.SubItems.Add(Reader.GetValue(2).ToString());
SetListViewText(listresult, rowFile);
}
Reader.Close();
enableBtn();
SetStatusLabelText(StatusLabel, "Done");
rdr=0;
}
/* void CompareClick(object sender, EventArgs e)
{
int maxID=0;
MySqlDataReader Reader;
Reader = connect.executeGetFileID();
while (Reader.Read())
{
maxID = (int)Reader.GetUInt32(0);
}
Reader.Close();
Stack<int> fileIDs = new Stack<int>();
MySqlDataReader ReaderF;
ReaderF = connect.GetFileIDs();
while (ReaderF.Read())
{
fileIDs.Push(ReaderF.GetInt32(0));
}
ReaderF.Close();
string suborA="";
string suborB="";
int ID;
int cID;
int count = fileIDs.Count;
int c=count;
int [] FileIDarray;
FileIDarray = new int[count];
progressBar1.Maximum = count;
StatusLabel.Text = "Checking";
StatusLabel.Invalidate();
this.Update();
for (c=count-1;c>-1;c--)
{
FileIDarray[c] = fileIDs.Pop();
// richTextBox2.Text = richTextBox2.Text + FileIDarray[c]+"\n";
}
for (ID=0;ID<count;ID++)
{
// richTextBox2.Text = richTextBox2.Text + ID+"\n";
MySqlDataReader ReaderX;
ReaderX = connect.GetFileText(FileIDarray[ID]);
while (ReaderX.Read())
{
suborA = ReaderX.GetValue(0).ToString();
}
ReaderX.Close();
cID = ID+1;
for (cID=(1+ID);cID<count;cID++)
{
MySqlDataReader ReaderY;
ReaderY = connect.GetFileText(FileIDarray[cID]);
while (ReaderY.Read())
{
suborB = ReaderY.GetValue(0).ToString();
}
ReaderY.Close();
// richTextBox2.Text = richTextBox2.Text + cID+"\n";
double compare = Cosine.compare(suborA, suborB);
connect.executeCompare(FileIDarray[ID], FileIDarray[cID], compare);
}
this.progressBar1.Value = ID + 1;
}
StatusLabel.Text = "Done";
}
*/
// private Thread newThread;
void DownloadClick(object sender, EventArgs e)
{
disableBtn();
/*
newThread = new Thread(FnkcVlakna);
newThread.Start();
}
private void FnkcVlakna()
{
*/
int ID;
try
{
// conn.Open();
FolderBrowserDialog downloadFolder = new FolderBrowserDialog();
DialogResult result = downloadFolder.ShowDialog();
if (result != DialogResult.OK)
{
enableBtn();
return;
}
string path = downloadFolder.SelectedPath;
Stack<int> fileIDs = new Stack<int>();
MySqlDataReader ReaderF;
ReaderF = connect.GetFileIDs();
while (ReaderF.Read())
{
fileIDs.Push(ReaderF.GetInt32(0));
}
ReaderF.Close();
int count = fileIDs.Count;
int c=count;
int [] FileIDarray;
FileIDarray = new int[count];
SetProgressBarMax(progressBar1, count);
// progressBar1.Maximum = count;
SetStatusLabelText(StatusLabel, "Download");
// StatusLabel.Text = "Checking";
// StatusLabel.Invalidate();
// this.Update();
for (c=count-1;c>-1;c--)
{
FileIDarray[c] = fileIDs.Pop();
}
for (ID=0;ID<count;ID++)
{
/* MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
MySqlDataReader myData;
string SQL;
string File_name;
int File_size;
byte[] rawData;
FileStream fs;
SQL = "SELECT FileName, FileSize, File FROM file WHERE File_ID='"+FileIDarray[ID]+"';";
cmd.Connection = conn;
cmd.CommandText = SQL;
myData = cmd.ExecuteReader();
if (! myData.HasRows)
throw new Exception("There are no BLOBs to save");
myData.Read();
File_size = (int)myData.GetUInt32(myData.GetOrdinal("FileSize"));
rawData = new byte[File_size];
File_name = myData.GetValue(0).ToString();
myData.GetBytes(myData.GetOrdinal("File"), 0, rawData, 0, File_size);
string[] File_nam = File_name.Split('\\');
int FileN_count = File_nam.Length;
string FileN = File_nam[FileN_count-1];
myData.Close();
fs = new FileStream(@"C:\TEST\"+FileN+"", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(rawData, 0, File_size);
fs.Close();
*/ connect.downDB(FileIDarray, ID, path);
SetProgressBarText(progressBar1, ID+1);
// this.progressBar1.Value = ID + 1;
}
MessageBox.Show("File successfully written to disk in " +path,
"Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
SetStatusLabelText(StatusLabel, "Done");
// StatusLabel.Text = "Done";
// conn.Close();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
enableBtn();
}
void ListresultSelectedIndexChanged(object sender, EventArgs e)
{
if(rdr==0)
{
string readrow = "";
//richTextBox1.Text = "";
richTextBox1.Clear();
this.CondTextBox.Clear();
this.listviewdb.Items.Clear();
this.listCompare.Items.Clear();
filecont.Text ="Content of FileID: "+ listresult.FocusedItem.SubItems[0].Text;//.SelectedItems[0].SubItems[1].Text;
MySqlDataReader Reader;
Reader = connect.executeGetFileText(listresult);
while (Reader.Read())
{
for (int i=0;i<Reader.FieldCount;i++)
{
readrow =Reader.GetValue(i).ToString()+" \n";
// richTextBox1.Text = readrow;
}
}
Reader.Close();
richTextBox1.Text = readrow;
Reader = connect.executeGetCondition(listresult);
while(Reader.Read())
{
ListViewItem rowCond = new ListViewItem(Reader.GetValue(5).ToString());
rowCond.SubItems.Add(Reader.GetValue(1).ToString());
rowCond.SubItems.Add(Reader.GetValue(2).ToString());
rowCond.SubItems.Add(Reader.GetValue(3).ToString());
rowCond.SubItems.Add(Reader.GetValue(4).ToString());
listviewdb.Items.Add(rowCond);
}
Reader.Close();
Reader = connect.executeGetCompare(listresult);
while (Reader.Read())
{
ListViewItem rowCompare = new ListViewItem(Reader.GetValue(0).ToString());
double cmpr = Reader.GetDouble(1)*100;
cmpr = Math.Round(cmpr, 2);
rowCompare.UseItemStyleForSubItems = false;
if(cmpr>60)
{
rowCompare.SubItems.Add(cmpr.ToString(),Color.Black, Color.Red, rowCompare.Font);
}
else
{
rowCompare.SubItems.Add(cmpr.ToString(),Color.Black, Color.White, rowCompare.Font);
}
listCompare.Items.Add(rowCompare);
}
Reader.Close();
Reader = connect.executeGetCompareB(listresult);
while(Reader.Read())
{
ListViewItem rowCompare = new ListViewItem(Reader.GetValue(0).ToString());
double cmpr = Reader.GetDouble(1)*100;
cmpr = Math.Round(cmpr, 2);
rowCompare.UseItemStyleForSubItems = false;
if(cmpr>40)
{
rowCompare.SubItems.Add(cmpr.ToString(),Color.Black, Color.Red, rowCompare.Font);
}
else
{
rowCompare.SubItems.Add(cmpr.ToString(),Color.Black, Color.White, rowCompare.Font);
}
// rowCompare.SubItems.Add(cmpr.ToString());
listCompare.Items.Add(rowCompare);
}
Reader.Close();
}
}
void ListviewdbSelectedIndexChanged(object sender, EventArgs e)
{
CondTextBox.Text = listviewdb.FocusedItem.SubItems[3].Text;
}
/* void CreatedbClick(object sender, EventArgs e)
{
try
{
connect.close();
connect.testDatabase();
connect.createDB();
MessageBox.Show("Tabels in Database was successfully created!",
"Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
*/
void DropDBClick(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("\nDelete all data from database ?\n", "Warning" , MessageBoxButtons.YesNo,MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
connect.executeDrop();
}
if (result == DialogResult.No)
{
return;
}
}
delegate void SetbuttonCallback(Button ctrl, bool text);
private void SetbuttonEnable(Button ctrl, bool text)
{
if (this.InvokeRequired)
{
SetbuttonCallback d = new SetbuttonCallback(SetbuttonEnable);
this.Invoke(d, new object[] { ctrl, text });
}
else
{
ctrl.Enabled = text;
}
}
delegate void SetListViewCallback(ListView ctrl, ListViewItem item);
private void SetListViewText(ListView ctrl, ListViewItem item)
{
if (this.InvokeRequired)
{
SetListViewCallback d = new SetListViewCallback(SetListViewText);
this.Invoke(d, new object[] { ctrl, item });
}
else
{
ctrl.Items.Add(item);
}
}
delegate void SetStatusLabelTextCallback(ToolStripItem ctrl, string text);
private void SetStatusLabelText(ToolStripItem ctrl, string text)
{
if (this.InvokeRequired)
{
SetStatusLabelTextCallback d = new SetStatusLabelTextCallback(SetStatusLabelText);
this.Invoke(d, new object[] { ctrl, text });
}
else
{
ctrl.Text = text;
ctrl.Invalidate();
this.Update();
}
}
delegate void SetprogressBarCallback(ToolStripProgressBar ctrl, int number);
private void SetProgressBarText(ToolStripProgressBar ctrl, int number)
{
if (this.InvokeRequired)
{
SetprogressBarCallback d = new SetprogressBarCallback(SetProgressBarText);
this.Invoke(d, new object[] { ctrl, number });
}
else
{
ctrl.Value = number;
progressBar1.Invalidate();
this.Update();
}
}
private void SetProgressBarMax(ToolStripProgressBar ctrl, int number)
{
if (this.InvokeRequired)
{
SetprogressBarCallback d = new SetprogressBarCallback(SetProgressBarMax);
this.Invoke(d, new object[] { ctrl, number });
}
else
{
ctrl.Maximum = number;
progressBar1.Invalidate();
this.Update();
}
}
}
}