-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabasehelper.cpp
More file actions
114 lines (89 loc) · 2.83 KB
/
databasehelper.cpp
File metadata and controls
114 lines (89 loc) · 2.83 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include "databasehelper.h"
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QSettings>
#include <QCoreApplication>
#include <QNetworkInterface>
#include <QHostInfo>
#include <QUuid>
#include <QDebug>
//#include "common.h"
//#include <windows.h>
//#include <odbcinst.h>
QSqlDatabase DataBaseHelper::db = QSqlDatabase();
DataBaseHelper::DataBaseHelper()
{
}
void DataBaseHelper::init()
{
createConnection();
}
void DataBaseHelper::createODBC()
{
// SQLHENV henv;
// SQLHDBC hdbc;
// ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
// ret = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
// ret = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
// SQLConfigDataSource(NULL, ODBC_ADD_DSN, "SQL Server",
// ("DSN=360HIS\0"
// "Server=192.168.0.247\0"
// "Database=360HIS\0"
// "UID=sa\0"
// "PWD=zaq12wsx@@\0"
// "Trusted_Connection=no\0"));
}
bool DataBaseHelper::createConnection()
{
db = QSqlDatabase::addDatabase("QODBC");
QString name = QString("DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;UID=%3;PWD=%4;")
.arg("192.168.0.247").arg("360HIS").arg("sa").arg("zaq12wsx@@");
db.setDatabaseName(name);
if(!db.open()){
qDebug() << "can't connect the database.";
return false;
}
return true;
}
QSqlDatabase DataBaseHelper::DataBase()
{
return db;
}
int DataBaseHelper::login(QString username, QString password)
{
QSqlQuery query(db);
QString cmd = "select * from device where "
"username = '" + username +"' and password = '" + password + "'";
query.exec(cmd);
if(query.next()){
// _CUR_USER.id = query.value(0).toInt();
// _CUR_USER.type = query.value(1).toInt();
// strcpy(_CUR_USER.username,query.value(2).toString().toStdString().data());
// strcpy(_CUR_USER.password,query.value(3).toString().toStdString().data());
// strcpy(_CUR_USER.ipaddress,query.value(4).toString().toStdString().data());
// return _CUR_USER.id;
}else {
qDebug() << query.lastError().text();
}
return -1;
}
QString DataBaseHelper::Mac()
{
QList<QNetworkInterface> nets = QNetworkInterface::allInterfaces();
int nCnt = nets.count();
QString strMacAddr = "";
for (int i = 0; i < nCnt; i++)
{
if (nets[i].flags().testFlag(QNetworkInterface::IsUp) && nets[i].flags().testFlag(QNetworkInterface::IsRunning) && !nets[i].flags().testFlag(QNetworkInterface::IsLoopBack))
{
strMacAddr = nets[i].hardwareAddress();
break;
}
}
return strMacAddr;
}
QString DataBaseHelper::HostName()
{
return QHostInfo::localHostName();
}