-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstudent_page.cpp
More file actions
186 lines (149 loc) · 7.93 KB
/
Copy pathstudent_page.cpp
File metadata and controls
186 lines (149 loc) · 7.93 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
#include<QDebug>
#include<QDate>
#include<string>
#include<QPixmap>
#include "student_page.h"
#include "ui_student_page.h"
#include "login.h"
#include "json_parsing.h"
#include "date.h"
student_page::student_page(QJsonObject s_data, QWidget *parent) :
QDialog(parent),
ui(new Ui::student_page)
{
ui->setupUi(this);
student_page::s_data=s_data;
ui->label_4->setText("Welcome, "+student_page::s_data["name"].toString()+"!");
ui->label_detail_name->setText(student_page::s_data["name"].toString());
ui->label_detail_course->setText("Course: "+student_page::s_data["course"].toString());
ui->label_detail_roll->setText("Roll no.: "+student_page::s_data["roll"].toString());
ui->label_detail_year->setText("Year: "+student_page::s_data["year"].toString());
ui->label_detail_part->setText("Part: "+student_page::s_data["part"].toString());
QPixmap pic("../LibraryMS/img/default_profile.jpg");
int height=ui->label_profile->height();
ui->label_profile->setPixmap(pic.scaled(height,height,Qt::KeepAspectRatio));
ui->stackedWidget->setCurrentIndex(0);
}
student_page::~student_page()
{
delete ui;
}
void student_page::on_pushButton_clicked()
{
ui->stackedWidget->setCurrentIndex(0);
}
/*------------------------------------------------------------------------------------------------------------
* ---- ------
* ---- Issue-detail_page ------
* ---- ------
* ----------------------------------------------------------------------------------------------------------*/
void student_page::on_pushButton_2_clicked()
{
ui->stackedWidget->setCurrentIndex(1);
parsedata *json = new parsedata;
QJsonArray book_json = json->book_data();
QJsonObject s_json= student_page::s_data;
int fine=0;
// qDebug()<<"so were did it crash?";
ui->tableWidget_issuedBooks->setRowCount(1);
for(int j=0;j<=s_json["book_issued"].toArray().count();j++){
for(int i=0;i<=json->book_no();i++){
if(s_json["book_issued"].toArray().at(j).toString().toLower()==book_json.at(i).toObject()["id"].toString().toLower()){
QTableWidgetItem *temp_id = new QTableWidgetItem;
temp_id->setText(book_json.at(i).toObject()["id"].toString());
ui->tableWidget_issuedBooks->setItem(j, 0, temp_id);
QTableWidgetItem *temp_name = new QTableWidgetItem;
temp_name->setText(book_json.at(i).toObject()["name"].toString());
ui->tableWidget_issuedBooks->setItem(j, 1, temp_name);
date date;
QDate Today=date.today_Qdate();
QDate iss_Date=QDate::fromString(book_json.at(i).toObject()["issued_date"].toString(), "yyyyMMdd");
QDate return_date=date.add_deadline(iss_Date);
int day= return_date.daysTo(Today);
QTableWidgetItem *temp_issued = new QTableWidgetItem;
temp_issued->setText(iss_Date.toString("yyyy/MM/dd"));
ui->tableWidget_issuedBooks->setItem(j, 2, temp_issued);
QTableWidgetItem *temp_return = new QTableWidgetItem;
temp_return->setText(return_date.toString("yyyy/MM/dd"));
ui->tableWidget_issuedBooks->setItem(j, 3, temp_return);
QTableWidgetItem *temp_fine = new QTableWidgetItem;
if(day>0){
temp_fine->setText(QString::number(day*date.price()));
fine+=day*date.price();
}
else{
temp_fine->setText("0");
}
ui->tableWidget_issuedBooks->setItem(j,4,temp_fine);
// qDebug()<<"so it had crashed here!!!!!!!!!!!";
ui->tableWidget_issuedBooks->insertRow(ui->tableWidget_issuedBooks->rowCount());
break;
}
}
}
QTableWidgetItem *temp_fine_ = new QTableWidgetItem;
temp_fine_->setText("Total fine");
ui->tableWidget_issuedBooks->setItem(s_json["book_issued"].toArray().count(), 3, temp_fine_);
QTableWidgetItem *temp_fine_val = new QTableWidgetItem;
temp_fine_val->setText(QString::number(fine));
ui->tableWidget_issuedBooks->setItem(s_json["book_issued"].toArray().count(), 4, temp_fine_val);
ui->tableWidget_issuedBooks->item(s_json["book_issued"].toArray().count(), 4)->setTextColor(Qt::red);
}
/*------------------------------------------------------------------------------------------------------------
* ---- ------
* ---- book_search_page ------
* ---- ------
* ----------------------------------------------------------------------------------------------------------*/
void student_page::on_pushButton_3_clicked()
{
ui->stackedWidget->setCurrentIndex(2);
}
void student_page::on_pushButton_search_clicked()
{
std::string input = ui->lineEdit_search_words->text().toLower().toStdString();
parsedata *json = new parsedata;
QJsonArray book_json = json->book_data();
ui->tableWidget_show_result->setRowCount(0);
int row=0;
for(int i=0;i<=json->book_no();i++){
std::string temp_bname=book_json.at(i).toObject()["name"].toString().toLower().toStdString();
// qDebug()<<ui->lineEdit_search_words->text();
// qDebug()<<book_json.at(i).toObject()["name"].toString().toLower();
if(temp_bname.find(input)!=std::string::npos){
// qDebug()<<temp_bname.find(input);
ui->tableWidget_show_result->insertRow(ui->tableWidget_show_result->rowCount());
QTableWidgetItem *temp_B_id = new QTableWidgetItem;
temp_B_id->setText(book_json.at(i).toObject()["id"].toString());
ui->tableWidget_show_result->setItem(row, 0, temp_B_id);
QTableWidgetItem *temp_B_name = new QTableWidgetItem;
temp_B_name->setText(book_json.at(i).toObject()["name"].toString());
ui->tableWidget_show_result->setItem(row, 1, temp_B_name);
QTableWidgetItem *temp_B_author = new QTableWidgetItem;
temp_B_author->setText(book_json.at(i).toObject()["author"].toString());
ui->tableWidget_show_result->setItem(row, 2, temp_B_author);
QTableWidgetItem *temp_B_status = new QTableWidgetItem;
if(book_json.at(i).toObject()["issued_by"].toString()=="NULL"){
temp_B_status->setText("Not issued");
ui->tableWidget_show_result->setItem(row, 3, temp_B_status);
}
else{
temp_B_status->setText("Issued");
ui->tableWidget_show_result->setItem(row, 3, temp_B_status);
ui->tableWidget_show_result->item(row,3)->setTextColor(Qt::red);
}
row++;
}
}
ui->tableWidget_show_result->removeRow(ui->tableWidget_show_result->rowCount()+1);
}
/*------------------------------------------------------------------------------------------------------------
* ---- ------
* ---- logout_button ------
* ---- ------
* ----------------------------------------------------------------------------------------------------------*/
void student_page::on_pushButton_4_clicked()
{
hide();
login *login_page = new login();
login_page->show();
}