/
bookadd.cpp
73 lines (60 loc) · 1.83 KB
/
bookadd.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
#include "bookadd.h"
#include "ui_bookadd.h"
#include "mainwindow.h"
#include "booklist.h"
#include "database.h"
#include <QDir>
#include <QMessageBox>
#include <QLabel>
#include <QDebug>
#include <QByteArray>
#include <QTextCodec>
#include <QPixmap>
#include <QObject>
BookAdd::BookAdd(QWidget *parent) : QMainWindow(parent), ui(new Ui::BookAdd)
{
ui->setupUi(this);
this->setWindowTitle("Add | Book Manager");
// INIT DATABASE
bookManagerDb = Database::connection();
bookManagerQuery = new QSqlQuery(*bookManagerDb);
}
BookAdd::~BookAdd()
{
delete ui;
}
void BookAdd::on_saveButton_clicked()
{
QString name, author, pageNumber, description, language, isbnNumber, sizes, publishedAt, publishedOn;
name = ui->fieldName->text();
author = ui->fieldAuthor->text();
pageNumber = ui->fieldPagesNumber->text();
description = ui->fieldDescription->toPlainText();
language = ui->fieldLanguage->text();
isbnNumber = ui->fieldISBN->text();
sizes = ui->fieldSize->text();
publishedAt = ui->fieldPublishedAt->text();
publishedOn = ui->fieldPublishedOn->text();
bookManagerQuery->prepare("INSERT INTO Books VALUES(NULL, '"+name+"', '"+author+"', '"+pageNumber+"', '"+description+"', '"+language+"', '"+isbnNumber+"', '"+sizes+"', '"+publishedAt+"', '"+publishedOn+"');");
bookManagerQuery->exec();
ui->labelActionStatus->setText("The book successfully added!");
ui->labelActionStatus->setStyleSheet("color: green;");
}
void BookAdd::on_cancelButton_clicked()
{
this->hide();
BookList *bookList = new BookList;
bookList->show();
}
void BookAdd::on_actionLogout_triggered()
{
this->hide();
MainWindow *mainWindow = new MainWindow;
mainWindow->show();
}
void BookAdd::on_returnButton_clicked()
{
this->hide();
BookList *bookList = new BookList;
bookList->show();
}