mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
Настройки базы данных теперь в xml
This commit is contained in:
@@ -21,14 +21,16 @@ bool DataBaseLMS::createConnection()
|
||||
{
|
||||
mtxAccess.lock();
|
||||
|
||||
db = new QSqlDatabase(QSqlDatabase::addDatabase(dbType, connectionName));
|
||||
db->setDatabaseName(dbName);
|
||||
db->setUserName(dbUserName);
|
||||
db->setPassword(dbPassword);
|
||||
db->setPort(5432);
|
||||
//db->setHostName("192.168.100.87");
|
||||
//db->setHostName("192.168.100.248");
|
||||
db->setHostName("192.168.100.239");
|
||||
dbSettings = getDataBaseSettings();
|
||||
|
||||
dbSettings.connectionName = "Connection_" + dbSettings.dbName;
|
||||
|
||||
db = new QSqlDatabase(QSqlDatabase::addDatabase(dbSettings.dbType, dbSettings.connectionName));
|
||||
db->setDatabaseName(dbSettings.dbName);
|
||||
db->setUserName(dbSettings.dbUserName);
|
||||
db->setPassword(dbSettings.dbPassword);
|
||||
db->setHostName(dbSettings.dbHostName);
|
||||
db->setPort(dbSettings.dbPort);
|
||||
|
||||
bool res = db->open();
|
||||
|
||||
@@ -91,6 +93,63 @@ bool DataBaseLMS::isConnected()
|
||||
return false;
|
||||
}
|
||||
|
||||
DataBaseSettings DataBaseLMS::getDataBaseSettings()
|
||||
{
|
||||
DataBaseSettings settings;
|
||||
QFile file("config/settings.xml");
|
||||
if(!file.open(QIODevice::ReadOnly))
|
||||
{
|
||||
QMessageBox::critical(nullptr, "Attention!", "The file could not be opened: config/settings.xml");
|
||||
return settings;
|
||||
}
|
||||
QXmlStreamReader xmlReader(&file);
|
||||
|
||||
while (!xmlReader.atEnd()){
|
||||
|
||||
if(xmlReader.isStartElement()){
|
||||
|
||||
if(xmlReader.name() == "DataBaseSettings")
|
||||
{
|
||||
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes()){
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
|
||||
if(name == "Type"){
|
||||
settings.dbType = value;
|
||||
}
|
||||
|
||||
if(name == "Name"){
|
||||
settings.dbName = value;
|
||||
}
|
||||
|
||||
if(name == "UserName"){
|
||||
settings.dbUserName = value;
|
||||
}
|
||||
|
||||
if(name == "Password"){
|
||||
settings.dbPassword = value;
|
||||
}
|
||||
|
||||
if(name == "HostName"){
|
||||
settings.dbHostName = value;
|
||||
}
|
||||
|
||||
if(name == "Port"){
|
||||
settings.dbPort = value.toInt();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xmlReader.readNext();
|
||||
}
|
||||
|
||||
file.close();
|
||||
return settings;
|
||||
}
|
||||
|
||||
bool DataBaseLMS::transactionBegin()
|
||||
{
|
||||
/*
|
||||
@@ -1138,7 +1197,7 @@ bool DataBaseLMS::queryExec(QString queryStr, QSqlQuery *query)
|
||||
|
||||
void DataBaseLMS::messageWarningErrorQuery(QString queryStr, QSqlQuery* query)
|
||||
{
|
||||
QMessageBox::warning(nullptr, dbName,
|
||||
QMessageBox::warning(nullptr, dbSettings.dbName,
|
||||
"Error query:\n" + query->lastError().text() + "\n" +
|
||||
"String of query:\n" + queryStr + "\n" +
|
||||
"Executed query:\n" + query->executedQuery());
|
||||
|
||||
@@ -9,6 +9,18 @@
|
||||
#include "group.h"
|
||||
#include "tasksAmmFim.h"
|
||||
|
||||
class DataBaseSettings
|
||||
{
|
||||
public:
|
||||
QString dbName = "DataBaseLMS";
|
||||
QString dbType = "QPSQL";
|
||||
QString connectionName = "Connection";
|
||||
QString dbUserName = "postgres";
|
||||
QString dbPassword = "12345678";
|
||||
QString dbHostName = "";
|
||||
int dbPort = 5432;
|
||||
};
|
||||
|
||||
class DataBaseLMS
|
||||
{
|
||||
public:
|
||||
@@ -83,6 +95,7 @@ protected:
|
||||
int updateTrainee(Trainee trainee);
|
||||
|
||||
private:
|
||||
DataBaseSettings getDataBaseSettings();
|
||||
int queryExecInt(QString queryStr);
|
||||
QString queryExecString(QString queryStr);
|
||||
bool queryExecBool(QString queryStr);
|
||||
@@ -91,14 +104,10 @@ private:
|
||||
|
||||
protected:
|
||||
QSqlDatabase* db;
|
||||
const QString dbName = "DataBaseLMS";
|
||||
const QString connectionName = "Connection_DataBaseLMS";
|
||||
private:
|
||||
bool transactionBegined;
|
||||
const QString dbUserName = "postgres";
|
||||
const QString dbPassword = "12345678";
|
||||
const QString dbType = "QPSQL";
|
||||
DataBaseSettings dbSettings;
|
||||
|
||||
private:
|
||||
bool transactionBegined;
|
||||
QMutex mtxAccess;
|
||||
};
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ bool InterfaceDataBaseLMS::ConnectionToDB()
|
||||
{
|
||||
if(!createConnection())
|
||||
{
|
||||
QMessageBox::critical(nullptr, dbName, tr("Connection error: ") + db->lastError().text());
|
||||
QMessageBox::critical(nullptr, dbSettings.dbName, tr("Connection error: ") + db->lastError().text());
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
||||
BIN
TestServerLMS/resources/IcoServerRRJ.ico
Normal file
BIN
TestServerLMS/resources/IcoServerRRJ.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
Reference in New Issue
Block a user