forked from 3rd-year-CSE-20/SIS_GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
218 lines (198 loc) · 8.37 KB
/
mainwindow.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
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent){
main = new QWidget();
_main = new QWidget();
mainLayout = new QVBoxLayout();
_mainLayout = new QHBoxLayout();
loginWidget = new Login(this);
mainLayout->addWidget(new QWidget);
mainLayout->addWidget(_main);
mainLayout->addWidget(new QWidget);
main->setLayout(mainLayout);
setWidget(loginWidget);
this->setCentralWidget(main);
this->loadStyles();
connect(loginWidget, &Login::Register,this,&MainWindow::setSignupWidget);
connect(loginWidget, &Login::LoginAcc, this, &MainWindow::login);
}
void MainWindow::loadStyles(){
QFile css("../SIS_GUI/theme.css");
css.open(QFile::ReadOnly);
QString Styles = css.readAll();
this->setStyleSheet(Styles);
}
void MainWindow::setWidget(QWidget *w){
delete _mainLayout;
_mainLayout = new QHBoxLayout();
_mainLayout->addWidget(new QWidget);
_mainLayout->addWidget(w);
_mainLayout->addWidget(new QWidget);
_main->setLayout(_mainLayout);
}
void MainWindow::setSignupWidget(){
regWidget = new Register();
delete loginWidget;
setWidget(regWidget);
connect(regWidget,&Register::back,this,&MainWindow::setLoginWidget);
}
void MainWindow::setLoginWidget(){
loginWidget = new Login();
delete regWidget;
setWidget(loginWidget);
connect(loginWidget, &Login::Register,this,&MainWindow::setSignupWidget);
connect(loginWidget, &Login::LoginAcc, this, &MainWindow::login);
}
void MainWindow::login(QString usr, QString pass){
if(usr.toStdString()[0] == 'A'){
long long id = usr.mid(4,3).toLongLong();
qDebug() << id;
if(Admin::isInDatabase(id)){
qDebug() << "here";
Admin a = Admin::find(id);
qDebug() << a.getPassword();
if(!a.getPassword().compare(pass)){
delete loginWidget;
adminDashboard = new AdminDashboard();
setWidget(adminDashboard);
connect(adminDashboard, &AdminDashboard::Signout, this, &MainWindow::adminSignout);
connect(adminDashboard, &AdminDashboard::addStudent, this, &MainWindow::adminAddStudent);
connect(adminDashboard, &AdminDashboard::addAcademic, this, &MainWindow::adminAddAcademic);
connect(adminDashboard, &AdminDashboard::studentSelected, this, &MainWindow::studentSelected);
connect(adminDashboard, &AdminDashboard::academicSelected,this, &MainWindow::staffSelected);
}
else{
loginWidget->errLbl->setText("Wrong Password");
loginWidget->errLbl->setVisible(true);
}
}
else{
loginWidget->errLbl->setText("Wrong ID");
loginWidget->errLbl->setVisible(true);
}
}else if(usr.toStdString()[0] == 'S'){
long long id = usr.mid(4,3).toLongLong();
qDebug() << id;
if(StaffMember::isInDatabase(id)){
qDebug() << "here";
StaffMember a = StaffMember::find(id);
qDebug() << a.getPassword();
if(!a.getPassword().compare(pass)){
delete loginWidget;
staffDashboard = new StaffDashboard(&a);
setWidget(staffDashboard);
connect(staffDashboard, &StaffDashboard::Signout, this, &MainWindow::academicSignout);
}
else{
loginWidget->errLbl->setText("Wrong Password");
loginWidget->errLbl->setVisible(true);
}
}
else{
loginWidget->errLbl->setText("Wrong ID");
loginWidget->errLbl->setVisible(true);
}
}
else{
long long id = usr.mid(2,4).toLongLong();
qDebug() << "id is : " << id;
if(Student::isInDatabase(id)){
Student a = Student::find(id);
qDebug() << "password is : " << a.getPassword();
if(!a.getPassword().compare(pass)){
delete loginWidget;
studentDashboard = new Dashboard(&a);
setWidget(studentDashboard);
connect(studentDashboard, &Dashboard::Signout, this, &MainWindow::Signout);
}
else{
loginWidget->errLbl->setText("Wrong Password");
loginWidget->errLbl->setVisible(true);
}
}
else{
loginWidget->errLbl->setText("Wrong ID");
loginWidget->errLbl->setVisible(true);
}
}
}
void MainWindow::adminAddStudent(){
regWidget = new Register(nullptr,true);
delete adminDashboard;
setWidget(regWidget);
connect(regWidget,&Register::back,this,&MainWindow::adminDash);
}
void MainWindow::adminAddAcademic(){
regWidget = new Register(nullptr,true,true);
delete adminDashboard;
setWidget(regWidget);
connect(regWidget,&Register::back,this, &MainWindow::adminDash);
}
void MainWindow::adminDash(){
adminDashboard = new AdminDashboard();
delete regWidget;
setWidget(adminDashboard);
connect(adminDashboard, &AdminDashboard::Signout, this, &MainWindow::adminSignout);
connect(adminDashboard, &AdminDashboard::addStudent, this, &MainWindow::adminAddStudent);
connect(adminDashboard, &AdminDashboard::addAcademic, this, &MainWindow::adminAddAcademic);
connect(adminDashboard, &AdminDashboard::studentSelected, this, &MainWindow::studentSelected);
connect(adminDashboard, &AdminDashboard::academicSelected,this, &MainWindow::staffSelected);
}
void MainWindow::studentSelected(Student s){
studentDashboard = new Dashboard(&s,nullptr,true);
disconnect(adminDashboard, &AdminDashboard::studentSelected, this, &MainWindow::studentSelected);
adminDashboard->setVisible(false);
setWidget(studentDashboard);
connect(studentDashboard, &Dashboard::Back, this, &MainWindow::studentDashBack);
connect(studentDashboard, &Dashboard::Delete, this, &MainWindow::studentDashBack);
}
void MainWindow::staffSelected(StaffMember s){
staffDashboard = new StaffDashboard(&s,nullptr,true);
disconnect(adminDashboard, &AdminDashboard::academicSelected, this, &MainWindow::staffSelected);
adminDashboard->setVisible(false);
setWidget(staffDashboard);
connect(staffDashboard, &StaffDashboard::Back, this, &MainWindow::staffDashBack);
connect(staffDashboard, &StaffDashboard::Delete, this, &MainWindow::staffDashBack);
}
void MainWindow::studentDashBack(){
delete studentDashboard;
adminDashboard = new AdminDashboard();
setWidget(adminDashboard);
connect(adminDashboard, &AdminDashboard::Signout, this, &MainWindow::adminSignout);
connect(adminDashboard, &AdminDashboard::addStudent, this, &MainWindow::adminAddStudent);
connect(adminDashboard, &AdminDashboard::addAcademic, this, &MainWindow::adminAddAcademic);
connect(adminDashboard, &AdminDashboard::studentSelected, this, &MainWindow::studentSelected);
connect(adminDashboard, &AdminDashboard::academicSelected, this, &MainWindow::staffSelected);
}
void MainWindow::staffDashBack(){
delete staffDashboard;
adminDashboard = new AdminDashboard();
setWidget(adminDashboard);
connect(adminDashboard, &AdminDashboard::Signout, this, &MainWindow::adminSignout);
connect(adminDashboard, &AdminDashboard::addStudent, this, &MainWindow::adminAddStudent);
connect(adminDashboard, &AdminDashboard::addAcademic, this, &MainWindow::adminAddAcademic);
connect(adminDashboard, &AdminDashboard::studentSelected, this, &MainWindow::studentSelected);
connect(adminDashboard, &AdminDashboard::academicSelected, this, &MainWindow::staffSelected);
}
void MainWindow::Signout(){
loginWidget = new Login();
delete studentDashboard;
setWidget(loginWidget);
connect(loginWidget, &Login::Register,this,&MainWindow::setSignupWidget);
connect(loginWidget, &Login::LoginAcc, this, &MainWindow::login);
}
void MainWindow::adminSignout(){
loginWidget = new Login();
delete adminDashboard;
setWidget(loginWidget);
connect(loginWidget, &Login::Register,this,&MainWindow::setSignupWidget);
connect(loginWidget, &Login::LoginAcc, this, &MainWindow::login);
}
void MainWindow::academicSignout(){
loginWidget = new Login();
delete staffDashboard;
setWidget(loginWidget);
connect(loginWidget, &Login::Register,this,&MainWindow::setSignupWidget);
connect(loginWidget, &Login::LoginAcc, this, &MainWindow::login);
}
MainWindow::~MainWindow(){
}