-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatamodel.h
More file actions
36 lines (31 loc) · 1.11 KB
/
datamodel.h
File metadata and controls
36 lines (31 loc) · 1.11 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
#ifndef DATAMODEL_H
#define DATAMODEL_H
#include <QtSql>
#include <QDateTime>
class DataModel
{
public:
static QSqlDatabase db;
static bool initDB()
{
db=QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("sonali.db");
return db.open();
}
static void addTokenEntry(char *tokenStr) {
QString q=QString("insert into history (token,arrive_time,service) values(\'%1\',\'%2\',\'%3\')")
.arg(tokenStr).arg(QDateTime::currentDateTimeUtc().toTime_t()).arg(tokenStr[0]);
QSqlQuery(q).exec();
}
static void serviceStarted(char *tokenStr, char serviceBoothID) {
QString q = QString("update history set start_time=%1,booth_id=%2 where token=%3")
.arg(QDateTime::currentDateTimeUtc().toTime_t()).arg(serviceBoothID).arg(tokenStr);
QSqlQuery(q).exec();
}
static void serviceStopped(char *tokenStr) {
QString q = QString("update history set end_time=%1 where token=%3")
.arg(QDateTime::currentDateTimeUtc().toTime_t()).arg(tokenStr);
QSqlQuery(q).exec();
}
};
#endif // DATAMODEL_H