void touristResult::on_researchBtn_clicked()
{
qDebug()<<ui->keyWordComboBox->currentIndex();
QString reSearchWord=ui->searchLineEt->text();
switch(ui->keyWordComboBox->currentIndex())
{
case 0 :name(reSearchWord);break;
case 1 :author(reSearchWord);break;
case 2 :createTime(reSearchWord);break;
case 3 :publish(reSearchWord);break;
case 4 :index(reSearchWord);break;
}
}
void touristResult::name(QString keyWord)
{
for(int c=ui->tableWidget->rowCount();c>=0;c--)
{
ui->tableWidget->removeRow(c);
}
QSqlTableModel model;
model.setTable("Book");
model.select();
int Row=0;
for(int i=0;i<model.rowCount();++i)
{
QSqlRecord record=model.record(i);
QStringList rowData;
rowData<<record.value("Name").toString();
rowData<<record.value("Author").toString();
rowData<<record.value("Publish").toString();
rowData<<record.value("ISBN").toString();
rowData<<record.value("GreateDate").toString();
rowData<<record.value("StoreNumber").toString();
rowData<<record.value("IndexNumber").toString();
if(record.value("Name").toString().contains(keyWord))
{
ui->tableWidget->insertRow(Row);
for(int c=0;c<rowData.size();c++)
{
QTableWidgetItem *item = new QTableWidgetItem;
item->setText(rowData.at(c));
ui->tableWidget->setItem(Row,c,item);
}
Row++;
}
rowData.clear();
}
qDebug()<<Row;
if(Row==0)
{
QMessageBox::information(this,"提示","没有查询到结果");
}
}
检索
最新推荐文章于 2024-04-22 00:27:29 发布