Skip to content

Instantly share code, notes, and snippets.

@scope2229
Created April 20, 2018 16:46
Show Gist options
  • Save scope2229/19f2e25343ef20e479e9448301070eb5 to your computer and use it in GitHub Desktop.
Save scope2229/19f2e25343ef20e479e9448301070eb5 to your computer and use it in GitHub Desktop.
void roomManagementDialog::on_editRoomSearchBTN_clicked()
{
MainWindow conn;
QSqlQueryModel * model=new QSqlQueryModel();
QSqlQueryModel * model2=new QSqlQueryModel();
conn.openDB();
qDebug() << "db opened for search button";
QSqlQuery* qry=new QSqlQuery(conn.myDB);
QSqlQuery* qry2=new QSqlQuery(conn.myDB);
QString SearchQry;
SearchQry = ui->editRoomSearchInput->text();
if(SearchQry.isEmpty()){
qDebug() << "SearchField is empty";
conn.closeDB();
//ENTER QMESSAGEBOX
}else{
qDebug() << "User searched for " << SearchQry;
qry->prepare("SELECT * FROM RoomManagement WHERE RoomNum=\'"+ SearchQry + "\' ");
qry->bindValue(":RoomNum", SearchQry);
qDebug() << "Print out of query " << qry->executedQuery();
if(qry->exec()){
qry2->prepare("SELECT ImageFileName FROM RoomManagement WHERE RoomNum=\'"+ SearchQry + "\' ");
qDebug() << "Print out of query " << qry->executedQuery();
qry2->exec();
model2->setQuery(*qry2);
ui->editRoomImageList->setModel(model2);
while(qry->next()){
ui->editRoomID->setText(qry->value(0).toString());
ui->editRoomNumber->setText(qry->value(1).toString());
ui->editRoomName->setText(qry->value(2).toString());
//ui->editRoomDes->setPlainText(qry->value(3).toString());
// ui->editHSPrice->setValue(qry->value(6).toDouble());
// ui->editLSPrice->setValue(qry->value(7).toDouble());
// ui->editStPrice->setValue(qry->value(8).toDouble());
// ui->editDiscount->setValue(qry->value(9).toDouble());
// ui->editRoomKey->setText(qry->value(10).toString());
ui->editOccupied->setText(qry->value(11).toString());
//ui->editRoomNotes->setPlainText(qry->value(12).toString());
ui->editPax->setText(qry->value(13).toString());
}
conn.closeDB();
qDebug() << "Database closed username should change";
}else{
qDebug() << "if it fails here its your sql query not the application connection to db no need to check if the db is open it is 1122" << qry->lastError().text();
QMessageBox::warning(this, tr("ERROR"),qry->lastError().text(),tr("Please check logs and try again"));
}
qDebug() << "end of create function 1125";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment