コード例 #1
0
ファイル: videowindow.cpp プロジェクト: gavaza/pacca
void VideoWindow::loadUsers(){
    Database db;
    QList<Users> users = db.getAllUsers();
    QStringList completions;
    for(int l = 0; l < users.size(); l++){
        Users u = users.at(l);
        QString name = u.getName().toString();
        completions.push_back(name);
    }
    QCompleter *completer = new QCompleter(completions, this);
    completer->setCompletionMode(QCompleter::PopupCompletion);
    this->ui->observer->setCompleter(completer);
}
コード例 #2
0
ファイル: database.cpp プロジェクト: gavaza/pacca
int Database::insertUser(Users u)
{
    QVariant name = u.getName().toString().toLower();
    if(!this->userExist(name)){
        this->query.prepare("INSERT INTO Users (name) VALUES (:name);");
        this->query.bindValue(":name",name);
        if(!this->query.exec()){
            this->showError(this->query.lastError());
            return -1;
        }
        return this->query.lastInsertId().toInt();
    }
    this->showError(QMessageBox::tr("Esse usuário já existe!"));
    return 0;
}
コード例 #3
0
ファイル: database.cpp プロジェクト: gavaza/pacca
int Database::editUsers(Users u)
{
    QVariant name = u.getName().toString().toLower();
    if(this->userExist(name) > 0){
        this->showError(QMessageBox::tr("Esse usuário já existe"));
        return 0;
    }
    if(this->userExist(name) >= 0){
        this->query.prepare("UPDATE Users SET name=? WHERE Users.id=?;");
        this->query.addBindValue(name);
        this->query.addBindValue(u.getId());
        if(!this->query.exec()){
            this->showError(this->query.lastError());
            return -1;
        }
        return 1;
    }
    QMessageBox::information(0, QMessageBox::tr("Erro"),QMessageBox::tr("Usuário não encontrado!"));
    return 0;
}