This repository has been archived by the owner on May 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.cpp
90 lines (80 loc) · 2.02 KB
/
widget.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
#include "widget.h"
#include "ui_widget.h"
#include "newhome.h"
#include "newhome1.h"
#include "newhome2.h"
#include <QTimer>
#define Path_to_DB "C:/Users/shreetis13/Desktop/newse/untitled1/login.sqlite"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QTimer:: singleShot(5000,this,SLOT(showMaximized()));
myDB= QSqlDatabase::addDatabase("QSQLITE");
myDB.setDatabaseName(Path_to_DB);
QFileInfo checkFile(Path_to_DB);
if(checkFile.isFile())
{
if(myDB.open())
{
ui->Status->setText("PLEASE ENTER YOUR USERNAME AND PASSWORD ");
}
}
else{ui->Status->setText("Failure connection to db file");}
}
Widget::~Widget()
{
delete ui;
qDebug()<<" Closing the connection";
myDB.close();
}
void Widget::on_AdminButton_clicked()
{
Username=ui->User->text();
Password=ui->Pass->text();
Role="admin";
if(checkdb())
{ newhome *admin=new newhome;
admin->show();}
}
bool Widget::checkdb()
{
if(!myDB.isOpen())
{
qDebug()<< " No coonectn to db";
return false;
}
QSqlQuery qry;
if(qry.exec("SELECT username,password FROM login WHERE username=\'"+Username+"\' AND password=\'"+Password+"\' AND role=\'"+Role+"\' "))
{
if(qry.next())
{
ui->Status->setText("[+]VALID USERNAME AND PASSWORD");
return true;
}
else
{
ui->Status->setText(" UNKNOWN USERNAME AND PASSWORD ");
return false;
}
}
}
void Widget::on_SuperButton_clicked()
{
Username=ui->User->text();
Password=ui->Pass->text();
Role="supervisor";
if(checkdb())
{newhome1 *super=new newhome1;
super->show();}
}
void Widget::on_StaffButton_clicked()
{
Username=ui->User->text();
Password=ui->Pass->text();
Role="staff";
if(checkdb())
{newhome2 *staff=new newhome2;
staff->show();}
}