Esempio n. 1
0
void MatKatalog::deleteMaterial( int id )
{
    StockMaterialListIterator it( mAllMaterial );
    int cnt = 0;

    kDebug() << "Deleting material id=" << id;
    while( it.hasNext() ) {
        StockMaterial *mat = it.next();
        if( mat->getID() == id ) {
            break;
        }
        cnt++;
    }
    if( cnt < mAllMaterial.count() ) {
        mAllMaterial.removeAt( cnt );
    }

    // remove from database.
    QSqlQuery q;
    q.prepare( "DELETE FROM stockMaterial WHERE matID=:Id");
    q.bindValue( ":Id", id );
    q.exec();
    kDebug() << "SQL Delete Success: " << q.lastError().text();

}
void MaterialKatalogView::slDeleteTemplate()
{
  kDebug() << "delete template hit";
  MaterialKatalogListView* listview = static_cast<MaterialKatalogListView*>(getListView());
  if( listview )
  {
    StockMaterial *currTempl = static_cast<StockMaterial*> (listview->currentItemData());
    if( currTempl ) {
      int id = currTempl->getID();
      if( KMessageBox::questionYesNo( this,
                                     i18n( "Do you really want to delete the template from the catalog?" ),
                                     i18n( "Delete Template" ),
                                     KStandardGuiItem::yes(), KStandardGuiItem::no(), "DeleteTemplate" )
          == KMessageBox::Yes )
      {

        kDebug() << "Delete item with id " << id;
        MatKatalog *k = static_cast<MatKatalog*>( getKatalog( m_katalogName ) );

        if( k ) {
          k->deleteMaterial( id );
          listview->removeTemplateItem( listview->currentItem());
        }
      }
    }
  }
}