本文整理汇总了C++中DataBase::connectionOpen方法的典型用法代码示例。如果您正苦于以下问题:C++ DataBase::connectionOpen方法的具体用法?C++ DataBase::connectionOpen怎么用?C++ DataBase::connectionOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataBase
的用法示例。
在下文中一共展示了DataBase::connectionOpen方法的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();
}
示例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();
}
}
示例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();
}