-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
95 lines (78 loc) · 1.91 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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "adminmenu.h"
#include "teachermenu.h"
#include <QProcess>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->username_value->setFocus();
ui->teacher->setChecked(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::login()
{
QString username = ui->username_value->text();
QString password = ui->password_value->text();
if(ui->admin->isChecked())
{
if(utils->queryUser(username, password, "admin"))
{
id = username;
qDebug() << "系统管理员登录成功";
adminMenu();
}
else{
qDebug() << "账号或密码错误";
wrongMenu(ui->admin);
}
}
else if(ui->teacher->isChecked())
{
if(utils->queryUser(username, password, "teacher"))
{
id = username;
qDebug() << "登录成功";
teacherMenu();
}
else{
qDebug() << "账号或密码错误";
wrongMenu(ui->teacher);
}
}
else {
wrongMenu(ui->teacher);
}
}
void MainWindow::adminMenu()
{
this->hide();
adminmenu *admin = new adminmenu;
admin->show();
}
void MainWindow::teacherMenu()
{
this->hide();
teachermenu *teacher = new teachermenu;
teacher->show();
}
void MainWindow::wrongMenu(QAbstractButton *btn)
{
inform->warn(this, "用户名或密码错误!");
clearBtn(btn);
ui->username_value->clear();
ui->password_value->clear();
ui->username_value->setFocus();
ui->teacher->setChecked(true);
}
void MainWindow::clearBtn(QAbstractButton *btn)
{
btn->setAutoExclusive(false);
btn->setChecked(false);
btn->setAutoExclusive(true);
}