Example #1
0
void Interface::printCS(ComputerScientist cs)
{
    cout << "Name: " << cs.getFirstName() << " " << cs.getLastName() << "\t"
         << "Sex: " << cs.getGender() << "\t"
         << "Year of birth: " << cs.getYearOfBirth() << "\t"
         << "Year of death: " << cs.getYearOfDeath() << endl;
}
Example #2
0
//add
void Add_Scientist::on_add_clicked()
{
    bool valid = true;
    string tmpname = ui->FirstName->text().toStdString();
    string tmpmid = ui->MidName->text().toStdString();
    string tmplast = ui->LastName->text().toStdString();
    string tmpgender = ui->Gender->text().toStdString();
    QString tmpyearborn = ui->YearBorn->text();
    QString tmpyeardied = ui->Yeardied->text();
    Refresh();

    //Error checking
    if(!help.CheckValidtyOfString(tmpname))
    {
        valid = false;
        ui->first_label->setText("<font color='red'>First Name*</font>");
    }
    if(!help.CheckValidtyOfString(tmplast))
    {
        valid = false;
        ui->last_lable->setText("<font color='red'>Last Name*</font>");
    }
    if((!help.CheckValidtyOfString(tmpmid)) && (!tmpmid.empty()))
    {
        valid = false;
        ui->middle_label->setText("<font color='red'>Middle Name</font>");
    }
    if(!(tmpyearborn.toInt()) || (tmpyearborn.toInt() > help.CurrentYear()) || (tmpyearborn.toInt() < 0))
    {
        valid = false;
        ui->born_lable->setText("<font color='red'>Year Born*</font>");
    }
    if((tmpyearborn.toInt() > tmpyeardied.toInt()) && !tmpyeardied.isEmpty())
    {
        valid = false;
        ui->dead_lable->setText("<font color='red'>Year Died</font>");
    }

    help.Tolower(tmpgender);
    if(!((tmpgender == "male") || (tmpgender == "female")))
    {
        valid = false;
        ui->gender_lable->setText("<font color='red'>Gender*</font>");
    }
    if(valid == true)
    {
        ComputerScientist cstemp;
        cstemp.setFirst(tmpname);
        cstemp.setMid(tmpmid);
        cstemp.setLast(tmplast);
        cstemp.setgender(tmpgender);
        cstemp.setbday(tmpyearborn.toInt());
        cstemp.setdday(tmpyeardied.toInt());

        d.AddComputerScientist(cstemp);
        this->done(1);
    }
}
Example #3
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);
}
Example #4
0
void SQLQueryData::FillcsVector(QSqlQuery& query, vector<ComputerScientist> &temp)
{
    //Loop through and fill vector with ComputerScientists.
    while(query.next())
    {
        ComputerScientist tmp;

        tmp.setID(query.value("id").toInt());
        tmp.setFirst(query.value("first_name").toString().toStdString());
        tmp.setMid((query.value("middle_name").toString().toStdString()));
        tmp.setLast(query.value("last_name").toString().toStdString());
        tmp.setgender((query.value("gender").toString().toStdString()));
        tmp.setbday((query.value("birth_year").toInt()));
        tmp.setdday((query.value("death_year").toInt()));

        temp.push_back(tmp);
    }
    temp.shrink_to_fit();
}
Example #5
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;
}