当前位置: 首页>>代码示例>>C++>>正文


C++ DataBase::connectionClose方法代码示例

本文整理汇总了C++中DataBase::connectionClose方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBase::connectionClose方法的具体用法?C++ DataBase::connectionClose怎么用?C++ DataBase::connectionClose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataBase的用法示例。


在下文中一共展示了DataBase::connectionClose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: on_showAllBtn_clicked

void EvictionWindow::on_showAllBtn_clicked()
{
    DataBase db;
    db.connectionOpen();

    QSqlQuery query;
    query.prepare("select * from clients");
    query.exec();

    QSqlQueryModel * model = new QSqlQueryModel();
    model->setQuery(query);
    model->QSqlQueryModel::setHeaderData(0, Qt::Horizontal, "ID");
    model->QSqlQueryModel::setHeaderData(1, Qt::Horizontal, "Имя");
    model->QSqlQueryModel::setHeaderData(2, Qt::Horizontal, "Фамилия");
    model->QSqlQueryModel::setHeaderData(3, Qt::Horizontal, "Паспорт");
    model->QSqlQueryModel::setHeaderData(4, Qt::Horizontal, "Количество дней");
    model->QSqlQueryModel::setHeaderData(5, Qt::Horizontal, "Дата посления");
    model->QSqlQueryModel::setHeaderData(6, Qt::Horizontal, "№ комнаты");
    model->QSqlQueryModel::setHeaderData(7, Qt::Horizontal, "Тип комнаты");
    ui->tableView->setModel(model);
    ui->tableView->resizeColumnToContents(4);
    ui->tableView->resizeColumnToContents(5);

    db.connectionClose();
}
开发者ID:hmlON,项目名称:HotelAdministrator,代码行数:25,代码来源:evictionwindow.cpp

示例2: on_deleteBtn_clicked

void EvictionWindow::on_deleteBtn_clicked()
{
    bool ok;
    int id = ui->deleteEdit->text().toInt(&ok);
    if(ok){
        DataBase db;
        db.connectionOpen();

        QSqlQuery query;
        query.prepare("delete from clients where id='"+QString::number(id)+"'");
        if(query.exec())
        {
            QMessageBox::information(this, "Успех!", "Клиент успешно удален!");
        } else {
            QMessageBox::warning(this, "Ошибка!", query.lastError().text());
        }

        db.connectionClose();
        this->close();
    }
}
开发者ID:hmlON,项目名称:HotelAdministrator,代码行数:21,代码来源:evictionwindow.cpp

示例3: on_searchBtn_clicked

void EvictionWindow::on_searchBtn_clicked()
{
    DataBase db;
    db.connectionOpen();

    QSqlQuery query;
    QString searchText = ui->searchEdit->text();
    if(searchText == ""){
        query.prepare("select * from clients");
    } else if(ui->searchType->currentText() == "Номеру комнаты") {
        query.prepare("select * from clients where roomNumber=" + searchText);
    } else if(ui->searchType->currentText() == "Имени") {
        query.prepare("select * from clients where firstName like '%" + searchText + "%'");
    } else if(ui->searchType->currentText() == "Фамилии") {
        query.prepare("select * from clients where lastName like '%" + searchText + "%'");
    } else if(ui->searchType->currentText() == "Паспорту") {
        query.prepare("select * from clients where passport like '%" + searchText + "%'");
    }
    query.exec();

    QSqlQueryModel * model = new QSqlQueryModel();
    model->setQuery(query);
    model->QSqlQueryModel::setHeaderData(0, Qt::Horizontal, "ID");
    model->QSqlQueryModel::setHeaderData(1, Qt::Horizontal, "Имя");
    model->QSqlQueryModel::setHeaderData(2, Qt::Horizontal, "Фамилия");
    model->QSqlQueryModel::setHeaderData(3, Qt::Horizontal, "Паспорт");
    model->QSqlQueryModel::setHeaderData(4, Qt::Horizontal, "Количество дней");
    model->QSqlQueryModel::setHeaderData(5, Qt::Horizontal, "Дата посления");
    model->QSqlQueryModel::setHeaderData(6, Qt::Horizontal, "№ комнаты");
    model->QSqlQueryModel::setHeaderData(7, Qt::Horizontal, "Тип комнаты");
    ui->tableView->setModel(model);
    ui->tableView->resizeColumnToContents(4);
    ui->tableView->resizeColumnToContents(5);

    db.connectionClose();
}
开发者ID:hmlON,项目名称:HotelAdministrator,代码行数:36,代码来源:evictionwindow.cpp


注:本文中的DataBase::connectionClose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。