forked from voidhug/QtBookMIS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
80 lines (71 loc) · 2.41 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dbhelper.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->lineEditPassword->setEchoMode(QLineEdit::Password);
userView = new User(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButtonLogIn_clicked()
{
QString user = ui->lineEditUser->text();
QString pwd = ui->lineEditPassword->text();
DbHelper *dbhelper = new DbHelper();
if (user == "" || pwd == "") {
QMessageBox::warning(NULL, tr("Warning!"), tr("User name and password cannot be null!"));
} else if (dbhelper->queryOne(user, pwd)) {
if (user == "admin") {
QMessageBox::information(NULL, tr("Welcome!"), tr("Your are a manager!"));
manager.show();
} else {
QMessageBox::information(NULL, tr("Welcome!"), tr("Your are a user!"));
userView->show();
}
}
connect(this, SIGNAL(emitUser(QString,QString)),
userView, SLOT(showUser(QString,QString)));
emit emitUser(user, pwd);
}
void MainWindow::on_pushButtonSignUp_clicked()
{
QString user = ui->lineEditUser->text();
QString pwd = ui->lineEditPassword->text();
DbHelper *dbhelper = new DbHelper();
if (user == "" || pwd == "") {
QMessageBox::warning(NULL, tr("Warning!"), tr("User name and password cannot be null!"));
} else if (dbhelper->queryOne(user, pwd)) {
QMessageBox::warning(NULL, tr("Warning!"), tr("User name have exited!"));
} else {
if (dbhelper->addOne(user, pwd)){
QMessageBox::information(NULL, tr("Welcome!"), tr("You have been a user!"));
userView->show();
} else {
QMessageBox::warning(NULL, tr("Wrong!"), tr("Sorry, database wrong!"));
}
connect(this, SIGNAL(emitUser(QString,QString)),
userView, SLOT(showUser(QString,QString)));
emit emitUser(user, pwd);
}
}
void MainWindow::on_pushButtonVisitor_clicked()
{
QMessageBox::information(NULL, tr("Welcome!"), tr("You are a visitor!"));
visitor.show();
}
////code for test;
//void MainWindow::on_pushButton_clicked()
//{
// model = new QSqlTableModel(this);
// model->setTable("users");
// model->select();
// model->setEditStrategy(QSqlTableModel::OnManualSubmit);
// ui->tableView->setModel(model);
//}