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();

}
Esempio n. 2
0
int MatKatalog::load()
{
    Katalog::load();
    int cnt = 0;

    QSqlQuery q("SELECT matID, chapterID, material, unitID, perPack, priceIn, "
                "priceOut, modifyDate, enterDate FROM stockMaterial");
    q.exec();
    while ( q.next() ) {
        cnt++;
        int id = q.value( 0 ).toInt();
        int chapterID = q.value( 1 ).toInt();
        const QString material = q.value( 2 ).toString();
        int unitID = q.value( 3 ).toInt();
        double pPack = q.value( 4 ).toDouble();
        double priceIn = q.value( 5 ).toDouble();
        double priceOut = q.value(6 ).toDouble();
        QDate lastMod = q.value( 7 ).toDate();
        QDate entered = q.value( 8 ).toDate();

        StockMaterial *mat = new StockMaterial( id, chapterID, material, unitID,
                                                pPack, Geld( priceIn ), Geld( priceOut ) );
        mat->setEnterDate( entered );
        mat->setLastModified( lastMod );
        mAllMaterial.append( mat );

    }

    return cnt;
}
void MaterialKatalogView::slNewTemplate()
{
  KatalogListView *listview = getListView();
  if( !listview ) return;
  MaterialKatalogListView *matListView = static_cast<MaterialKatalogListView*>(listview);

  StockMaterial *newMat = new StockMaterial();
  newMat->setName( i18n( "<new material>" ) );
  QTreeWidgetItem *parentItem = static_cast<QTreeWidgetItem*>( listview->currentItem() );
  if ( parentItem ) {
    if ( ! ( matListView->isRoot( parentItem ) || matListView->isChapter( parentItem ) ) ) {
      parentItem = ( QTreeWidgetItem* ) parentItem->parent();
    }
  }

  if( parentItem && listview->isChapter( parentItem )) {
    // try to find out which catalog is open/current
    CatalogChapter *chap = static_cast<CatalogChapter*>(listview->itemData( parentItem ));
    newMat->setChapter( chap->id().toInt() );
  }

  mNewItem = matListView->addMaterialToView( parentItem, newMat );
  openDialog( mNewItem, newMat, true );

}
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());
        }
      }
    }
  }
}
Esempio n. 5
0
StockMaterialList MatKatalog::getRecordList( const CatalogChapter& chapter )
{
    StockMaterialList list;

    int chapID = chapter.id().toInt();
    StockMaterialListIterator it( mAllMaterial );

    while( it.hasNext() ) {
        StockMaterial *mat = it.next();

        if ( mat->chapter() == chapID ) {
            list.append( mat );
        }
    }
    return list;

}