-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
110 lines (79 loc) · 2.08 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
105
106
107
108
109
110
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>
#include <QFile>
#include <QtDebug>
#include <QSqlRecord>
#include <QFileDialog>
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
db.close();
}
void MainWindow::on_start_clicked()// when get started button is clicked
{
//Database Connection
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("data.sqlite3"); //Ptah+ file
db.open();
// set a "cursor"
QSqlQuery query;
query.exec("SELECT * FROM users");
int user[2];
QString inst[2]; //array to store accesibility of users
int i = 0;
while(query.next())
{ QString test = query.value(1).toString();
user[i] = query.value(2).toInt();
inst[i] = query.value(3).toString();
qDebug() << test;
i++;
}
// qDebug() << user[0] << user[1];
int CAO = user[0];
int staff = user[1];
if(CAO && staff)
{
//Error
//Both can't be 1 at same time
qDebug() << "Error";
db.close();
//db.removeDatabase(QSqlDatabase::defaultConnection);
}
else if(CAO == 0 && staff == 0) //Program is running for the first Time
{
//Open First Configure
hide();
first = new firstconfigure;
first -> showMaximized();
}
else if(!CAO && staff)//When staff is selected
{
//open staff
// Qstring name_of_inst =
hide();
slogin = new staff_login;
slogin -> showMaximized();
}
else if(CAO && !staff)//When CAO is selected
{
//open admin
hide();
alogin = new Admin_Login;
alogin -> showMaximized();
}
if (query.isActive()){
qDebug()<<"Connection Successful";
query.first();
}
else{
qDebug()<< "Database connection:Error";
}
}