Beispiel #1
0
void AddLink::displayCSS(vector<ComputerScientist>& css)
{
    ui->table_linking->setSortingEnabled(false);

    ui->table_linking->clearContents();
    ui->table_linking->setColumnCount(7);
    ui->table_linking->setRowCount(css.size());

    ui->table_linking->setHorizontalHeaderItem(0,new QTableWidgetItem(QString("Id")));
    ui->table_linking->setHorizontalHeaderItem(1,new QTableWidgetItem(QString("First Name")));
    ui->table_linking->setHorizontalHeaderItem(2,new QTableWidgetItem(QString("Middle Name")));
    ui->table_linking->setHorizontalHeaderItem(3,new QTableWidgetItem(QString("Last Name")));
    ui->table_linking->setHorizontalHeaderItem(4,new QTableWidgetItem(QString("Gender")));
    ui->table_linking->setHorizontalHeaderItem(5,new QTableWidgetItem(QString("Birth Year")));
    ui->table_linking->setHorizontalHeaderItem(6,new QTableWidgetItem(QString("Death Year")));

    for(size_t i = 0; i < css.size(); i++)
    {
        ComputerScientist temp = css[i];

        QTableWidgetItem* id = new QTableWidgetItem;
        QTableWidgetItem* yearborn = new QTableWidgetItem;
        QTableWidgetItem* yeardied = new QTableWidgetItem;
        id->setData(Qt::DisplayRole,temp.getID());
        yearborn->setData(Qt::DisplayRole,temp.getBday());
        yeardied->setData(Qt::DisplayRole,temp.getDday());

        ui->table_linking->setItem(i,0, id);
        ui->table_linking->setItem(i,1, new QTableWidgetItem(QString::fromStdString(temp.getFirst())));
        ui->table_linking->setItem(i,2, new QTableWidgetItem(QString::fromStdString(temp.getMid())));
        ui->table_linking->setItem(i,3, new QTableWidgetItem(QString::fromStdString(temp.getLast())));
        ui->table_linking->setItem(i,4, new QTableWidgetItem(QString::fromStdString(temp.getGender())));
        ui->table_linking->setItem(i,5, yearborn);
        if(temp.getDday() != 0)
        {
            ui->table_linking->setItem(i,6, yeardied);
        }
        else
        {
            ui->table_linking->setItem(i,6,new QTableWidgetItem(QString("Alive")));
        }
    }

    ui->table_linking->setSortingEnabled(true);
}
Beispiel #2
0
bool SQLQueryData::AddComputerScientist(ComputerScientist& input)
{
    SQLConnect database;
    database.ConnectToDB();
    QSqlQuery query = database.GetQuery();

    query.prepare("INSERT INTO scientists (first_name, middle_name, last_name, gender, birth_year, death_year, deleted) VALUES (?, ?, ?, ?, ?, ?, 0)");
    query.bindValue(0,QString::fromStdString(input.getFirst()));
    if(input.getMid() != "")
    {
        query.bindValue(1, QString::fromStdString(input.getMid()));
    }
    else
    {
        query.bindValue(1,QString());
    }
    query.bindValue(2,QString::fromStdString(input.getLast()));
    query.bindValue(3,QString::fromStdString(input.getGender()));
    query.bindValue(4,input.getBday());
    if(input.getDday() != 0)
    {
        query.bindValue(5,input.getDday());
    }
    else
    {
        query.bindValue(5,"");
    }

    if(query.exec())
    {
        database.Disconnect();
        query.clear();
        return true;
    }
    database.Disconnect();
    query.clear();
    return false;
}