#include "dialogconfig.h"
|
#include "ui_dialogconfig.h"
|
|
DialogConfig::DialogConfig(QWidget *parent) :
|
QDialog(parent),
|
ui(new Ui::DialogConfig)
|
{
|
ui->setupUi(this);
|
}
|
|
DialogConfig::~DialogConfig()
|
{
|
delete ui;
|
}
|
|
int DialogConfig::ShowParams()
|
{
|
QString s1;
|
/*
|
* ui->comboBox_DB_Type->setDuplicatesEnabled(false);
|
|
int n=ui->comboBox_DB_Type->count();
|
int found=0;
|
int foundindex=0;
|
for (int i=0;i<n;i++)
|
{
|
s1=ui->comboBox_DB_Type->itemText(i);
|
if (s1.compare(dbconn.DB_Type,Qt::CaseInsensitive)==0)
|
{
|
found=1;
|
foundindex=i;
|
break;
|
|
}
|
}
|
if (!found) {ui->comboBox_DB_Type->insertItem(0,dbconn.DB_Type);}
|
else {ui->comboBox_DB_Type->setCurrentIndex(foundindex);}
|
|
*/
|
|
QStringList driverList = QSqlDatabase::drivers();
|
ui->comboBox_DB_Type->clear();
|
ui->comboBox_DB_Type->addItems(driverList);
|
|
ui->comboBox_DB_Type->setCurrentText(dbconn.DB_Type);
|
ui->comboBox_DB_Type->setEditText(dbconn.DB_Type);
|
|
ui->lineEdit_hostname->setText(dbconn.db_HostName);
|
ui->lineEdit_port->setText(QString::number(dbconn.db_Port));
|
ui->lineEdit_dbname->setText(dbconn.db_Name);
|
ui->lineEdit_username->setText(dbconn.db_UserName);
|
ui->lineEdit_password->setEchoMode(QLineEdit::EchoMode::Password);
|
ui->lineEdit_password->setText(dbconn.db_Password);
|
|
return 0;
|
}
|
|
int DialogConfig::GetParams()
|
{
|
dbconn.DB_Type=ui->comboBox_DB_Type->currentText();
|
dbconn.db_HostName=ui->lineEdit_hostname->text();
|
dbconn.db_Port=ui->lineEdit_port->text().toInt();
|
dbconn.db_Name=ui->lineEdit_dbname->text();
|
dbconn.db_UserName=ui->lineEdit_username->text();
|
dbconn.db_Password=ui->lineEdit_password->text();
|
return 0;
|
}
|
|
void DialogConfig::on_pushButton_TestConn_clicked()
|
{
|
QString s1;
|
|
GetParams();
|
ui->label_result->setText("test result");
|
|
{
|
QSqlDatabase dbtest;
|
|
dbtest=QSqlDatabase::addDatabase(dbconn.DB_Type,"testdb");
|
|
dbtest.setHostName(dbconn.db_HostName);
|
dbtest.setPort(dbconn.db_Port);
|
dbtest.setDatabaseName(dbconn.db_Name);
|
dbtest.setUserName(dbconn.db_UserName);
|
dbtest.setPassword(dbconn.db_Password);
|
bool ok = dbtest.open();
|
if (ok){
|
s1="connected OK";
|
ui->label_result->setText(s1);
|
// QMessageBox::information(nullptr,"infor","link success");
|
|
}
|
else {
|
s1="connected failed: ";
|
s1+= dbtest.lastError().text();
|
ui->label_result->setText(s1);
|
// QMessageBox::information(nullptr,"info","link failed " + s1);
|
// qDebug()<<"Error open datebase because "<<db.lastError().text();
|
}
|
}
|
QSqlDatabase::removeDatabase("testdb");
|
}
|
|
void DialogConfig::on_pushButton_Test_PLC_clicked()
|
{
|
|
}
|
|
void DialogConfig::on_pushButton_Test_Network_clicked()
|
{
|
|
}
|
|
void DialogConfig::on_pushButton_OK_clicked()
|
{
|
GetParams();
|
done(Accepted);
|
}
|
|
void DialogConfig::on_pushButton_CANCEL_clicked()
|
{
|
done(Rejected);
|
}
|