#include "marchandise.h"
marchandise::marchandise()
{
     id=0;
      prix=0;
     poids=0;
        nom="";
         marque="";
}
marchandise::marchandise(int id,int prix,QString nom,int poids,QString marque)
{
  this->id=id;
  this->prix=prix;
  this->nom=nom;
  this->poids=poids;
  this->marque=marque;
}


bool marchandise::ajoutermarchandise()
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("INSERT INTO marchandise (id,prix, nom, poids, marque) "
                    "VALUES (:id, :prix, :nom, :poids, :marque)");
query.bindValue(":id", res);
query.bindValue(":prix", prix);
query.bindValue(":nom", nom);
query.bindValue(":poids", poids);
query.bindValue(":marque", marque);

return    query.exec();
}

QSqlQueryModel * marchandise::affichermarchendise()
{QSqlQueryModel * model= new QSqlQueryModel();

model->setQuery("select * from marchandise");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("prix"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("nom"));
model->setHeaderData(3, Qt::Horizontal, QObject::tr("poids"));
model->setHeaderData(4, Qt::Horizontal, QObject::tr("marque"));
    return model;
}

bool marchandise::supprimermarchendise(int id)
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("Delete from marchandise where ID = :id ");
query.bindValue(":id", res);
return    query.exec();
}


bool marchandise::modifiermarchendise(int id, int prix, QString nom,int poids, QString marque )
{
    QSqlQuery query;
    QString res= QString::number(id);
    query.prepare("Update from marchandise where ID = :id (prix,nom,poids,marque) "
                                    "VALUES (:prix,:nom, :poids, :marque)");
    query.bindValue(":id", res);
    query.bindValue(":prix", prix);
    query.bindValue(":nom", nom);
    query.bindValue(":poids", poids);
    query.bindValue(":marque", marque);
  return    query.exec();

}



