-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextrapickupwindow.cpp
154 lines (124 loc) · 5.28 KB
/
extrapickupwindow.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
#include "extrapickupwindow.h"
#include "ui_extrapickupwindow.h"
#include "smtp.h"
#include "userdatabasemanager.h"
#include <QDebug>
#include <QSqlError>
#include <string>
#include <string.h>
#include <historydatabasemanager.h>
ExtraPickupWindow::ExtraPickupWindow(QWidget *parent, int id) :
QWidget(parent),
ui(new Ui::ExtraPickupWindow)
{
ui->setupUi(this);
userId = id;
EMAIL_USER_NAME = "stcb376";
EMAIL_PASSWORD = "SimplePassword";
EMAIL_SERVER = "smtp.gmail.com";
EMAIL_PORT = 465;
EMAIL_SUBJECT = "Smart Trash Can pick up order confirmed!";
}
void ExtraPickupWindow::pickupTimeHandler(){
trashTimeOne = ui->time1CheckBox->checkState();
trashTimeTwo = ui->time2CheckBox->checkState();
trashTimeFive = ui->time5CheckBox->checkState();
if (trashTimeOne == true){
ui->timeLabel->setText("Price: 15 Bottle caps");
timePrice = 15;
trashTime = "Today";
intTrashTime = 1;
}
if (trashTimeTwo == true){
ui->timeLabel->setText("Price: 10 Bottle caps");
timePrice = 10;
trashTime = "2 days";
intTrashTime = 2;
}
if (trashTimeFive == true){
ui->timeLabel->setText("Price: 5 Bottle caps");
timePrice = 5;
trashTime = "5 days";
intTrashTime = 5;
}
}
bool ExtraPickupWindow::sizeTimeMoneyHandler(){
trashSizeSmallBool = ui->itemSmallCheckBox->checkState();
trashSizeMediumBool = ui->itemMediumCheckBox->checkState();
trashSizeBigBool = ui->itemBigCheckBox->checkState();
request = "";
if (trashSizeSmallBool == true || trashSizeMediumBool == true || trashSizeBigBool == true) {
request = "You have selected ";
}
if(trashSizeSmallBool == true){
request = request + "small size item(s) with the quantity of " + ui->spinBox->cleanText() + " for 10 Bottle caps per item";
}
if(trashSizeMediumBool == true){
request = request + ", medium size item(s) with the quantity of " + ui->spinBox_2->cleanText() + " for 20 Bottle caps per item";
}
if(trashSizeBigBool == true){
request = request + ", and large size item(s) with the quantity of " + ui->spinBox_3->cleanText() + " for 30 Bottle caps per item";
}
price = ui->spinBox->cleanText().toInt() * 10 + ui->spinBox_2->cleanText().toInt() * 20 + ui->spinBox_3->cleanText().toInt() * 30;
if (trashSizeSmallBool == true || trashSizeMediumBool == true || trashSizeBigBool == true) {
request = request + ". The price of the selected item(s) is; " + QString::number(price) + " Bottle caps.";
request = request + "The time of pick up is in; " + trashTime + ". The collection will arrive on; " + QDate::currentDate().addDays(intTrashTime).toString(Qt::ISODate)
+ ". For the price of " + QString::number(timePrice)
+ ". "
+ "The total price of your services is; "
+ QString::number(timePrice + price)
+ ". ";
ui->totalPriceLabel->setText(QString::number(timePrice + price) + " Bottle caps.");
ui->priceLabel->setText("Item price: " + QString::number(price) + " Bottle caps.");
invoiceNumber = rand() % 10000 + 1000;
currentDate = QDate::currentDate().addDays(intTrashTime).toString(Qt::ISODate);
return true;
}
else{
ui->extraPickUpUOutputLabel->setText("You have not specified items to be picked up.");
return false;
}
}
void ExtraPickupWindow::on_extrapickupConfirmButton_clicked()
{
Smtp* smtp = new Smtp(EMAIL_USER_NAME, EMAIL_PASSWORD, EMAIL_SERVER, EMAIL_PORT);
connect(smtp, SIGNAL(status(QString)), this, SLOT(mailSent(QString)));
pickupTimeHandler();
if(sizeTimeMoneyHandler() == true){
QString commentMsg = request + "You have added the following comments; '"
+ ui->extrapickupCommentText->toPlainText() + "'";
QString emailAddress = dataBase.userDataBaseRetrieveUserEmail(userId);
historyManager.historyDatabaseInsert(userId, trashSizeSmallBool, trashSizeMediumBool, trashSizeBigBool,
ui->spinBox->cleanText().toInt(), ui->spinBox_2->cleanText().toInt(),
ui->spinBox_3->cleanText().toInt(), ui->extrapickupCommentText->toPlainText(),
intTrashTime, price, timePrice, (timePrice+price), currentDate, invoiceNumber);
smtp->sendMail(EMAIL_USER_NAME, emailAddress, EMAIL_SUBJECT, commentMsg);
}
else{
sizeTimeMoneyHandler();
}
}
void ExtraPickupWindow::mailSent(QString status)
{
if(status == "Message sent"){
ui->extraPickUpUOutputLabel->setText("We've sent you a confirmation email of your purchase.");
ui->extrapickupCommentText->setText("");
ui->itemSmallCheckBox->setChecked(false);
ui->itemMediumCheckBox->setChecked(false);
ui->itemBigCheckBox->setChecked(false);
ui->time1CheckBox->setChecked(false);
ui->time2CheckBox->setChecked(false);
ui->time5CheckBox->setChecked(false);
ui->spinBox->setValue(0);
ui->spinBox_2->setValue(0);
ui->spinBox_3->setValue(0);
}
}
ExtraPickupWindow::~ExtraPickupWindow()
{
delete ui;
}
void ExtraPickupWindow::on_pushButton_2_clicked()
{
emit cancel_service();
}