-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbookmanagement.cpp
More file actions
134 lines (125 loc) · 4.14 KB
/
bookmanagement.cpp
File metadata and controls
134 lines (125 loc) · 4.14 KB
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
#include "bookmanagement.h"
#include <QMessageBox>
enum Category switchCategoryQStringToEnum(QString category) {
if(category == "Aerospace")
return Category::Aerospace;
else if(category == "Argiculture")
return Category::Argiculture;
else if(category == "Art")
return Category::Art ;
else if(category == "BiologicalScience")
return Category::BiologicalScience;
else if(category == "Comprehensive")
return Category::Comprehensive;
else if(category == "Economic")
return Category::Economic;
else if(category == "Education")
return Category::Education;
else if(category == "HistoryAndGeography")
return Category::HistoryAndGeography;
else if(category == "IndustrialTechnology")
return Category::IndustrialTechnology;
else if(category == "LanguageAndWriting")
return Category::LanguageAndWriting;
else if(category == "Literature")
return Category::Literature;
else if(category == "MathematicalAndChemistry")
return Category::MathematicalAndChemistry;
else if(category == "Military")
return Category::Military;
else if(category == "Philosophy")
return Category::Philosophy;
else if(category == "ScienceFiction")
return Category::ScienceFiction;
else if(category == "SocialScience")
return Category::SocialScience;
else if(category == "PoliticalAndLaw")
return Category::PoliticalAndLaw;
else if(category == "Transportation")
return Category::Transportation;
else if(category == "MedicineAndHealth")
return Category::MedicineAndHealth;
else if(category == "EnvironmentScience")
return Category::EnvironmentScience;
else
return Category::Comprehensive;
}
BookManagement::BookManagement()
{
model = new QSqlQueryModel;
}
BookManagement::~BookManagement()
{
delete model;
}
void BookManagement::searchBook(QString keyword, enum SearchWay way)
{
switch(way) {
case SearchWay::ByName: {
QString sqlStr = QString("select * from book where b_name = '%1'").arg(keyword);
insertData(sqlStr);
break;
}
case SearchWay::ByAuthor: {
QString sqlStr = QString("select * from book where author = '%1'").arg(keyword);
insertData(sqlStr);
break;
}
case SearchWay::ByBookISBN: {
QString sqlStr = QString("select * from book where isbn = '%1'").arg(keyword);
insertData(sqlStr);
break;
}
default: {
qDebug() << "into default";
break;
}
}
}
void BookManagement::insertData(QString sqlStr)
{
model->setQuery(sqlStr);
for(int i = 0; i < model->rowCount(); i++) {
Book *book = new Book();
for(int j = 0; j < model->columnCount(); j++) {
QModelIndex index = model->index(i, j);
QString data = model->data(index).toString();
switch(j) {
case 0:
book->id =data;
break;
case 1:
book->ISBN = data;
break;
case 2:
book->inventory = data.toInt();
break;
case 3:
book->bookName = data;
break;
case 4:
book->author = data;
break;
case 5:
book->shelfLife = data;
break;
case 6:
book->price = data.toDouble();
break;
case 7:
book->category = switchCategoryQStringToEnum(data);
case 8:
book->press = data;
break;
case 9:
book->loanStatus = data == "OnLean" ? LeanStatus::OnLean :
data == "NotOnLean" ? LeanStatus::NotOnLead : LeanStatus::Ordered;
break;
default:
qDebug() << "default";
break;
}
}
bookList.push_back(book);
}
}