-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
109 lines (88 loc) · 2.29 KB
/
mainwindow.cpp
File metadata and controls
109 lines (88 loc) · 2.29 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "user.h"
#include<iostream>
QString MainWindow::login_id;
using namespace std;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->label->setAlignment(Qt::AlignCenter);
if(!openConnection()){
ui->label->setText("Failed to open DB");
}
else{
ui->label->setText("Connected");
}
closeConnection();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_login_clicked()
{
if(openConnection()){
qDebug()<<"Failed to open the database";
}
QString username,password;
username = ui->lineEdit_username->text();
password = ui->lineEdit_password->text();
QSqlQuery qry;
QString who = "SELECT * FROM employee WHERE name = '" + username + "' AND password = '" + password + "'";
qDebug()<<who;
qry.prepare(who);
if(!qry.exec() )
{
qDebug() << qry.lastError().text();
}
else{
int cnt = 0;
while(qry.next()){
cnt++;
}
if(cnt==1){
ui->label->setText("Correct");
login_id = username;
hide();
user *NewLogin = new user();
NewLogin->show();
}
else if (cnt>1){
ui->label->setText("Duplicate username and passwords");
}
else{
ui->label->setText("Incorrect Username or password");
}
}
closeConnection();
}
void MainWindow::on_SignUp_clicked()
{
if(openConnection()){
qDebug()<<"Failed to open the database";
}
QString username,password;
username = ui->lineEdit_username->text();
password = ui->lineEdit_password->text();
if(!mydb.open()){
qDebug()<<"Failed to open the database";
}
QSqlQuery qry;
qry.prepare("SELECT COUNT(name) FROM employee WHERE name = '"+username+"'");
qry.exec();
while(qry.next()){
quint64 val = qry.value(0).toInt();
if(val==1){
ui->label->setText("Username already taken.");
}
else{
qry.prepare("INSERT INTO employee VALUES('"+username+"','"+password+"'");
qry.exec();
ui->label->setText("You've been signed up!!!");
}
}
closeConnection();
}