#include "chariot.h"
#include <QDebug>
#include <QString>
chariot::chariot()
{
  id=0;
  etat=0;
  couleur="";
}

chariot::chariot(int id,int etat,QString couleur)
{
  this->id=id;
    this->etat=etat;
    this->couleur=couleur;
}
int chariot::get_id(){return  id;}
int chariot::get_etat(){return  etat;}

QString chariot::get_couleur(){return  couleur;}

bool chariot::ajouter()
{
QSqlQuery query;
QString res= QString::number(id);
query.prepare("INSERT INTO chariot (id, etat, couleur) "
                    "VALUES (:id, :etat,  :couleur)");
query.bindValue(":id", res);
query.bindValue(":etat", etat);
query.bindValue(":couleur", couleur);


return    query.exec();
}

QSqlQueryModel * chariot::afficher()
{QSqlQueryModel * model= new QSqlQueryModel();

model->setQuery("select * from chariot");
model->setHeaderData(0, Qt::Horizontal, QObject::tr("id"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("etat "));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("couleur "));
    return model;
}

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

bool chariot::modifier(int id ,int etat,QString couleur)
{

    QSqlQuery query;
    QString res= QString::number(id);
query.prepare("update chariot set etat=:etat , couleur=:couleur where id=:id ");
query.bindValue(":id",res);
    query.bindValue(":etat",etat);
    query.bindValue(":couleur",couleur);
          query.exec();

}

bool chariot::modifier_etat(int id)
{

    QSqlQuery query;
    QString res= QString::number(id);
query.prepare("update chariot set etat=:etat where id=:id");
query.bindValue(":id",res);
    query.bindValue(":etat",etat);
          query.exec();
}
