-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclerkform.cpp
322 lines (263 loc) · 8.59 KB
/
clerkform.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
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#include "clerkform.h"
#include "studentform.h"
#include "ui_clerkform.h"
#include "lms.h"
#include "filing.h"
#include "interface.h"
#include "user.h"
#include "item.h"
#include "loan.h"
#include "QDebug"
#include <QDate>
#include "loan.h"
#include "student.h"
#include <QMessageBox>
extern lms *obj;
extern Filing *file;
extern interface *w;
extern user* active;
clerkform::clerkform(QWidget *parent) :studentform(parent),ui(new Ui::clerkform){
ui->setupUi(this);
this->setWindowTitle(" Welcome Clerk");
setsearch();
setclerks();
}
void clerkform::setclerks(){
label_2 = new QLabel();
line_2 = new QLineEdit();
formLayout = new QFormLayout();
formWidget = new QWidget();
formWidget->setFixedSize(300,150);
for (int i = 0 ; i < 4; i++)
formlines.push_back(new QLineEdit());
formWidget->setWindowTitle("Fill out the form");
formLayout->addRow(tr(" Roll No: "), formlines[0]);
formLayout->addRow(tr(" Name: "), formlines[1]);
formLayout->addRow(tr(" Address: "), formlines[2]);
formLayout->addRow(tr(" Telephone: "), formlines[3]);
addsave();
formWidget->setLayout(formLayout);
}
clerkform::~clerkform(){
delete ui;
}
void clerkform::setmore() {
Layout->addWidget(label_2);
Layout->addWidget(line_2);
Widget->setLayout(Layout);
}
void clerkform::removeform() {
if (label_2!= NULL && line_2!= NULL) {
Layout->removeWidget(label_2);
Layout->removeWidget(line_2);
delete label_2;
delete line_2;
label_2 = NULL;
line_2 = NULL;
}
}
void clerkform::on_searchTitleclerk_clicked(){
removeform();
on_searchTitle_clicked();
}
void clerkform::on_searchAuthorclerk_clicked(){
removeform();
on_searchAuthor_clicked();
}
void clerkform::on_searchSubjectclerk_clicked(){
removeform();
on_searchSubject_clicked();
}
void clerkform::on_detailsclerk_clicked(){
removeform();
on_details_clicked();
}
void clerkform::on_holdclerk_clicked(){
removeform();
on_hold_clicked();
}
void clerkform::instantiateform() {
line->setText(NULL);
label_2 = new QLabel;
line_2 = new QLineEdit;
setmore();
removebutton();
createbutton();
label->setText("Enter the id of the book: ");
label_2->setText("Enter the roll-no: ");
}
void clerkform::on_checkin_clicked(){
removeform();
instantiateform();
QObject::connect(button,SIGNAL(clicked()),this,SLOT(checkin()));
Widget->setWindowTitle("Check in an item");
Widget->show();
}
void clerkform::on_checkout_clicked(){
removeform();
instantiateform();
QObject::connect(button,SIGNAL(clicked()),this,SLOT(checkout()));
Widget->setWindowTitle("Check out an item");
Widget->show();
}
void clerkform::on_renew_clicked(){
removeform();
instantiateform();
QObject::connect(button,SIGNAL(clicked()),this,SLOT(renew()));
Widget->setWindowTitle("Renew an item");
Widget->show();
}
//return
void clerkform::checkin() {
QString Itemname = line->text();
QString Username = line_2->text();
if(Itemname.isEmpty() || Username.isEmpty())
QMessageBox::critical(this,"Check In","Please fill in the details");
else {
item * ptr = obj->searchitem(Itemname.toLocal8Bit().constData());
user * current = obj->searchuser(Username.toLocal8Bit().constData());
QString message = QString::fromStdString(obj->checkIn(ptr,current));
QMessageBox::information(this,"Check In",message);
}
}
//issue
void clerkform::checkout() {
QString Itemname = line->text();
QString Username = line_2->text();
if(Itemname.isEmpty() || Username.isEmpty())
QMessageBox::critical(this,"Check In","Please fill in the details");
else {
item * ptr = obj->searchitem(Itemname.toLocal8Bit().constData());
user * current = obj->searchuser(Username.toLocal8Bit().constData());
QString message = QString::fromStdString(obj->checkOut(ptr,current));
QMessageBox::information(this,"Check Out",message);
}
}
//re-issue
void clerkform::renew() {
QString Itemname = line->text();
QString Username = line_2->text();
if(Itemname.isEmpty() || Username.isEmpty())
QMessageBox::critical(this,"Check In","Please fill in the details");
else {
item * ptr = obj->searchitem(Itemname.toLocal8Bit().constData());
user * current = obj->searchuser(Username.toLocal8Bit().constData());
QString message = QString::fromStdString(obj->renew(ptr,current));
QMessageBox::information(this,"Renew",message);
}
}
void clerkform::on_fine_clicked(){
removeform();
removebutton();
createbutton();
label->setText("Enter the id of the user: ");
QObject::connect(button,SIGNAL(clicked()),this,SLOT(fine()));
Widget->setWindowTitle("Enter User ID");
Widget->show();
}
void clerkform::fine() {
QString Username = line->text();
if(Username.isEmpty())
QMessageBox::critical(this,"Pay Fine","User is Required");
else{
Widget->close();
QString message = QString::fromStdString(obj->calculatefine(Username.toLocal8Bit().constData(), QDate::currentDate()));
QMessageBox::information(this,"Pay Fine",message);
}
line->setText(NULL);
}
void clerkform::removesave(){
if (save!= NULL) {
formLayout->removeWidget(save);
delete save;
save = NULL;
}
}
void clerkform::addsave() {
save = new QPushButton("Save");
formLayout->addWidget(save);
}
void clerkform::on_add_clicked(){
removeform();
removesave();
addsave();
QObject::connect(save,SIGNAL(clicked()),this,SLOT(add()));
formWidget->show();
}
void clerkform::on_update_clicked(){
removeform();
removebutton();
createbutton();
label->setText("Enter the roll-no: ");
QObject::connect(button,SIGNAL(clicked()),this,SLOT(edit()));
Widget->setWindowTitle("Edit the borrower");
Widget->show();
}
void clerkform::add() {
QString id = formlines[0]->text();
QString name = formlines[1]->text();
QString address = formlines[2]->text();
QString telephone = formlines[3]->text();
if (id.isEmpty() || name.isEmpty() || address.isEmpty() || telephone.isEmpty())
QMessageBox::critical(this,"Add User","All fields are Required");
else {
formWidget->hide();
QString message = QString::fromStdString(obj->addnewuser(id.toStdString(),
"12345",name.toStdString(),address.toStdString(),
telephone.toStdString()));
QMessageBox::information(this,"Add User",message);
}
}
void clerkform::edit() {
Widget->hide();
removesave();
addsave();
user * u = obj->searchuser(line->text().toLocal8Bit().constBegin());
if (u!= NULL) {
formlines[0]->setText(u->getid().c_str());
formlines[1]->setText(u->getname().c_str());
formlines[2]->setText(u->getaddress().c_str());
formlines[3]->setText(u->getphone().c_str());
QObject::connect(save,SIGNAL(clicked()),this,SLOT(update()));
formWidget->show();
}
else {
QMessageBox::information(this,"Edit User","User not found!");
}
}
void clerkform::update() {
QString id = formlines[0]->text();
QString name = formlines[1]->text();
QString address = formlines[2]->text();
QString telephone = formlines[3]->text();
if (id.isEmpty() || name.isEmpty() || address.isEmpty() || telephone.isEmpty())
QMessageBox::critical(this,"Edit User","All fields are Required");
else {
formWidget->hide();
QString message = QString::fromStdString(obj->edituser(
line->text().toLocal8Bit().constData(),
id.toStdString(),
name.toStdString(),address.toStdString(),
telephone.toStdString()));
QMessageBox::information(this,"Edit User",message);
}
}
void clerkform::on_logoutclerk_clicked(){
for (int i = 0; i < 4; i++) {
delete formlines[i];
formlines[i] = NULL;
}
delete save;
save = NULL;
delete formLayout;
formLayout = NULL;
delete formWidget;
formWidget = NULL;
delete label_2;
label_2 = NULL;
delete line_2;
line_2 = NULL;
delete result;
result = NULL;
on_logout_clicked();
}