-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
1165 lines (945 loc) · 35.6 KB
/
mainwindow.cpp
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
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "ui_mainwindow.h"
#include <fstream>
#include <string>
#include <QMessageBox>
#include <QFileDialog>
#include <QStandardPaths>
#include "mainwindow.h"
#include "team.h"
#include "examprop.h"
#include "advancedsearch.h"
#include "selectexam.h"
#include "advancedpupilsearch.h"
using Query = std::shared_ptr<querryResult>;
#define cout qDebug()
std::map<num_type, QString> MainWindow::sPrivillages{};
std::map<num_type, QString> MainWindow::sSubjects{};
std::map<num_type, QString> MainWindow::sRegions{};
QString MainWindow::LIMIT_RESULTS = " LIMIT 50;";
num_type MainWindow::privStr2Id(const QString & src) noexcept
{
for(auto var : sPrivillages) if(src == var.second) return var.first;
return 0;
}
num_type MainWindow::subStr2Id(const QString & src) noexcept
{
for(auto var : sSubjects) if(src == var.second) return var.first;
return 0;
}
num_type MainWindow::regionStr2Id(const QString & src) noexcept
{
for(auto var : sRegions) if(src == var.second) return var.first;
return 0;
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->showFullScreen();
__loadEverythink();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::resolve(std::queue<QString> & dst, const num_type src) noexcept
{
for(auto var : sPrivillages)
if(__divadable(src, var.first)) dst.push(var.second);
}
num_type MainWindow::process(const std::list<num_type> & src) noexcept
{
size_t toReturn = 1;
for(auto var : src)
toReturn *= var;
return toReturn;
}
void MainWindow::getPath(QLineEdit * dst)
{
const QString path = QFileDialog::getOpenFileUrl(this, "Wybierz plik CSV do importu", QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)).toString();
if(path == QString()) return;
dst->setText(path);
}
void MainWindow::loadEgzTab(Query src) noexcept
{
ui->EgzTabRes->clear();
ui->EgzTabRes->setRowCount(0);
ui->EgzTabRes->setColumnCount(3);
ui->EgzTabRes->setHorizontalHeaderLabels(QStringList({"ID Egzaminu", "Nazwa Przedmiotu", "Data Egzaminu"}));
for(const auto& var : src->data())
{
QString temp = var[2];
temp.truncate(10);
const int row = ui->EgzTabRes->rowCount();
ui->EgzTabRes->insertRow(row);
ui->EgzTabRes->setItem(row, 0, new QTableWidgetItem(var[0]));
ui->EgzTabRes->setItem(row, 1, new QTableWidgetItem(sSubjects.at(var[1].toUInt())));
ui->EgzTabRes->setItem(row, 2, new QTableWidgetItem( temp ));
}
src->clear();
}
void MainWindow::loadZespTab(Query src) noexcept
{
ui->ZespTabRes->clear();
ui->ZespTabRes->setRowCount(0);
ui->ZespTabRes->setColumnCount(3);
ui->ZespTabRes->setHorizontalHeaderLabels(QStringList({"ID Egzaminu", "Okręg", "Ilość Osób w Zespole"}));
for(const auto& var : src->data())
{
const int row = ui->ZespTabRes->rowCount();
ui->ZespTabRes->insertRow(row);
ui->ZespTabRes->setItem(row, 0, new QTableWidgetItem(QString::number(var[0].toUInt())));
ui->ZespTabRes->setItem(row, 1, new QTableWidgetItem(sRegions.at(var[1].toUInt())));
ui->ZespTabRes->setItem(row, 2, new QTableWidgetItem(var[2]));
}
src->clear();
}
void MainWindow::loadPracTab(Query src) noexcept
{
ui->PracTabRes->clear();
ui->PracTabRes->setRowCount(0);
ui->PracTabRes->setColumnCount(5);
ui->PracTabRes->setHorizontalHeaderLabels(QStringList({"ID Pracownika", "Imię", "Nazwisko", "Okręg", "Uprawnienia"}));
for(const auto& var : src->data())
{
const int row = ui->PracTabRes->rowCount();
ui->PracTabRes->insertRow(row);
ui->PracTabRes->setItem(row, 0, new QTableWidgetItem(var[0]));
ui->PracTabRes->setItem(row, 1, new QTableWidgetItem(var[1]));
ui->PracTabRes->setItem(row, 2, new QTableWidgetItem(var[2]));
ui->PracTabRes->setItem(row, 3, new QTableWidgetItem(sRegions.at(var[3].toUInt())));
ui->PracTabRes->setItem(row, 4, new QTableWidgetItem(var[4]));
}
src->clear();
}
void MainWindow::loadTerTab(Query src) noexcept
{
ui->TerTabRes->clear();
ui->TerTabRes->setRowCount(0);
ui->TerTabRes->setColumnCount(10);
ui->TerTabRes->setHorizontalHeaderLabels(QStringList({"PESEL", "Przedmiot 1", "Przedmiot 2", "Przedmiot 3","Przedmiot 4","Przedmiot 5", "Przedmiot 6", "Przedmiot 7", "Przedmiot 8", "Przedmiot 9"}));
for(const auto& var : src->data())
{
const int row = ui->TerTabRes->rowCount();
ui->TerTabRes->insertRow(row);
std::queue<QString> huehue;
const num_type subjects = var[1].toULongLong();
resolve(huehue, subjects);
ui->TerTabRes->setItem(row, 0, new QTableWidgetItem(var[0]));
int col = 0;
while (!huehue.empty())
{
col++;
ui->TerTabRes->setItem(row, col, new QTableWidgetItem(huehue.front()));
huehue.pop();
}
}
src->clear();
}
void MainWindow::loadZdaTab(Query src) noexcept
{
ui->ZdaTabRes->clear();
ui->ZdaTabRes->setRowCount(0);
ui->ZdaTabRes->setColumnCount(5);
ui->ZdaTabRes->setHorizontalHeaderLabels(QStringList({"PESEL", "Imię", "Nazwisko", "Okręg", "Zdawane Przedmioty"}));
for(const auto& var : src->data())
{
const int row = ui->ZdaTabRes->rowCount();
ui->ZdaTabRes->insertRow(row);
ui->ZdaTabRes->setItem(row, 0, new QTableWidgetItem(var[0]));
ui->ZdaTabRes->setItem(row, 1, new QTableWidgetItem(var[1]));
ui->ZdaTabRes->setItem(row, 2, new QTableWidgetItem(var[2]));
ui->ZdaTabRes->setItem(row, 3, new QTableWidgetItem(sRegions.at(var[3].toUInt())));
ui->ZdaTabRes->setItem(row, 4, new QTableWidgetItem(var[4]));
}
src->clear();
}
void MainWindow::loadAllDefaults() noexcept
{
//Wypełnianie Tabel
db->open();
Query Egz{db->exec(loadEgzQuer+LIMIT_RESULTS)};
Query Zes{db->exec(loadZesQuer+LIMIT_RESULTS)};
Query Prac{db->exec(loadPracQuer+LIMIT_RESULTS)};
Query Ter{db->exec(loadTerQuer+LIMIT_RESULTS)};
Query Zda{db->exec(loadZdaQuer+LIMIT_RESULTS)};
db->close();
//Ładowanie Egzaminów
loadEgzTab(Egz);
//Ładowanie zespołów
loadZespTab(Zes);
//Ładowanie pracowników
loadPracTab(Prac);
//Ładowanie Terminarza
loadTerTab(Ter);
//Ładowanie Zdających
loadZdaTab(Zda);
}
QString MainWindow::extract(const QString & src) const noexcept
{
bool first = false;
QString tmp = "";
for(auto var : src)
{
if(var == '\'')
{
if(first) return tmp;
first = true;
continue;
}
if(first) tmp += var;
}
}
bool MainWindow:: __divadable(const num_type thisOne, const num_type byThisOne) noexcept
{
return (thisOne % byThisOne == 0) ? true : false;
}
void MainWindow::__EgzProps()
{
if(ui->EgzTabRes->selectedItems().empty()) return;
db->open();
Query q1{db->exec(ExamProp::pracQuer + ui->EgzTabRes->selectedItems().front()->text()+";")};
Query q2{db->exec(ExamProp::regioQuert + ui->EgzTabRes->selectedItems().front()->text()+";")};
db->close();
ExamProp tmp(ui->EgzTabRes->selectedItems().front()->text().toUInt(), q1, q2, this);
tmp.show();
tmp.topLevelWidget();
tmp.exec();
}
void MainWindow::__ZdaSetModState(const bool state) noexcept
{
if(ui->ZdaTabRes->currentRow() < 0 && state) return;
//{"PESEL", "Imię", "Nazwisko", "Okręg", "Zdawane Przedmioty"}
if(state)
{
ui->ZdaHas->setText("");
ui->label_19->setToolTip("Jeżeli pozostawisz puste, hasło pozostanie bez zmian");
ui->ZdaPESEL->setText(ui->ZdaTabRes->selectedItems()[0]->text());
ui->ZdaImi->setText(ui->ZdaTabRes->selectedItems()[1]->text());
ui->ZdaNaz->setText(ui->ZdaTabRes->selectedItems()[2]->text());
ui->ZdaCombOkr->setCurrentIndex(ui->ZdaCombOkr->findText(ui->ZdaTabRes->selectedItems()[3]->text()));
ui->ZdaPrzed->setText(ui->ZdaTabRes->selectedItems()[4]->text());
ui->ZdaTabRes->setEnabled(false);
ui->ZdaButDod->setEnabled(false);
ui->ZdaButImport->setEnabled(false);
ui->ZdaButUsu->setEnabled(false);
ui->ZdaButSzu->setEnabled(false);
ui->ZdaButPathSelect->setEnabled(false);
ui->pushButton->setEnabled(false);
ui->ZdaButMod->setText("Zatwierdź");
}
else
{
db->open();
Query{db->exec( "UPDATE uczniowie SET imie='"+ui->ZdaImi->text()+"', nazwisko='"
+ ui->ZdaNaz->text()+"', idOkregu="+QString::number(regionStr2Id(ui->ZdaCombOkr->currentText()))
+ ", zdawanePrzedmioty="+ui->ZdaPrzed->text()+", pesel="+ui->ZdaPESEL->text()+ ((ui->ZdaHas->text() == "") ? "" : ", password=SHA2('"+ui->ZdaHas->text()+"', 256) ")
+ " WHERE pesel=" + ui->ZdaTabRes->selectedItems().front()->text() + ";")};
/*cout << ( "UPDATE pracownicy SET imie='"+ui->PracImi->text()+"', nazwisko='"
+ ui->PracNaz->text()+"', idOkregu="+QString::number(regionStr2Id(ui->PracCombOkr->currentText()))
+ ", uprawnienia="+ui->PracUpr->text()+", idpracownicy="+ui->PracLeg->text()+ ((ui->PracHas->text() == "") ? "" : " SHA2('"+ui->PracHas->text()+"', 256) ")
+ " WHERE idpracownicy=" + ui->PracTabRes->selectedItems().front()->text() + ";");*/
loadZdaTab(Query{db->exec( loadZdaQuer + LIMIT_RESULTS )});
db->close();
ui->ZdaPESEL->setText("");
ui->ZdaHas->setText("");
ui->ZdaImi->setText("");
ui->ZdaNaz->setText("");
ui->ZdaPrzed->setText("1");
ui->ZdaCombOkr->setCurrentIndex(0);
ui->label_19->setToolTip("");
ui->ZdaTabRes->setEnabled(true);
ui->ZdaButDod->setEnabled(true);
ui->ZdaButImport->setEnabled(true);
ui->ZdaButUsu->setEnabled(true);
ui->ZdaButSzu->setEnabled(true);
ui->ZdaButPathSelect->setEnabled(true);
ui->pushButton->setEnabled(true);
ui->ZdaButMod->setText("Modyfikuj");
}
}
void MainWindow::__PracSetModState(const bool state) noexcept
{
if(ui->PracTabRes->currentRow() < 0 && state) return;
//"SELECT idpracownicy, imie, nazwisko, idOkregu, uprawnienia FROM pracownicy "
if(state)
{
ui->PracHas->setText("");
ui->label_13->setToolTip("Jeżeli pozostawisz puste, hasło pozostanie bez zmian");
ui->PracLeg->setText(ui->PracTabRes->selectedItems()[0]->text());
ui->PracImi->setText(ui->PracTabRes->selectedItems()[1]->text());
ui->PracNaz->setText(ui->PracTabRes->selectedItems()[2]->text());
ui->PracUpr->setText(ui->PracTabRes->selectedItems()[4]->text());
ui->PracCombOkr->setCurrentIndex(ui->PracCombOkr->findText(ui->PracTabRes->selectedItems()[3]->text()));
ui->PracTabRes->setEnabled(false);
ui->PracButDod->setEnabled(false);
ui->PracButImp->setEnabled(false);
ui->PracButUsu->setEnabled(false);
ui->PracButZna->setEnabled(false);
ui->PracButPathSelect->setEnabled(false);
ui->PracButMod->setText("Zatwierdź");
}
else
{
db->open();
Query{db->exec( "UPDATE pracownicy SET imie='"+ui->PracImi->text()+"', nazwisko='"
+ ui->PracNaz->text()+"', idOkregu="+QString::number(regionStr2Id(ui->PracCombOkr->currentText()))
+ ", uprawnienia="+ui->PracUpr->text()+", idpracownicy="+ui->PracLeg->text()+ ((ui->PracHas->text() == "") ? "" : ", password=SHA2('"+ui->PracHas->text()+"', 256) ")
+ " WHERE idpracownicy=" + ui->PracTabRes->selectedItems().front()->text() + ";")};
loadPracTab(Query{db->exec(loadPracQuer+LIMIT_RESULTS)});
db->close();
ui->PracLeg->setText("");
ui->PracHas->setText("");
ui->PracImi->setText("");
ui->PracNaz->setText("");
ui->PracUpr->setText("1");
ui->PracCombOkr->setCurrentIndex(0);
ui->label_13->setToolTip("");
ui->PracTabRes->setEnabled(true);
ui->PracButDod->setEnabled(true);
ui->PracButImp->setEnabled(true);
ui->PracButUsu->setEnabled(true);
ui->PracButZna->setEnabled(true);
ui->PracButPathSelect->setEnabled(true);
ui->PracButMod->setText("Modyfikuj");
}
}
void MainWindow::__ZdaProps()
{
// {"PESEL", "Imię", "Nazwisko", "Okręg", "Zdawane Przedmioty"}
if(ui->ZdaTabRes->currentRow() < 0) return;
auto data = ui->ZdaTabRes->selectedItems();
QString dane = "Podstawowe Dane: \n\n";
dane+="\tPESEL: "+data[0]->text()+"\n";
dane+="\tImię: "+data[1]->text()+"\n";
dane+="\tNazwisko: "+data[2]->text()+"\n";
dane+="\tOkręg: "+data[3]->text()+"\n\n";
dane+="Zdawane Przedmioty: \n\n";
std::queue<QString> tmp;
resolve(tmp, data[4]->text().toULongLong());
if(tmp.size() > 1) tmp.pop();
while(!tmp.empty()) { dane+="\t"+tmp.front()+"\n"; tmp.pop(); }
QMessageBox(QMessageBox::Icon::NoIcon, "Informacje", dane).exec();
}
void MainWindow::__loadEverythink()
{
const std::string path{ QDir::toNativeSeparators((QStandardPaths::writableLocation(QStandardPaths::HomeLocation))+"/settings.ini").toStdString() };
std::ifstream input(path);
if(!input.good())
{
input.close();
QMessageBox a(QMessageBox::Icon::Critical, "Błąd", "Brak pliku `settings.ini` w katalogu domowym, utworzyć?", QMessageBox::Yes | QMessageBox::No);
if(a.exec() == QMessageBox::Yes)
{
std::ofstream output(path);
output<<"#current"<<std::endl;
output<<"host=''"<<std::endl;
output<<"port=''"<<std::endl;
output<<"dbName=''"<<std::endl;
output<<"user=''"<<std::endl;
output<<"password=''"<<std::endl;
output<<std::endl;
output<<std::endl;
output<<"#default - do not delete!!!!!!!"<<std::endl;
output<<"#host='www.db4free.net'"<<std::endl;
output<<"#port='3306'"<<std::endl;
output<<"#dbName='cy8h8p1of1'"<<std::endl;
output<<"#user='cy8h8p1of1'"<<std::endl;
output<<"#password='0JpOagXzku'";
output.close();
}
}
std::string line, ihost, iuser, ipass, idbname;
unsigned short iport;
while(std::getline(input, line))
{
if(line[0] == '#') continue;
QString tmp(line.c_str());
QString t = extract(tmp);
if(tmp.indexOf("host='") != -1)
{
ihost = t.toStdString();
ui->UstSerwAdr->setText(t);
}
else if(tmp.indexOf("port='") != -1)
{
iport = t.toUShort();
ui->UstPort->setText(t);
}
else if(tmp.indexOf("dbName='") != -1)
{
idbname = t.toStdString();
ui->UstDBName->setText(t);
}
else if(tmp.indexOf("user='") != -1)
{
iuser = t.toStdString();
ui->UstUzyt->setText(t);
}
else if(tmp.indexOf("password='") != -1)
{
ipass = t.toStdString();
ui->UstHas->setText(t);
}else continue;
}
input.close();
db = new mysqldriver(ihost, iuser, ipass, idbname, iport);
if(!__testDB())
{
QMessageBox(QMessageBox::Icon::Critical, "Błąd krytyczny", "Nie udało się ustanowić połączenia z bazą danych!!!\n\nPrzejdź do ustawień (ostatnie zakładka), sprawdź parametry połączenia i połącz ponownie!").exec();
ui->tabWidget->setCurrentIndex(5);
ui->EgzTab->setEnabled(false);
ui->ZesTab->setEnabled(false);
ui->PracTab->setEnabled(false);
ui->tab->setEnabled(false);
ui->ZdaTab->setEnabled(false);
return;
}
if(db->open())
{
std::unique_ptr<querryResult> q{db->exec("SELECT idprzedmiot, nazwa FROM przedmiot;")};
db->close();
for(const auto & var : q->data()) { sSubjects[QString(var[0]).toUInt()] = QString(var[1]); }
db->open();
q.reset(db->exec("SELECT idstanowiska, nazwa FROM stanowiska;"));
db->close();
for(const auto & var : q->data()) { sPrivillages[QString(var[0]).toUInt()] = QString(var[1]); }
db->open();
q.reset(db->exec("SELECT idOkregu, nazwaOkregu FROM okregi;"));
db->close();
for(const auto & var : q->data()) { sRegions[QString(var[0]).toUInt()] = QString(var[1]); }
}else db->close();
//Dodawanie przedmiotów
ui->EgzCombPrzed->clear();
for(const auto & var : sSubjects) ui->EgzCombPrzed->addItem(var.second);
//Dodawanie okręgów
ui->PracCombOkr->clear();
ui->ZdaCombOkr->clear();
for(const auto & var : sRegions)
{
ui->PracCombOkr->addItem(var.second);
ui->ZdaCombOkr->addItem(var.second);
}
loadAllDefaults();
//Ładowanie Szczegółów
//Kalendarz, Ilość Zakończonych Egzaminów
if(!db->open()) try{ throw std::bad_function_call(); }catch(...) { db->close(); throw; }
Query Zda{db->exec("SELECT MIN(data) FROM egzamin;")};
Query Ter{db->exec("SELECT COUNT(*)/(SELECT COUNT(*) FROM egzamin) FROM egzamin WHERE data<CURRENT_DATE;")};
db->close();
//Konwersja std::string -> QDate
ui->EgzDat->setDate(str2date(Zda->data().front().front()).date());
ui->EgzBar->setValue(static_cast<int>(Ter->data().front().front().toDouble() * 100.0));
engine = new exportXLSX(db);
ui->WynName->setText("raport_"+QDateTime::currentDateTime().toString("yyyy_MM_dd")+"_LVL"+QString::number(ui->WynDetail->value()));
ui->WynPathView->setText(QStandardPaths::writableLocation(QStandardPaths::HomeLocation));
ui->EgzTab->setEnabled(true);
ui->ZesTab->setEnabled(true);
ui->PracTab->setEnabled(true);
ui->tab->setEnabled(true);
ui->ZdaTab->setEnabled(true);
}
void MainWindow::__updateLIMIT_RESULTS(const QString & src) noexcept
{
if(src == "0")
{
LIMIT_RESULTS = " ;";
return;
}
LIMIT_RESULTS = " LIMIT "+src+";";
}
bool MainWindow::__testDB() noexcept
{
if(!db->open()) return false;
Query t1{db->exec("SHOW TABLES;")};
db->close();
int wyn = 0;
for(const auto& var : t1->data())
{
if(
var[0] == "egzamin" ||
var[0] == "oceny" ||
var[0] == "okregi" ||
var[0] == "pracownicy" ||
var[0] == "przedmiot" ||
var[0] == "stanowiska" ||
var[0] == "uczniowie" ||
var[0] == "zespoly"
) wyn++;
}
return wyn >= 8;
}
void MainWindow::on_PracUprCreator_clicked()
{
Permissions dial(ui->PracUpr->text().toULongLong(),false, this);
dial.show();
dial.topLevelWidget();
dial.exec();
ui->PracUpr->setText(QString::number(dial.result));
}
void MainWindow::on_ZdaButPrzed_clicked()
{
Permissions dial(ui->ZdaPrzed->text().toULongLong(), true, this);
dial.show();
dial.topLevelWidget();
dial.exec();
ui->ZdaPrzed->setText(QString::number(dial.result));
}
void MainWindow::on_EgzButZespWyb_clicked()
{
Team tmp(db, &__mNewTeamBuffor, __mLastSearchTeam, this);
tmp.show();
tmp.topLevelWidget();
tmp.exec();
__mNewTeamBuffor = tmp.curr;
QString t = "";
for(auto var : __mNewTeamBuffor) t+=QString::number(var)+" ";
__mLastSearchTeam = tmp.__last;
ui->EgzZesp->setText(t);
}
void MainWindow::on_PomButKalk_clicked()
{
std::queue<QString> tmp;
resolve(tmp, static_cast<num_type>(ui->PomSpinKalk->text().toULongLong()));
QString wyn = "";
if(tmp.size() > 1) tmp.pop();
while (!tmp.empty())
{
wyn+=tmp.front() + "\n";
tmp.pop();
}
QMessageBox a(QMessageBox::Icon::Information, "Obliczone Uprawnienia", wyn);
a.show();
a.topLevelWidget();
a.exec();
}
void MainWindow::on_EgzPathSelect_clicked()
{
getPath(ui->EgzPathView);
}
void MainWindow::on_ZespPathSelect_clicked()
{
getPath(ui->ZespPathView);
}
void MainWindow::on_PracButPathSelect_clicked()
{
getPath(ui->PracPathView);
}
void MainWindow::on_ZdaButPathSelect_clicked()
{
getPath(ui->ZdaPathView);
}
void MainWindow::on_EgzButImp_clicked()
{
if(ui->EgzPathView->text() == "") return;
CSVImporter(CSVImporter::Egzaminy, ui->EgzPathView->text(), db).exec();
}
void MainWindow::on_ZespButImp_clicked()
{
if(ui->ZespPathView->text() == "") return;
CSVImporter(CSVImporter::Zespoly, ui->ZespPathView->text(), db).exec();
}
void MainWindow::on_PracButImp_clicked()
{
if(ui->PracPathView->text() == "") return;
CSVImporter(CSVImporter::Pracownicy, ui->PracPathView->text(), db).exec();
}
void MainWindow::on_ZdaButImport_clicked()
{
if(ui->ZdaPathView->text() == "") return;
CSVImporter(CSVImporter::Zdajacy, ui->ZdaPathView->text(), db).exec();
}
void MainWindow::on_EgzButDod_clicked()
{
//Przetestować
QString quer = "SELECT MAX(idegzamin) FROM egzamin;";
db->open();
Query q { db->exec(quer) };
db->close();
size_t max = q->data().front().front().toUInt();
q->clear();
max++;
quer = "INSERT INTO egzamin VALUES("+QString::number(max)+", "+QString::number(subStr2Id(ui->EgzCombPrzed->currentText()))+", '"+ui->EgzDat->date().toString("yyyy-MM-dd")+"');";
db->open();
try
{
q.reset(db->exec(quer));
}
catch(const std::invalid_argument& e)
{
QMessageBox(QMessageBox::Icon::Information, "Błąd", "Nie można dodać pozycji").exec();
return;
}
q->clear();
for(auto var : __mNewTeamBuffor)
{
Query tmp { db->exec("INSERT INTO zespoly VALUES("+QString::number(var)+", "+QString::number(max)+");") };
}
db->close();
__mNewTeamBuffor.clear();
__mLastSearchTeam = "";
ui->EgzZesp->setText("");
if(ui->EgzCombPrzed->currentIndex() + 1 != ui->EgzCombPrzed->count()) ui->EgzCombPrzed->setCurrentIndex(ui->EgzCombPrzed->currentIndex() + 1);
}
void MainWindow::on_spinBox_valueChanged(const QString &arg1)
{
__updateLIMIT_RESULTS(arg1);
}
void MainWindow::on_spinBox_editingFinished()
{
loadAllDefaults();
}
void MainWindow::on_EgzButSzu_clicked()
{
QString q = loadEgzQuer + " JOIN przedmiot ON idprzedmiot=idprzedmiotu JOIN zespoly ON id_egzamin=idegzamin "
+ "WHERE data='"+ui->EgzDat->date().toString("yyyy-MM-dd") + "' "
+ "AND idprzedmiot%" +QString::number(subStr2Id(ui->EgzCombPrzed->currentText()))+"=0 ";
if(!__mNewTeamBuffor.empty())
{
for(auto var : __mNewTeamBuffor)
{
q+=" AND idpracownika="+QString::number(var)+" ";
}
}
q+=LIMIT_RESULTS;
db->open();
loadEgzTab(Query{db->exec(q)});
db->close();
}
void MainWindow::on_EgzButUsu_clicked()
{
if(ui->EgzTabRes->selectedItems().empty()) return;
QString id = ui->EgzTabRes->selectedItems().front()->text();
db->open();
Query{db->exec("DELETE FROM egzamin WHERE idegzamin="+id+";")};
loadEgzTab(Query{db->exec(loadEgzQuer+LIMIT_RESULTS)});
db->close();
__mNewTeamBuffor.clear();
__mLastSearchTeam = "";
ui->EgzZesp->setText("");
ui->EgzCombPrzed->setCurrentIndex(0);
}
void MainWindow::on_EgzButInf_clicked()
{
__EgzProps();
}
void MainWindow::on_EgzTabRes_itemDoubleClicked(QTableWidgetItem *item)
{
__EgzProps();
}
void MainWindow::on_ZespButDod_clicked()
{
db->open();
Query{db->exec("INSERT INTO zespoly VALUES("+ui->ZespSpinEgz->text()+", "+ui->ZespSpinPrac->text()+");")};
loadZespTab(Query{db->exec(loadZesQuer+LIMIT_RESULTS)});
db->close();
ui->ZespSpinEgz->setValue(0);
ui->ZespSpinPrac->setValue(0);
}
void MainWindow::on_ZespButUsu_clicked()
{
db->open();
Query{db->exec("DELETE FROM zespoly WHERE idpracownika="+ui->ZespSpinPrac->text()+" AND id_egzamin="+ui->ZespSpinEgz->text()+";")};
loadZespTab(Query{db->exec(loadZesQuer+LIMIT_RESULTS)});
db->close();
ui->ZespSpinEgz->setValue(0);
ui->ZespSpinPrac->setValue(0);
}
void MainWindow::on_ZespButSzu_clicked()
{
db->open();
loadZespTab(Query{db->exec(loadZesQuer+" HAVING id_egzamin LIKE '%"+ui->ZespSpinEgz->text()+"%' "+LIMIT_RESULTS)});
db->close();
}
void MainWindow::on_ZespButPraWyb_clicked()
{
std::list<size_t> x;
advancedSearch tmp{db, x, "SELECT idpracownicy FROM pracownicy WHERE ", true};
tmp.show();
tmp.exec();
if(tmp.everythingGoesGoog)
{
db->open();
Query q{db->exec(tmp.res)};
db->close();
ui->ZespSpinPrac->setValue(q->data().front().front().toInt());
}
}
void MainWindow::on_ZespButEgzWyb_clicked()
{
SelectExam tmp(db, this);
tmp.show();
tmp.topLevelWidget();
tmp.exec();
if(tmp.IDresult == 0) return;
ui->ZespSpinEgz->setValue(static_cast<int>(tmp.IDresult));
}
void MainWindow::on_PracButDod_clicked()
{
if(
ui->PracLeg->text() == "" ||
ui->PracImi->text() == "" ||
ui->PracNaz->text() == "" ||
ui->PracUpr->text() == "" ||
ui->PracHas->text() == ""
)
{
QMessageBox(QMessageBox::Icon::Warning, "Błąd", "Proszę Uzupełnić Wszystkie Dane!").exec();
return;
}
QString querry = "INSERT INTO pracownicy VALUES("+ui->PracLeg->text()
+ ", '"+ui->PracImi->text() + "' "
+ ", '"+ui->PracNaz->text() + "' "
+ ", "+QString::number(regionStr2Id(ui->PracCombOkr->currentText()))
+ ", "+ui->PracUpr->text()
+ ", SHA2('"+ui->PracHas->text()+"', 256));";
db->open();
Query{db->exec(querry)};
db->close();
ui->PracLeg->setText("");
ui->PracImi->setText("");
ui->PracNaz->setText("");
ui->PracUpr->setText("");
ui->PracHas->setText("");
}
void MainWindow::on_PracHas_textChanged(const QString &arg1)
{
for(const auto& var : arg1)
{
if(!var.isLetterOrNumber())
{
QMessageBox(QMessageBox::Icon::Critical, "Błąd Formatu","Użyto Niedozwolonego znaku.\nDozwolone Tylko litery i liczby.").exec();
QString tmp = "";
for(auto i : arg1) if(i.isLetterOrNumber()) tmp+=i;
ui->PracHas->setText(tmp);
return;
}
}
}
void MainWindow::on_PracChck_stateChanged(int arg1)
{
ui->PracHas->setEchoMode(ui->PracChck->isChecked() ? QLineEdit::EchoMode::Password : QLineEdit::EchoMode::Normal);
}
void MainWindow::on_PracButZna_clicked()
{
//loadPracQuer = "SELECT idpracownicy, imie, nazwisko, idOkregu, uprawnienia FROM pracownicy ";
QString querry = loadPracQuer + " WHERE idpracownicy LIKE '%"+ui->PracLeg->text()+"%'"
+ " AND imie LIKE '%"+ui->PracImi->text()+"%' AND nazwisko LIKE '%"+ui->PracNaz->text()+"%'"
+ " AND idOkregu="+QString::number(regionStr2Id(ui->PracCombOkr->currentText()))
+ " AND uprawnienia%"+ui->PracUpr->text()+"=0 "
+ LIMIT_RESULTS;
db->open();
loadPracTab(Query{db->exec(querry)});
db->close();
}
void MainWindow::on_PracButUsu_clicked()
{
if(ui->PracTabRes->currentRow() < 0) return;
db->open();
Query{db->exec("DELETE FROM pracownicy WHERE idpracownicy="+ui->PracTabRes->selectedItems().front()->text()+";")};
loadPracTab(Query{db->exec(loadPracQuer + LIMIT_RESULTS)});
db->close();
}
void MainWindow::on_PracButMod_clicked()
{
__mActPracModState = !__mActPracModState;
__PracSetModState(__mActPracModState);
}
void MainWindow::on_TerButPESEL_clicked()
{
advancedPupilSearch tmp(db, this);
tmp.show();
tmp.topLevelWidget();
tmp.exec();
if(tmp.ok)
{
db->open();
Query q{db->exec("SELECT pesel FROM uczniowie "+tmp.Result)};
db->close();
ui->TerPESEL->setText(q->data().front().front());
}
}
void MainWindow::on_TerButDod_clicked()
{
num_type add=0;
db->open();
Query q1{db->exec("SELECT idprzedmiot FROM przedmiot JOIN egzamin ON idprzedmiot=idprzedmiotu WHERE idegzamin="+ui->TerEgzID->text()+";")};
q1.reset(db->exec("SELECT zdawanePrzedmioty FROM uczniowie WHERE pesel='"+ui->TerPESEL->text()+"';"));
Query q{db->exec("SELECT COUNT(*) FROM uczniowie WHERE zdawanePrzedmioty%"+q1->data().front().front()+"=0 AND pesel='"+ui->TerPESEL->text()+"';")};
db->close();
if(q->data().front().front().toInt() != 0)
{
QMessageBox(QMessageBox::Icon::Warning, "Błąd", "Ta osoba zdaje już ten przedmiot!").exec();
return;
}
num_type przedm = q1->data().front().front().toULongLong();
przedm = przedm*add;
db->open();
Query{db->exec("UPDATE uczniowie SET zdawanePrzedmioty="+QString::number(przedm)+" WHERE pesel='"+ui->TerPESEL->text()+"';")};
loadTerTab(Query{db->exec(loadTerQuer+LIMIT_RESULTS)});
db->close();
}
void MainWindow::on_TerButSzu_clicked()
{
db->open();
Query q1{db->exec("SELECT idprzedmiot FROM przedmiot JOIN egzamin ON idprzedmiot=idprzedmiotu WHERE idegzamin="+ui->TerEgzID->text()+";")};
loadTerTab(Query{db->exec(loadTerQuer+" WHERE pesel LIKE '%"+ui->TerPESEL->text()+"%' AND zdawanePrzedmioty%"+q1->data().front().front()+"=0 "+LIMIT_RESULTS)});
db->close();
}
void MainWindow::on_TerButEgz_clicked()
{
SelectExam tmp(db, this);
tmp.show();
tmp.topLevelWidget();
tmp.exec();
if(tmp.IDresult == 0) return;
ui->TerEgzID->setValue(tmp.IDresult);
}
void MainWindow::on_TerButUsu_clicked()
{
num_type add=0;
db->open();
Query q1{db->exec("SELECT idprzedmiot FROM przedmiot JOIN egzamin ON idprzedmiot=idprzedmiotu WHERE idegzamin="+ui->TerEgzID->text()+";")};
Query q{db->exec("SELECT COUNT(*) FROM uczniowie WHERE zdawanePrzedmioty%"+q1->data().front().front()+"=0 AND pesel='"+ui->TerPESEL->text()+"';")};
q1.reset(db->exec("SELECT zdawanePrzedmioty FROM uczniowie WHERE pesel='"+ui->TerPESEL->text()+"';"));
db->close();
if(q->data().front().front().toInt() == 0)
{
QMessageBox(QMessageBox::Icon::Warning, "Błąd", "Ta osoba nie zdaje tego przedmiotu!").exec();
return;
}
num_type przedm = q1->data().front().front().toULongLong();
przedm = przedm/add;