-
Notifications
You must be signed in to change notification settings - Fork 0
/
modifyweatherrecord.cpp
91 lines (79 loc) · 2.75 KB
/
modifyweatherrecord.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
#include "modifyweatherrecord.h"
#include "ui_modifyweatherrecord.h"
ModifyWeatherRecord::ModifyWeatherRecord(QWidget *parent) :
QWidget(parent),
ui(new Ui::ModifyWeatherRecord)
{
ui->setupUi(this);
db = new DataBase();
}
ModifyWeatherRecord::~ModifyWeatherRecord()
{
delete ui;
}
void ModifyWeatherRecord::on_pushButton_clicked()
{
QVariantList data;
QString weekday = ui->weekdayLineEdit->text();
QString date = ui->dateLineEdit->text();
QString month = ui->monthLineEdit->text();
QString label = ui->labelLineEdit->text();
QString temperature = ui->temperatureLineEdit->text() + "°";
int id = ui->IDLineEdit->text().toInt();
for(int i = 0; i < weekday.length(); i++){
if(weekday[i] == ' ')
weekday[i] = '_';
}
for(int i = 0; i < date.length(); i++){
if(date[i] == ' ')
date[i] = '_';
}
for(int i = 0; i < month.length(); i++){
if(month[i] == ' ')
month[i] = '_';
}
for(int i = 0; i < label.length(); i++){
if(label[i] == ' ')
label[i] = '_';
}
for(int i = 0; i < temperature.length(); i++){
if(temperature[i] == ' ')
temperature[i] = '_';
}
data.append(weekday);
data.append(date);
data.append(month);
data.append(label);
data.append(temperature);
if(db->checkingForIDInWeatherDB(id)){
if(weekday == nullptr || date == nullptr || month == nullptr ||
label == nullptr || temperature == nullptr || ui->IDLineEdit->text() == nullptr){
QMessageBox::warning(this, "Внимание", "Некоторые поля не заполнены.");
}
else if(weekday != nullptr && date != nullptr && month != nullptr &&
label != nullptr && temperature != nullptr && ui->IDLineEdit->text() != nullptr){
db->modifyWeatherRecordWithID(data, id);
QMessageBox msgBox;
msgBox.setWindowTitle("Изменение");
msgBox.setText("Запись была успешно изменена.");
msgBox.exec();
}
else{
QMessageBox::warning(this, "Внимание", "Произошла неизвестная ошибка!");
}
}
else if(!db->checkingForIDInWeatherDB(id)){
QMessageBox::warning(this, "Внимание", "Вы ввели неверный ID.");
}
else{
QMessageBox::warning(this, "Внимание", "Произошла неизвестная ошибка!");
}
ui->IDLineEdit->clear();
ui->weekdayLineEdit->clear();
ui->dateLineEdit->clear();
ui->monthLineEdit->clear();
ui->labelLineEdit->clear();
ui->temperatureLineEdit->clear();
data.clear();
this->close();
}