home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / examples / demo / sql / book.ui.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-13  |  2.3 KB  |  81 lines

  1. #include <qspinbox.h>
  2.  
  3. void BookForm::init()
  4. {
  5.  
  6. }
  7.  
  8. void BookForm::destroy()
  9. {
  10.  
  11. }
  12.  
  13. void BookForm::editClicked()
  14. {
  15.     EditBookForm *dialog = new EditBookForm( this, "Edit Book Form", TRUE );
  16.     QSqlCursor cur( "book" );
  17.     dialog->BookDataBrowser->setSqlCursor( &cur );
  18.     dialog->BookDataBrowser->setFilter( BookDataTable->filter() );
  19.     dialog->BookDataBrowser->setSort(QSqlIndex::fromStringList(
  20.     BookDataTable->sort(), &cur ) );
  21.     dialog->BookDataBrowser->refresh();
  22.     int i = BookDataTable->currentRow();
  23.     if ( i == -1 ) i = 0; // Always use the first row
  24.     dialog->BookDataBrowser->seek( i );
  25.     dialog->exec();
  26.     delete dialog;
  27.     BookDataTable->refresh();
  28. }
  29.  
  30. void BookForm::connectClicked()
  31. {
  32.     bool ok = FALSE;
  33.     ConnectDialog* dialog = new ConnectDialog( this, "Connect", TRUE );
  34.     dialog->editDatabase->setText( "book" );
  35.     if ( dialog->exec() == QDialog::Accepted ) {
  36.     QSqlDatabase::removeDatabase( QSqlDatabase::defaultConnection );
  37.     QSqlDatabase* db = QSqlDatabase::addDatabase( dialog->comboDriver->currentText() );
  38.     db->setDatabaseName( dialog->editDatabase->text() );
  39.     db->setUserName( dialog->editUsername->text() );
  40.     db->setPassword( dialog->editPassword->text() );
  41.     db->setHostName( dialog->editHostname->text() );
  42.     db->setPort( dialog->portSpinBox->value() );
  43.     if ( !db->open() ) {
  44.         //## warning?
  45.         ok= FALSE;
  46.     } else
  47.         ok = TRUE;
  48.     } 
  49.     if ( !ok ) {
  50.     editButton->setEnabled( FALSE ); 
  51.     BookDataTable->setSqlCursor( 0 );
  52.     AuthorDataTable->setSqlCursor( 0 );
  53.     }  else {
  54.     editButton->setEnabled( TRUE );
  55.     QSqlCursor* authorCursor = new QSqlCursor( "author" );
  56.     AuthorDataTable->setSqlCursor( authorCursor, FALSE, TRUE );
  57.     QSqlCursor* bookCursor = new QSqlCursor( "book" );    
  58.     BookDataTable->setSqlCursor( bookCursor, FALSE, TRUE );
  59.     AuthorDataTable->refresh( QDataTable::RefreshAll );
  60.     BookDataTable->refresh( QDataTable::RefreshAll );    
  61.     }
  62.     delete dialog;
  63. }
  64.  
  65. void BookForm::newCurrentAuthor( QSqlRecord * author )
  66. {
  67.     BookDataTable->setFilter( "authorid=" + author->value( "id" ).toString() );
  68.     BookDataTable->refresh();
  69. }
  70.  
  71. void BookForm::primeInsertAuthor( QSqlRecord * buffer )
  72. {
  73.     QSqlQuery q;
  74.     q.exec( "UPDATE sequence SET sequence = sequence + 1 WHERE tablename='author';" );
  75.     q.exec( "SELECT sequence FROM sequence WHERE tablename='author';" );
  76.     if ( q.next() ) {
  77.     buffer->setValue( "id", q.value( 0 ) );
  78.     }
  79. }
  80.  
  81.