-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
104 lines (91 loc) · 3.39 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPixmap>
#include <QTimer>
#include "user.h"
#include "rememberme.h"
#include "signup.h"
#include <QSettings>
#include "adminpanel.h"
#include "clientpanel.h"
#include "customerpanel.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->notification->hide();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_loginBtn_clicked()
{
QString username = ui->usernameInput->text().trimmed();
QString password = ui->passwordInput->text().trimmed();
bool returnValue = user::loginUser(username,password);
ui->notification->show();
if (returnValue) {
if(user::isActive(username)){
QString role = user::getRole(username);
QSettings settings("c:/windows/winf32.ini", QSettings::IniFormat);
settings.setValue("login",true);
settings.setValue("username", username);
settings.setValue("role",role);
settings.setValue("name",user::getName(username));
if (role == "admin") {
adminpanel *admin = new adminpanel();
admin->setFixedSize(admin->width(),admin->height());
admin->setWindowState(Qt::WindowMaximized);
admin->setWindowTitle(" ");
admin->setWindowIcon(QIcon(":/images/icon"));
admin->show();
this->hide();
}else if (role == "client") {
clientpanel *client = new clientpanel();
client->setFixedSize(client->width(),client->height());
client->setWindowState(Qt::WindowMaximized);
client->setWindowTitle(" ");
client->setWindowIcon(QIcon(":/images/icon"));
client->show();
this->hide();
}else{
customerPanel *customer = new customerPanel();
customer->setFixedSize(customer->width(),customer->height());
customer->setWindowState(Qt::WindowMaximized);
customer->setWindowTitle(" ");
customer->setWindowIcon(QIcon(":/images/icon"));
customer->show();
this->hide();
}
}else{
ui->notification->show();
ui->notification->setStyleSheet("color:red;");
ui->notification->setText("این کاربر غیر فعال می باشد");
}
}else{
ui->notification->show();
ui->notification->setStyleSheet("color:red;");
ui->notification->setText("نام کاربری یا رمز عبور اشتباه است");
}
QTimer::singleShot(5000, this, [this] () { ui->notification->hide();});
}
void MainWindow::on_rememberMe_clicked()
{
rememberMe *r = new rememberMe(this);
r->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
connect(r,SIGNAL(remember_me(QString,QString)),this,SLOT(remember_me(QString,QString)));
r->show();
}
void MainWindow::remember_me(QString username , QString password)
{
ui->usernameInput->setText(username);
ui->passwordInput->setText(password);
}
void MainWindow::on_signupBtn_clicked()
{
signup *s = new signup(this);
s->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
s->show();
}