-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow_search.cpp
More file actions
207 lines (172 loc) · 6.87 KB
/
window_search.cpp
File metadata and controls
207 lines (172 loc) · 6.87 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#include "window_search.h"
#include "ui_window_search.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <bits/stdc++.h>
#include <QDate>
#include <QString>
#include<QMessageBox>
#include<QDir>
//==============================================================================================
Window_Search::Window_Search(QWidget *parent) :
QDialog(parent),
ui(new Ui::Window_Search)
{
ui->setupUi(this);
ui->lineEdit_BookId->setFocus();
ui->tableWidget->insertColumn ( ui->tableWidget->columnCount() );
ui->tableWidget->hide();
}
Window_Search::~Window_Search()
{
delete ui;
}
void Window_Search::on_pushButton_ID_clicked()
{
QString BookId = ui->lineEdit_BookId->text();
QDir AddedBook;
AddedBook.cd("..");
AddedBook.cd("Login_MY_FINAL");
AddedBook.cd("RowData");
QFile AddedBooksFile(AddedBook.path()+"/AddedBooks.json");
AddedBooksFile.open(QIODevice::ReadWrite | QIODevice::Text);
QByteArray B = AddedBooksFile.readAll();
QJsonDocument D = QJsonDocument::fromJson(B);
QJsonObject Obj = D.object();
AddedBooksFile.close();
if(Obj.find(BookId)==Obj.end()){
QMessageBox::warning(this," ","Book not found!");
return;
}
// QJsonObject empty ={};
QJsonValueRef found_ref = Obj.find(BookId).value();
QJsonObject found_obj= found_ref.toObject();
QString BookName= found_obj["name"].toString();
QString subject= found_obj["subject"].toString();
QString date_added= found_obj["date_added"].toString();
QString status= found_obj["status"].toString();
QString author= found_obj["author"].toString();
ui->tableWidget->show();
ui-> tableWidget->setItem ( 0, 0 , new QTableWidgetItem(BookName));
ui-> tableWidget->setItem ( 1, 0 , new QTableWidgetItem(author));
ui-> tableWidget->setItem ( 2, 0 , new QTableWidgetItem(subject));
ui-> tableWidget->setItem ( 3, 0 , new QTableWidgetItem(status));
ui-> tableWidget->setItem ( 4, 0 , new QTableWidgetItem(BookId));
}
void Window_Search::on_pushButton_name_clicked()
{
QString BookName_lineEdit = ui->lineEdit_BookName->text();
QDir AddedBook;
AddedBook.cd("..");
AddedBook.cd("Login_MY_FINAL");
AddedBook.cd("RowData");
QFile AddedBooksFile(AddedBook.path()+"/AddedBooks.json");
AddedBooksFile.open(QIODevice::ReadWrite | QIODevice::Text);
QByteArray B = AddedBooksFile.readAll();
QJsonDocument D = QJsonDocument::fromJson(B);
QJsonObject Obj = D.object();
AddedBooksFile.close();
int found_flag=0;
foreach(QJsonValue x,Obj){
QString BookName=(x.toObject())["name"].toString();
if(BookName_lineEdit==BookName){
QString subject= (x.toObject())["subject"].toString();
QString date_added= (x.toObject())["date_added"].toString();
QString status= (x.toObject())["status"].toString();
QString author= (x.toObject())["author"].toString();
QString BookId= (x.toObject())["id"].toString();
found_flag=1;
ui->tableWidget->show();
ui-> tableWidget->setItem ( 0, 0 , new QTableWidgetItem(BookName));
ui-> tableWidget->setItem ( 1, 0 , new QTableWidgetItem(author));
ui-> tableWidget->setItem ( 2, 0 , new QTableWidgetItem(subject));
ui-> tableWidget->setItem ( 3, 0 , new QTableWidgetItem(status));
ui-> tableWidget->setItem ( 4, 0 , new QTableWidgetItem(BookId));
break;
}
}
if(found_flag==0){
QMessageBox::warning(this," ","Book not found!");
return;
}
}
void Window_Search::on_pushButton_author_clicked()
{
QString Author_lineEdit = ui->lineEdit_AuthorName->text();
QDir AddedBook;
AddedBook.cd("..");
AddedBook.cd("Login_MY_FINAL");
AddedBook.cd("RowData");
QFile AddedBooksFile(AddedBook.path()+"/AddedBooks.json");
AddedBooksFile.open(QIODevice::ReadWrite | QIODevice::Text);
QByteArray B = AddedBooksFile.readAll();
QJsonDocument D = QJsonDocument::fromJson(B);
QJsonObject Obj = D.object();
AddedBooksFile.close();
int found_flag=0;
foreach(QJsonValue x,Obj){
QString author=(x.toObject())["author"].toString();
if(Author_lineEdit==author){
QString subject= (x.toObject())["subject"].toString();
QString date_added= (x.toObject())["date_added"].toString();
QString status= (x.toObject())["status"].toString();
QString BookName=(x.toObject())["name"].toString();
QString BookId= (x.toObject())["id"].toString();
found_flag=1;
ui->tableWidget->show();
ui-> tableWidget->setItem ( 0, 0 , new QTableWidgetItem(BookName));
ui-> tableWidget->setItem ( 1, 0 , new QTableWidgetItem(author));
ui-> tableWidget->setItem ( 2, 0 , new QTableWidgetItem(subject));
ui-> tableWidget->setItem ( 3, 0 , new QTableWidgetItem(status));
ui-> tableWidget->setItem ( 4, 0 , new QTableWidgetItem(BookId));
//MR.MOUSAVI : GET ALL THE STUFF TO PRINT IN THIS BLOCK
//IF YOU TRY TO USE THESE STRINGS OUT OF THE IF BLOCK YOU WILL FACE BUGS!!!!
break;
}
}
if(found_flag==0){
QMessageBox::warning(this," ","Book not found!");
return;
}
}
void Window_Search::on_pushButton_subject_clicked()
{
QString Subject_lineEdit = ui->lineEdit_Subject->text();
QDir AddedBook;
AddedBook.cd("..");
AddedBook.cd("Login_MY_FINAL");
AddedBook.cd("RowData");
QFile AddedBooksFile(AddedBook.path()+"/AddedBooks.json");
AddedBooksFile.open(QIODevice::ReadWrite | QIODevice::Text);
QByteArray B = AddedBooksFile.readAll();
QJsonDocument D = QJsonDocument::fromJson(B);
QJsonObject Obj = D.object();
AddedBooksFile.close();
int found_flag=0;
foreach(QJsonValue x,Obj){
QString subject=(x.toObject())["subject"].toString();
if(Subject_lineEdit==subject){
QString author= (x.toObject())["author"].toString();
QString date_added= (x.toObject())["date_added"].toString();
QString status= (x.toObject())["status"].toString();
QString BookName=(x.toObject())["name"].toString();
QString BookId= (x.toObject())["id"].toString();
found_flag=1;
ui->tableWidget->show();
ui-> tableWidget->setItem ( 0, 0 , new QTableWidgetItem(BookName));
ui-> tableWidget->setItem ( 1, 0 , new QTableWidgetItem(author));
ui-> tableWidget->setItem ( 2, 0 , new QTableWidgetItem(subject));
ui-> tableWidget->setItem ( 3, 0 , new QTableWidgetItem(status));
ui-> tableWidget->setItem ( 4, 0 , new QTableWidgetItem(BookId));
break;
}
}
if(found_flag==0){
QMessageBox::warning(this," ","Book not found!");
return;
}
}