-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
3323 lines (2336 loc) · 101 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 "mainwindow.h"
#include "ui_mainwindow.h"
//#include "C:/Users/Mayssa/Desktop/Qt-Table-Printer-master/Qt-Table-Printer-master/tableprinter.h"
//#include "C:/Users/eyaou/Desktop/Qt-Table-Printer-master/tableprinter.h"
//#include "C:/Users/eyaou/Desktop/Smart_Factory_2A4-master/Smart_factory_2A4/Qt-Table-Printer-master/tableprinter.h"
#include<QPixmap>
#include <QComboBox>
#include "QMessageBox"
#include <QString>
#include <QSqlQuery>
#include <QSqlQueryModel>
#include <QPainter>
#include <QFileDialog>
#include <QTextDocument>
#include <QTextEdit>
#include <QtSql/QSqlQueryModel>
#include <QtPrintSupport/QPrinter>
#include <QVector2D>
#include"messengerconnectiondialog.h"
#include <QVector>
#include <QDesktopServices>
#include <QUrl>
#include <QPixmap>
#include <QTabWidget>
#include <QValidator>
#include <QtSql/QSqlQuery>
#include <QVariant>
#include <QPrintDialog>
#include <QFile>
#include <QDataStream>
#include <QTextStream>
#include<arduino1.h>
#include "exportexcelobject.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->stackedWidget->setCurrentWidget(ui->login) ;
///arduino
arduino_is_available=false;
arduino_port_name="";
arduino = new QSerialPort;
foreach(const QSerialPortInfo &serial_port_info , QSerialPortInfo::availablePorts())
{
if(serial_port_info.hasProductIdentifier() && serial_port_info.hasVendorIdentifier())
{
if(serial_port_info.vendorIdentifier()==arduino_uno_vendor_id && serial_port_info.productIdentifier()==arduino_uno_producy_id)
{
arduino_port_name = serial_port_info.portName();
arduino_is_available=true;
}
}
}
qDebug()<<"arduino_port_name is:"<<arduino_port_name;
if(arduino_is_available)
{
arduino->setPortName(arduino_port_name);
if(arduino->open(QSerialPort::ReadWrite))
{
arduino->setBaudRate(QSerialPort::Baud9600);
arduino->setDataBits(QSerialPort::Data8);
arduino->setParity(QSerialPort::NoParity);
arduino->setStopBits(QSerialPort::OneStop);
arduino->setFlowControl(QSerialPort::NoFlowControl);
}
}
ui->ag_aj_cin->setValidator(new QIntValidator(0,99999999,this));
ui->adm_id_supp->setValidator(new QIntValidator(0,99999999,this));
ui->adm_aj_salaire->setValidator(new QIntValidator(0,99999999,this));
ui->adm_aj_cin->setValidator(new QIntValidator(0,99999999,this));
processLabel = new QLabel(this);
QMovie *movie = new QMovie(":/new/prefix1/image/car-loader-gif-1.gif");
movie->start();
processLabel->setWindowFlags(Qt::FramelessWindowHint);
//processLabel->setMask((new QPixmap(":/image/res/car-loader-gif-1.gif"))->mask());
if (ui->stackedWidget->currentWidget()==ui->login) {
movie->setScaledSize(QSize(500,500));
processLabel->setMovie(movie);
processLabel->setAttribute(Qt::WA_NoSystemBackground);
processLabel->setAttribute(Qt::WA_TranslucentBackground,true);
processLabel->setGeometry(800,100,451,570);
processLabel->setScaledContents(true);
scene.addWidget(processLabel);
}
son =new QSound("C:/Users/Mayssa/Desktop/gestion_production/projett/son.wav");
ui->tableView_voiture->setModel(vtmp.afficher());
ui->tableView_chaine->setModel(ctmp.afficher());
ui->comboBox_ch->addItem("REFERENCE");
ui->comboBox_ch->addItem("NB_MACHINE");
ui->comboBox_ch->addItem("TYPE_PRODUIT");
//pfd
model = new QSqlTableModel;
model->setTable("chaine");
model->select();
//controle de saisie sue les entiers
ui->tableView_chaine->setModel(model);
ui->lineEdit_prix->setValidator(new QIntValidator(0,999999,this));
ui->lineEdit_p_op->setValidator(new QIntValidator(0,999999,this));
ui->lineEdit_reference_voi->setValidator(new QIntValidator(0,99999999,this));
ui->lineEdit_reference_ch->setValidator(new QIntValidator(0,99999999,this));
ui->lineEdit_ref_ch->setValidator(new QIntValidator(0,99999999,this));
ui->lineEdit_nb_mach->setValidator(new QIntValidator(0,999999,this));
//controle de saisie sur les chaines de caracteres
ui->lineEdit_maq->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_marque->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_mod->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_modele->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_couleur->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_option->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_type->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_type_prod->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
/////eya
//////pdf
model1 = new QSqlTableModel;
model1->setTable("client");
model1->select();
ui->tabclient_2->setModel(model1);
//////
ui->tri_four->addItem("CIN");
ui->tri_four->addItem("NOM");
ui->tri_four->addItem("PRENOM");
//// affichage client et fournisseur
ui->tabclient_2->setModel(tmpclient.afficher());
ui->tabfour_2->setModel(tmpfournisseur.afficherFour());
///////filtrer les données d'un client
modClient= new QSqlRelationalTableModel(this);
modClient->setTable("client");
modClient->select();
proxyclient=new QSortFilterProxyModel(this);
proxyclient->setSourceModel(modClient);
proxyclient->setFilterCaseSensitivity(Qt::CaseInsensitive);
proxyclient->setFilterKeyColumn(0);
ui->tabclient_2->setModel(proxyclient);
/////////filtrer les donnees fournisseur
modFournisseur= new QSqlRelationalTableModel(this);
modFournisseur->setTable("fournisseur");
modFournisseur->select();
proxyfournisseur=new QSortFilterProxyModel(this);
proxyfournisseur->setSourceModel(modFournisseur);
proxyfournisseur->setFilterCaseSensitivity(Qt::CaseInsensitive);
proxyfournisseur->setFilterKeyColumn(1);
ui->tabfour_2->setModel(proxyfournisseur);
ui->lineEdit_cin_2->setValidator(new QIntValidator(0,99999999,this));
ui->cinfour_2->setValidator(new QIntValidator(0,99999999,this));
ui->lineEdit_paiement_2->setValidator(new QIntValidator(0,99999999,this));
ui->prixpayer_4->setValidator(new QIntValidator(0,99999999,this));
ui->nbre_2->setValidator(new QIntValidator(0,99999999,this));
ui->lineEdit_achat_2->setValidator(new QIntValidator(0,99999999,this));
ui->lineEdit_nom_2->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_prenom_2->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->lineEdit_model_2->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->NomFournisseur_4->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->prenomfour_2->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->piecedemand_2->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->choix_2->addItem("reference");
ui->choix_2->addItem("place");
ui->choix_2->addItem("nom");
ui->choix_3->addItem("reference");
ui->choix_3->addItem("parking number");
ui->choix_3->addItem("name");
ui->ln_reference->setValidator(new QIntValidator(0,99999999,this));
ui->ln_prix->setValidator(new QIntValidator(0,99999999,this));
ui->ln_compagnie->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->ln_type->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
ui->reference_2->setValidator(new QIntValidator( 0,99999999, this ));
ui->nbr_place_2->setValidator(new QIntValidator( 0,99999999, this ));
ui->nom_employe_2->setValidator(new QRegExpValidator( QRegExp("[A-Za-z0_]{0,255}"), this ));
int ret=A.connect_arduino();
switch(ret){
case (0):
qDebug() << "arduino is available and connect to : " << A.getarduino_port_name();
//QObject::connect(A.getserial(),SIGNAL(readyRead()),this,SLOT(Pointage2()));
break;
case(1):qDebug() << "arduino is available and connect to : " << A.getarduino_port_name();
// QObject::connect(A.getserial(),SIGNAL(readyRead()),this,SLOT(Pointage2()));
break;
case(-1):qDebug()<< "arduino is available and connect to : " ;
//QObject::connect(A.getserial(),SIGNAL(readyRead()),this,SLOT(Pointage2()));
break;
}
QObject::connect(A.getserial(),SIGNAL(readyRead()) ,this,SLOT(update_label()) ) ;
}
void MainWindow::update_label() {
data=A.read_from_arduino() ;
QString temp=QString::fromStdString(data.toStdString()) ;
qDebug()<<temp;
if(temp.isEmpty()) {
qDebug()<<"no";
}
else {
int count=0 ;
QSqlQuery query ;
query.prepare("SELECT * FROM TABLE1 where RFID = :id ");
QString a=temp ;
query.bindValue(":id", a );
if(query.exec())
{
while(query.next())
{
count++;
}
if(count!=0)
{
QDate d ;
QTime t ;
query.first() ;
qDebug()<<query.value(0).toInt() ;
qDebug()<<query.value(1).toString() ;
qDebug()<<query.value(2).toString() ;
qDebug()<<d.currentDate() ;
qDebug()<< t.currentTime().toString();
QSqlQuery query2 ;
query2.first() ;
query2.prepare("INSERT INTO POINTAGE (CIN,NOM,PRENOM,D,TIME) "
"VALUES (:cin,:nom,:prenom,:date,:time)");
query2.bindValue(":cin",query.value(0).toInt() );
query2.bindValue(":nom",query.value(1).toString() );
query2.bindValue(":prenom",query.value(2).toString());
query2.bindValue(":date", d.currentDate());
query2.bindValue(":time",t.currentTime().toString());
//query.bindValue(":adresse",getadresse());
//query.bindValue(":passe",getpasse());
query2.exec() ;
QByteArray name ;
name="Bienvenue "+query.value(2).toByteArray()+" "+query.value(1).toByteArray() ;
A.write_to_arduino(name) ;
ui->tab_pointage->setModel(A.afficher());
// A.write_to_arduino(query.value(8).toByteArray()) ;
}
}
if(count==0 )
{
A.write_to_arduino("Acces refusé ") ;
qDebug()<<"mabrouuk ";
}
}
//qDebug() <<"fooook ";
}
MainWindow::~MainWindow()
{
if(arduino->isOpen())
{
arduino->close();
}
delete ui;
}
QByteArray MainWindow::read_from_arduino()
{
if(arduino->isReadable())
{
data=arduino->readAll();
}
return data;
}
void MainWindow::write_to_arduino(QByteArray d)
{
if(arduino->isWritable())
{
arduino->write(d);
}else
qDebug() <<"couldn't write to serial!";
}
void MainWindow::on_arreter_clicked()
{
write_to_arduino("0");
}
void MainWindow::on_ajouter_voi_clicked()
{
son->play();
QString marque = ui->lineEdit_marque->text();//text pour recuperer les infos des lineedit
QString modele=ui->lineEdit_modele->text();
QString type=ui->lineEdit_type->text();
QString options=ui->lineEdit_option->text();
QString couleur=ui->lineEdit_couleur->text();
int prix=ui->lineEdit_prix->text().toInt();
int prix_option=ui->lineEdit_p_op->text().toInt();
int reference=ui->lineEdit_reference_voi->text().toInt();
voiture v(marque,reference,modele,prix,type,prix_option,couleur,options);
bool test=v.ajouter();
if(test)
{
ui->tableView_voiture->setModel(vtmp.afficher());
QMessageBox::information(nullptr, QObject::tr("ajout effectuee"),
QObject::tr("voiture ajouté avec succés.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
else
QMessageBox::critical(nullptr, QObject::tr("ajout non effectuee"),
QObject::tr("voiture non ajouté.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
void MainWindow::on_ajouter_ch_clicked()
{
son->play();
QString type_produit = ui->lineEdit_type_prod->text();
int reference=ui->lineEdit_reference_ch->text().toInt();
int nb_machine=ui->lineEdit_nb_mach->text().toInt();
chaine c(reference,nb_machine,type_produit);
bool test=c.ajouter();
if(test)
{
ui->tableView_chaine->setModel(ctmp.afficher());
QMessageBox::information(nullptr, QObject::tr("ajout effectuee"),
QObject::tr("chaine ajouté avec succés.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
else
QMessageBox::critical(nullptr, QObject::tr("ajout non effectuee"),
QObject::tr("chaine non ajouté.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
void MainWindow::on_afficher_voi_clicked()
{
son->play();
ui->tableView_voiture->setModel(vtmp.afficher());
}
void MainWindow::on_afficher_ch_clicked()
{
son->play();
ui->tableView_chaine->setModel(ctmp.afficher());
}
void MainWindow::on_modifier_voi_clicked()
{
son->play();
QMessageBox msgBox;
QMessageBox msgBox1;
voiture v(ui->lineEdit_maq->text(),ui->lineEdit_reference_voi->text().toInt(),ui->lineEdit_modele->text(),ui->lineEdit_prix->text().toInt(),ui->lineEdit_type->text(),ui->lineEdit_p_op->text().toInt(),ui->lineEdit_couleur->text(),ui->lineEdit_option->text());
bool test=v.modifier();
if(test)
{
ui->tableView_voiture->setModel(vtmp.afficher());
msgBox.setText("voiture modifié");
msgBox.exec();
}
else
{
msgBox1.setText("voiture non modifié");
msgBox1.exec();
}
}
void MainWindow::on_supprimer_voi_clicked()
{
son->play();
int reference=ui->lineEdit_ref_voi->text().toInt();
bool test=vtmp.supprimer(reference);
if(test)
{
ui->tableView_voiture->setModel(vtmp.afficher());
QMessageBox::information(nullptr, QObject::tr("suppression effectuee"),
QObject::tr("voiture supprimé.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
else
QMessageBox::critical(nullptr, QObject::tr("suppression non effectuee"),
QObject::tr("voiture non supprimé.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
void MainWindow::on_trier_2_clicked()
{
son->play();
int test=0;
if (ui->comboBox_ch->currentText()=="REFERENCE")
{test=1;}
else if (ui->comboBox_ch->currentText()=="NB_MACHINE")
{test=2;}
else if (ui->comboBox_ch->currentText()=="TYPE_PRODUIT")
{test=3;}
ui->tableView_chaine->setModel(ctmp.trier(test)) ;
}
void MainWindow::on_rechercher_voi_clicked()
{
son->play();
ui->tableView_voiture->setModel(vtmp.recherche(ui->lineEdit_ref_voi->text(),ui->lineEdit_maq->text(),ui->lineEdit_mod->text()));
}
void MainWindow::on_comboBox_ch_currentIndexChanged()
{
son->play();
QString REFERENCE = ui->comboBox_ch->currentText();
QSqlQuery query;
query.prepare("select* from CHAINE where REFERENCE =:REFERENCE");
query.bindValue(":REFERENCE",REFERENCE);
if(query.exec())
{
while(query.next())
{
ui->lineEdit_ref_ch->setText(query.value(0).toString());
ui->lineEdit_nb_mach->setText(query.value(1).toString());
ui->lineEdit_type_prod->setText(query.value(2).toString());
}
}
}
void MainWindow::on_modifier_ch_clicked()
{
son->play();
QSqlQuery query;
QMessageBox msgBox;
QMessageBox msgBox1;
chaine c(ui->lineEdit_ref_ch->text().toInt(),ui->lineEdit_nb_mach->text().toInt(),ui->lineEdit_type_prod->text());
bool test=c.modifier();
if(test)
{
ui->tableView_chaine->setModel(ctmp.afficher());
msgBox.setText("chaine modifié");
msgBox.exec();
}
else
{
msgBox1.setText("chaine non modifié");
msgBox1.exec();
}
}
void MainWindow::on_supp_ch_clicked()
{
son->play();
bool test=ctmp.supprimer(ui->lineEdit_ref_ch->text().toInt());
if(test)
{
ui->tableView_chaine->setModel(ctmp.afficher());
QMessageBox::information(nullptr, QObject::tr("suppression effectuee"),
QObject::tr("chaine supprimé.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
else
QMessageBox::critical(nullptr, QObject::tr("suppression non effectuee"),
QObject::tr("chaine non supprimé.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
void MainWindow::on_pdf_clicked()
{
QString strStream;
QTextStream out(&strStream);
const int rowCount = ui->tableView_chaine->model()->rowCount();
const int columnCount = ui->tableView_chaine->model()->columnCount();
out << "<html>\n"
"<head>\n"
"<meta Content=\"Text/html; charset=Windows-1251\">\n"
<< QString("<title>%1</title>\n").arg("strTitle")
<< "</head>\n"
"<body bgcolor=#ffffff link=#5000A0>\n"
// "<align='right'> " << datefich << "</align>"
"<center> <H1>Liste des Agences </H1></br></br><table border=1 cellspacing=0 cellpadding=2>\n";
// headers
out << "<thead><tr bgcolor=#f0f0f0> <th>Numero</th>";
for (int column = 0; column < columnCount; column++)
if (!ui->tableView_chaine->isColumnHidden(column))
out << QString("<th>%1</th>").arg(ui->tableView_chaine->model()->headerData(column, Qt::Horizontal).toString());
out << "</tr></thead>\n";
// data table
for (int row = 0; row < rowCount; row++) {
out << "<tr> <td bkcolor=0>" << row+1 <<"</td>";
for (int column = 0; column < columnCount; column++) {
if (!ui->ag_tab_aff->isColumnHidden(column)) {
QString data = ui->tableView_chaine->model()->data(ui->tableView_chaine->model()->index(row, column)).toString().simplified();
out << QString("<td bkcolor=0>%1</td>").arg((!data.isEmpty()) ? data : QString(" "));
}
}
out << "</tr>\n";
}
out << "</table> </center>\n"
"</body>\n"
"</html>\n";
QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Sauvegarder en PDF", QString(), "*.pdf");
if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }
QPrinter printer (QPrinter::PrinterResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(fileName);
QTextDocument doc;
doc.setHtml(strStream);
doc.setPageSize(printer.pageRect().size()); // This is necessary if you want to hide the page number
doc.print(&printer);
}
void MainWindow::on_stat_clicked()
{
son->play();
chart=new QChart();
int pos=0 ;
QPieSeries *series = new QPieSeries();
QSqlQuery query ;
query.prepare("select * from VOITURE1 ") ;
if(query.exec()) {
while(query.next()){
series->append(query.value(1).toString(), query.value(3).toInt());
QPieSlice *slice = series->slices().at(pos);
slice->setLabelVisible(true);
pos++ ;
}
chart->addSeries(series);
chart->setTheme( QChart::ChartThemeDark);
chart->setAnimationOptions(QChart::AllAnimations);
chart->setAnimationDuration(2000);
chart->setAnimationEasingCurve(QEasingCurve::InOutBounce);
chart->setTitle("les prix");
QChartView *chartview = new QChartView(chart);
chartview->setParent(ui->frame_chaine);
chartview->setBaseSize(300,300);
chartview->setGeometry(0,0,1000,600);
chart->addSeries(series);
chart->setTitle("LES PRIX DES DIFFERENT MARQUE");
chartview->setParent(ui->frame_chaine);
ui->stackedWidget->setCurrentWidget(ui->page) ;
}
}
void MainWindow::on_tableView_voiture_activated(const QModelIndex &index)
{
son->play();
QString val=ui->tableView_voiture->model()->data(index).toString();
QSqlQuery qry;
qry.prepare("select * from VOITURE1 where REFERENCE='"+val+"'or MARQUE='"+val+"'");
if(qry.exec())
{
while(qry.next())
{
ui->lineEdit_reference_voi->setText(qry.value(0).toString());
ui->lineEdit_marque->setText(qry.value(1).toString());
ui->lineEdit_modele->setText(qry.value(2).toString());
ui->lineEdit_prix->setText(qry.value(3).toString());
ui->lineEdit_type->setText(qry.value(4).toString());
ui->lineEdit_p_op->setText(qry.value(5).toString());
ui->lineEdit_couleur->setText(qry.value(6).toString());
ui->lineEdit_option->setText(qry.value(7).toString());
}
}
else
{
QMessageBox::critical(this,tr("error::"),qry.lastError().text());
}
}
void MainWindow::on_tableView_chaine_activated(const QModelIndex &index)
{
son->play();
QString val=ui->tableView_chaine->model()->data(index).toString();
QSqlQuery qry;
qry.prepare("select * from CHAINE where REFERENCE='"+val+"'or TYPE_PRODUIT='"+val+"'");
if(qry.exec())
{
while(qry.next())
{
ui->lineEdit_reference_ch->setText(qry.value(0).toString());
ui->lineEdit_nb_mach->setText(qry.value(1).toString());
ui->lineEdit_type_prod->setText(qry.value(2).toString());
}
}
else
{
QMessageBox::critical(this,tr("error::"),qry.lastError().text());
}
}
void MainWindow::on_btn_login_clicked()
{
employer e ;
if(e.auth(ui->logpass->text(),ui->log_add->text() ) ) {
QSqlQuery query ;
query.prepare("SELECT * FROM TABLE1 WHERE PASSE=:passe AND ADRESSE=:adresse");
query.bindValue(":passe",ui->logpass->text());
query.bindValue(":adresse", ui->log_add->text()) ;
// query.exec() ;
if (query.exec()&&query.next()) {
processLabel->hide() ;
ui->stackedWidget->setCurrentWidget(ui->Menu) ;
processLabel->hide() ;
mSocket= new QTcpSocket(this);
connect(mSocket,&QTcpSocket::readyRead,[&](){
QTextStream T(mSocket);
auto text=T.readAll();
ui->textEdit_message->append(text);
});
QTextStream T(mSocket);
MessengerConnectionDialog D ;
mSocket->connectToHost(D.hostname(), D.port());
QSound *son=new QSound(":/new/prefix1/image/Welcome - Male Voice Speaks (128 kbps) (mp3cut.net)(1).wav");
son->play() ;
QString qs = query.value(4).toString();
// Either this if you use UTF-8 anywhere
std::string utf8_text = qs.toUtf8().constData();
utf8_text.substr(0,13) ;
// or this if you're on Windows :-)
// std::string current_locale_text = qs.toLocal8Bit().constData();
if(utf8_text=="administrateur") {
// ui->tabWidget->insertTab(max,ui->adm_menu,"Home") ;
name=query.value(2).toString()+" " + query.value(1).toString() ;
T<<name<<" is connected";
}
else {
name=query.value(2).toString()+ " " + query.value(1).toString() ;
T<<name<<" is connected";
// processLabel->close() ;
// ui->tabWidget->insertTab(max,ui->em_profil,"Profile") ;
ui->aff_cin->setText(query.value(0).toString() );
ui->aff_nom->setText(query.value(1).toString() );
ui->aff_prenom->setText(query.value(2).toString() );
ui->aff_sal->setText(query.value(3).toString() );
ui->aff_poste->setText(query.value(4).toString() );
if(query.value(5).toString()=="married"){
}
else
ui->aff_combo_etat->setCurrentIndex(1) ;
ui->stackedWidget->setCurrentWidget(ui->employer) ;
}
}
ui->logpass->clear() ;
ui->log_add->clear() ;
}
}
void MainWindow::on_ajouterFour_clicked()
{
if(ui->adm_aj_cin->text().isEmpty()||ui->adm_aj_salaire->text().isEmpty()||ui->adm_aj_nom->text().isEmpty()|| ui->adm_aj_prenom->text().isEmpty() ||ui->adm_aj_poste->text().isEmpty() || ui->adm_aj_rfid->text().isEmpty() ) {
QMessageBox::critical(nullptr, QObject::tr("Erreur"),
QObject::tr("Information incomplete.\n""Click Cancel to exit."), QMessageBox::Cancel);
}
else {
int count=0 ;
QSqlQuery query ;
query.prepare("SELECT * FROM TABLE1 where CIN = :cin ");
query.bindValue(":cin", ui->adm_aj_cin->text().toInt() );
if(query.exec())
{
while(query.next())
{
count++;
}
if(count!=0)
{
QMessageBox::critical(nullptr, QObject::tr("Erreur"),
QObject::tr(" CIN existe deja !.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
if(count==0 )
{
int count2=0 ;
QSqlQuery query2 ;
query2.prepare("SELECT * FROM TABLE1 where RFID = :rfid ");
query2.bindValue(":rfid", ui->adm_aj_rfid->text());
query2.exec() ;
while(query2.next())
{
count2++;
}
if(count2!=0)
{
QMessageBox::critical(nullptr, QObject::tr("Erreur"),
QObject::tr(" RFID existe deja !.\n"
"Click Cancel to exit."), QMessageBox::Cancel);
}
if(count2==0 )
{
int cin=ui->adm_aj_cin->text().toInt() ;
int salaire=ui->adm_aj_salaire->text().toInt() ;
QString nom=ui->adm_aj_nom->text() ;
QString prenom=ui->adm_aj_prenom->text() ;
QString poste=ui->adm_aj_poste->text() ;
QString etat=ui->adm_aj_combo_etat->currentText() ;
int nombre=ui->adm_aj_spin_nbrenfant->value() ;
QDateTime time ;
QString passe= ui->adm_aj_cin->text()+ui->adm_aj_spin_nbrenfant->text()+ui->adm_aj_cin->text()+ui->adm_aj_spin_nbrenfant->text();
QString adresse=nom+"."+prenom+"[email protected]" ;
QString rfid=ui->adm_aj_rfid->text() ;
employer e(cin,nom,prenom,poste,etat,adresse,passe,salaire,nombre,rfid) ;
if(e.ajouter()) {
QMessageBox::information(nullptr, QObject::tr("OK "),
QObject::tr(" Employer ajouter avec succes ok.\n""Click Cancel to exit."), QMessageBox::Cancel);
ui->adm_tab_aff->setModel(e.afficher());
}
else {
QMessageBox::critical(nullptr, QObject::tr("Erreur"),
QObject::tr("Probleme de conixion.\n""Click Cancel to exit."), QMessageBox::Cancel);
}
}
}
}
}
}
void MainWindow::on_afficherfour_clicked()
{
employer e ;
ui->adm_tab_aff->setModel(e.afficher());
}
void MainWindow::on_trier_clicked()
{
QSqlQueryModel *model=new QSqlQueryModel() ;
model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Nom "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Prénom"));
ui->adm_tab_aff->setModel(model) ;