#include "parking.h"
#include <QDebug>
#include <QString>

parking::parking()
{
  id=0;
  numero=0;
  etat="";
}

parking::parking(int id,int numero,QString etat)
{
  this->id=id;
    this->numero=numero;
    this->etat=etat;
}
int parking::get_id(){return  id;}
int parking::get_numero(){return  numero;}
QString parking::get_etat(){return  etat;}

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


return    query.exec();
}

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

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

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

bool parking::modifier(int id ,int numero,QString etat)
{

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

}

bool parking::modifier_etat(int id)
{

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