-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
739 lines (596 loc) · 26.8 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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QJsonDocument>
#include <QJsonObject>
#include <QUrlQuery>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_stackedWidget_currentChanged(int arg1)
{
}
void MainWindow::on_get_started_home_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
}
void MainWindow::on_sl_admin_pushButton_1_clicked()
{
ui->stackedWidget->setCurrentIndex(2);
}
void MainWindow::on_sl_user_pushButton_2_clicked()
{
ui->stackedWidget->setCurrentIndex(4);
}
void MainWindow::on_al_pushButton_goto_login_clicked()
{
ui->stackedWidget->setCurrentIndex(5);
}
void MainWindow::on_ur_pushButton_goto_login_clicked()
{
ui->stackedWidget->setCurrentIndex(4);
}
void MainWindow::on_backpush_clicked()
{
int previousIndex = ui->stackedWidget->currentIndex() - 1;
if (previousIndex < 0) {
previousIndex = ui->stackedWidget->count() - 1;
}
ui->stackedWidget->setCurrentIndex(previousIndex);
}
void MainWindow::on_backpushTosl_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
}
//Slot function for registration (user admin db)
void MainWindow::on_ur_pushButton_userReg_clicked()
{
// Disable button
ui->ur_pushButton_userReg->setEnabled(false);
// user inputs
QString name = ui->ur_lineEdit_name->text();
QString email = ui->ur_lineEdit_email->text();
QString password = ui->ur_lineEdit_pass->text();
// Creating a object with the user data
QJsonObject userObject;
userObject["name"] = name;
userObject["email"] = email;
userObject["password"] = password;
userObject["role "] = "user";
//Object to a string
QJsonDocument jsonDoc(userObject);
QByteArray jsonData = jsonDoc.toJson();
//POST request to databse
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
// Enable button
ui->ur_pushButton_userReg->setEnabled(true);
if (reply->error() == QNetworkReply::NoError) {
qDebug() << "User registered successfully!";
ui->stackedWidget->setCurrentIndex(4);
} else {
qDebug() << "Failed to register user:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed to register user: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/users.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
url.setQuery(urlQuery);
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
networkManager->post(request, jsonData);
}
//Slot function for user and db login
void MainWindow::on_al_pushButton_admin_login_2_clicked()
{
//Button Disable
ui->al_pushButton_admin_login_2->setEnabled(false);
// Getting the email and password
QString email = ui->al_lineEdit_email_2->text();
QString password = ui->al_lineEdit_pass_2->text();
//GET request to database
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
// Enable button
ui->al_pushButton_admin_login_2->setEnabled(true);
if (reply->error() == QNetworkReply::NoError) {
// Get data from the reply
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
// User with the entered email exists and the password match
bool userExists = false;
for (const auto& user : jsonObj) {
QJsonObject userObj = user.toObject();
if (userObj.value("email").toString() == email) {
userExists = true;
if (userObj.value("password").toString() == password) {
QString role = userObj["role "].toString();
if (role == "db") {
ui->stackedWidget->setCurrentIndex(7);
QString name = userObj["name"].toString();
QString userEmail = userObj["email"].toString();
//setting the user's name and email
ui->usernamelabel_2->setText(name);
ui->useremaillabel_2->setText(userEmail);
userEmailAddress = userEmail;
} else{
ui->stackedWidget->setCurrentIndex(6);
// getting the user's name and email
QString name = userObj["name"].toString();
QString userEmail = userObj["email"].toString();
//setting the user's name and email
ui->usernamelabel->setText(name);
ui->useremaillabel->setText(userEmail);
ui->ap_lineEdit_name->setText(name);
ui->ap_lineEdit_email->setText(userEmail);
userEmailAddress = userEmail;
qDebug() <<name;
qDebug() <<userEmail;
}
} else {
// Wrong password
QMessageBox::critical(this, "Error", "Wrong Password");
break;
}
}
}
if (!userExists) {
// User not found
QMessageBox::critical(this, "Error", "User Not Found");
}
} else {
// Error occurred
qDebug() << "Error:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed To Fetch Data From Database: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/users.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("print", "pretty");
url.setQuery(urlQuery);
QNetworkRequest request(url);
networkManager->get(request);
}
//Slot function for Admin login
void MainWindow::on_al_pushButton_admin_login_clicked()
{
//Button Disable
ui->al_pushButton_admin_login->setEnabled(false);
// Getting the email and password
QString email = ui->al_lineEdit_email->text();
QString password = ui->al_lineEdit_pass->text();
//GET request to database
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
// Enable button
ui->al_pushButton_admin_login->setEnabled(true);
if (reply->error() == QNetworkReply::NoError) {
// Get data from the reply
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
// User with the entered email exists and the password match
bool userExists = false;
for (const auto& user : jsonObj) {
QJsonObject userObj = user.toObject();
if (userObj.value("email").toString() == email) {
userExists = true;
if (userObj.value("password").toString() == password) {
QString role = userObj["role "].toString();
if (role == "admin") {
ui->stackedWidget->setCurrentIndex(8);
QString name = userObj["name"].toString();
QString userEmail = userObj["email"].toString();
ui->adminhome_name_label->setText(name);
ui->adminhome_email_label->setText(userEmail);
} else{
// Wrong password
QMessageBox::critical(this, "Error", "Access Denied : Not An Admin Account");
break;
}
} else {
// Wrong password
QMessageBox::critical(this, "Error", "Wrong Password");
break;
}
}
}
if (!userExists) {
// User not found
QMessageBox::critical(this, "Error", "User Not Found");
}
} else {
// Error occurred
qDebug() << "Error:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed To Fetch Data From Database: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/users.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("print", "pretty");
url.setQuery(urlQuery);
QNetworkRequest request(url);
networkManager->get(request);
}
void MainWindow::on_userlogut_clicked()
{
ui->stackedWidget->setCurrentIndex(5);
}
//Add Percele
void MainWindow::on_ap_pushButton_add_clicked()
{
// Disable button
ui->ap_pushButton_add->setEnabled(false);
// user inputs
QString name = ui->ap_lineEdit_name->text();
QString reciverName = ui->ap_lineEdit_reciverName->text();
QString email = ui->ap_lineEdit_email->text();
QString mobile = ui->ap_lineEdit_mobile->text();
QString receiverMobile = ui->ap_lineEdit_receiverMobile->text();
QString address = ui->ap_lineEdit_address->text();
QString destination = ui->ap_destination_comboBox->currentText();
QString type = ui->ap_type_comboBox->currentText();
QString status = "pending";
QString costing;
if (destination == "Inside Chittagong") {
costing = "60";
} else {
costing = "120";
}
// Creating a object with the user data
QJsonObject parcelObject;
parcelObject["name"] = name;
parcelObject["reciverName"] = reciverName;
parcelObject["email"] = email;
parcelObject["mobile"] = mobile;
parcelObject["receiverMobile"] = receiverMobile;
parcelObject["address"] = address;
parcelObject["destination"] = destination;
parcelObject["type"] = type;
parcelObject["status"] = status;
parcelObject["costing"] = costing;
parcelObject["dbmail"] = "N/A";
//Object to a string
QJsonDocument jsonDoc(parcelObject);
QByteArray jsonData = jsonDoc.toJson();
//POST request to databse
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
// Enable button
ui->ap_pushButton_add->setEnabled(true);
if (reply->error() == QNetworkReply::NoError) {
qDebug() << "Parcel Added Successfully!";
ui->stackedWidget->setCurrentIndex(6);
} else {
qDebug() << "Failed To Add Parcel:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed To Add Parcel: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/parcels.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
url.setQuery(urlQuery);
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
networkManager->post(request, jsonData);
}
void MainWindow::on_userlogut_2_clicked()
{
ui->stackedWidget->setCurrentIndex(6);
}
void MainWindow::on_user_pushButton_goaddpercle_clicked()
{
ui->stackedWidget->setCurrentIndex(9);
}
void MainWindow::on_myPercle_pushButton_clicked()
{
}
//USER MY PERCELS
void MainWindow::on_user_pushButton_addpercle_2_clicked()
{
// Disable button
ui->user_pushButton_addpercle_2->setEnabled(false);
ui->stackedWidget->setCurrentIndex(10);
// Get the user's email
if (userEmailAddress.isEmpty()) {
QMessageBox::critical(this, "Error", "User email not found.");
return;
}
//GET request to retrieve parcels based on the user's email
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
ui->user_pushButton_addpercle_2->setEnabled(true);
// Get data from the reply
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
// Loop through the parcels and display them
for (const auto& parcel : jsonObj) {
QJsonObject parcelObj = parcel.toObject();
if (parcelObj.value("email").toString() == userEmailAddress) {
// Displaying parcel information
QString name = parcelObj["name"].toString();
QString email = parcelObj["email"].toString();
QString reciverName = parcelObj["reciverName"].toString();
QString mobile = parcelObj["mobile"].toString();
QString receiverMobile = parcelObj["receiverMobile"].toString();
QString address = parcelObj["address"].toString();
QString destination = parcelObj["destination"].toString();
QString type = parcelObj["type"].toString();
QString status = parcelObj["status"].toString();
QString costing = parcelObj["costing"].toString();
ui->pd_name_label->setText(name);
ui->pd_email_label->setText(email);
ui->pd_phone_label->setText(mobile);
ui->pd_sndr_name_label->setText(reciverName);
ui->pd_sndr_Destination_label->setText(destination);
ui->pd_sndr_phone_label->setText(receiverMobile);
ui->pd_type_label->setText(type);
ui->pd_costing_label->setText(costing);
ui->pd_status_label->setText(status);
ui->pd_address_label->setText(address);
}
}
} else {
qDebug() << "Failed To Fetch Parcels:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed To Fetch Parcels: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/parcels.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
url.setQuery(urlQuery);
QNetworkRequest request(url);
networkManager->get(request);
}
void MainWindow::on_userlogut_5_clicked()
{
ui->stackedWidget->setCurrentIndex(6);
}
void MainWindow::on_admin_logout_clicked()
{
ui->stackedWidget->setCurrentIndex(5);
}
//Admin All Parcels
void MainWindow::on_user_pushButton_goaddpercle_3_clicked()
{
ui->stackedWidget->setCurrentIndex(12);
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
// Getting Data
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
for (const auto& parcel : jsonObj) {
QJsonObject parcelObj = parcel.toObject();
// Displaying parcel information
QString name = parcelObj["name"].toString();
QString email = parcelObj["email"].toString();
QString reciverName = parcelObj["reciverName"].toString();
QString mobile = parcelObj["mobile"].toString();
QString receiverMobile = parcelObj["receiverMobile"].toString();
QString address = parcelObj["address"].toString();
QString destination = parcelObj["destination"].toString();
QString type = parcelObj["type"].toString();
QString status = parcelObj["status"].toString();
QString costing = parcelObj["costing"].toString();
QString dbmail = parcelObj["dbmail"].toString();
percleMail = email;
ui->allp_name_label->setText(name);
ui->allp_email_label->setText(email);
ui->pd_phone_label_3->setText(mobile);
ui->pd_sndr_name_label_3->setText(reciverName);
ui->pd_sndr_Destination_label_3->setText(destination);
ui->pd_sndr_phone_label_3->setText(receiverMobile);
ui->pd_type_label_3->setText(type);
ui->allp_costing_label_2->setText(costing);
ui->pd_status_label_3->setText(status);
ui->allp_address_label->setText(address);
ui->allp_dbmail_label->setText(dbmail);
}
} else {
qDebug() << "Failed To Fetch Parcels:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed To Fetch Parcels: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/parcels.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
url.setQuery(urlQuery);
QNetworkRequest request(url);
networkManager->get(request);
// Call the function to load DB users
loadDbUsers();
}
// Loading DB users
void MainWindow::loadDbUsers()
{
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
for (const auto& user : jsonObj) {
QJsonObject userObj = user.toObject();
QString email = userObj["email"].toString();
QString role = userObj["role "].toString();
qDebug() << role;
qDebug() << userObj;
if (role == "db") {
ui->allp_db_select_comboBox->addItem(email);
}
}
} else {
qDebug() << "Failed to fetch users:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed to fetch users: " + reply->errorString());
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/users.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
url.setQuery(urlQuery);
QNetworkRequest request(url);
networkManager->get(request);
}
//Adimn Assign Db
void MainWindow::on_allp_updatep_pushButton_clicked()
{
QString selectedEmail = ui->allp_db_select_comboBox->currentText();
//Finding the parcel with the email
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
bool parcelFound = false;
QString parcelId;
QJsonObject existingParcelData;
for (auto it = jsonObj.constBegin(); it != jsonObj.constEnd(); ++it) {
const QString& key = it.key();
const QJsonValue& value = it.value();
if (value.isObject()) {
const QJsonObject& parcelObj = value.toObject();
QString email = parcelObj["email"].toString();
if (email == percleMail) {
parcelFound = true;
parcelId = key;
existingParcelData = parcelObj;
break;
}
}
}
if (parcelFound) {
// Updating The dbmail
existingParcelData["dbmail"] = selectedEmail;
//PUT request
QByteArray updateJsonData = QJsonDocument(existingParcelData).toJson();
QNetworkAccessManager* updateManager = new QNetworkAccessManager(this);
connect(updateManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* updateReply) {
if (updateReply->error() == QNetworkReply::NoError) {
qDebug() << "Parcel updated successfully";
ui->stackedWidget->setCurrentIndex(8);
} else {
qDebug() << "Failed to update parcel:" << updateReply->errorString();
QMessageBox::critical(this, "Error", "Failed to update parcel: " + updateReply->errorString());
}
updateReply->deleteLater();
});
QString updateUrlStr = "https://parcelplus-25cc2-default-rtdb.firebaseio.com/parcels/" + parcelId + ".json";
QUrl updateUrl(updateUrlStr);
QUrlQuery updateUrlQuery;
updateUrlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
updateUrl.setQuery(updateUrlQuery);
QNetworkRequest updateRequest(updateUrl);
updateRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
updateManager->put(updateRequest, updateJsonData);
} else {
qDebug() << "Parcel not found";
QMessageBox::critical(this, "Error", "Parcel not found");
}
} else {
qDebug() << "Failed to fetch parcels:" << reply->errorString();
QMessageBox::critical(this, "Error", "Failed to fetch parcels: " + reply->errorString());
}
reply->deleteLater();
});
QString fetchUrlStr = "https://parcelplus-25cc2-default-rtdb.firebaseio.com/parcels.json";
QUrl fetchUrl(fetchUrlStr);
QUrlQuery fetchUrlQuery;
fetchUrlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
fetchUrl.setQuery(fetchUrlQuery);
QNetworkRequest fetchRequest(fetchUrl);
networkManager->get(fetchRequest);
}
void MainWindow::on_userlogut_9_clicked()
{
ui->stackedWidget->setCurrentIndex(8);
}
void MainWindow::on_userlogut_3_clicked()
{
ui->stackedWidget->setCurrentIndex(5);
}
//Parcel to dalevery
void MainWindow::on_user_pushButton_addpercle_3_clicked()
{
ui->stackedWidget->setCurrentIndex(11);
QNetworkAccessManager* networkManager = new QNetworkAccessManager(this);
connect(networkManager, &QNetworkAccessManager::finished, this, [=](QNetworkReply* reply) {
if (reply->error() == QNetworkReply::NoError) {
QByteArray jsonData = reply->readAll();
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData);
QJsonObject jsonObj = jsonDoc.object();
// Find the parcel with the given email
QJsonObject parcelObj;
for (const auto& parcel : jsonObj) {
QJsonObject currentParcelObj = parcel.toObject();
QString email = currentParcelObj["email"].toString();
if (email == userEmailAddress) {
parcelObj = currentParcelObj;
break;
}
}
// Check if the parcel was found
if (!parcelObj.isEmpty()) {
// Display parcel information
QString name = parcelObj["name"].toString();
QString email = parcelObj["email"].toString();
QString reciverName = parcelObj["reciverName"].toString();
QString mobile = parcelObj["mobile"].toString();
QString receiverMobile = parcelObj["receiverMobile"].toString();
QString address = parcelObj["address"].toString();
QString destination = parcelObj["destination"].toString();
QString type = parcelObj["type"].toString();
QString status = parcelObj["status"].toString();
QString costing = parcelObj["costing"].toString();
QString dbmail = parcelObj["dbmail"].toString();
percleMail = email;
ui->allp_name_label_6->setText(name);
ui->allp_email_label_2->setText(email);
ui->pd_phone_label_4->setText(mobile);
ui->pd_sndr_name_label_4->setText(reciverName);
ui->pd_sndr_Destination_label_4->setText(destination);
ui->pd_sndr_phone_label_4->setText(receiverMobile);
ui->pd_type_label_4->setText(type);
ui->allp_costing_label_3->setText(costing);
ui->pd_status_label_4->setText(status);
ui->allp_address_label_2->setText(address);
ui->allp_dbmail_label_2->setText(dbmail);
} else {
}
} else {
}
reply->deleteLater();
});
QUrl url("https://parcelplus-25cc2-default-rtdb.firebaseio.com/parcels.json");
QUrlQuery urlQuery;
urlQuery.addQueryItem("auth", "53gKbnYDUOuvyuQNmf72svwvvSyjtUCVhWGiWVmg");
url.setQuery(urlQuery);
QNetworkRequest request(url);
networkManager->get(request);
}
void MainWindow::on_userlogut_10_clicked()
{
ui->stackedWidget->setCurrentIndex(7);
}