void CreateBooking::setEditMode(bool mode) { this->mEditMode = true; this->setWindowTitle("Edit Booking"); DbMysql* d = DbMysql::getInstance(); QMessageBox msgBox; if(!d->getConnection().open()) { msgBox.critical(this,"Error","Failed to connect database.1"); } else { QSqlQuery query1( "select * from booking_details where booking_id="+QString::number(this->mBookingId)+";" ,d->getConnection()); QSqlQuery query2( "select * from booking where booking_id="+QString::number(this->mBookingId)+";" ,d->getConnection()); QSqlQuery query3( "SELECT room_bookings.*,rooms.room_number FROM `room_bookings`left join rooms on rooms.room_id = room_bookings.room_id where booking_id="+QString::number(this->mBookingId)+";" ,d->getConnection()); if((!query1.isActive() || !query2.isActive()) || !query3.isActive()) { msgBox.critical(this,"Error","Failed to connect database."); } else { query1.next(); query2.next(); if(query1.value("booking_from").toDate() == query1.value("booking_to").toDate()) { ui->single_day->setChecked(true); } else { ui->multiple_day->setChecked(true); ui->to_date->setDisabled(false); } mBookingFrom = query1.value("booking_from").toDate(); mBookingTo = query1.value("booking_to").toDate(); ui->from_date->setDate(query1.value("booking_from").toDate()); ui->to_date->setDate(query1.value("booking_to").toDate()); ui->c_customer_name->setText(query1.value("customer_name").toString()); //ui->c_customer_name->completer()->setCurrentRow(); QStandardItemModel* md = (QStandardItemModel*)ui->c_customer_name->completer()->model(); qDebug() <<md->rowCount(); QModelIndexList ml = md->match(md->index(0,0),Qt::UserRole,QVariant::fromValue(query2.value("customer_id").toInt())); if(ml.size() > 0) { ui->c_customer_name->completer()->activated(ml.at(0)); } ui->customer_status->setCurrentIndex(query2.value("customer_status").toInt()-1); ui->check_in_date_time->setDateTime(query2.value("in_time").toDateTime()); ui->num_of_person->setText(query2.value("nop").toString()); ui->persons_name->setPlainText(query2.value("persons_name").toString()); ui->comments->setPlainText(query2.value("commnets").toString()); int i = 0; ui->room_status_table->setRowCount(query3.size()); while(query3.next()) { QTableWidgetItem* tItem = new QTableWidgetItem(); tItem->setText(query3.value("room_number").toString()); tItem->setFlags(tItem->flags() & ~Qt::ItemIsEditable); QTableWidgetItem* tItem1 = new QTableWidgetItem(); tItem1->setText(QString::number(query3.value("room_rate").toDouble(),'f',2)); QTableWidgetItem* tItem2 = new QTableWidgetItem(); tItem2->setText(query3.value("booking_from").toString()); tItem2->setFlags(tItem2->flags() & ~Qt::ItemIsEditable); QTableWidgetItem* tItem3 = new QTableWidgetItem(); if(ui->single_day->isChecked()) { tItem3->setText(""); } if(ui->multiple_day->isChecked()) { tItem3->setText(query3.value("booking_to").toString()); } tItem3->setFlags(tItem3->flags() & ~Qt::ItemIsEditable); QTableWidgetItem* tItem4 = new QTableWidgetItem(); tItem4->setText("Available"); tItem4->setFlags(tItem4->flags() & ~Qt::ItemIsEditable); ui->room_status_table->setItem(i,0,tItem); ui->room_status_table->setItem(i,1,tItem1); ui->room_status_table->setItem(i,2,tItem2); ui->room_status_table->setItem(i,3,tItem3); ui->room_status_table->setItem(i,4,tItem4); i++; for(int j= 0 ;j<ui->room_list->count();j++) { if(ui->room_list->item(j)->data(Qt::UserRole).toInt() == query3.value("room_id").toInt()) { ui->room_list->item(j)->setSelected(true); } } } ui->advPayGBox->setVisible(false); ui->room_status_table->resizeColumnsToContents(); } } }
int main (){ int i, num = 1, lido=0; for(i = 0; i < 12; i++){ contas[i] = NULL; compras[i] = NULL; } while(num > 0 && num < 15){ system("clear"); carregaTextArt("textart-big.txt"); puts("\n"); num = menuOpcoes(); printf("Opção: %d\n",num); switch(num){ case 1: { if(lido){ for(i = 0; i < 12; i++){ contas[i] = NULL; compras[i] = NULL; } for(i = 0; i < 26; i++){ clientes[i] = NULL; produtos[i] = NULL; } } query1(); lido=1; break; } case 2: { if(lido) query2(); } break; case 3: { if(lido) query3(); } break; case 4: { if(lido) query4(); } break; case 5: { if(lido) query5(); } break; case 6: { if(lido) query6(); } break; case 7: { if(lido) query7(); } break; case 8: { if(lido) query8(); } break; case 9: { if(lido) query9(); } break; case 10: { if(lido) query10(); } break; case 11: { if(lido) query11(); } break; case 12: { if(lido) query12(); } break; case 13: { if(lido) query13(); } break; case 14: { if(lido) query14(); } break; } } return 0; }