Пример #1
0
void MainWindow::setup()
{

    bool ok;
    QString host, user, pw, dBase;

    QFile file("../UHCore/Core/config/database.yaml");

    if (!file.exists())
    {
       qDebug()<<"No database config found!!";
    }

    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
        closeDownRequest = true;
        return;
    }

    QTextStream in(&file);
    while (!in.atEnd())
    {
       QString line = in.readLine();

       if (line.startsWith("mysql_log_user"))
       {
          user = line.section(":",1,1).trimmed();
       }
       if (line.startsWith("mysql_log_password"))
       {
           pw = line.section(":",1,1).trimmed();
       }
       if (line.startsWith("mysql_log_server"))
       {
          host = line.section(":",1,1).trimmed();
       }
       if (line.startsWith("mysql_log_db"))
       {
          dBase = line.section(":",1,1).trimmed();
       }
    }

    user = QInputDialog::getText ( this, "Accompany DB", "User:"******"Accompany DB", "Password:"******"Accompany DB", "Host:",QLineEdit::Normal,
                                     host, &ok);
    if (!ok)
    {
      closeDownRequest = true;
      return;
    };

    dBase = QInputDialog::getText ( this, "Accompany DB", "Database:",QLineEdit::Normal,
                                     dBase, &ok);
    if (!ok)
    {
      closeDownRequest = true;
      return;
    };

    ui->userLabel->setText(user + ":" + host);


    db = QSqlDatabase::addDatabase("QMYSQL");

    db.setHostName(host);
    db.setDatabaseName(dBase);
    db.setUserName(user);
    db.setPassword(pw);

    dbOpen = db.open();

    if (!dbOpen)
    {

        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);

        msgBox.setText("Database error - login problem - see console log!");
        msgBox.exec();

        qCritical("Cannot open database: %s (%s)",
                  db.lastError().text().toLatin1().data(),
                  qt_error_string().toLocal8Bit().data());

        closeDownRequest = true;

        return;
    }
    else
    {
        qDebug() << "Database Opened";
    }

    // get experimental location


    QSqlQuery query("SELECT ExperimentalLocationId,Sessionuser  FROM SessionControl WHERE SessionId = 1 LIMIT 1");

    if (query.next())
    {
       experimentLocation = query.value(0).toInt();
       experimentLocationString = query.value(0).toString();
       sessionUser = query.value(1).toString();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);

        msgBox.setText("Cant find session control table!");
        msgBox.exec();
        closeDownRequest = true;
        return;
    }

    // get language

    query = "SELECT languageId FROM Users where userId = " + sessionUser + " LIMIT 1";

    if (query.next())
    {
       languageId = query.value(0).toString();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);

        msgBox.setText("Cant find users table!");
        msgBox.exec();
        closeDownRequest = true;
        return;
    }

    fillAPTextCombo();
    fillAPPredicates();
    fillDisplayArea();

 }
Пример #2
0
void MainWindow::setup()
{

    bool ok;
    QString host, user, pw, dBase;

    user = QInputDialog::getText ( this, "Accompany DB", "User:"******"", &ok);
    if (!ok)
    {
       closeDownRequest = true;
       return;
    }


    pw = QInputDialog::getText ( this, "Accompany DB", "Password:"******"", &ok);
    if (!ok)
    {
       closeDownRequest = true;
       return;
    }


    host = QInputDialog::getText ( this, "Accompany DB", "Host:",QLineEdit::Normal,
                                   "", &ok);
    if (!ok)
    {
       closeDownRequest = true;
       return;
    };

    dBase = QInputDialog::getText ( this, "Accompany DB", "Database:",QLineEdit::Normal,
                                   "", &ok);
    if (!ok)
    {
       closeDownRequest = true;
       return;
    };

    ui->locnLabel->setText(lv);

    if (lv=="ZUYD")
    {
       if (host=="") host = "accompany1";
       if (user=="") user = "******";
       if (pw=="") pw = "accompany";

    }
    else
    {
        if (host=="") host = "localhost";
        if (user=="") user = "******";
        if (pw=="") pw = "waterloo";
    }

    if (dBase=="")  dBase = "Accompany";


    ui->userLabel->setText(user + ":" + host);


    db = QSqlDatabase::addDatabase("QMYSQL");

    db.setHostName(host);
    db.setDatabaseName(dBase);
    db.setUserName(user);
    db.setPassword(pw);

    dbOpen = db.open();

    if (!dbOpen)
    {

        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);

        msgBox.setText("Database error - login problem - see console log!");
        msgBox.exec();

        qCritical("Cannot open database: %s (%s)",
                  db.lastError().text().toLatin1().data(),
                  qt_error_string().toLocal8Bit().data());

        closeDownRequest = true;

        return;
    }
    else
    {
        qDebug() << "Database Opened";
    }

    // get experimental location


    QSqlQuery query("SELECT ExperimentalLocationId,Sessionuser  FROM SessionControl WHERE SessionId = 1 LIMIT 1");

    if (query.next())
    {
       experimentLocation = query.value(0).toInt();
       sessionUser = query.value(1).toString();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);

        msgBox.setText("Cant find session control table!");
        msgBox.exec();
        closeDownRequest = true;
        return;
    }

    // get language

    query = "SELECT languageId FROM Users where userId = " + sessionUser + " LIMIT 1";

    if (query.next())
    {
       languageId = query.value(0).toString();
    }
    else
    {
        QMessageBox msgBox;
        msgBox.setIcon(QMessageBox::Critical);

        msgBox.setText("Cant find users table!");
        msgBox.exec();
        closeDownRequest = true;
        return;
    }

    fillAPTextCombo();
    fillAPPredicates();
    fillDisplayArea();

 }