-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatacenter.cpp
More file actions
59 lines (53 loc) · 1.63 KB
/
datacenter.cpp
File metadata and controls
59 lines (53 loc) · 1.63 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
#include "datacenter.h"
#include <QDebug>
#include <QSqlError>
#include <QMessageBox>
#include "databaseexception.h"
#include "teachersinfotable.h"
#include "accountmanage.h"
DataCenter *DataCenter::m_DataCenter = NULL;
TeachersInfoTable *DataCenter::m_TeachersInfoTable = NULL;
AccountManage *DataCenter::m_AccountManage = NULL;
DataCenter::DataCenter(const QString &hostName,int tcpPort,
const QString &dbName,
const QString &username,
const QString& password,
const QString& driverType)
: m_Database(QSqlDatabase::addDatabase(driverType))
{
m_Database.setHostName(hostName);
m_Database.setDatabaseName(dbName);
m_Database.setPort(tcpPort);
m_Database.setUserName(username);
m_Database.setPassword(password);
if(!m_Database.open())
{
qDebug()<<m_Database.lastError();
throw DatabaseException(m_Database.lastError().text(), m_Database);
}
}
DataCenter *DataCenter::instance(const QString &hostName,
int tcpPort,
const QString &dbName,
const QString &username,
const QString &password ,
const QString &driverType)
{
if(m_DataCenter == NULL)
m_DataCenter = new DataCenter(hostName,tcpPort,
dbName,username,
password,driverType);
return m_DataCenter;
}
TeachersInfoTable *DataCenter::techersInfoTableInstance()
{
if(m_TeachersInfoTable == NULL)
m_TeachersInfoTable = new TeachersInfoTable(*this);
return m_TeachersInfoTable;
}
AccountManage* DataCenter::accountManageInstance()
{
if(m_AccountManage == NULL)
m_AccountManage = new AccountManage(*this);
return m_AccountManage;
}