-
Notifications
You must be signed in to change notification settings - Fork 6
/
in.cpp
executable file
·107 lines (90 loc) · 2.7 KB
/
in.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
#include "in.h"
#include "ui_in.h"
in::in(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::in)
{
ui->setupUi(this);
setWindowTitle("停车场管理系统");
this -> initWindow();
}
in::~in()
{
delete ui;
}
void in::on_back_clicked()
{
MainWindow *m;
m = new MainWindow();
this -> close();
m -> show();
}
void in::initWindow(){
QTimer *timer = new QTimer(this);
displayTime();
connect(timer, SIGNAL(timeout()), this, SLOT(displayTime()));
timer->start(1000);
QString car_pos = this -> allocationPos();
if(car_pos == "false") {
ui -> pos -> setAlignment(Qt::AlignCenter);
ui -> pos -> setStyleSheet("border: 1px solid red;");
ui -> pos -> setText("车库已满");
ui -> car_num -> setEnabled(false);
} else {
ui -> pos -> setAlignment(Qt::AlignCenter);
ui -> pos -> setStyleSheet("border: 1px solid green;");
ui -> pos -> setText(car_pos);
}
}
void in::displayTime(){
QDateTime dt;
QTime time;
QDate date;
dt.setTime(time.currentTime());
dt.setDate(date.currentDate());
QString currentDate = dt.toString("yyyy-MM-dd hh:mm:ss");
ui -> in_time -> setAlignment(Qt::AlignCenter);
ui -> in_time -> setStyleSheet("border: 1px solid green;");
ui->in_time->setText(currentDate);
}
QString in::allocationPos(){
// new database();
QSqlQuery qry;
qry.prepare( "SELECT * FROM `car_pos` WHERE `status` = 'free' and `type` = 'position' LIMIT 1" );
if( !qry.exec() ){
qDebug() << qry.lastError();
return "DB ERROR";
} else {
while( qry.next() ){
return qry.value(0).toString();
}
return "false";
}
}
void in::on_enter_clicked() {
// new database();
if(ui -> car_num -> isEnabled()){
QString input_car_num = ui -> car_num -> text();
QString input_in_time = ui -> in_time -> text();
QString input_place_id = ui -> pos -> text();
QSqlQuery qry;
QString sql = "INSERT INTO `spaces` (`car_num`, `place_id`, `in_time`) VALUES ('"+ input_car_num +"', '"+ input_place_id +"', '"+ input_in_time +"')";
qry.prepare(sql);
if( !qry.exec() ) {
qDebug() << qry.lastError();
} else {
QString sql_up = "UPDATE `car_pos` SET `status` = 'full' WHERE id = '"+input_place_id+"'";
qry.prepare(sql_up);
if( !qry.exec() )
qDebug() << qry.lastError();
}
QMessageBox msgBox;
msgBox.setText("入库成功!");
msgBox.exec();
this -> initWindow();
} else {
QMessageBox msgBox;
msgBox.setText("车库已满,不要乱点!!");
msgBox.exec();
}
}